Skip to content

Commit bb91c0c

Browse files
bonzinishuahkh
authored andcommitted
selftests: pidfd: do not use ksft_exit_skip after ksft_set_plan
Calling ksft_exit_skip after ksft_set_plan results in executing fewer tests than planned. Use ksft_test_result_skip instead. The plan passed to ksft_set_plan was wrong, too, so fix it while at it. Acked-by: Christian Brauner <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 0ef67a8 commit bb91c0c

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tools/testing/selftests/pidfd/pidfd_test.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <sched.h>
99
#include <signal.h>
1010
#include <stdio.h>
11+
#include <stdbool.h>
1112
#include <stdlib.h>
1213
#include <string.h>
1314
#include <syscall.h>
@@ -27,6 +28,8 @@
2728

2829
#define MAX_EVENTS 5
2930

31+
static bool have_pidfd_send_signal;
32+
3033
static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *))
3134
{
3235
size_t stack_size = 1024;
@@ -56,6 +59,13 @@ static int test_pidfd_send_signal_simple_success(void)
5659
int pidfd, ret;
5760
const char *test_name = "pidfd_send_signal send SIGUSR1";
5861

62+
if (!have_pidfd_send_signal) {
63+
ksft_test_result_skip(
64+
"%s test: pidfd_send_signal() syscall not supported\n",
65+
test_name);
66+
return 0;
67+
}
68+
5969
pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC);
6070
if (pidfd < 0)
6171
ksft_exit_fail_msg(
@@ -86,6 +96,13 @@ static int test_pidfd_send_signal_exited_fail(void)
8696
pid_t pid;
8797
const char *test_name = "pidfd_send_signal signal exited process";
8898

99+
if (!have_pidfd_send_signal) {
100+
ksft_test_result_skip(
101+
"%s test: pidfd_send_signal() syscall not supported\n",
102+
test_name);
103+
return 0;
104+
}
105+
89106
pid = fork();
90107
if (pid < 0)
91108
ksft_exit_fail_msg("%s test: Failed to create new process\n",
@@ -137,6 +154,13 @@ static int test_pidfd_send_signal_recycled_pid_fail(void)
137154
pid_t pid1;
138155
const char *test_name = "pidfd_send_signal signal recycled pid";
139156

157+
if (!have_pidfd_send_signal) {
158+
ksft_test_result_skip(
159+
"%s test: pidfd_send_signal() syscall not supported\n",
160+
test_name);
161+
return 0;
162+
}
163+
140164
ret = unshare(CLONE_NEWPID);
141165
if (ret < 0)
142166
ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n",
@@ -325,15 +349,17 @@ static int test_pidfd_send_signal_syscall_support(void)
325349

326350
ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0);
327351
if (ret < 0) {
328-
if (errno == ENOSYS)
329-
ksft_exit_skip(
352+
if (errno == ENOSYS) {
353+
ksft_test_result_skip(
330354
"%s test: pidfd_send_signal() syscall not supported\n",
331355
test_name);
332-
356+
return 0;
357+
}
333358
ksft_exit_fail_msg("%s test: Failed to send signal\n",
334359
test_name);
335360
}
336361

362+
have_pidfd_send_signal = true;
337363
close(pidfd);
338364
ksft_test_result_pass(
339365
"%s test: pidfd_send_signal() syscall is supported. Tests can be executed\n",
@@ -521,7 +547,7 @@ static void test_pidfd_poll_leader_exit(int use_waitpid)
521547
int main(int argc, char **argv)
522548
{
523549
ksft_print_header();
524-
ksft_set_plan(4);
550+
ksft_set_plan(8);
525551

526552
test_pidfd_poll_exec(0);
527553
test_pidfd_poll_exec(1);

0 commit comments

Comments
 (0)