test/efivar: Rework for efi_mount
[petitboot] / test / lib / test-process-sync.c
1
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5
6 #include <process/process.h>
7 #include <waiter/waiter.h>
8 #include <talloc/talloc.h>
9
10 static int do_child(void)
11 {
12         return 42;
13 }
14
15 int main(int argc, char **argv)
16 {
17         struct waitset *waitset;
18         struct process *process;
19         const char *child_argv[3];
20         void *ctx;
21
22         if (argc == 2 && !strcmp(argv[1], "child"))
23                 return do_child();
24
25         ctx = talloc_new(NULL);
26
27         waitset = waitset_create(ctx);
28
29         process_init(ctx, waitset, false);
30
31         child_argv[0] = argv[0];
32         child_argv[1] = "child";
33         child_argv[2] = NULL;
34
35         process = process_create(ctx);
36         process->path = child_argv[0];
37         process->argv = child_argv;
38
39         process_run_sync(process);
40
41         assert(WIFEXITED(process->exit_status));
42         assert(WEXITSTATUS(process->exit_status) == 42);
43
44         talloc_free(ctx);
45
46         return EXIT_SUCCESS;
47 }