|
Szabolcs Nagy |
f9c2d6 |
libc tests based on libc-testsuit by Rich Felker
|
|
nsz |
58c843 |
see http://git.musl-libc.org/cgit
|
|
nsz |
7308b3 |
|
|
Szabolcs Nagy |
f9c2d6 |
configure tests:
|
|
nsz |
b36267 |
cp dist/config.mak .
|
|
nsz |
b36267 |
# edit config.mak
|
|
Szabolcs Nagy |
f9c2d6 |
build tests:
|
|
nsz |
7308b3 |
make
|
|
nsz |
7308b3 |
run tests:
|
|
nsz |
58c843 |
make run
|
|
nsz |
7308b3 |
|
|
Szabolcs Nagy |
f9c2d6 |
design goals:
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
- tests should be easy to run 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 |
f9c2d6 |
- test output should point to the cause of 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 |
|
|
nsz |
7d87d3 |
framework:
|
|
nsz |
7308b3 |
|
|
nsz |
58c843 |
the convention is that each test is in a separate file
|
|
nsz |
58c843 |
at a path like src/directory/file.c with its own main
|
|
nsz |
7308b3 |
|
|
nsz |
58c843 |
the test should return 0 on success and non-0 on failure
|
|
Szabolcs Nagy |
f9c2d6 |
error messages relevant to the test system should be
|
|
Szabolcs Nagy |
f9c2d6 |
printed to standard out (fd 1)
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
src/functional/test.h usage:
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
use error in tests when possible instead of printf
|
|
Szabolcs Nagy |
f9c2d6 |
(error truncates the formatted string to 512 bytes and uses a
|
|
Szabolcs Nagy |
f9c2d6 |
single write call to output it to fd 1, terminating the error
|
|
Szabolcs Nagy |
f9c2d6 |
string with a \n is the responsibility of the caller)
|
|
Szabolcs Nagy |
f9c2d6 |
and return test_status from main (set by error, 0 by default)
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
when many similar checks are done, helper macros can be used like
|
|
Szabolcs Nagy |
f9c2d6 |
#define T1(a,b) (check(a,b) || (error("check(%s,%s) failed\n", a, b),0))
|
|
Szabolcs Nagy |
f9c2d6 |
#define T2(f,w) (result=(f), result==(w) || (error("%s failed: got %s, want %s\n", #f, result, w),0))
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
a simple example:
|
|
Szabolcs Nagy |
f9c2d6 |
|
|
Szabolcs Nagy |
f9c2d6 |
#include "test.h"
|
|
Szabolcs Nagy |
f9c2d6 |
#define T(c,...) ((c) || (error(#c " failed: " __VA_ARGS__),0))
|
|
Szabolcs Nagy |
f9c2d6 |
int main(void)
|
|
Szabolcs Nagy |
f9c2d6 |
{
|
|
Szabolcs Nagy |
f9c2d6 |
T('a'+1=='b', "'a'==%d 'b'==%d\n", 'a', 'b');
|
|
Szabolcs Nagy |
f9c2d6 |
T(-5%3==-2, "bad mod semantics\n");
|
|
Szabolcs Nagy |
f9c2d6 |
return test_status;
|
|
Szabolcs Nagy |
f9c2d6 |
}
|
|
nsz |
7308b3 |
|