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" {
949949 if (native_os == .wasi or native_os == .windows)
950950 return error.SkipZigTest;
951951
952 if (true) {
953 // https://github.com/ziglang/zig/issues/24380
954 return error.SkipZigTest;
955 }
952 const NO_SIG: i32 = 0;
956953
957954 const S = struct {
958955 var expected_sig: i32 = undefined;
959 var handler_called_count: u32 = 0;
956 var seen_sig: i32 = NO_SIG;
960957
961958 fn handler(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
962959 _ = ctx_ptr;
......@@ -965,23 +962,25 @@ test "sigset_t bits" {
965962 .netbsd => info.info.signo,
966963 else => info.signo,
967964 };
968 if (sig == expected_sig and sig == info_sig) {
969 handler_called_count += 1;
965 if (seen_sig == NO_SIG and sig == expected_sig and sig == info_sig) {
966 seen_sig = sig;
970967 }
971968 }
972969 };
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
976975 // To check that sigset_t mapping matches kernel (think u32/u64 mismatches on
977976 // big-endian), try sending a blocked signal to make sure the mask matches the
978977 // signal. (Send URG and CHLD because they're ignored by default in the
979978 // 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| {
981980 if (test_signo >= posix.NSIG) continue;
982981
983982 S.expected_sig = test_signo;
984 S.handler_called_count = 0;
983 S.seen_sig = NO_SIG;
985984
986985 const sa: posix.Sigaction = .{
987986 .handler = .{ .sigaction = &S.handler },
......@@ -1001,18 +1000,18 @@ test "sigset_t bits" {
10011000
10021001 // qemu maps target signals to host signals 1-to-1, so targets
10031002 // 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);
10051004 switch (posix.errno(rc)) {
10061005 .SUCCESS => {
10071006 // 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);
10091008 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);
10111010 },
10121011 .INVAL => {
10131012 // Signal won't get delviered. Just clean up.
10141013 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);
10161015 },
10171016 else => |errno| return posix.unexpectedErrno(errno),
10181017 }