selftests/powerpc: Don't rely on segfault to rerun the test
authorGustavo Luiz Duarte <gustavold@linux.ibm.com>
Tue, 11 Feb 2020 03:38:31 +0000 (00:38 -0300)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 25 Mar 2020 01:06:30 +0000 (12:06 +1100)
commit0f8f554e5244f56f496b4ce30ada1126fe290345
tree74666d64331a65f96e26716957162f185e777553
parent915b7f6f9a5e232c138bb36743a1fdb0fcf2c432
selftests/powerpc: Don't rely on segfault to rerun the test

The test case tm-signal-context-force-tm expects a segfault to happen
on returning from signal handler, and then does a setcontext() to run
the test again. However, the test doesn't always segfault, causing the
test to run a single time.

This patch fixes the test by putting it within a loop and jumping, via
setcontext, just prior to the loop in case it segfaults. This way we
get the desired behavior (run the test COUNT_MAX times) regardless if
it segfaults or not. This also reduces the use of setcontext for
control flow logic, keeping it only in the segfault handler.

Also, since 'count' is changed within the signal handler, it is
declared as volatile to prevent any compiler optimization getting
confused with asynchronous changes.

Signed-off-by: Gustavo Luiz Duarte <gustavold@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200211033831.11165-3-gustavold@linux.ibm.com
tools/testing/selftests/powerpc/tm/tm-signal-context-force-tm.c