]> git.ozlabs.org Git - petitboot/blob - test/lib/test-process-stderr.c
configure: Add signed-boot openssl configuration support
[petitboot] / test / lib / test-process-stderr.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         fprintf(stderr, "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         process->add_stderr = true;
41
42         process_run_sync(process);
43
44         assert(WIFEXITED(process->exit_status));
45         assert(WEXITSTATUS(process->exit_status) == 42);
46
47         assert(process->stdout_len == strlen("forty two\n"));
48         assert(!memcmp(process->stdout_buf, "forty two\n",
49                                 process->stdout_len));
50
51         talloc_free(ctx);
52
53         return EXIT_SUCCESS;
54 }