[KERNEL][TEST] Print informative message on test fail.

git-svn-id: svn://kolibrios.org@9920 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2023-06-18 13:47:38 +00:00
parent 82d8c58e1e
commit 8b6c817da7
2 changed files with 35 additions and 15 deletions

View File

@ -12,6 +12,7 @@ import urllib.request
import subprocess import subprocess
from threading import Thread from threading import Thread
import filecmp import filecmp
import traceback
sys.path.append('test') sys.path.append('test')
import common import common
@ -145,6 +146,7 @@ def collect_tests():
def run_tests_serially_thread(test, root_dir): def run_tests_serially_thread(test, root_dir):
errors = []
test_number = 1 test_number = 1
for test in tests: for test in tests:
test_dir = f"{root_dir}/{test}" test_dir = f"{root_dir}/{test}"
@ -154,17 +156,22 @@ def run_tests_serially_thread(test, root_dir):
try: try:
loader = SourceFileLoader("test", f"{test_dir}/test.py") loader = SourceFileLoader("test", f"{test_dir}/test.py")
loader.load_module().run(root_dir, test_dir) loader.load_module().run(root_dir, test_dir)
except common.TestTimeoutException: except common.TestException as exception:
result = "TIMEOUT" result = exception.kind()
except common.TestFailureException: errors.append((test, exception))
result = "FAILURE"
else: else:
result = "SUCCESS" result = "SUCCESS"
finish = timeit.default_timer() finish = timeit.default_timer()
print(f"{result} ({finish - start:.2f} seconds)") print(f"{result} ({finish - start:.2f} seconds)")
test_number += 1 test_number += 1
if len(errors) != 0:
print("Some tests failed:")
for error in errors:
test, exception = error
print(f"\n{test}: {str(exception)}\n\nTraceback:")
traceback.print_tb(exception.__traceback__)
print(f"\nQemu command:\n {exception.cmd()}\n")
def run_tests_serially(tests, root_dir): def run_tests_serially(tests, root_dir):
thread = Thread(target=run_tests_serially_thread, args=(tests, root_dir)) thread = Thread(target=run_tests_serially_thread, args=(tests, root_dir))

View File

@ -21,12 +21,25 @@ def is_linux():
def is_osx(): def is_osx():
return True if sys.platform == "darwin" else False return True if sys.platform == "darwin" else False
class TestTimeoutException(Exception): class TestException(Exception):
pass def __init__(self, error_kind, message, qemu_cmd):
self.error_kind = error_kind
super().__init__(message)
self.qemu_cmd = qemu_cmd
class TestFailureException(Exception): def kind(self):
def __init__(self, message): return self.error_kind
self.message = message
def cmd(self):
return self.qemu_cmd
class TestException_Timeout(TestException):
def __init__(self, message, qemu_cmd):
super().__init__("TIMEOUT", message, qemu_cmd)
class TestException_Failure(TestException):
def __init__(self, message, qemu_cmd):
super().__init__("FAILURE", message, qemu_cmd)
class Qemu: class Qemu:
def __init__(self, popen, debug_log): def __init__(self, popen, debug_log):
@ -34,7 +47,7 @@ class Qemu:
# Qemu needs time to create debug.log file # Qemu needs time to create debug.log file
while not os.path.exists(debug_log) and self.qemu_is_alive(): while not os.path.exists(debug_log) and self.qemu_is_alive():
self.wait(0.250) self.wait(0.250)
self.assert_qemu_not_died("waiting for the debug log file") self.assert_qemu_not_died("waiting for the debug log file creation")
self.debug = open(debug_log, "rb") self.debug = open(debug_log, "rb")
def qemu_is_alive(self): def qemu_is_alive(self):
@ -42,7 +55,7 @@ class Qemu:
def assert_qemu_not_died(self, while_): def assert_qemu_not_died(self, while_):
if not self.qemu_is_alive(): if not self.qemu_is_alive():
raise TestFailureException(f"Qemu has finished while {while_}.") raise TestException_Failure(f"Qemu has finished while {while_}.", ' '.join(self.popen.args))
def wait_for_debug_log(self, needle, timeout = 1): def wait_for_debug_log(self, needle, timeout = 1):
needle = bytes(needle, "utf-8") needle = bytes(needle, "utf-8")
@ -69,7 +82,7 @@ class Qemu:
self.assert_qemu_not_died("waiting for the debug log") self.assert_qemu_not_died("waiting for the debug log")
self.timeout() self.timeout("waiting for the debug log")
def kill(self): def kill(self):
if is_win32(): if is_win32():
@ -78,9 +91,9 @@ class Qemu:
else: else:
os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM) os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM)
def timeout(self): def timeout(self, while_):
self.kill() self.kill()
raise TestTimeoutException() raise TestException_Timeout(while_, ' '.join(self.popen.args))
def wait(self, seconds): def wait(self, seconds):
time.sleep(seconds) time.sleep(seconds)