X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcoroutine%2Ftest%2Fapi-1.c;h=c59793a0542fe3be3018fe9f3d990eb7c5bb1826;hp=fbf66df60b117b9ef140601231e96d4fbc16d38b;hb=b4f0767d388c7f3629666400f48ede1a7b4be7f5;hpb=1ddc881f084e2527ad9e3541807469920ac299b4 diff --git a/ccan/coroutine/test/api-1.c b/ccan/coroutine/test/api-1.c index fbf66df6..c59793a0 100644 --- a/ccan/coroutine/test/api-1.c +++ b/ccan/coroutine/test/api-1.c @@ -3,6 +3,8 @@ #include #include +#define STKSZ (COROUTINE_MIN_STKSZ + COROUTINE_STK_OVERHEAD) + static int global = 0; static void trivial_fn(void *p) @@ -18,6 +20,10 @@ static void test_trivial(struct coroutine_stack *stack) { struct coroutine_state t, master; + ok1(stack != NULL); + ok1(coroutine_stack_check(stack, NULL) == stack); + ok1(coroutine_stack_size(stack) == COROUTINE_MIN_STKSZ); + if (!COROUTINE_AVAILABLE) { skip(1, "Coroutines not available"); return; @@ -30,21 +36,22 @@ static void test_trivial(struct coroutine_stack *stack) } +static char buf[STKSZ]; + 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); + plan_tests(2 * 4 + 1); 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); + ok1(!coroutine_stack_check(stack, NULL)); + stack = coroutine_stack_alloc(STKSZ, 0); + test_trivial(stack); coroutine_stack_release(stack, 0); /* This exits depending on whether all tests passed */