6 * failtest - unit test helpers for testing malloc and other failures.
8 * The failtest module overrides various standard functions, and forks
9 * your unit test at those points to test failure paths. The failing
10 * child are expected to fail (eg. when malloc fails), but should not
11 * leak memory or crash.
13 * The unit test is a normal CCAN tap-style test, except it should
14 * start by calling failtest_init() and end by calling
17 * You can control what functions fail: see failtest_hook.
23 * #include <ccan/tap/tap.h>
24 * #include <ccan/failtest/failtest_override.h>
25 * #include <ccan/failtest/failtest.h>
27 * int main(int argc, char *argv[])
31 * failtest_init(argc, argv);
34 * // Simple malloc test.
38 * memset(a, 'x', 100);
39 * b = realloc(a, 200);
41 * // Fill the rest of the memory.
42 * memset(b + 100, 'y', 100);
43 * // Check it got a copy of a as expected.
44 * ok1(strspn(b, "x") == 100);
47 * // Easy to miss: free a on realloc failure!
51 * failtest_exit(exit_status());
55 * Author: Rusty Russell <rusty@rustcorp.com.au>
57 int main(int argc, char *argv[])
62 if (strcmp(argv[1], "depends") == 0) {
63 printf("ccan/compiler\n");
64 printf("ccan/read_write_all\n");