summaryrefslogtreecommitdiff
path: root/lib/ccan/failtest/_info
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-02-22 14:59:32 +1030
committerAmitay Isaacs <amitay@gmail.com>2012-03-07 13:16:16 +1100
commit361f3ea9ee577c5a3e2fed687a0b417b257c31de (patch)
tree6d356c3aa64317c609ff4e208be76e18996a55f8 /lib/ccan/failtest/_info
parent4f5412dda687c3ff76b426842bf284d01d56a997 (diff)
downloadsamba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.tar.gz
samba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.tar.bz2
samba-361f3ea9ee577c5a3e2fed687a0b417b257c31de.zip
lib/ccan: import failtest and required ccan modules for TDB2 unit tests.
New modules: failtest, list, time, read_write_all and tlist. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ccan/failtest/_info')
-rw-r--r--lib/ccan/failtest/_info76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/ccan/failtest/_info b/lib/ccan/failtest/_info
new file mode 100644
index 0000000000..14dcb783be
--- /dev/null
+++ b/lib/ccan/failtest/_info
@@ -0,0 +1,76 @@
+#include <stdio.h>
+#include <string.h>
+#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. After including failtest_override.h, you can
+ * include failtest_restore.h to return to non-failing versions.
+ *
+ * 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 <stdio.h>
+ * #include <stdlib.h>
+ * #include <string.h>
+ * #include <ccan/tap/tap.h>
+ * #include <ccan/failtest/failtest_override.h>
+ * #include <ccan/failtest/failtest.h>
+ *
+ * int main(int argc, char *argv[])
+ * {
+ * char *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 <rusty@rustcorp.com.au>
+ */
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ return 1;
+
+ if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/build_assert\n");
+ printf("ccan/compiler\n");
+ printf("ccan/hash\n");
+ printf("ccan/htable\n");
+ printf("ccan/read_write_all\n");
+ printf("ccan/str\n");
+ printf("ccan/time\n");
+ printf("ccan/tlist\n");
+ return 0;
+ }
+
+ return 1;
+}