Skip to content

Commit 11fde16

Browse files
author
Christian Brauner
committed
selftests/clone3: skip if clone3() is ENOSYS
If the clone3() syscall is not implemented we should skip the tests. Fixes: 41585bb ("selftests: add tests for clone3() with *set_tid") Fixes: 17a8106 ("selftests: add tests for clone3()") Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent a019ff3 commit 11fde16

4 files changed

Lines changed: 33 additions & 30 deletions

File tree

tools/testing/selftests/clone3/clone3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])
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

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,6 @@
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)
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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,30 @@ static pid_t sys_clone3(struct clone_args *args, size_t size)
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,13 @@ int main(int argc, char *argv[])
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(

0 commit comments

Comments
 (0)