]> git.ozlabs.org Git - ccan/blob - ccan/antithread/test/run-spawn.c
Adapt antithread to new talloc locking, and fix so talloc destructor
[ccan] / ccan / antithread / test / run-spawn.c
1 #include "antithread/antithread.c"
2 #include <assert.h>
3 #include "tap/tap.h"
4
5 int main(int argc, char *argv[])
6 {
7         struct at_pool *atp;
8         struct athread *at;
9         int err, *pid;
10         void *arg;
11         char *bad_args[] = { "/", NULL };
12
13         atp = at_get_pool(&argc, argv, &arg);
14         if (atp) {
15                 *(int *)arg = getpid();
16                 at_tell_parent(atp, arg);
17                 exit(0);
18         }
19         assert(!argv[1]);
20
21         err = errno;
22         plan_tests(7);
23         ok1(err == EINVAL);
24
25         atp = at_pool(1*1024*1024);
26         assert(atp);
27         pid = talloc(at_pool_ctx(atp), int);
28         assert(pid);
29         ok1((char *)pid >= (char *)atp->p->pool
30             && (char *)pid < (char *)atp->p->pool + atp->p->poolsize);
31
32         /* This is a failed spawn. */
33         at = at_spawn(atp, pid, bad_args);
34         ok1(at == NULL);
35
36         /* This should work */
37         at = at_spawn(atp, pid, argv);
38         ok1(at);
39
40         /* Should read back the pid pointer. */
41         ok1(at_read(at) == pid);
42         talloc_free(at);
43
44         ok1(*pid != 0);
45         ok1(*pid != getpid());
46
47         return exit_status();
48 }