authorgravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-08-01 12:43:59-07:00
committergravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-09-09 22:07:03-07:00
loge46ddeeb296aeb259d1bb9f96cb977f4868309e7
tree758090bc7c2aa1947a31c001a4f32fc7ee649903
parent0edccc1079003e2c96f5c808fdaf00d465e6e004

posix/test.zig: "sigset_t bits" test fixes

Re-enable the test. Will trigger #24380 as-is, but follow-on change moes this code over to test/standalone. Make the test a bit easier to debug by stashing the "seen" signal number in the shared `seen_sig` (instead of just incrementing a counter for each hit). And only doing so if the `seen_sig` is zero.

1 files changed, 13 insertions(+), 14 deletions(-)

lib/std/posix/test.zig+13-14
...@@ -949,14 +949,11 @@ test "sigset_t bits" {...@@ -949,14 +949,11 @@ test "sigset_t bits" {
949 if (native_os == .wasi or native_os == .windows)949 if (native_os == .wasi or native_os == .windows)
950 return error.SkipZigTest;950 return error.SkipZigTest;
951951
952 if (true) {952 const NO_SIG: i32 = 0;
953 // https://github.com/ziglang/zig/issues/24380
954 return error.SkipZigTest;
955 }
956953
957 const S = struct {954 const S = struct {
958 var expected_sig: i32 = undefined;955 var expected_sig: i32 = undefined;
959 var handler_called_count: u32 = 0;956 var seen_sig: i32 = NO_SIG;
960957
961 fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {958 fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
962 _ = ctx_ptr;959 _ = ctx_ptr;
...@@ -965,23 +962,25 @@ test "sigset_t bits" {...@@ -965,23 +962,25 @@ test "sigset_t bits" {
965 .netbsd => info.info.signo,962 .netbsd => info.info.signo,
966 else => info.signo,963 else => info.signo,
967 };964 };
968 if (sig == expected_sig and sig == info_sig) {965 if (seen_sig == NO_SIG and sig == expected_sig and sig == info_sig) {
969 handler_called_count += 1;966 seen_sig = sig;
970 }967 }
971 }968 }
972 };969 };
973970
974 const self_pid = posix.system.getpid();971 // Assume this is a single-threaded process where the current thread has the
972 // 'pid' thread id. (The sigprocmask calls are thread-private state.)
973 const self_tid = posix.system.getpid();
975974
976 // To check that sigset_t mapping matches kernel (think u32/u64 mismatches on975 // To check that sigset_t mapping matches kernel (think u32/u64 mismatches on
977 // big-endian), try sending a blocked signal to make sure the mask matches the976 // big-endian), try sending a blocked signal to make sure the mask matches the
978 // signal. (Send URG and CHLD because they're ignored by default in the977 // signal. (Send URG and CHLD because they're ignored by default in the
979 // debugger, vs. USR1 or other named signals)978 // debugger, vs. USR1 or other named signals)
980 inline for ([_]usize{ posix.SIG.URG, posix.SIG.CHLD, 62, 94, 126 }) |test_signo| {979 inline for ([_]i32{ posix.SIG.URG, posix.SIG.CHLD, 62, 94, 126 }) |test_signo| {
981 if (test_signo >= posix.NSIG) continue;980 if (test_signo >= posix.NSIG) continue;
982981
983 S.expected_sig = test_signo;982 S.expected_sig = test_signo;
984 S.handler_called_count = 0;983 S.seen_sig = NO_SIG;
985984
986 const sa: posix.Sigaction = .{985 const sa: posix.Sigaction = .{
987 .handler = .{ .sigaction = &S.handler },986 .handler = .{ .sigaction = &S.handler },
...@@ -1001,18 +1000,18 @@ test "sigset_t bits" {...@@ -1001,18 +1000,18 @@ test "sigset_t bits" {
10011000
1002 // qemu maps target signals to host signals 1-to-1, so targets1001 // qemu maps target signals to host signals 1-to-1, so targets
1003 // with more signals than the host will fail to send the signal.1002 // with more signals than the host will fail to send the signal.
1004 const rc = posix.system.kill(self_pid, test_signo);1003 const rc = posix.system.kill(self_tid, test_signo);
1005 switch (posix.errno(rc)) {1004 switch (posix.errno(rc)) {
1006 .SUCCESS => {1005 .SUCCESS => {
1007 // See that the signal is blocked, then unblocked1006 // See that the signal is blocked, then unblocked
1008 try testing.expectEqual(0, S.handler_called_count);1007 try testing.expectEqual(NO_SIG, S.seen_sig);
1009 posix.sigprocmask(posix.SIG.UNBLOCK, &block_one, null);1008 posix.sigprocmask(posix.SIG.UNBLOCK, &block_one, null);
1010 try testing.expectEqual(1, S.handler_called_count);1009 try testing.expectEqual(test_signo, S.seen_sig);
1011 },1010 },
1012 .INVAL => {1011 .INVAL => {
1013 // Signal won't get delviered. Just clean up.1012 // Signal won't get delviered. Just clean up.
1014 posix.sigprocmask(posix.SIG.UNBLOCK, &block_one, null);1013 posix.sigprocmask(posix.SIG.UNBLOCK, &block_one, null);
1015 try testing.expectEqual(0, S.handler_called_count);1014 try testing.expectEqual(NO_SIG, S.seen_sig);
1016 },1015 },
1017 else => |errno| return posix.unexpectedErrno(errno),1016 else => |errno| return posix.unexpectedErrno(errno),
1018 }1017 }