From 28a0754de0a41e62d151a4353a5428042420383d Mon Sep 17 00:00:00 2001 From: Kostiantyn Kostiuk Date: Thu, 25 Jan 2024 14:10:27 +0200 Subject: [PATCH] Fail test run when QEMU fails too quickly Signed-off-by: Kostiantyn Kostiuk --- lib/setupmanagers/qemuhck/exceptions.rb | 2 ++ lib/setupmanagers/qemuhck/qemu_machine.rb | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/setupmanagers/qemuhck/exceptions.rb b/lib/setupmanagers/qemuhck/exceptions.rb index 528e0f1e..5eed1f67 100644 --- a/lib/setupmanagers/qemuhck/exceptions.rb +++ b/lib/setupmanagers/qemuhck/exceptions.rb @@ -6,4 +6,6 @@ module AutoHCK # A custom QemuHCKError error exception class QemuHCKError < SetupManagerError; end + + class QemuRunError < QemuHCKError; end end diff --git a/lib/setupmanagers/qemuhck/qemu_machine.rb b/lib/setupmanagers/qemuhck/qemu_machine.rb index 2dd9cfc6..19c2dc80 100644 --- a/lib/setupmanagers/qemuhck/qemu_machine.rb +++ b/lib/setupmanagers/qemuhck/qemu_machine.rb @@ -89,6 +89,18 @@ def run_qemu(scope) qemu end + def check_fails_too_quickly(status) + if status&.zero? + @first_fail_time = nil + false + elsif @first_fail_time.nil? + @first_fail_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + false + else + Process.clock_gettime(Process::CLOCK_MONOTONIC) - @first_fail_time <= 10 + end + end + def run_vm @machine.dump_config @@ -99,8 +111,10 @@ def run_vm @machine.run_pre_start_commands qemu = run_qemu(scope) - qemu.wait_no_fail + fails_quickly = check_fails_too_quickly(qemu.wait_no_fail.exitstatus) qemu = nil + + raise QemuRunError, 'QEMU fails repeated too quickly' if fails_quickly ensure unless qemu.nil? Process.kill 'KILL', qemu.pid