2021-07-12 20:08:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
#
|
2022-01-15 20:50:11 +00:00
|
|
|
# Copyright (c) 2019-2022 Andre Richter <andre.o.richter@gmail.com>
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
require 'English'
|
|
|
|
require_relative 'test'
|
2022-02-15 22:21:37 +00:00
|
|
|
require 'io/wait'
|
2021-07-12 20:08:22 +00:00
|
|
|
|
|
|
|
# A test that only inspects the exit code of the QEMU binary.
|
|
|
|
class ExitCodeTest < Test
|
|
|
|
MAX_WAIT_SECS = 5
|
|
|
|
|
|
|
|
def initialize(qemu_cmd, test_name)
|
|
|
|
super()
|
|
|
|
|
|
|
|
@qemu_cmd = qemu_cmd
|
|
|
|
|
|
|
|
@test_name = test_name
|
|
|
|
@test_description = nil
|
|
|
|
@test_output = []
|
|
|
|
@test_error = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-03-14 20:57:58 +00:00
|
|
|
# override
|
|
|
|
def setup
|
|
|
|
@qemu_serial = IO.popen(@qemu_cmd)
|
|
|
|
end
|
|
|
|
|
|
|
|
# override
|
2021-07-12 20:08:22 +00:00
|
|
|
# Convert the recorded output to an array of lines, and extract the test description.
|
2022-03-14 20:57:58 +00:00
|
|
|
def finish
|
2021-07-12 20:08:22 +00:00
|
|
|
@test_output = @test_output.join.split("\n")
|
|
|
|
@test_description = @test_output.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
# override
|
|
|
|
def run_concrete_test
|
|
|
|
Timeout.timeout(MAX_WAIT_SECS) do
|
2022-02-15 22:21:37 +00:00
|
|
|
@test_output << @qemu_serial.read_nonblock(1024) while @qemu_serial.wait_readable
|
2021-07-12 20:08:22 +00:00
|
|
|
end
|
|
|
|
rescue EOFError
|
|
|
|
@qemu_serial.close
|
|
|
|
@test_error = $CHILD_STATUS.to_i.zero? ? false : 'QEMU exit status != 0'
|
|
|
|
rescue Timeout::Error
|
|
|
|
@test_error = 'Timed out waiting for test'
|
|
|
|
rescue StandardError => e
|
2022-03-14 20:57:58 +00:00
|
|
|
@test_error = e.inspect
|
2021-07-12 20:08:22 +00:00
|
|
|
end
|
|
|
|
end
|