X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ffailtest%2F_info;fp=ccan%2Ffailtest%2F_info;h=73aa6a2daef21d92d48afd68833f5e5f40ad191f;hp=0000000000000000000000000000000000000000;hb=f0002cb9e4f6f403a25ad50252c06694439900f0;hpb=fece6c238afd41bd3ffba1287afa598863d7165e diff --git a/ccan/failtest/_info b/ccan/failtest/_info new file mode 100644 index 00000000..73aa6a2d --- /dev/null +++ b/ccan/failtest/_info @@ -0,0 +1,69 @@ +#include +#include +#include "config.h" + +/** + * failtest - unit test helpers for testing malloc and other failures. + * + * The failtest module overrides various standard functions, and forks + * your unit test at those points to test failure paths. The failing + * child are expected to fail (eg. when malloc fails), but should not + * leak memory or crash. + * + * The unit test is a normal CCAN tap-style test, except it should + * start by calling failtest_init() and end by calling + * failtest_exit(). + * + * You can control what functions fail: see failtest_hook. + * + * Example: + * #include + * #include + * #include + * #include + * #include + * #include + * + * int main(int argc, char *argv[]) + * { + * void *a, *b; + * + * failtest_init(argc, argv); + * plan_tests(3); + * + * // Simple malloc test. + * a = malloc(100); + * if (ok1(a)) { + * // Fill the memory. + * memset(a, 'x', 100); + * b = realloc(a, 200); + * if (ok1(b)) { + * // Fill the rest of the memory. + * memset(b + 100, 'y', 100); + * // Check it got a copy of a as expected. + * ok1(strspn(b, "x") == 100); + * free(b); + * } else { + * // Easy to miss: free a on realloc failure! + * free(a); + * } + * } + * failtest_exit(exit_status()); + * } + * + * License: LGPL + * Author: Rusty Russell + */ +int main(int argc, char *argv[]) +{ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/compiler\n"); + printf("ccan/read_write_all\n"); + return 0; + } + + return 1; +}