]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/darwintests/xnu_quick_test.c
5e2e66701e77c33d1eda8295e70733d95a689c9c
1 #define T_NAMESPACE xnu.quicktest
3 #include <darwintest.h>
10 /* **************************************************************************************************************
11 * Test fork wait4, and exit system calls.
12 * **************************************************************************************************************
14 T_DECL(fork_wait4_exit_test
,
15 "Tests forking off a process and waiting for the child to exit", T_META_CHECK_LEAKS(false))
17 int my_err
, my_status
;
18 pid_t my_pid
, my_wait_pid
;
19 struct rusage my_usage
;
20 char * g_target_path
="/";
22 /* spin off another process */
23 T_ASSERT_NE(my_pid
= fork(), -1, "Fork off a process");
28 /* child process does very little then exits */
29 my_err
= stat( &g_target_path
[0], &my_sb
);
31 T_ASSERT_TRUE(my_err
== 0, "stat call with path: \"%s\" returned \"%d\"", &g_target_path
[0], errno
);
35 /* parent process waits for child to exit */
36 T_ASSERT_NE(my_wait_pid
= wait4( my_pid
, &my_status
, 0, &my_usage
), -1,
37 "Wait for child to exit\n");
39 /* wait4 should return our child's pid when it exits */
40 T_ASSERT_EQ(my_wait_pid
, my_pid
,
41 "wait4 should return our child's pid when it exits");
43 /* kind of just guessing on these values so if this fails we should take a closer
44 * look at the returned rusage structure.
46 T_ASSERT_FALSE(( my_usage
.ru_utime
.tv_sec
> 1 ||
47 my_usage
.ru_stime
.tv_sec
> 1 || my_usage
.ru_majflt
> 1000 ||
48 my_usage
.ru_msgsnd
> 100 ), "wait4 returned rusage structure");
50 T_ASSERT_TRUE(( WIFEXITED( my_status
) && WEXITSTATUS( my_status
) == 44 ),
51 "check if wait4 returns right exit status");