|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
| 9 | +#include "src/__support/OSUtil/syscall.h" |
9 | 10 | #include "src/pthread/pthread_atfork.h"
|
10 | 11 | #include "src/signal/raise.h"
|
| 12 | +#include "src/stdlib/exit.h" |
11 | 13 | #include "src/sys/wait/wait.h"
|
12 | 14 | #include "src/sys/wait/wait4.h"
|
13 | 15 | #include "src/sys/wait/waitpid.h"
|
14 | 16 | #include "src/unistd/fork.h"
|
15 |
| - |
| 17 | +#include "src/unistd/getpid.h" |
| 18 | +#include "src/unistd/gettid.h" |
16 | 19 | #include "test/IntegrationTest/test.h"
|
17 | 20 |
|
18 | 21 | #include <errno.h>
|
19 | 22 | #include <signal.h>
|
| 23 | +#include <sys/syscall.h> |
20 | 24 | #include <sys/wait.h>
|
21 | 25 | #include <unistd.h>
|
22 | 26 |
|
@@ -140,7 +144,25 @@ void fork_with_atfork_callbacks() {
|
140 | 144 | ASSERT_NE(child, DONE);
|
141 | 145 | }
|
142 | 146 |
|
| 147 | +void fork_pid_tid_test() { |
| 148 | + pid_t pid = fork(); |
| 149 | + ASSERT_TRUE(pid >= 0); |
| 150 | + ASSERT_EQ(LIBC_NAMESPACE::gettid(), |
| 151 | + LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid)); |
| 152 | + ASSERT_EQ(LIBC_NAMESPACE::getpid(), |
| 153 | + LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_getpid)); |
| 154 | + |
| 155 | + if (pid == 0) { |
| 156 | + LIBC_NAMESPACE::exit(0); |
| 157 | + } else { |
| 158 | + int status; |
| 159 | + LIBC_NAMESPACE::waitpid(pid, &status, 0); |
| 160 | + ASSERT_EQ(status, 0); |
| 161 | + } |
| 162 | +} |
| 163 | + |
143 | 164 | TEST_MAIN(int argc, char **argv, char **envp) {
|
| 165 | + fork_pid_tid_test(); |
144 | 166 | fork_and_wait_normal_exit();
|
145 | 167 | fork_and_wait4_normal_exit();
|
146 | 168 | fork_and_waitpid_normal_exit();
|
|
0 commit comments