X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=test%2Flib%2Ftest-process-async.c;fp=test%2Flib%2Ftest-process-async.c;h=61780ad7a46f9c971bd716794ad3c96c419d0f78;hb=d20e98b93afaf25faca4db2a3583c191bdabe439;hp=0000000000000000000000000000000000000000;hpb=c7e26c27c7e029e6670dfebc8f27d9295e9fdeb7;p=petitboot diff --git a/test/lib/test-process-async.c b/test/lib/test-process-async.c new file mode 100644 index 0000000..61780ad --- /dev/null +++ b/test/lib/test-process-async.c @@ -0,0 +1,66 @@ + +#include +#include +#include + +#include +#include +#include + +static int do_child(void) +{ + return 42; +} + +static bool exited; +static int exit_status; + +static void exit_cb(struct process *process) +{ + exited = true; + exit_status = process->exit_status; +} + +int main(int argc, char **argv) +{ + struct waitset *waitset; + struct process *process; + const char *child_argv[3]; + void *ctx; + + if (argc == 2 && !strcmp(argv[1], "child")) + return do_child(); + + ctx = talloc_new(NULL); + + waitset = waitset_create(ctx); + + process_init(ctx, waitset); + + child_argv[0] = argv[0]; + child_argv[1] = "child"; + child_argv[2] = NULL; + + process = process_create(ctx); + process->path = child_argv[0]; + process->argv = child_argv; + process->exit_cb = exit_cb; + + exited = false; + + process_run_async(process); + + for (;;) { + waiter_poll(waitset); + + if (exited) + break; + } + + assert(WIFEXITED(exit_status)); + assert(WEXITSTATUS(exit_status) == 42); + + talloc_free(ctx); + + return EXIT_SUCCESS; +}