Skip to content

Commit 2a59503

Browse files
committed
Standalone kill test
1 parent 5aff6cd commit 2a59503

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

lib/std/os/plan9.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ pub fn getpid() u32 {
141141
return tos.pid;
142142
}
143143
pub const SIG = struct {
144+
/// Invalid signal. Used in kill to perform checking without sending signal.
145+
pub const INVAL = 0;
144146
/// hangup
145147
pub const HUP = 1;
146148
/// interrupt

lib/std/posix/test.zig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -980,12 +980,3 @@ const CommonOpenFlags = packed struct {
980980
return result;
981981
}
982982
};
983-
984-
test "kill 0 can be used to perform checks of sending signal" {
985-
if (native_os == .wasi) return error.SkipZigTest;
986-
if (native_os == .windows) return error.SkipZigTest;
987-
posix.kill(posix.getpid(), .INVAL) catch |err| switch (err) {
988-
posix.KillError.PermissionDenied => return,
989-
else => return err,
990-
};
991-
}

test/standalone/posix/build.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const cases = [_]Case{
2020
.{
2121
.src_path = "relpaths.zig",
2222
},
23+
.{
24+
.src_path = "kill.zig",
25+
},
2326
};
2427

2528
pub fn build(b: *std.Build) void {

test/standalone/posix/kill.zig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const std = @import("std");
2+
const posix = std.posix;
3+
const builtin = @import("builtin");
4+
5+
const path_max = std.fs.max_path_bytes;
6+
7+
pub fn main() !void {
8+
try test_kill_zero_self_should_succeed();
9+
try test_kill_nonexistent();
10+
}
11+
12+
fn test_kill_nonexistent() !void {
13+
const impossible_pid: posix.pid_t = 1_999_999_999;
14+
posix.kill(impossible_pid, .INVAL) catch |err| switch (err) {
15+
posix.KillError.ProcessNotFound => return,
16+
else => return err,
17+
};
18+
return error.ProcessShouldHaveNotBeenFound;
19+
}
20+
21+
fn test_kill_zero_self_should_succeed() !void {
22+
try posix.kill(posix.getpid(), .INVAL);
23+
}

0 commit comments

Comments
 (0)