Blame README

Szabolcs Nagy cfa23c
libc-test is developed as part of the musl project
Szabolcs Nagy cfa23c
http://www.musl-libc.org/
nsz 7308b3
Szabolcs Nagy cfa23c
configuring:
Szabolcs Nagy 6ba7f3
	cp config.mak.def config.mak
Szabolcs Nagy cfa23c
	edit config.mak
Szabolcs Nagy cfa23c
build and run tests:
nsz 7308b3
	make
Szabolcs Nagy cfa23c
clean up:
Szabolcs Nagy cfa23c
	make clean
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
make builds all test binaries and runs them to create
Szabolcs Nagy cfa23c
a REPORT file that contains all build and runtime errors
Szabolcs Nagy cfa23c
(this means that make does not stop at build failures)
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
contributing tests:
nsz 7308b3
Szabolcs Nagy f9c2d6
design goals:
Szabolcs Nagy f9c2d6
Szabolcs Nagy cfa23c
- tests should be easy to run and build even a single test in isolation
Szabolcs Nagy f9c2d6
(so test should be self contained if possible)
Szabolcs Nagy f9c2d6
- failure of one test should not interfere with others
Szabolcs Nagy f9c2d6
(build failure, crash or unexpected results are all failures)
Szabolcs Nagy cfa23c
- test output should point to the cause of the failure
Szabolcs Nagy f9c2d6
- test results should be robust
Szabolcs Nagy f9c2d6
- the test system should have minimal dependency
Szabolcs Nagy f9c2d6
(libc, posix sh, gnu make)
Szabolcs Nagy f9c2d6
- the test system should run on all archs and libcs
Szabolcs Nagy f9c2d6
- tests should leave the system in a clean state
Szabolcs Nagy f9c2d6
Szabolcs Nagy cfa23c
conventions:
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
each test is in a separate file at a path like src/directory/file.c with
Szabolcs Nagy cfa23c
its own main
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
the test should return 0 on success and non-0 on failure, on failure it
Szabolcs Nagy cfa23c
should print error messages to standard out if possible, on success no
Szabolcs Nagy cfa23c
message should be printed
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
to help with the above test protocol use t_error function for printing
Szabolcs Nagy cfa23c
errors and return t_status from main, see src/common/test.h
Szabolcs Nagy cfa23c
(t_error allows standard printf formatting, outputs at most 512bytes
Szabolcs Nagy cfa23c
in a single write call to fd 1, so there is no buffering, long outputs
Szabolcs Nagy cfa23c
are truncated, it sets the global t_status to 1)
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
it is common to do many similar checks in a test, in such cases macros
Szabolcs Nagy cfa23c
may be used to simplify the code like
Szabolcs Nagy cfa23c
#define T1(a,b) (check(a,b) || (t_error("check(%s,%s) failed\n", a, b),0))
Szabolcs Nagy cfa23c
#define T2(f,w) (result=(f), result==(w) || (t_error("%s failed: got %s, want %s\n", #f, result, w),0))
Szabolcs Nagy cfa23c
Szabolcs Nagy 92a651
binaries should be possible to run from arbitrary directory.
Szabolcs Nagy 92a651
the build system runs the tests using the src/common/run tool which
Szabolcs Nagy 92a651
kills the test process after a timeout and reports the exit status
Szabolcs Nagy 92a651
in case of failure
Szabolcs Nagy 92a651
Szabolcs Nagy cfa23c
directories:
Szabolcs Nagy cfa23c
Szabolcs Nagy cfa23c
src/api: interface tests, build time include header tests
Szabolcs Nagy cfa23c
src/common: common utilities compiled into libtest.a
Szabolcs Nagy cfa23c
src/functional: functional tests aiming for large coverage of libc
Szabolcs Nagy cfa23c
src/math: tests for each math function with input-output test vectors
Szabolcs Nagy cfa23c
src/regression: regression tests aiming for testing particular bugs
nsz 7308b3
Szabolcs Nagy cfa23c
initial set of functional tests are derived from the libc-testsuit of
Szabolcs Nagy cfa23c
Rich Felker, regression tests should contain reference of the bug
Szabolcs Nagy cfa23c
(musl commit hash, glibc bug tracker url, etc)
nsz 7308b3
Szabolcs Nagy cfa23c
build system:
Szabolcs Nagy f9c2d6
Szabolcs Nagy 92a651
the main non-file make targets are all, run, clean and cleanall.
Szabolcs Nagy fd13cb
(cleanall removes the reports unlike clean, run reruns the dynamically
Szabolcs Nagy 92a651
linked executables)
Szabolcs Nagy 92a651
Szabolcs Nagy fd13cb
make variable can be overridden from config.mak or the make command line,
Szabolcs Nagy fd13cb
the variable B sets the build directory which is src by default
Szabolcs Nagy fd13cb
Szabolcs Nagy fd13cb
for each directory under src there are targets like $(B)/directory/all,
Szabolcs Nagy fd13cb
$(B)/directory/run and $(B)/directory/clean to make only the contents
Szabolcs Nagy 92a651
of that directory, each directory has its own Makefile set up so it
Szabolcs Nagy fd13cb
invokes the top level make with B=src src/directory/foo for the foo
Szabolcs Nagy fd13cb
target, so it is possible to work only under a specific test directory
Szabolcs Nagy f9c2d6
Szabolcs Nagy cfa23c
the build and runtime errors of each target are accumulated into a
Szabolcs Nagy cfa23c
target.err file and in the end they are concatenated into a REPORT
Szabolcs Nagy f9c2d6
Szabolcs Nagy cfa23c
each .c file in src/functional and src/regression are built into a
Szabolcs Nagy cfa23c
dynamic linked and a static linked executable test binary by default,
Szabolcs Nagy cfa23c
this behaviour can be changed by a similarly named .mk file changing
Szabolcs Nagy cfa23c
make variables and specifying additional rules:
Szabolcs Nagy f9c2d6
Szabolcs Nagy fd13cb
$(B)/$(N) is the name of the binary target (the file name without the .c)
Szabolcs Nagy fd13cb
$(B)/$(N)-static is the name of the static binary target
Szabolcs Nagy fd13cb
$(B)/$(D) is the build directory
Szabolcs Nagy cfa23c
$(N).CFLAGS are added to the CFLAGS at compilation
Szabolcs Nagy cfa23c
$(N).LDFLAGS are added to the LDFLAGS at linking
Szabolcs Nagy cfa23c
$(N).LDLIBS are added to the LDLIBS at linking
Szabolcs Nagy cfa23c
$(N).BINS are the targets (if empty no binaries are built)
Szabolcs Nagy cfa23c
$(N).LIBS are the non-executable targets (shared objects may use it)
Szabolcs Nagy f9c2d6
Szabolcs Nagy cfa23c
if a binary is linked together from several .o files then they
Szabolcs Nagy cfa23c
have to be specified as prerequisits for the binary targets and
Szabolcs Nagy cfa23c
added to the $(N).LDLIBS as well
nsz 7308b3
Szabolcs Nagy cfa23c
if a binary depends on a file at runtime (eg. a .so opened by dlopen)
Szabolcs Nagy cfa23c
then the $(N).err target should depend on that file