77// ===----------------------------------------------------------------------===//
88
99#include " src/__support/OSUtil/syscall.h" // For internal syscall function.
10- #include " src/__support/threads/sleep.h"
1110#include " src/errno/libc_errno.h"
1211#include " src/signal/kill.h"
12+ #include " src/signal/raise.h"
1313#include " src/stdlib/exit.h"
1414#include " src/sys/mman/process_mrelease.h"
1515#include " src/unistd/close.h"
1818#include " test/UnitTest/LibcTest.h"
1919
2020#include < sys/syscall.h>
21-
21+ # if defined(SYS_process_mrelease) && defined(SYS_pidfd_open)
2222using namespace LIBC_NAMESPACE ::testing::ErrnoSetterMatcher;
2323
2424int pidfd_open (pid_t pid, unsigned int flags) {
@@ -30,13 +30,11 @@ TEST(LlvmLibcProcessMReleaseTest, NoError) {
3030 EXPECT_GE (child_pid, 0 );
3131
3232 if (child_pid == 0 ) {
33- // Child process: wait a bit then exit gracefully.
34- LIBC_NAMESPACE::sleep_briefly ();
35- LIBC_NAMESPACE::exit (0 );
33+ // pause the child process
34+ LIBC_NAMESPACE::raise (SIGSTOP);
3635 } else {
3736 // Parent process: wait a bit and then kill the child.
3837 // Give child process some time to start.
39- LIBC_NAMESPACE::sleep_briefly ();
4038 int pidfd = pidfd_open (child_pid, 0 );
4139 EXPECT_GE (pidfd, 0 );
4240
@@ -54,12 +52,9 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
5452 EXPECT_GE (child_pid, 0 );
5553
5654 if (child_pid == 0 ) {
57- // Child process: wait a bit then exit gracefully.
58- LIBC_NAMESPACE::sleep_briefly ();
59- LIBC_NAMESPACE::exit (0 );
55+ // pause the child process
56+ LIBC_NAMESPACE::raise (SIGSTOP);
6057 } else {
61- // Give child process some time to start.
62- LIBC_NAMESPACE::sleep_briefly ();
6358 int pidfd = pidfd_open (child_pid, 0 );
6459 EXPECT_GE (pidfd, 0 );
6560
@@ -72,3 +67,4 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
7267TEST (LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
7368 EXPECT_THAT (LIBC_NAMESPACE::process_mrelease (-1 , 0 ), Fails (EBADF));
7469}
70+ #endif
0 commit comments