Skip to content

Commit 05790fd

Browse files
bonzinishuahkh
authored andcommitted
selftests: pidfd: skip test if unshare fails with EPERM
Similar to how ENOSYS causes a skip if pidfd_send_signal is not present, we can do the same for unshare if it fails with EPERM. This way, running the test without privileges causes four tests to skip but no early bail out. Acked-by: Christian Brauner <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent bb91c0c commit 05790fd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tools/testing/selftests/pidfd/pidfd_test.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,26 @@ static int test_pidfd_send_signal_recycled_pid_fail(void)
162162
}
163163

164164
ret = unshare(CLONE_NEWPID);
165-
if (ret < 0)
165+
if (ret < 0) {
166+
if (errno == EPERM) {
167+
ksft_test_result_skip("%s test: Unsharing pid namespace not permitted\n",
168+
test_name);
169+
return 0;
170+
}
166171
ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n",
167172
test_name);
173+
}
168174

169175
ret = unshare(CLONE_NEWNS);
170-
if (ret < 0)
171-
ksft_exit_fail_msg(
172-
"%s test: Failed to unshare mount namespace\n",
173-
test_name);
176+
if (ret < 0) {
177+
if (errno == EPERM) {
178+
ksft_test_result_skip("%s test: Unsharing mount namespace not permitted\n",
179+
test_name);
180+
return 0;
181+
}
182+
ksft_exit_fail_msg("%s test: Failed to unshare mount namespace\n",
183+
test_name);
184+
}
174185

175186
ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
176187
if (ret < 0)

0 commit comments

Comments
 (0)