selftests/clone3: skip if clone3() is ENOSYS
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 18 Nov 2019 07:49:44 +0000 (08:49 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 18 Nov 2019 07:59:03 +0000 (08:59 +0100)
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>
tools/testing/selftests/clone3/clone3.c
tools/testing/selftests/clone3/clone3_clear_sighand.c
tools/testing/selftests/clone3/clone3_selftests.h
tools/testing/selftests/clone3/clone3_set_tid.c

index 4669b3d418e760c885afcfb5f9a7b0c15081dcb1..f14c269a5a184bc786f66efb6f1fe9ae59b7b1f2 100644 (file)
@@ -131,6 +131,7 @@ int main(int argc, char *argv[])
 
        uid_t uid = getuid();
 
+       test_clone3_supported();
        ksft_print_header();
        ksft_set_plan(17);
 
index 456783ad19d66820b80f35cf8a3a22f79c0b2daa..9e1af8aa769860242aad4ffc84b7c2fa86dbd242 100644 (file)
 #define CLONE_CLEAR_SIGHAND 0x100000000ULL
 #endif
 
-static void test_clone3_supported(void)
-{
-       pid_t pid;
-       struct clone_args args = {};
-
-       if (__NR_clone3 < 0)
-               ksft_exit_skip("clone3() syscall is not supported\n");
-
-       /* Set to something that will always cause EINVAL. */
-       args.exit_signal = -1;
-       pid = sys_clone3(&args, sizeof(args));
-       if (!pid)
-               exit(EXIT_SUCCESS);
-
-       if (pid > 0) {
-               wait(NULL);
-               ksft_exit_fail_msg(
-                       "Managed to create child process with invalid exit_signal\n");
-       }
-
-       if (errno == ENOSYS)
-               ksft_exit_skip("clone3() syscall is not supported\n");
-
-       ksft_print_msg("clone3() syscall supported\n");
-}
-
 static void nop_handler(int signo)
 {
 }
@@ -145,9 +119,10 @@ static void test_clone3_clear_sighand(void)
 int main(int argc, char **argv)
 {
        ksft_print_header();
+       test_clone3_supported();
+
        ksft_set_plan(1);
 
-       test_clone3_supported();
        test_clone3_clear_sighand();
 
        return ksft_exit_pass();
index 0e3dea58855f78b1fb9adc43ebe09cf246137f3c..a3f2c8ad8bcc3a35e6d45090648be2f1b9799816 100644 (file)
@@ -34,4 +34,30 @@ static pid_t sys_clone3(struct clone_args *args, size_t size)
        return syscall(__NR_clone3, args, size);
 }
 
+static inline void test_clone3_supported(void)
+{
+       pid_t pid;
+       struct clone_args args = {};
+
+       if (__NR_clone3 < 0)
+               ksft_exit_skip("clone3() syscall is not supported\n");
+
+       /* Set to something that will always cause EINVAL. */
+       args.exit_signal = -1;
+       pid = sys_clone3(&args, sizeof(args));
+       if (!pid)
+               exit(EXIT_SUCCESS);
+
+       if (pid > 0) {
+               wait(NULL);
+               ksft_exit_fail_msg(
+                       "Managed to create child process with invalid exit_signal\n");
+       }
+
+       if (errno == ENOSYS)
+               ksft_exit_skip("clone3() syscall is not supported\n");
+
+       ksft_print_msg("clone3() syscall supported\n");
+}
+
 #endif /* _CLONE3_SELFTESTS_H */
index c6309f5d7d8834655835762e6e14edab6f9de42c..25beb22f35b50d9affe29feed3cb88df1b0fd757 100644 (file)
@@ -156,12 +156,13 @@ int main(int argc, char *argv[])
        pid_t pid, ns1, ns2, ns3, ns_pid;
        pid_t set_tid[MAX_PID_NS_LEVEL * 2];
 
-       if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
-               ksft_exit_fail_msg("pipe() failed\n");
-
        ksft_print_header();
+       test_clone3_supported();
        ksft_set_plan(29);
 
+       if (pipe(pipe_1) < 0 || pipe(pipe_2) < 0)
+               ksft_exit_fail_msg("pipe() failed\n");
+
        f = fopen("/proc/sys/kernel/pid_max", "r");
        if (f == NULL)
                ksft_exit_fail_msg(