77// ===----------------------------------------------------------------------===//
88
99#include " src/__support/OSUtil/syscall.h" // For internal syscall function.
10+ #include " src/__support/threads/sleep.h"
1011#include " src/errno/libc_errno.h"
1112#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- # if defined(SYS_process_mrelease) && defined(SYS_pidfd_open)
21+
2222using namespace LIBC_NAMESPACE ::testing::ErrnoSetterMatcher;
2323
2424int pidfd_open (pid_t pid, unsigned int flags) {
@@ -30,11 +30,13 @@ TEST(LlvmLibcProcessMReleaseTest, NoError) {
3030 EXPECT_GE (child_pid, 0 );
3131
3232 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 );
3536 } else {
3637 // Parent process: wait a bit and then kill the child.
3738 // Give child process some time to start.
39+ LIBC_NAMESPACE::sleep_briefly ();
3840 int pidfd = pidfd_open (child_pid, 0 );
3941 EXPECT_GE (pidfd, 0 );
4042
@@ -52,9 +54,12 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
5254 EXPECT_GE (child_pid, 0 );
5355
5456 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 );
5760 } else {
61+ // Give child process some time to start.
62+ LIBC_NAMESPACE::sleep_briefly ();
5863 int pidfd = pidfd_open (child_pid, 0 );
5964 EXPECT_GE (pidfd, 0 );
6065
@@ -67,4 +72,3 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
6772TEST (LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
6873 EXPECT_THAT (LIBC_NAMESPACE::process_mrelease (-1 , 0 ), Fails (EBADF));
6974}
70- #endif
0 commit comments