]> git.ozlabs.org Git - petitboot/blob - test/lib/test-process-parent-stdout.c
discover: Call mount syscall directly
[petitboot] / test / lib / test-process-parent-stdout.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         printf("forty two\n");
13         return 42;
14 }
15
16 int main(int argc, char **argv)
17 {
18         struct waitset *waitset;
19         struct process *process;
20         const char *child_argv[3];
21         void *ctx;
22
23         if (argc == 2 && !strcmp(argv[1], "child"))
24                 return do_child();
25
26         ctx = talloc_new(NULL);
27
28         waitset = waitset_create(ctx);
29
30         process_init(ctx, waitset, false);
31
32         child_argv[0] = argv[0];
33         child_argv[1] = "child";
34         child_argv[2] = NULL;
35
36         process = process_create(ctx);
37         process->path = child_argv[0];
38         process->argv = child_argv;
39         process->keep_stdout = true;
40
41         printf("not this stdout\n");
42
43         process_run_sync(process);
44
45         assert(WIFEXITED(process->exit_status));
46         assert(WEXITSTATUS(process->exit_status) == 42);
47
48         assert(process->stdout_len == strlen("forty two\n"));
49         assert(!memcmp(process->stdout_buf, "forty two\n",
50                                 process->stdout_len));
51
52         talloc_free(ctx);
53
54         return EXIT_SUCCESS;
55 }