From 4a61bac1001c682738cbead210fc7d948029539e Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Fri, 2 Aug 2024 02:15:52 +0200 Subject: [PATCH] posix: fix test on netbsd --- core/sys/posix/signal.odin | 2 +- core/sys/posix/sys_wait.odin | 4 ++-- tests/core/sys/posix/posix.odin | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/sys/posix/signal.odin b/core/sys/posix/signal.odin index 6b1817d4f..c35494185 100644 --- a/core/sys/posix/signal.odin +++ b/core/sys/posix/signal.odin @@ -408,7 +408,7 @@ SA_Flags_Bits :: enum c.int { RESTART = log2(SA_RESTART), // Cause extra information to be passed to signal handlers at the time of receipt of a signal. SIGINFO = log2(SA_SIGINFO), - // Cause implemention not to create zombie processes or status information on child termination. + // Cause implementation not to create zombie processes or status information on child termination. NOCLDWAIT = log2(SA_NOCLDWAIT), // Cause signal not to be automatically blocked on entry to signal handler. SA_NODEFER = log2(SA_NODEFER), diff --git a/core/sys/posix/sys_wait.odin b/core/sys/posix/sys_wait.odin index 6d0336e80..8421c8bfd 100644 --- a/core/sys/posix/sys_wait.odin +++ b/core/sys/posix/sys_wait.odin @@ -290,7 +290,7 @@ when ODIN_OS == .Darwin { @(private) _WEXITSTATUS :: #force_inline proc "contextless" (x: c.int) -> c.int { - return (x >> 8) & 0x000000ff + return c.int((c.uint(x) >> 8) & 0xff) } @(private) @@ -310,7 +310,7 @@ when ODIN_OS == .Darwin { @(private) _WSTOPSIG :: #force_inline proc "contextless" (x: c.int) -> Signal { - return Signal((x >> 8) & 0xff) + return Signal(c.int((c.uint(x) >> 8) & 0xff)) } @(private) diff --git a/tests/core/sys/posix/posix.odin b/tests/core/sys/posix/posix.odin index 03a2f932c..bfe4f7875 100644 --- a/tests/core/sys/posix/posix.odin +++ b/tests/core/sys/posix/posix.odin @@ -249,10 +249,21 @@ test_signal :: proc(t: ^testing.T) { case 0: posix.exit(69) case: - status: i32 - posix.waitpid(pid, &status, {}) - testing.expect(t, posix.WIFEXITED(status)) - testing.expect(t, posix.WEXITSTATUS(status) == 69) + for { + status: i32 + res := posix.waitpid(pid, &status, {}) + if res == -1 { + if !testing.expect_value(t, posix.errno(), posix.Errno.EINTR) { + break + } + } + + if posix.WIFEXITED(status) || posix.WIFSIGNALED(status) { + testing.expect(t, posix.WIFEXITED(status)) + testing.expect(t, posix.WEXITSTATUS(status) == 69) + break + } + } } }