selftests/harness: Run TEARDOWN for ASSERT failures
authorKees Cook <keescook@chromium.org>
Thu, 24 Mar 2022 23:19:06 +0000 (16:19 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 4 Apr 2022 19:37:37 +0000 (13:37 -0600)
commit63e6b2a42342c3297cce286fb124c99be9e0f3fd
treef59175e765c1ba913867f02ea66334d3ab1dc685
parent187816d07729ff88e75d84efbc668642106cebf3
selftests/harness: Run TEARDOWN for ASSERT failures

The kselftest test harness has traditionally not run the registered
TEARDOWN handler when a test encountered an ASSERT. This creates
unexpected situations and tests need to be very careful about using
ASSERT, which seems a needless hurdle for test writers.

Because of the harness's design for optional failure handlers, the
original implementation of ASSERT used an abort() to immediately
stop execution, but that meant the context for running teardown was
lost. Instead, use setjmp/longjmp so that teardown can be done.

Failed SETUP routines continue to not be followed by TEARDOWN, though.

Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/kselftest_harness.h