History

selftests/clone3: skip if clone3() is ENOSYS

If the clone3() syscall is not implemented we should skip the tests.

Christian Brauner committed 6 years ago

Commit 11fde161 parent a019ff34 files · +33 −30Browse files

Unified · Split

4 files
  1. tools/testing/selftests/clone3/clone3.c +1 −0
  2. tools/testing/selftests/clone3/clone3_clear_sighand.c +2 −27
  3. tools/testing/selftests/clone3/clone3_selftests.h +26 −0
  4. tools/testing/selftests/clone3/clone3_set_tid.c +4 −3
tools/testing/selftests/clone3/clone3.c+1−0
@@ -131,6 +131,7 @@ int main(int argc, char *argv[]) · 130 unmodified lines
131 131
132 uid_t uid = getuid();132 uid_t uid = getuid();
133 133
134 test_clone3_supported();
134 ksft_print_header();135 ksft_print_header();
135 ksft_set_plan(17);136 ksft_set_plan(17);
136 137
tools/testing/selftests/clone3/clone3_clear_sighand.c+2−27
@@ -20,32 +20,6 @@ · 19 unmodified lines
20#define CLONE_CLEAR_SIGHAND 0x100000000ULL20#define CLONE_CLEAR_SIGHAND 0x100000000ULL
21#endif21#endif
22 22
23static void test_clone3_supported(void)
24{
25 pid_t pid;
26 struct clone_args args = {};
27
28 if (__NR_clone3 < 0)
29 ksft_exit_skip("clone3() syscall is not supported\n");
30
31 /* Set to something that will always cause EINVAL. */
32 args.exit_signal = -1;
33 pid = sys_clone3(&args, sizeof(args));
34 if (!pid)
35 exit(EXIT_SUCCESS);
36
37 if (pid > 0) {
38 wait(NULL);
39 ksft_exit_fail_msg(
40 "Managed to create child process with invalid exit_signal\n");
41 }
42
43 if (errno == ENOSYS)
44 ksft_exit_skip("clone3() syscall is not supported\n");
45
46 ksft_print_msg("clone3() syscall supported\n");
47}
48
49static void nop_handler(int signo)23static void nop_handler(int signo)
50{24{
51}25}
@@ -145,9 +119,10 @@ static void test_clone3_clear_sighand(void) · 93 unmodified lines
145int main(int argc, char **argv)119int main(int argc, char **argv)
146{120{
147 ksft_print_header();121 ksft_print_header();
122 test_clone3_supported();
123
148 ksft_set_plan(1);124 ksft_set_plan(1);
149 125
150 test_clone3_supported();
151 test_clone3_clear_sighand();126 test_clone3_clear_sighand();
152 127
153 return ksft_exit_pass();128 return ksft_exit_pass();
tools/testing/selftests/clone3/clone3_selftests.h+26−0
@@ -34,4 +34,30 @@ static pid_t sys_clone3(struct clone_args *args, size_t size) · 33 unmodified lines
34 return syscall(__NR_clone3, args, size);34 return syscall(__NR_clone3, args, size);
35}35}
36 36
37static inline void test_clone3_supported(void)
38{
39 pid_t pid;
40 struct clone_args args = {};
41
42 if (__NR_clone3 < 0)
43 ksft_exit_skip("clone3() syscall is not supported\n");
44
45 /* Set to something that will always cause EINVAL. */
46 args.exit_signal = -1;
47 pid = sys_clone3(&args, sizeof(args));
48 if (!pid)
49 exit(EXIT_SUCCESS);
50
51 if (pid > 0) {
52 wait(NULL);
53 ksft_exit_fail_msg(
54 "Managed to create child process with invalid exit_signal\n");
55 }
56
57 if (errno == ENOSYS)
58 ksft_exit_skip("clone3() syscall is not supported\n");
59
60 ksft_print_msg("clone3() syscall supported\n");
61}
62
37#endif /* _CLONE3_SELFTESTS_H */63#endif /* _CLONE3_SELFTESTS_H */
tools/testing/selftests/clone3/clone3_set_tid.c+4−3
@@ -156,12 +156,13 @@ int main(int argc, char *argv[]) · 155 unmodified lines
156 pid_t pid, ns1, ns2, ns3, ns_pid;156 pid_t pid, ns1, ns2, ns3, ns_pid;
157 pid_t set_tid[MAX_PID_NS_LEVEL * 2];157 pid_t set_tid[MAX_PID_NS_LEVEL * 2];
158 158
159 if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
160 ksft_exit_fail_msg("pipe() failed\n");
161
162 ksft_print_header();159 ksft_print_header();
160 test_clone3_supported();
163 ksft_set_plan(29);161 ksft_set_plan(29);
164 162
163 if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
164 ksft_exit_fail_msg("pipe() failed\n");
165
165 f = fopen("/proc/sys/kernel/pid_max", "r");166 f = fopen("/proc/sys/kernel/pid_max", "r");
166 if (f == NULL)167 if (f == NULL)
167 ksft_exit_fail_msg(168 ksft_exit_fail_msg(