Add a TM test to check that when TM is not advertised by the OS (is disabled) a transaction can not really be started and generates a SIGILL, which is the right behavior in that case.
Signed-off-by: Gustavo Romero <grom...@linux.ibm.com> --- tools/testing/selftests/powerpc/tm/.gitignore | 1 + tools/testing/selftests/powerpc/tm/Makefile | 2 +- tools/testing/selftests/powerpc/tm/tm-no-tm.c | 48 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/tm/tm-no-tm.c diff --git a/tools/testing/selftests/powerpc/tm/.gitignore b/tools/testing/selftests/powerpc/tm/.gitignore index d8900a0..1d23309 100644 --- a/tools/testing/selftests/powerpc/tm/.gitignore +++ b/tools/testing/selftests/powerpc/tm/.gitignore @@ -20,3 +20,4 @@ tm-unavailable tm-trap tm-sigreturn tm-poison +tm-no-tm diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile index 5881e97..756a03f 100644 --- a/tools/testing/selftests/powerpc/tm/Makefile +++ b/tools/testing/selftests/powerpc/tm/Makefile @@ -5,7 +5,7 @@ SIGNAL_CONTEXT_CHK_TESTS := tm-signal-context-chk-gpr tm-signal-context-chk-fpu TEST_GEN_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \ tm-vmxcopy tm-fork tm-tar tm-tmspr tm-vmx-unavail tm-unavailable tm-trap \ $(SIGNAL_CONTEXT_CHK_TESTS) tm-sigreturn tm-signal-sigreturn-nt \ - tm-signal-context-force-tm tm-poison tm-signal-pagefault + tm-signal-context-force-tm tm-poison tm-signal-pagefault tm-no-tm TEST_FILES := settings diff --git a/tools/testing/selftests/powerpc/tm/tm-no-tm.c b/tools/testing/selftests/powerpc/tm/tm-no-tm.c new file mode 100644 index 0000000..3b83e20 --- /dev/null +++ b/tools/testing/selftests/powerpc/tm/tm-no-tm.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2020, Gustavo Romero, IBM Corp. + * + * This test checks if when TM is not supported by the OS indeed it's not + * possible to start a TM transaction. Moreover, when trying to start a new + * transaction the user gets an illegal instruction, which is the correct + * behavior in that case, instead of any other signal, like SIGSEGV etc. + * + * Since firmware can change the TM instruction behavior in many ways, it's good + * to have a test to check if TM is properly disabled when the OS advertises + * that TM is not available in userspace. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> + +#include "utils.h" +#include "tm.h" + +void illegal_signal_handler(int signo_notused, siginfo_t *si_notused, void *uc_notused) +{ + exit(EXIT_SUCCESS); +} + +int tm_no_tm_test(void) +{ + struct sigaction illegal_sa; + + SKIP_IF(have_htm()); + + illegal_sa.sa_flags = SA_SIGINFO; + illegal_sa.sa_sigaction = illegal_signal_handler; + + sigaction(SIGILL, &illegal_sa, NULL); + + /* It must cause a SIGILL since TM is not supported by the OS */ + asm("tbegin.;"); + + return EXIT_FAILURE; +} + +int main(int argc, char **argv) +{ + return test_harness(tm_no_tm_test, "tm_no_tm_test"); +} -- 2.7.4