From 82d8c58e1e3ec919b1dfebb376ef640bd01922c7 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Sun, 18 Jun 2023 12:44:38 +0000 Subject: [PATCH] [KERNEL][TEST] Fail on prematurely finished qemu. git-svn-id: svn://kolibrios.org@9919 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/test/common/__init__.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/kernel/trunk/test/common/__init__.py b/kernel/trunk/test/common/__init__.py index 3379710144..4e49940383 100644 --- a/kernel/trunk/test/common/__init__.py +++ b/kernel/trunk/test/common/__init__.py @@ -25,16 +25,25 @@ class TestTimeoutException(Exception): pass class TestFailureException(Exception): - pass + def __init__(self, message): + self.message = message class Qemu: def __init__(self, popen, debug_log): self.popen = popen # Qemu needs time to create debug.log file - while not os.path.exists(debug_log): - self.wait() + while not os.path.exists(debug_log) and self.qemu_is_alive(): + self.wait(0.250) + self.assert_qemu_not_died("waiting for the debug log file") self.debug = open(debug_log, "rb") + def qemu_is_alive(self): + return self.popen.poll() == None + + def assert_qemu_not_died(self, while_): + if not self.qemu_is_alive(): + raise TestFailureException(f"Qemu has finished while {while_}.") + def wait_for_debug_log(self, needle, timeout = 1): needle = bytes(needle, "utf-8") start = timeit.default_timer() @@ -42,6 +51,7 @@ class Qemu: # While no timeout, read and search logs while timeit.default_timer() - start < timeout: + # TODO: Non-blocking read. log += self.debug.read(1) if needle in log: return @@ -57,6 +67,8 @@ class Qemu: if len(log) > len(needle) * 2: log = log[len(needle):] + self.assert_qemu_not_died("waiting for the debug log") + self.timeout() def kill(self): @@ -66,15 +78,11 @@ class Qemu: else: os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM) - def failure(self): - self.kill() - raise TestFailureException() - def timeout(self): self.kill() raise TestTimeoutException() - def wait(self, seconds = 0.25): + def wait(self, seconds): time.sleep(seconds) def run_qemu(root_dir, test_dir, debug_log):