From 64b3ffd8ffb970ca881827a21ef6546f7ad6de99 Mon Sep 17 00:00:00 2001 From: Ryan Schneider Date: Wed, 2 Nov 2022 17:11:02 -0700 Subject: [PATCH] std.os: Add IGN coverage to sigaction tests * Should start failing on aarch64 and other word-aligned CPUs. --- lib/std/os/test.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index a8497586f9..ef75058140 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -739,7 +739,7 @@ test "shutdown socket" { os.closeSocket(sock); } -var signal_test_failed = true; +var signal_test_handler_called_count: u32 = 0; test "sigaction" { if (native_os == .wasi or native_os == .windows) @@ -756,11 +756,11 @@ test "sigaction" { switch (native_os) { .netbsd => { if (sig == os.SIG.USR1 and sig == info.info.signo) - signal_test_failed = false; + signal_test_handler_called_count += 1; }, else => { if (sig == os.SIG.USR1 and sig == info.signo) - signal_test_failed = false; + signal_test_handler_called_count += 1; }, } } @@ -782,10 +782,19 @@ test "sigaction" { try testing.expect((old_sa.flags & os.SA.SIGINFO) != 0); // Invoke the handler. try os.raise(os.SIG.USR1); - try testing.expect(signal_test_failed == false); + try testing.expect(signal_test_handler_called_count == 1); // Check if the handler has been correctly reset to SIG_DFL try os.sigaction(os.SIG.USR1, null, &old_sa); try testing.expectEqual(os.SIG.DFL, old_sa.handler.handler); + // ensure we can ignore a signal + sa.handler = .{ .handler = os.SIG.IGN }; + try os.sigaction(os.SIG.USR1, &sa, null); + // and ensure it is now ignored + try os.raise(os.SIG.USR1); + try testing.expect(signal_test_handler_called_count == 1); + // and that ignored state is returned when querying + try os.sigaction(os.SIG.USR1, null, &old_sa); + try testing.expectEqual(os.SIG.IGN, old_sa.handler.handler.?); } test "dup & dup2" {