X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcoroutine%2Ftest%2Fapi-3.c;h=4b90b46310b2952ba2a780ac72089db842670496;hp=e06c03d3c47f2eec23e4dd9c0bee666ecd1ee0f6;hb=f6557ca6537bc4d37fb4be215184a632533ba4e7;hpb=1ddc881f084e2527ad9e3541807469920ac299b4 diff --git a/ccan/coroutine/test/api-3.c b/ccan/coroutine/test/api-3.c index e06c03d3..4b90b463 100644 --- a/ccan/coroutine/test/api-3.c +++ b/ccan/coroutine/test/api-3.c @@ -27,9 +27,6 @@ static void clobber(void *p) buf[i] = random() & 0xff; } - diag("Wrote random to buffer\n"); - - s->total = 0; for (i = 0; i < sizeof(buf); i++) { s->total += buf[i]; } @@ -50,6 +47,7 @@ static void test_metadata(struct coroutine_stack *stack) if (COROUTINE_AVAILABLE) { struct coroutine_state t; struct state s = { + .total = 0, }; coroutine_init(&t, clobber, &s, stack); @@ -66,16 +64,19 @@ static void test_metadata(struct coroutine_stack *stack) int main(void) { - char buf[BUFSIZE]; + char *buf; struct coroutine_stack *stack; /* This is how many tests you plan to run */ - plan_tests(9); + plan_tests(10); /* Fix seed so we get consistent, though pseudo-random results */ srandom(0); - stack = coroutine_stack_init(buf, sizeof(buf), sizeof(struct metadata)); + buf = malloc(BUFSIZE); + ok1(buf != NULL); + + stack = coroutine_stack_init(buf, BUFSIZE, sizeof(struct metadata)); ok1(stack != NULL); ok1(coroutine_stack_check(stack, NULL) == stack); ok1(coroutine_stack_size(stack) @@ -85,6 +86,8 @@ int main(void) coroutine_stack_release(stack, sizeof(struct metadata)); + free(buf); + /* This exits depending on whether all tests passed */ return exit_status(); }