diff options
Diffstat (limited to 'src/base/test.c')
-rw-r--r-- | src/base/test.c | 112 |
1 files changed, 4 insertions, 108 deletions
diff --git a/src/base/test.c b/src/base/test.c index a29be1d..de53125 100644 --- a/src/base/test.c +++ b/src/base/test.c @@ -4,111 +4,6 @@ #include <time.h> -uintptr -printtest(Coro *c, uintptr d) -{ - printf("--> Recieved %lu\n", d); - d = coro·yield(c, d+10); - printf("--> Now %lu\n", d); - - return d; -} - -uintptr -sequence(Coro *c, uintptr start) -{ - int d = start; - for (;;) { - coro·yield(c, d++); - } - - return d; -} - -struct PrimeMsg -{ - Coro *seq; - int p; -}; - -uintptr -filter(Coro *c, uintptr data) -{ - int x, p; - Coro *seq; - struct PrimeMsg *msg; - - // Need to copy relevant variables onto the local stack - // Data is volatile. - msg = (struct PrimeMsg*)data; - seq = msg->seq; - p = msg->p; - - for (;;) { - x = coro·yield(seq, x); - if (x % p != 0) { - x = coro·yield(c, x); - } - } - - return 0; -} - -error -test·coro() -{ - int i; - Coro *c[4]; - uintptr d; - - printf("Starting singleton test\n"); - - for (i = 0; i < arrlen(c); i++) { - c[i] = coro·make(0, &printtest); - } - - /* Singleton test */ - d = 0; - for (i = 0; i < 10; i++) { - d = coro·yield(c[0], d); - } - - printf("Starting triplet test\n"); - - /* Triplet test */ - for (i = 0; i < 10; i++) { - d = coro·yield(c[1], d); - d = coro·yield(c[2], d+100); - d = coro·yield(c[3], d+200); - } - - for (i = 0; i < arrlen(c); i++) { - coro·free(c[i]); - } - - /* Prime sieve */ - printf("Starting prime test\n"); - uintptr num; - Coro *cur, *seq[50]; - - num = 2; - seq[0] = coro·make(4096, &sequence); - cur = *seq; - - num = coro·yield(cur, num); - for (i = 1; i < arrlen(seq); i++) { - seq[i] = coro·make(4096, &filter); - struct PrimeMsg msg = { - .seq = cur, - .p = num, - }; - cur = seq[i]; - num = coro·yield(cur, (uintptr)&msg); - printf("--> prime number %lu\n", num); - } - return 0; -} - int less(void* a, void* b) { @@ -119,7 +14,7 @@ less(void* a, void* b) return ai - bi; } -error +int test·sort() { clock_t t; @@ -155,10 +50,10 @@ test·sort() return 0; } -error +int main() { - error err; + int err; #if 0 if (err = test·coro(), err) { errorf("test fail: coroutine"); @@ -167,4 +62,5 @@ main() if (err = test·sort(), err) { errorf("test fail: coroutine"); } + return 0; } |