Skip to content

Commit

Permalink
test: handle exiting via signal as a failure regardless of assertCmd …
Browse files Browse the repository at this point in the history
…type

Currently, assertCmdFalse only checks that a command exited with a
nonzero return code, but not WHY it returned nonzero. That means, this
assert is perfectly happy with a command exiting with SIGSEGV, passing
the test.

This commit changes two things:
 1. check for exit via a signal
 2. force ASAN to abort on error, causing an exit via SIGABRT

This way, SIGSEGVs should be caught on assertCmdFalse cases, meaning that
we should be asserting that our command handles invalid input correctly
instead of crashing. ASAN needs to specifically be configured to abort,
otherwise it will return a nonzero return code that might just be picked
up as a "correct error" by mistake.

Signed-off-by: Eric Richter <[email protected]>
  • Loading branch information
erichte-ibm authored and nick-child-ibm committed Feb 6, 2024
1 parent b008dc7 commit 5c45a35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ GNUTLS = 0
HOST_BACKEND = 1
GUEST_BACKEND = 1

export ASAN_OPTIONS = abort_on_error=1

define test_host
@$(py) host_tests.py
@$(py) host_generate_tests.py
Expand Down
7 changes: 6 additions & 1 deletion test/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import subprocess
import os
import signal

SECTOOLS = os.environ.get("SECVAR_TOOL", "../bin/secvarctl-dbg")
SECVARPATH = "/sys/firmware/secvar/vars/"
Expand Down Expand Up @@ -31,7 +32,11 @@ def command(self, args):
print(f"Error in command '{' '.join(args)}")
raise e

return CommandOutput(out)
ret = CommandOutput(out)
if out.returncode < 0:
sig = signal.Signals(-out.returncode).name
self.assertTrue(out.returncode >= 0, msg=f"Command exited via signal {sig}: '{' '.join(args)}'\n{ret}'")
return ret

def assertCmd(self, args, expected: bool):
tmp_assert, msg = {
Expand Down

0 comments on commit 5c45a35

Please sign in to comment.