Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/clone3: skip if clone3() is ENOSYS

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

Fixes: 41585bbeeef9 ("selftests: add tests for clone3() with *set_tid")
Fixes: 17a810699c18 ("selftests: add tests for clone3()")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

+33 -30
+1
tools/testing/selftests/clone3/clone3.c
··· 131 131 132 132 uid_t uid = getuid(); 133 133 134 + test_clone3_supported(); 134 135 ksft_print_header(); 135 136 ksft_set_plan(17); 136 137
+2 -27
tools/testing/selftests/clone3/clone3_clear_sighand.c
··· 20 20 #define CLONE_CLEAR_SIGHAND 0x100000000ULL 21 21 #endif 22 22 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 - 49 23 static void nop_handler(int signo) 50 24 { 51 25 } ··· 119 145 int main(int argc, char **argv) 120 146 { 121 147 ksft_print_header(); 148 + test_clone3_supported(); 149 + 122 150 ksft_set_plan(1); 123 151 124 - test_clone3_supported(); 125 152 test_clone3_clear_sighand(); 126 153 127 154 return ksft_exit_pass();
+26
tools/testing/selftests/clone3/clone3_selftests.h
··· 34 34 return syscall(__NR_clone3, args, size); 35 35 } 36 36 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 + 37 63 #endif /* _CLONE3_SELFTESTS_H */
+4 -3
tools/testing/selftests/clone3/clone3_set_tid.c
··· 156 156 pid_t pid, ns1, ns2, ns3, ns_pid; 157 157 pid_t set_tid[MAX_PID_NS_LEVEL * 2]; 158 158 159 + ksft_print_header(); 160 + test_clone3_supported(); 161 + ksft_set_plan(29); 162 + 159 163 if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0) 160 164 ksft_exit_fail_msg("pipe() failed\n"); 161 - 162 - ksft_print_header(); 163 - ksft_set_plan(29); 164 165 165 166 f = fopen("/proc/sys/kernel/pid_max", "r"); 166 167 if (f == NULL)