]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kselftest/arm64: Allow signals tests to specify an expected si_code
authorMark Brown <broonie@kernel.org>
Tue, 1 Oct 2024 22:59:11 +0000 (23:59 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 4 Oct 2024 11:04:43 +0000 (12:04 +0100)
Currently we ignore si_code unless the expected signal is a SIGSEGV, in
which case we enforce it being SEGV_ACCERR. Allow test cases to specify
exactly which si_code should be generated so we can validate this, and
test for other segfault codes.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20241001-arm64-gcs-v13-32-222b78d87eee@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
tools/testing/selftests/arm64/signal/test_signals.h
tools/testing/selftests/arm64/signal/test_signals_utils.c

index 7ada43688c0240acbcd175e594aaf04b1fd12af9..ee75a2c25ce7e7fe5eb69d60c23f793d926ed517 100644 (file)
@@ -71,6 +71,10 @@ struct tdescr {
         * Zero when no signal is expected on success
         */
        int                     sig_ok;
+       /*
+        * expected si_code for sig_ok, or 0 to not check
+        */
+       int                     sig_ok_code;
        /* signum expected on unsupported CPU features. */
        int                     sig_unsupp;
        /* a timeout in second for test completion */
index dcc49e3ce1ebe7666c33dcb54d977a412bbfe9e8..5d3621921cfedf2d009890ce23569ad2b6df415f 100644 (file)
@@ -143,16 +143,25 @@ static bool handle_signal_ok(struct tdescr *td,
                        "current->token ZEROED...test is probably broken!\n");
                abort();
        }
-       /*
-        * Trying to narrow down the SEGV to the ones generated by Kernel itself
-        * via arm64_notify_segfault(). This is a best-effort check anyway, and
-        * the si_code check may need to change if this aspect of the kernel
-        * ABI changes.
-        */
-       if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) {
-               fprintf(stdout,
-                       "si_code != SEGV_ACCERR...test is probably broken!\n");
-               abort();
+       if (td->sig_ok_code) {
+               if (si->si_code != td->sig_ok_code) {
+                       fprintf(stdout, "si_code is %d not %d\n",
+                               si->si_code, td->sig_ok_code);
+                       abort();
+               }
+       } else {
+               /*
+                * Trying to narrow down the SEGV to the ones
+                * generated by Kernel itself via
+                * arm64_notify_segfault(). This is a best-effort
+                * check anyway, and the si_code check may need to
+                * change if this aspect of the kernel ABI changes.
+                */
+               if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) {
+                       fprintf(stdout,
+                               "si_code != SEGV_ACCERR...test is probably broken!\n");
+                       abort();
+               }
        }
        td->pass = 1;
        /*