|
8 | 8 | #include <sched.h> |
9 | 9 | #include <signal.h> |
10 | 10 | #include <stdio.h> |
| 11 | +#include <stdbool.h> |
11 | 12 | #include <stdlib.h> |
12 | 13 | #include <string.h> |
13 | 14 | #include <syscall.h> |
|
27 | 28 |
|
28 | 29 | #define MAX_EVENTS 5 |
29 | 30 |
|
| 31 | +static bool have_pidfd_send_signal; |
| 32 | + |
30 | 33 | static pid_t pidfd_clone(int flags, int *pidfd, int (*fn)(void *)) |
31 | 34 | { |
32 | 35 | size_t stack_size = 1024; |
@@ -56,6 +59,13 @@ static int test_pidfd_send_signal_simple_success(void) |
56 | 59 | int pidfd, ret; |
57 | 60 | const char *test_name = "pidfd_send_signal send SIGUSR1"; |
58 | 61 |
|
| 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 | + |
59 | 69 | pidfd = open("/proc/self", O_DIRECTORY | O_CLOEXEC); |
60 | 70 | if (pidfd < 0) |
61 | 71 | ksft_exit_fail_msg( |
@@ -86,6 +96,13 @@ static int test_pidfd_send_signal_exited_fail(void) |
86 | 96 | pid_t pid; |
87 | 97 | const char *test_name = "pidfd_send_signal signal exited process"; |
88 | 98 |
|
| 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 | + |
89 | 106 | pid = fork(); |
90 | 107 | if (pid < 0) |
91 | 108 | 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) |
137 | 154 | pid_t pid1; |
138 | 155 | const char *test_name = "pidfd_send_signal signal recycled pid"; |
139 | 156 |
|
| 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 | + |
140 | 164 | ret = unshare(CLONE_NEWPID); |
141 | 165 | if (ret < 0) |
142 | 166 | 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) |
325 | 349 |
|
326 | 350 | ret = sys_pidfd_send_signal(pidfd, 0, NULL, 0); |
327 | 351 | if (ret < 0) { |
328 | | - if (errno == ENOSYS) |
329 | | - ksft_exit_skip( |
| 352 | + if (errno == ENOSYS) { |
| 353 | + ksft_test_result_skip( |
330 | 354 | "%s test: pidfd_send_signal() syscall not supported\n", |
331 | 355 | test_name); |
332 | | - |
| 356 | + return 0; |
| 357 | + } |
333 | 358 | ksft_exit_fail_msg("%s test: Failed to send signal\n", |
334 | 359 | test_name); |
335 | 360 | } |
336 | 361 |
|
| 362 | + have_pidfd_send_signal = true; |
337 | 363 | close(pidfd); |
338 | 364 | ksft_test_result_pass( |
339 | 365 | "%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) |
521 | 547 | int main(int argc, char **argv) |
522 | 548 | { |
523 | 549 | ksft_print_header(); |
524 | | - ksft_set_plan(4); |
| 550 | + ksft_set_plan(8); |
525 | 551 |
|
526 | 552 | test_pidfd_poll_exec(0); |
527 | 553 | test_pidfd_poll_exec(1); |
|
0 commit comments