X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcoroutine%2Ftest%2Fapi-1.c;fp=ccan%2Fcoroutine%2Ftest%2Fapi-1.c;h=fbf66df60b117b9ef140601231e96d4fbc16d38b;hp=0000000000000000000000000000000000000000;hb=1ddc881f084e2527ad9e3541807469920ac299b4;hpb=8967bc9e1bdd68f2dc33e9d80bbf0f944fb7e772 diff --git a/ccan/coroutine/test/api-1.c b/ccan/coroutine/test/api-1.c new file mode 100644 index 00000000..fbf66df6 --- /dev/null +++ b/ccan/coroutine/test/api-1.c @@ -0,0 +1,52 @@ +#include + +#include +#include + +static int global = 0; + +static void trivial_fn(void *p) +{ + struct coroutine_state *ret = (struct coroutine_state *)p; + + global = 1; + + coroutine_jump(ret); +} + +static void test_trivial(struct coroutine_stack *stack) +{ + struct coroutine_state t, master; + + if (!COROUTINE_AVAILABLE) { + skip(1, "Coroutines not available"); + return; + } + + coroutine_init(&t, trivial_fn, &master, stack); + coroutine_switch(&master, &t); + + ok1(global == 1); +} + + +int main(void) +{ + char buf[COROUTINE_MIN_STKSZ + COROUTINE_STK_OVERHEAD]; + struct coroutine_stack *stack; + + /* This is how many tests you plan to run */ + plan_tests(4); + + stack = coroutine_stack_init(buf, sizeof(buf), 0); + ok1(stack != NULL); + ok1(coroutine_stack_check(stack, NULL) == stack); + ok1(coroutine_stack_size(stack) == COROUTINE_MIN_STKSZ); + + test_trivial(stack); + + coroutine_stack_release(stack, 0); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}