summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-05-29 12:58:53 -0400
committerRich Felker <dalias@aerifal.cx>2011-05-29 12:58:53 -0400
commitad056d9aa0ce3a04e85504a357581d54930594d8 (patch)
tree0c1e8ac623800e085f12700432155a5fc6a9586e
parent51301ea856288510abd0fbdcb4aa5623ca6c8472 (diff)
downloadlibc-testsuite-ad056d9aa0ce3a04e85504a357581d54930594d8.tar.gz
add test for posix_spawn (so far very simple)
-rw-r--r--spawn.c44
-rw-r--r--testsuite.c1
2 files changed, 45 insertions, 0 deletions
diff --git a/spawn.c b/spawn.c
new file mode 100644
index 0000000..7bbd8d2
--- /dev/null
+++ b/spawn.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <spawn.h>
+#include <sys/wait.h>
+
+#define TEST(r, f, x, m) ( \
+((r) = (f)) == (x) || \
+(printf(__FILE__ ":%d: %s failed (" m ")\n", __LINE__, #f, r, x), err++, 0) )
+
+#define TEST_E(f) ( (errno = 0), (f) || \
+(printf(__FILE__ ":%d: %s failed (errno = %d)\n", __LINE__, #f, errno), err++, 0) )
+
+#define TEST_S(s, x, m) ( \
+!strcmp((s),(x)) || \
+(printf(__FILE__ ":%d: [%s] != [%s] (%s)\n", __LINE__, s, x, m), err++, 0) )
+
+int test_spawn(void)
+{
+ int r;
+ char foo[10];
+ int p[2];
+ pid_t pid;
+ int status;
+ int err = 0;
+ posix_spawnattr_t attr;
+ posix_spawn_file_actions_t fa;
+
+ TEST_E(!pipe(p));
+ TEST(r, posix_spawn_file_actions_init(&fa), 0, "%d != %d");
+ TEST(r, posix_spawn_file_actions_addclose(&fa, p[0]), 0, "%d != %d");
+ TEST(r, posix_spawn_file_actions_adddup2(&fa, p[1], 1), 0, "%d != %d");
+ TEST(r, posix_spawn_file_actions_addclose(&fa, p[1]), 0, "%d != %d");
+ TEST(r, posix_spawnp(&pid, "echo", &fa, 0, (char *[]){"echo","hello",0}, 0), 0, "%d != %d");
+ close(p[1]);
+ TEST(r, waitpid(pid, &status, 0), pid, "%d != %d");
+ TEST(r, read(p[0], foo, sizeof foo), 6, "%d != %d");
+ close(p[0]);
+ TEST(r, posix_spawn_file_actions_destroy(&fa), 0, "%d != %d");
+
+ return err;
+}
diff --git a/testsuite.c b/testsuite.c
index bd52966..0ba976d 100644
--- a/testsuite.c
+++ b/testsuite.c
@@ -16,6 +16,7 @@ int main()
RUN_TEST(fnmatch);
RUN_TEST(fscanf);
RUN_TEST(popen);
+ RUN_TEST(spawn);
RUN_TEST(qsort);
RUN_TEST(time);
RUN_TEST(sscanf);