[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:
parent
82d8c58e1e
commit
8b6c817da7
@ -12,6 +12,7 @@ import urllib.request
|
||||
import subprocess
|
||||
from threading import Thread
|
||||
import filecmp
|
||||
import traceback
|
||||
|
||||
sys.path.append('test')
|
||||
import common
|
||||
@ -145,6 +146,7 @@ def collect_tests():
|
||||
|
||||
|
||||
def run_tests_serially_thread(test, root_dir):
|
||||
errors = []
|
||||
test_number = 1
|
||||
for test in tests:
|
||||
test_dir = f"{root_dir}/{test}"
|
||||
@ -154,17 +156,22 @@ def run_tests_serially_thread(test, root_dir):
|
||||
try:
|
||||
loader = SourceFileLoader("test", f"{test_dir}/test.py")
|
||||
loader.load_module().run(root_dir, test_dir)
|
||||
except common.TestTimeoutException:
|
||||
result = "TIMEOUT"
|
||||
except common.TestFailureException:
|
||||
result = "FAILURE"
|
||||
except common.TestException as exception:
|
||||
result = exception.kind()
|
||||
errors.append((test, exception))
|
||||
else:
|
||||
result = "SUCCESS"
|
||||
finish = timeit.default_timer()
|
||||
print(f"{result} ({finish - start:.2f} seconds)")
|
||||
|
||||
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):
|
||||
thread = Thread(target=run_tests_serially_thread, args=(tests, root_dir))
|
||||
|
@ -21,12 +21,25 @@ def is_linux():
|
||||
def is_osx():
|
||||
return True if sys.platform == "darwin" else False
|
||||
|
||||
class TestTimeoutException(Exception):
|
||||
pass
|
||||
class TestException(Exception):
|
||||
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 __init__(self, message):
|
||||
self.message = message
|
||||
def kind(self):
|
||||
return self.error_kind
|
||||
|
||||
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:
|
||||
def __init__(self, popen, debug_log):
|
||||
@ -34,7 +47,7 @@ class Qemu:
|
||||
# Qemu needs time to create debug.log file
|
||||
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.assert_qemu_not_died("waiting for the debug log file creation")
|
||||
self.debug = open(debug_log, "rb")
|
||||
|
||||
def qemu_is_alive(self):
|
||||
@ -42,7 +55,7 @@ class Qemu:
|
||||
|
||||
def assert_qemu_not_died(self, while_):
|
||||
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):
|
||||
needle = bytes(needle, "utf-8")
|
||||
@ -69,7 +82,7 @@ class Qemu:
|
||||
|
||||
self.assert_qemu_not_died("waiting for the debug log")
|
||||
|
||||
self.timeout()
|
||||
self.timeout("waiting for the debug log")
|
||||
|
||||
def kill(self):
|
||||
if is_win32():
|
||||
@ -78,9 +91,9 @@ class Qemu:
|
||||
else:
|
||||
os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM)
|
||||
|
||||
def timeout(self):
|
||||
def timeout(self, while_):
|
||||
self.kill()
|
||||
raise TestTimeoutException()
|
||||
raise TestException_Timeout(while_, ' '.join(self.popen.args))
|
||||
|
||||
def wait(self, seconds):
|
||||
time.sleep(seconds)
|
||||
|
Loading…
Reference in New Issue
Block a user