-
Notifications
You must be signed in to change notification settings - Fork 206
kill: implement an option for trigger kernel oom killer #362
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
Changes from 3 commits
ad4478a
ed58978
65054d4
4efb492
717121e
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 |
|---|---|---|
|
|
@@ -405,3 +405,38 @@ func Benchmark_parse_proc_pid_stat(b *testing.B) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| func TestTriggerKernelOomKiller_Dryrun(t *testing.T) { | ||
| // Test dryrun mode - should check permission and return 0 if has permission | ||
| // or -1 if no permission (even in dryrun mode) | ||
| args := poll_loop_args_t_with_kernel_oom(false, true, true) | ||
|
|
||
| res := trigger_kernel_oom_killer(args) | ||
|
|
||
| // If running as root, should have permission and return 0 | ||
| // If not root, should return -1 (permission denied) | ||
| if os.Getuid() == 0 { | ||
|
Owner
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. This check does not work in a container (and in github actions). I suggest you do
Contributor
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. Done. I have swithed to |
||
| if res != 0 { | ||
| t.Errorf("dryrun mode as root should return 0, got %d", res) | ||
| } | ||
| } else { | ||
| if res != -1 { | ||
| t.Errorf("dryrun mode as non-root should return -1 (permission denied), got %d", res) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestTriggerKernelOomKiller_NonRoot(t *testing.T) { | ||
| // Non-root user test should fail (permission denied) | ||
| if os.Getuid() == 0 { | ||
| t.Skip("Skipping test that requires non-root user") | ||
| } | ||
|
|
||
| args := poll_loop_args_t_with_kernel_oom(false, true, false) | ||
|
|
||
| res := trigger_kernel_oom_killer(args) | ||
| // Expect -1 (permission denied, cannot open /proc/sysrq-trigger) | ||
| if res != -1 { | ||
| t.Errorf("Expected -1 for non-root user, got %d", res) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.