From 32c05a3034f84ab383c3d1eb8de32084db1dcda4 Mon Sep 17 00:00:00 2001 From: Eric Richter Date: Wed, 10 Jan 2024 14:56:59 -0600 Subject: [PATCH] test: handle exiting via signal as a failure regardless of assertCmd 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 --- test/Makefile | 2 ++ test/common.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index f4bca7d0..e4d81c13 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/common.py b/test/common.py index bd606444..a04b7310 100644 --- a/test/common.py +++ b/test/common.py @@ -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/" @@ -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 = {