]> git.ozlabs.org Git - ccan/blobdiff - ccan/antithread/test/run-spawn.c
Add antithread. Not finished, but useful as example of module whose
[ccan] / ccan / antithread / test / run-spawn.c
diff --git a/ccan/antithread/test/run-spawn.c b/ccan/antithread/test/run-spawn.c
new file mode 100644 (file)
index 0000000..d298727
--- /dev/null
@@ -0,0 +1,48 @@
+#include "antithread/antithread.c"
+#include <assert.h>
+#include "tap/tap.h"
+
+int main(int argc, char *argv[])
+{
+       struct at_pool *atp;
+       struct athread *at;
+       int err, *pid;
+       void *arg;
+       char *bad_args[] = { "/", NULL };
+
+       atp = at_get_pool(&argc, argv, &arg);
+       if (atp) {
+               *(int *)arg = getpid();
+               at_tell_parent(atp, arg);
+               exit(0);
+       }
+       assert(!argv[1]);
+
+       err = errno;
+       plan_tests(7);
+       ok1(err == EINVAL);
+
+       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);
+
+       /* This is a failed spawn. */
+       at = at_spawn(atp, pid, bad_args);
+       ok1(at == NULL);
+
+       /* This should work */
+       at = at_spawn(atp, pid, argv);
+       ok1(at);
+
+       /* Should read back the pid pointer. */
+       ok1(at_read(at) == pid);
+       talloc_free(at);
+
+       ok1(*pid != 0);
+       ok1(*pid != getpid());
+
+       return exit_status();
+}