Skip to content

Commit 12fc9a5

Browse files
committed
tests: explicitly log on signal-induced crashes
Ideally we'd want a general way to include the relevant microvm logs in the test report for any failing tests. Since that's not possible/easy with current framework, at least explicitly include logs for any microvm that is killed by a signal. At the very least this provides visibility into any seccomp failures, and other traps the microvm process might hit during tests. Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 8afe5a4 commit 12fc9a5

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

tests/framework/microvm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,31 @@ def __init__(
144144
# External clone/exec tool, because Python can't into clone
145145
self.bin_cloner_path = bin_cloner_path
146146

147+
# Flag checked in destructor to see abnormal signal-induced crashes.
148+
self.expect_kill_by_signal = False
149+
147150
def kill(self):
148151
"""All clean up associated with this microVM should go here."""
149152
# pylint: disable=subprocess-run-check
150153
if self.logging_thread is not None:
151154
self.logging_thread.stop()
152155

156+
if self.expect_kill_by_signal is False and \
157+
"Shutting down VM after intercepting signal" in self.log_data:
158+
# Too late to assert at this point, pytest will still report the
159+
# test as passed. BUT we can dump full logs for debugging,
160+
# as well as an intentional eye-sore in the test report.
161+
print(self.log_data)
162+
153163
if self._jailer.daemonize:
154164
if self.jailer_clone_pid:
155165
utils.run_cmd(
156166
'kill -9 {}'.format(self.jailer_clone_pid),
157167
ignore_return_code=True)
158168
else:
169+
# Killing screen will send SIGHUP to underlying Firecracker.
170+
# Needed to avoid false positives in case kill() is called again.
171+
self.expect_kill_by_signal = True
159172
utils.run_cmd(
160173
'screen -XS {} kill || true'.format(self._session_name))
161174

tests/integration_tests/functional/test_signals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_generic_signal_handler(test_microvm_with_api, signum):
6767
response = microvm.actions.put(action_type='FlushMetrics')
6868
assert microvm.api_session.is_status_no_content(response.status_code)
6969
else:
70+
microvm.expect_kill_by_signal = True
7071
# Ensure that the process was terminated.
7172
utils.wait_process_termination(firecracker_pid)
7273
msg = 'Shutting down VM after intercepting signal {}'.format(signum)
@@ -119,6 +120,7 @@ def test_sigxfsz_handler(test_microvm_with_api):
119120
except ChildProcessError:
120121
break
121122

123+
microvm.expect_kill_by_signal = True
122124
msg = 'Shutting down VM after intercepting signal 25, code 0'
123125
microvm.check_log_message(msg)
124126
metric_line = json.loads(metrics_fd.readlines()[0])

tests/integration_tests/security/test_custom_seccomp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def test_failing_filter(test_microvm_with_api):
176176
# Give time for the process to get killed
177177
time.sleep(1)
178178

179+
test_microvm.expect_kill_by_signal = True
179180
# Check the logger output
180181
ioctl_num = 16 if platform.machine() == "x86_64" else 29
181182
assert "Shutting down VM after intercepting a bad syscall ({})".format(

0 commit comments

Comments
 (0)