7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " src/__support/OSUtil/syscall.h" // For internal syscall function.
10
+ #include " src/__support/threads/sleep.h"
10
11
#include " src/errno/libc_errno.h"
11
12
#include " src/signal/kill.h"
12
- #include " src/signal/raise.h"
13
13
#include " src/stdlib/exit.h"
14
14
#include " src/sys/mman/process_mrelease.h"
15
15
#include " src/unistd/close.h"
18
18
#include " test/UnitTest/LibcTest.h"
19
19
20
20
#include < sys/syscall.h>
21
- # if defined(SYS_process_mrelease) && defined(SYS_pidfd_open)
21
+
22
22
using namespace LIBC_NAMESPACE ::testing::ErrnoSetterMatcher;
23
23
24
24
int pidfd_open (pid_t pid, unsigned int flags) {
@@ -30,11 +30,13 @@ TEST(LlvmLibcProcessMReleaseTest, NoError) {
30
30
EXPECT_GE (child_pid, 0 );
31
31
32
32
if (child_pid == 0 ) {
33
- // pause the child process
34
- LIBC_NAMESPACE::raise (SIGSTOP);
33
+ // Child process: wait a bit then exit gracefully.
34
+ LIBC_NAMESPACE::sleep_briefly ();
35
+ LIBC_NAMESPACE::exit (0 );
35
36
} else {
36
37
// Parent process: wait a bit and then kill the child.
37
38
// Give child process some time to start.
39
+ LIBC_NAMESPACE::sleep_briefly ();
38
40
int pidfd = pidfd_open (child_pid, 0 );
39
41
EXPECT_GE (pidfd, 0 );
40
42
@@ -52,9 +54,12 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
52
54
EXPECT_GE (child_pid, 0 );
53
55
54
56
if (child_pid == 0 ) {
55
- // pause the child process
56
- LIBC_NAMESPACE::raise (SIGSTOP);
57
+ // Child process: wait a bit then exit gracefully.
58
+ LIBC_NAMESPACE::sleep_briefly ();
59
+ LIBC_NAMESPACE::exit (0 );
57
60
} else {
61
+ // Give child process some time to start.
62
+ LIBC_NAMESPACE::sleep_briefly ();
58
63
int pidfd = pidfd_open (child_pid, 0 );
59
64
EXPECT_GE (pidfd, 0 );
60
65
@@ -67,4 +72,3 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
67
72
TEST (LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
68
73
EXPECT_THAT (LIBC_NAMESPACE::process_mrelease (-1 , 0 ), Fails (EBADF));
69
74
}
70
- #endif
0 commit comments