Skip to content

Commit 956573a

Browse files
brooniectmarinas
authored andcommitted
kselftest/arm64: Allow signals tests to specify an expected si_code
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 <[email protected]> Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 0d426f7 commit 956573a

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

tools/testing/selftests/arm64/signal/test_signals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ struct tdescr {
7171
* Zero when no signal is expected on success
7272
*/
7373
int sig_ok;
74+
/*
75+
* expected si_code for sig_ok, or 0 to not check
76+
*/
77+
int sig_ok_code;
7478
/* signum expected on unsupported CPU features. */
7579
int sig_unsupp;
7680
/* a timeout in second for test completion */

tools/testing/selftests/arm64/signal/test_signals_utils.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,25 @@ static bool handle_signal_ok(struct tdescr *td,
143143
"current->token ZEROED...test is probably broken!\n");
144144
abort();
145145
}
146-
/*
147-
* Trying to narrow down the SEGV to the ones generated by Kernel itself
148-
* via arm64_notify_segfault(). This is a best-effort check anyway, and
149-
* the si_code check may need to change if this aspect of the kernel
150-
* ABI changes.
151-
*/
152-
if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) {
153-
fprintf(stdout,
154-
"si_code != SEGV_ACCERR...test is probably broken!\n");
155-
abort();
146+
if (td->sig_ok_code) {
147+
if (si->si_code != td->sig_ok_code) {
148+
fprintf(stdout, "si_code is %d not %d\n",
149+
si->si_code, td->sig_ok_code);
150+
abort();
151+
}
152+
} else {
153+
/*
154+
* Trying to narrow down the SEGV to the ones
155+
* generated by Kernel itself via
156+
* arm64_notify_segfault(). This is a best-effort
157+
* check anyway, and the si_code check may need to
158+
* change if this aspect of the kernel ABI changes.
159+
*/
160+
if (td->sig_ok == SIGSEGV && si->si_code != SEGV_ACCERR) {
161+
fprintf(stdout,
162+
"si_code != SEGV_ACCERR...test is probably broken!\n");
163+
abort();
164+
}
156165
}
157166
td->pass = 1;
158167
/*

0 commit comments

Comments
 (0)