test/lib: Add parent stdout test
authorJeremy Kerr <jk@ozlabs.org>
Mon, 16 Dec 2013 07:16:36 +0000 (15:16 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 18 Dec 2013 01:51:11 +0000 (09:51 +0800)
Looks like we missed adding a test source file.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
test/lib/Makefile.am
test/lib/test-process-parent-stdout.c [new file with mode: 0644]

index 3b4d8cb4767d0428d77e378270027e8bb8af3c59..36067100553a09de2e7deec2e018f9fcd2b52dad 100644 (file)
@@ -28,6 +28,7 @@ check_PROGRAMS = list-test \
        test-process-sync-stdout \
        test-process-async \
        test-process-async-stdout \
        test-process-sync-stdout \
        test-process-async \
        test-process-async-stdout \
+       test-process-parent-stdout \
        test-process-both
 
 TESTS = $(check_PROGRAMS)
        test-process-both
 
 TESTS = $(check_PROGRAMS)
diff --git a/test/lib/test-process-parent-stdout.c b/test/lib/test-process-parent-stdout.c
new file mode 100644 (file)
index 0000000..334201a
--- /dev/null
@@ -0,0 +1,55 @@
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <process/process.h>
+#include <waiter/waiter.h>
+#include <talloc/talloc.h>
+
+static int do_child(void)
+{
+       printf("forty two\n");
+       return 42;
+}
+
+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, false);
+
+       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->keep_stdout = true;
+
+       printf("not this stdout\n");
+
+       process_run_sync(process);
+
+       assert(WIFEXITED(process->exit_status));
+       assert(WEXITSTATUS(process->exit_status) == 42);
+
+       assert(process->stdout_len == strlen("forty two\n"));
+       assert(!memcmp(process->stdout_buf, "forty two\n",
+                               process->stdout_len));
+
+       talloc_free(ctx);
+
+       return EXIT_SUCCESS;
+}