From b61452e9e1547ce4f945b40f1d1fa3f50b114c85 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Sat, 27 Nov 2021 09:46:44 +0000 Subject: [PATCH] [KERNEL][TEST] Make qemu tests position-independent git-svn-id: svn://kolibrios.org@9331 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/runtests.py | 4 +--- kernel/trunk/test/common/__init__.py | 27 ++++++++++++----------- kernel/trunk/test/kernel_revision/test.py | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/kernel/trunk/runtests.py b/kernel/trunk/runtests.py index a1f1012cc2..4fef44110e 100755 --- a/kernel/trunk/runtests.py +++ b/kernel/trunk/runtests.py @@ -150,11 +150,10 @@ def run_tests_serially_thread(test, root_dir): for test in tests: test_dir = f"{root_dir}/{test}" - os.chdir(test_dir) print(f"[{test_number}/{len(tests)}] {test}... ", end = "", flush=True) start = timeit.default_timer() try: - SourceFileLoader("test", "test.py").load_module().run() + SourceFileLoader("test", f"{test_dir}/test.py").load_module().run(root_dir, test_dir) except common.TestTimeoutException: result = "TIMEOUT" except common.TestFailureException: @@ -163,7 +162,6 @@ def run_tests_serially_thread(test, root_dir): result = "SUCCESS" finish = timeit.default_timer() print(f"{result} ({finish - start:.2f} seconds)") - os.chdir(root_dir) test_number += 1 diff --git a/kernel/trunk/test/common/__init__.py b/kernel/trunk/test/common/__init__.py index 2bd1b388f5..13433f1139 100644 --- a/kernel/trunk/test/common/__init__.py +++ b/kernel/trunk/test/common/__init__.py @@ -28,12 +28,12 @@ class TestFailureException(Exception): pass class Qemu: - def __init__(self, popen): + def __init__(self, popen, debug_log): self.popen = popen # Qemu needs time to create debug.log file - while not os.path.exists("debug.log"): + while not os.path.exists(debug_log): self.wait() - self.debug = open("debug.log", "rb") + self.debug = open(debug_log, "rb") def wait_for_debug_log(self, needle, timeout = 1): needle = bytes(needle, "utf-8") @@ -87,14 +87,14 @@ def get_file_directory(path): else: return "." # Just a filename, let's return current folder -def run_qemu(): +def run_qemu(root_dir, test_dir, debug_log): qemu_command = f"qemu-system-i386" flags = "" flags += "-nographic " # Makes it faster - flags += "-debugcon file:debug.log " # 0xe9 port output + flags += f"-debugcon file:{debug_log} " # 0xe9 port output flags += "-L . " # IDK why it does not work without this flags += "-m 128 " - flags += "-drive format=raw,file=../../kolibri_test.img,index=0,if=floppy -boot a " + flags += f"-drive format=raw,file={root_dir}/kolibri_test.img,index=0,if=floppy -boot a " flags += "-vga vmware " flags += "-net nic,model=rtl8139 -net user " flags += "-soundhw ac97 " @@ -103,17 +103,18 @@ def run_qemu(): qemu_directory = get_file_directory(qemu_full_path) flags += f"-L {qemu_directory} " s = f"{qemu_command} {flags}" - qemu_stdout = open("qemu_stdout.log", "w") - qemu_stderr = open("qemu_stderr.log", "w") + qemu_stdout = open(f"{test_dir}/qemu_stdout.log", "w") + qemu_stderr = open(f"{test_dir}/qemu_stderr.log", "w") if is_win32(): return subprocess.Popen(s, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, shell = True, start_new_session = True) else: a = shlex.split(s) return subprocess.Popen(a, bufsize = 0, stdout = qemu_stdout, stderr = qemu_stderr, stdin = subprocess.DEVNULL, start_new_session = True) -def run(): - if os.path.exists("debug.log"): - os.remove("debug.log") - popen = run_qemu() - return Qemu(popen) +def run(root_dir, test_dir): + debug_log = f"{test_dir}/debug.log" + if os.path.exists(debug_log): + os.remove(debug_log) + popen = run_qemu(root_dir, test_dir, debug_log) + return Qemu(popen, debug_log) diff --git a/kernel/trunk/test/kernel_revision/test.py b/kernel/trunk/test/kernel_revision/test.py index a4f6a1609a..9e49dfdfa8 100644 --- a/kernel/trunk/test/kernel_revision/test.py +++ b/kernel/trunk/test/kernel_revision/test.py @@ -4,8 +4,8 @@ import sys sys.path.append('../') import common -def run(): - os = common.run() +def run(root_dir, test_dir): + os = common.run(root_dir, test_dir) os.wait_for_debug_log("K : kernel SVN", timeout = 10) os.kill()