]> git.ozlabs.org Git - ccan/blobdiff - ccan/coroutine/test/api-1.c
coroutine: Stack allocation
[ccan] / ccan / coroutine / test / api-1.c
index fbf66df60b117b9ef140601231e96d4fbc16d38b..c59793a0542fe3be3018fe9f3d990eb7c5bb1826 100644 (file)
@@ -3,6 +3,8 @@
 #include <ccan/coroutine/coroutine.h>
 #include <ccan/tap/tap.h>
 
+#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 */