summaryrefslogtreecommitdiff
path: root/ccan/antithread/test/run-simple.c
blob: 56569bb24b646615ad278c85fe855cf8858a7e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <ccan/antithread/antithread.c>
#include <assert.h>
#include <ccan/tap/tap.h>

static void *test(struct at_pool *atp, int *pid)
{
	*pid = getpid();
	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->p->pool
	    && (char *)pid < (char *)atp->p->pool + atp->p->poolsize);
	at = at_run(atp, test, pid);
	assert(at);

	ok1(at_read(at) == NULL);
	talloc_free(at);

	ok1(*pid != 0);
	ok1(*pid != getpid());

	return exit_status();
}