-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add 0 to SIG enum #26012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 0 to SIG enum #26012
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const std = @import("std"); | ||
| const posix = std.posix; | ||
|
|
||
| pub fn main() !void { | ||
| try test_kill_zero_self_should_succeed(); | ||
| try test_kill_nonexistent(); | ||
| } | ||
|
|
||
| fn test_kill_nonexistent() !void { | ||
| const impossible_pid: posix.pid_t = 1_999_999_999; | ||
| posix.kill(impossible_pid, .INVAL) catch |err| switch (err) { | ||
| posix.KillError.ProcessNotFound => return, | ||
| else => return err, | ||
| }; | ||
| return error.ProcessShouldHaveNotBeenFound; | ||
| } | ||
|
Comment on lines
11
to
18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All it takes is a write to Unless you can come up with a non-flaky and portable way of obtaining a truly "impossible" PID, this part of the test can't be merged.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think you might be wrong. There appears to be a constant in linux PID_MAX_LIMIT which limits that number to somewhere around 4 million. https://github.com/torvalds/linux/blob/master/include/linux/threads.h#L34 Attempting
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have the test if it's only enabled for operating systems on which it can be verified that the PID is in fact impossible. We have a pretty strict "no flaky tests" policy.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have limited the test to linux (limited by the constant) and macos (results of searching generally agree on a non-configurable and verifiable number) I have also excluded windows from the test because it apparently does not have
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given this is testing Zig's handling of the error path (vs. testing the OS's error path), it seems sufficient (and safe) to make this a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies, github didn't show me your most recent update, which basically does what I suggested, plus MacOS.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, I have already limited to linux and macos. both of which I am confident of never being able to hit the PID limit, if that is fine?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same, same :D That is resolved than. |
||
|
|
||
| fn test_kill_zero_self_should_succeed() !void { | ||
| try posix.kill(posix.getpid(), .INVAL); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use
std.testing.expectError()here to simplify a bit:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll have to inspect std.testing more.