1570af302Sopenharmony_cilibc-test is developed as part of the musl project 2570af302Sopenharmony_cihttp://www.musl-libc.org/ 3570af302Sopenharmony_ci 4570af302Sopenharmony_ciconfiguring: 5570af302Sopenharmony_ci cp config.mak.def config.mak 6570af302Sopenharmony_ci edit config.mak 7570af302Sopenharmony_cibuild and run tests: 8570af302Sopenharmony_ci make 9570af302Sopenharmony_ciclean up: 10570af302Sopenharmony_ci make clean 11570af302Sopenharmony_ci 12570af302Sopenharmony_cimake builds all test binaries and runs them to create 13570af302Sopenharmony_cia REPORT file that contains all build and runtime errors 14570af302Sopenharmony_ci(this means that make does not stop at build failures) 15570af302Sopenharmony_ci 16570af302Sopenharmony_cicontributing tests: 17570af302Sopenharmony_ci 18570af302Sopenharmony_cidesign goals: 19570af302Sopenharmony_ci 20570af302Sopenharmony_ci- tests should be easy to run and build even a single test in isolation 21570af302Sopenharmony_ci(so test should be self contained if possible) 22570af302Sopenharmony_ci- failure of one test should not interfere with others 23570af302Sopenharmony_ci(build failure, crash or unexpected results are all failures) 24570af302Sopenharmony_ci- test output should point to the cause of the failure 25570af302Sopenharmony_ci- test results should be robust 26570af302Sopenharmony_ci- the test system should have minimal dependency 27570af302Sopenharmony_ci(libc, posix sh, gnu make) 28570af302Sopenharmony_ci- the test system should run on all archs and libcs 29570af302Sopenharmony_ci- tests should leave the system in a clean state 30570af302Sopenharmony_ci 31570af302Sopenharmony_ciconventions: 32570af302Sopenharmony_ci 33570af302Sopenharmony_cieach test is in a separate file at a path like src/directory/file.c with 34570af302Sopenharmony_ciits own main 35570af302Sopenharmony_ci 36570af302Sopenharmony_cithe test should return 0 on success and non-0 on failure, on failure it 37570af302Sopenharmony_cishould print error messages to standard out if possible, on success no 38570af302Sopenharmony_cimessage should be printed 39570af302Sopenharmony_ci 40570af302Sopenharmony_cito help with the above test protocol use t_error function for printing 41570af302Sopenharmony_cierrors and return t_status from main, see src/common/test.h 42570af302Sopenharmony_ci(t_error allows standard printf formatting, outputs at most 512bytes 43570af302Sopenharmony_ciin a single write call to fd 1, so there is no buffering, long outputs 44570af302Sopenharmony_ciare truncated, it sets the global t_status to 1) 45570af302Sopenharmony_ci 46570af302Sopenharmony_ciit is common to do many similar checks in a test, in such cases macros 47570af302Sopenharmony_cimay be used to simplify the code like 48570af302Sopenharmony_ci#define T1(a,b) (check(a,b) || (t_error("check(%s,%s) failed\n", a, b),0)) 49570af302Sopenharmony_ci#define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0)) 50570af302Sopenharmony_ci 51570af302Sopenharmony_cibinaries should be possible to run from arbitrary directory. 52570af302Sopenharmony_cithe build system runs the tests using the src/common/runtest tool which 53570af302Sopenharmony_cikills the test process after a timeout and reports the exit status 54570af302Sopenharmony_ciin case of failure 55570af302Sopenharmony_ci 56570af302Sopenharmony_cidirectories: 57570af302Sopenharmony_ci 58570af302Sopenharmony_cisrc/api: interface tests, build time include header tests 59570af302Sopenharmony_cisrc/common: common utilities compiled into libtest.a 60570af302Sopenharmony_cisrc/functional: functional tests aiming for large coverage of libc 61570af302Sopenharmony_cisrc/math: tests for each math function with input-output test vectors 62570af302Sopenharmony_cisrc/regression: regression tests aiming for testing particular bugs 63570af302Sopenharmony_ci 64570af302Sopenharmony_ciinitial set of functional tests are derived from the libc-testsuit of 65570af302Sopenharmony_ciRich Felker, regression tests should contain reference of the bug 66570af302Sopenharmony_ci(musl commit hash, glibc bug tracker url, etc) 67570af302Sopenharmony_ci 68570af302Sopenharmony_cibuild system: 69570af302Sopenharmony_ci 70570af302Sopenharmony_cithe main non-file make targets are all, run, clean and cleanall. 71570af302Sopenharmony_ci(cleanall removes the reports unlike clean, run reruns the dynamically 72570af302Sopenharmony_cilinked executables) 73570af302Sopenharmony_ci 74570af302Sopenharmony_cimake variable can be overridden from config.mak or the make command line, 75570af302Sopenharmony_cithe variable B sets the build directory which is src by default 76570af302Sopenharmony_ci 77570af302Sopenharmony_cifor each directory under src there are targets like $(B)/directory/all, 78570af302Sopenharmony_ci$(B)/directory/run and $(B)/directory/clean to make only the contents 79570af302Sopenharmony_ciof that directory, each directory has its own Makefile set up so it 80570af302Sopenharmony_ciinvokes the top level make with B=src src/directory/foo for the foo 81570af302Sopenharmony_citarget, so it is possible to work only under a specific test directory 82570af302Sopenharmony_ci 83570af302Sopenharmony_cithe build and runtime errors of each target are accumulated into a 84570af302Sopenharmony_citarget.err file and in the end they are concatenated into a REPORT 85570af302Sopenharmony_ci 86570af302Sopenharmony_cieach .c file in src/functional and src/regression are built into a 87570af302Sopenharmony_cidynamic linked and a static linked executable test binary by default, 88570af302Sopenharmony_cithis behaviour can be changed by a similarly named .mk file changing 89570af302Sopenharmony_cimake variables and specifying additional rules: 90570af302Sopenharmony_ci 91570af302Sopenharmony_ci$(B)/$(N) is the name of the binary target (the file name without the .c) 92570af302Sopenharmony_ci$(B)/$(N)-static is the name of the static binary target 93570af302Sopenharmony_ci$(B)/$(D) is the build directory 94570af302Sopenharmony_ci$(N).CFLAGS are added to the CFLAGS at compilation 95570af302Sopenharmony_ci$(N).LDFLAGS are added to the LDFLAGS at linking 96570af302Sopenharmony_ci$(N).LDLIBS are added to the LDLIBS at linking 97570af302Sopenharmony_ci$(N).BINS are the targets (if empty no binaries are built) 98570af302Sopenharmony_ci$(N).LIBS are the non-executable targets (shared objects may use it) 99570af302Sopenharmony_ci 100570af302Sopenharmony_ciif a binary is linked together from several .o files then they 101570af302Sopenharmony_cihave to be specified as prerequisits for the binary targets and 102570af302Sopenharmony_ciadded to the $(N).LDLIBS as well 103570af302Sopenharmony_ci 104570af302Sopenharmony_ciif a binary depends on a file at runtime (eg. a .so opened by dlopen) 105570af302Sopenharmony_cithen the $(N).err target should depend on that file 106