summaryrefslogtreecommitdiffstats
path: root/test/unit/fork.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-05-04 00:34:40 (GMT)
committerJason Evans <jasone@canonware.com>2016-05-04 00:34:40 (GMT)
commite02b83cc5e3c4d30f93dba945162e3aa58d962d6 (patch)
treedc1cf37bd624061c6351ea3a78f993d2a19310ac /test/unit/fork.c
parentdf900dbfaf4835d3efc06d771535f3e781544913 (diff)
parent2e5eb21184cccabc829265b5f5237f3c13563be6 (diff)
downloadjemalloc-4.1.1.zip
jemalloc-4.1.1.tar.gz
jemalloc-4.1.1.tar.bz2
Merge branch.4.1.1
Diffstat (limited to 'test/unit/fork.c')
-rw-r--r--test/unit/fork.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/unit/fork.c b/test/unit/fork.c
new file mode 100644
index 0000000..c0d5642
--- /dev/null
+++ b/test/unit/fork.c
@@ -0,0 +1,45 @@
+#include "test/jemalloc_test.h"
+
+#ifndef _WIN32
+#include <sys/wait.h>
+#endif
+
+TEST_BEGIN(test_fork)
+{
+#ifndef _WIN32
+ void *p;
+ pid_t pid;
+
+ p = malloc(1);
+ assert_ptr_not_null(p, "Unexpected malloc() failure");
+
+ pid = fork();
+ if (pid == -1) {
+ /* Error. */
+ test_fail("Unexpected fork() failure");
+ } else if (pid == 0) {
+ /* Child. */
+ exit(0);
+ } else {
+ int status;
+
+ /* Parent. */
+ free(p);
+ do {
+ if (waitpid(pid, &status, 0) == -1)
+ test_fail("Unexpected waitpid() failure");
+ } while (!WIFEXITED(status) && !WIFSIGNALED(status));
+ }
+#else
+ test_skip("fork(2) is irrelevant to Windows");
+#endif
+}
+TEST_END
+
+int
+main(void)
+{
+
+ return (test(
+ test_fork));
+}