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
131131
132132 uid_t uid = getuid();
133133
134+ test_clone3_supported();
134135 ksft_print_header();
135136 ksft_set_plan(17);
136137
tools/testing/selftests/clone3/clone3_clear_sighand.c+2−27
@@ -20,32 +20,6 @@ · 19 unmodified lines
2020 #define CLONE_CLEAR_SIGHAND 0x100000000ULL
2121 #endif
2222
23−static 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−
4923 static void nop_handler(int signo)
5024 {
5125 }
@@ -145,9 +119,10 @@ static void test_clone3_clear_sighand(void) · 93 unmodified lines
145119 int main(int argc, char **argv)
146120 {
147121 ksft_print_header();
122+ test_clone3_supported();
123+
148124 ksft_set_plan(1);
149125
150− test_clone3_supported();
151126 test_clone3_clear_sighand();
152127
153128 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
3434 return syscall(__NR_clone3, args, size);
3535 }
3636
37+static 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+
3763 #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
156156 pid_t pid, ns1, ns2, ns3, ns_pid;
157157 pid_t set_tid[MAX_PID_NS_LEVEL * 2];
158158
159− if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
160− ksft_exit_fail_msg("pipe() failed\n");
161−
162159 ksft_print_header();
160+ test_clone3_supported();
163161 ksft_set_plan(29);
164162
163+ if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
164+ ksft_exit_fail_msg("pipe() failed\n");
165+
165166 f = fopen("/proc/sys/kernel/pid_max", "r");
166167 if (f == NULL)
167168 ksft_exit_fail_msg(