Limit test to OS with known maximum PID. Omit windows from kill 0 test

This commit is contained in:
psznm 2025-11-24 20:26:59 +01:00
parent 2f738eb877
commit cdb85b2c87

View file

@ -1,5 +1,7 @@
const std = @import("std");
const posix = std.posix;
const builtin = @import("builtin");
const native_os = builtin.target.os.tag;
pub fn main() !void {
try test_kill_zero_self_should_succeed();
@ -7,6 +9,10 @@ pub fn main() !void {
}
fn test_kill_nonexistent() !void {
if ((native_os != .linux) and (native_os != .macos)) return;
// Linux is limited by PID_MAX_LIMIT constant which is around 4 million
// MacOS maximum pid appears to be 99999 and not configurable.
// Others are unknown thus not tested.
const impossible_pid: posix.pid_t = 1_999_999_999;
posix.kill(impossible_pid, .INVAL) catch |err| switch (err) {
posix.KillError.ProcessNotFound => return,
@ -16,5 +22,7 @@ fn test_kill_nonexistent() !void {
}
fn test_kill_zero_self_should_succeed() !void {
// Windows does not have kill -0 equivalent
if (native_os == .windows) return;
try posix.kill(posix.getpid(), .INVAL);
}