summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-12-16 15:16:36 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-12-18 09:51:11 +0800
commit8b09f179fb71f13223e78ceb91f6a692053957b0 (patch)
treedaf5b65eba123ac968f735d3cf0c7e07844f72cb /test
parent32e2eac76dcdc7b54454c9f3731496f8947cdbbc (diff)
downloadpetitboot-8b09f179fb71f13223e78ceb91f6a692053957b0.zip
petitboot-8b09f179fb71f13223e78ceb91f6a692053957b0.tar.gz
test/lib: Add parent stdout test
Looks like we missed adding a test source file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test')
-rw-r--r--test/lib/Makefile.am1
-rw-r--r--test/lib/test-process-parent-stdout.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am
index 3b4d8cb..3606710 100644
--- a/test/lib/Makefile.am
+++ b/test/lib/Makefile.am
@@ -28,6 +28,7 @@ check_PROGRAMS = list-test \
test-process-sync-stdout \
test-process-async \
test-process-async-stdout \
+ test-process-parent-stdout \
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
index 0000000..334201a
--- /dev/null
+++ b/test/lib/test-process-parent-stdout.c
@@ -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;
+}
OpenPOWER on IntegriCloud