Skip to content

Commit

Permalink
Fail test run when QEMU fails too quickly
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Feb 1, 2024
1 parent 0d3f735 commit 28a0754
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/setupmanagers/qemuhck/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
module AutoHCK
# A custom QemuHCKError error exception
class QemuHCKError < SetupManagerError; end

class QemuRunError < QemuHCKError; end
end
16 changes: 15 additions & 1 deletion lib/setupmanagers/qemuhck/qemu_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 28a0754

Please sign in to comment.