If the clone3() syscall is not implemented we should skip the tests.
Unified · Split
| @@ -131,6 +131,7 @@ int main(int argc, char *argv[]) · 130 unmodified lines | ||
| 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 | |
| @@ -20,32 +20,6 @@ · 19 unmodified lines | ||
| 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 | } |
| @@ -145,9 +119,10 @@ static void test_clone3_clear_sighand(void) · 93 unmodified lines | ||
| 145 | 119 | int main(int argc, char **argv) |
| 146 | 120 | { |
| 147 | 121 | ksft_print_header(); |
| 122 | + test_clone3_supported(); | |
| 123 | + | |
| 148 | 124 | ksft_set_plan(1); |
| 149 | 125 | |
| 150 | − test_clone3_supported(); | |
| 151 | 126 | test_clone3_clear_sighand(); |
| 152 | 127 | |
| 153 | 128 | return ksft_exit_pass(); |
| @@ -34,4 +34,30 @@ static pid_t sys_clone3(struct clone_args *args, size_t size) · 33 unmodified lines | ||
| 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 */ |
| @@ -156,12 +156,13 @@ int main(int argc, char *argv[]) · 155 unmodified lines | ||
| 156 | 156 | pid_t pid, ns1, ns2, ns3, ns_pid; |
| 157 | 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 | 159 | ksft_print_header(); |
| 160 | + test_clone3_supported(); | |
| 163 | 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 | 166 | f = fopen("/proc/sys/kernel/pid_max", "r"); |
| 166 | 167 | if (f == NULL) |
| 167 | 168 | ksft_exit_fail_msg( |