selftests/harness: Handle timeouts cleanly
authorKees Cook <keescook@chromium.org>
Fri, 13 Mar 2020 23:12:52 +0000 (16:12 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 26 Mar 2020 21:27:52 +0000 (15:27 -0600)
commitc31801da6e3d7ef6115a0b5af1816a8f7ab120c2
treeade4d820e11857fc1149f9f8c8f13d0289646af5
parentf46f576280595f7c8feba454526b95a54e635798
selftests/harness: Handle timeouts cleanly

When a selftest would timeout before, the program would just fall over
and no accounting of failures would be reported (i.e. it would result in
an incomplete TAP report). Instead, add an explicit SIGALRM handler to
cleanly catch and report the timeout.

Before:

[==========] Running 2 tests from 2 test cases.
[ RUN      ] timeout.finish
[       OK ] timeout.finish
[ RUN      ] timeout.too_long
Alarm clock

After:

[==========] Running 2 tests from 2 test cases.
[ RUN      ] timeout.finish
[       OK ] timeout.finish
[ RUN      ] timeout.too_long
timeout.too_long: Test terminated by timeout
[     FAIL ] timeout.too_long
[==========] 1 / 2 tests passed.
[  FAILED  ]

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/kselftest_harness.h