658eaf90f52da52f1ed40aeefd3326b1cfae205b
[libc-test] / README
1 libc tests based on libc-testsuit by Rich Felker
2 see http://git.musl-libc.org/cgit
3
4 configure tests:
5         cp dist/config.mak .
6         # edit config.mak
7 build tests:
8         make
9 run tests:
10         make run
11
12 design goals:
13
14 - tests should be easy to run even a single test in isolation
15 (so test should be self contained if possible)
16 - failure of one test should not interfere with others
17 (build failure, crash or unexpected results are all failures)
18 - test output should point to the cause of failure
19 - test results should be robust
20 - the test system should have minimal dependency
21 (libc, posix sh, gnu make)
22 - the test system should run on all archs and libcs
23 - tests should leave the system in a clean state
24
25 framework:
26
27 the convention is that each test is in a separate file
28 at a path like src/directory/file.c with its own main
29
30 the test should return 0 on success and non-0 on failure
31 error messages relevant to the test system should be
32 printed to standard out (fd 1)
33
34 src/functional/test.h usage:
35
36 use error in tests when possible instead of printf
37 (error truncates the formatted string to 512 bytes and uses a
38 single write call to output it to fd 1, terminating the error
39 string with a \n is the responsibility of the caller)
40 and return test_status from main (set by error, 0 by default)
41
42 when many similar checks are done, helper macros can be used like
43 #define T1(a,b) (check(a,b) || (error("check(%s,%s) failed\n", a, b),0))
44 #define T2(f,w) (result=(f), result==(w) || (error("%s failed: got %s, want %s\n", #f, result, w),0))
45
46 a simple example:
47
48 #include "test.h"
49 #define T(c,...) ((c) || (error(#c " failed: " __VA_ARGS__),0))
50 int main(void)
51 {
52         T('a'+1=='b', "'a'==%d 'b'==%d\n", 'a', 'b');
53         T(-5%3==-2, "bad mod semantics\n");
54         return test_status;
55 }
56