diff options
| author | Tom Harley | 2020-01-24 05:15:35 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-24 05:15:35 +0000 |
| commit | c9f0de12be31eea463bf022f3eee76490b30f8dc (patch) | |
| tree | a80718ff00fa2dcb1c52c2af6828feffc7f89d8b /test/test.c | |
| download | parapat-c9f0de12be31eea463bf022f3eee76490b30f8dc.tar.gz parapat-c9f0de12be31eea463bf022f3eee76490b30f8dc.zip | |
Diffstat (limited to 'test/test.c')
| -rw-r--r-- | test/test.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..8f51f62 --- /dev/null +++ b/test/test.c @@ -0,0 +1,55 @@ +#include <stdio.h> + +#include "parapat.h" + +typedef struct { + int v; +} arg_t; + +void *test_work(void *v) { + arg_t *a = v; + a->v *= 2; + return a; +} + +void *test_fold(void *a, void *b) { + arg_t *x = a, *y = b; + + x->v += y->v; + + return x; +} + +int main() { + int i; + arg_t a, *res = &a; + + arg_t args[10]; + arg_t *ptrs[10]; + + work *fns[4] = { + &test_work, + &test_work, + &test_work, + &test_work + }; + + pipeline *pl; + + for (i = 0; i < 10; ++i) { + args[i].v = i; + ptrs[i] = &args[i]; + } + + a.v = 0; + + res = create_farm(&test_work, &test_fold, 10, (void **) &ptrs[0]); + printf("after farm: %d\n", res->v); + + pl = create_pipeline(fns, 4); + push(pl->in, res); + res = pop(pl->out); + printf("after pipeline: %d\n", res->v); + + return 0; +} |
