@@ -0,0 +1,59 @@
1+#include <assert.h>
2+#include <fcntl.h>
3+#include <spawn.h>
4+#include <stdio.h>
5+#include <unistd.h>
6+
7+#include <sys/stat.h>
8+#include <sys/types.h>
9+#include <sys/wait.h>
10+
11+#define TESTPATH "/foo/bar/test"
12+
13+extern char **environ;
14+
15+void test_spawn(void) {
16+ pid_t pid;
17+ int ret;
18+ posix_spawn_file_actions_t file_actions;
19+ char *argv[] = {"true", NULL};
20+
21+ assert(posix_spawn_file_actions_init(&file_actions) == 0);
22+
23+ ret = posix_spawn(&pid, TESTPATH, &file_actions, NULL, argv, environ);
24+
25+ assert(ret == 0);
26+ assert(waitpid(pid, NULL, 0) != -1);
27+}
28+
29+void test_execv(void) {
30+ char *argv[] = {"true", NULL};
31+ assert(execv(TESTPATH, argv) == 0);
32+}
33+
34+int main(void)
35+{
36+ FILE *testfp;
37+ int testfd;
38+ struct stat testsb;
39+
40+ testfp = fopen(TESTPATH, "r");
41+ assert(testfp != NULL);
42+ fclose(testfp);
43+
44+ testfd = open(TESTPATH, O_RDONLY);
45+ assert(testfd != -1);
46+ close(testfd);
47+
48+ assert(access(TESTPATH, X_OK) == 0);
49+
50+ assert(stat(TESTPATH, &testsb) != -1);
51+
52+ test_spawn();
53+ test_execv();
54+
55+ /* If all goes well, this is never reached because test_execv() replaces
56+ * the current process.
57+ */
58+ return 0;
59+}