]> git.ozlabs.org Git - ccan/blobdiff - ccan/antithread/test/run-tell_parent.c
Add antithread. Not finished, but useful as example of module whose
[ccan] / ccan / antithread / test / run-tell_parent.c
diff --git a/ccan/antithread/test/run-tell_parent.c b/ccan/antithread/test/run-tell_parent.c
new file mode 100644 (file)
index 0000000..a38f8c9
--- /dev/null
@@ -0,0 +1,36 @@
+#include "antithread/antithread.c"
+#include <assert.h>
+#include "tap/tap.h"
+
+static void *test(struct at_pool *atp, int *pid)
+{
+       *pid = getpid();
+       at_tell_parent(atp, test);
+       return NULL;
+};
+
+int main(int argc, char *argv[])
+{
+       struct at_pool *atp;
+       struct athread *at;
+       int *pid;
+
+       plan_tests(4);
+
+       atp = at_pool(1*1024*1024);
+       assert(atp);
+       pid = talloc(at_pool_ctx(atp), int);
+       assert(pid);
+       ok1((char *)pid >= (char *)atp->pool
+           && (char *)pid < (char *)atp->pool + atp->poolsize);
+       at = at_run(atp, test, pid);
+       assert(at);
+
+       ok1(at_read(at) == test);
+       talloc_free(at);
+
+       ok1(*pid != 0);
+       ok1(*pid != getpid());
+
+       return exit_status();
+}