aboutsummaryrefslogtreecommitdiff
path: root/test/unit/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/fork.c')
-rw-r--r--test/unit/fork.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/unit/fork.c b/test/unit/fork.c
new file mode 100644
index 0000000..890bc86
--- /dev/null
+++ b/test/unit/fork.c
@@ -0,0 +1,39 @@
+#include "test/jemalloc_test.h"
+
+#include <sys/wait.h>
+
+TEST_BEGIN(test_fork)
+{
+ 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));
+ }
+}
+TEST_END
+
+int
+main(void)
+{
+
+ return (test(
+ test_fork));
+}