[KERNEL][TEST] Make it run on Windows

git-svn-id: svn://kolibrios.org@9319 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2021-11-26 15:42:19 +00:00
parent 3d9d07ba7c
commit 18562cd78f

View File

@ -4,13 +4,24 @@
import io import io
import os import os
import sys
import subprocess import subprocess
import timeit import timeit
import time import time
import shlex import shlex
import signal import signal
import shutil
from . makeflop import Floppy from . makeflop import Floppy
def is_win32():
return True if sys.platform == "win32" else False
def is_linux():
return True if sys.platform == "linux" or sys.platform == "linux2" else False
def is_osx():
return True if sys.platform == "darwin" else False
class TestTimeoutException(Exception): class TestTimeoutException(Exception):
pass pass
@ -24,7 +35,6 @@ class Qemu:
while not os.path.exists("debug.log"): while not os.path.exists("debug.log"):
self.wait() self.wait()
self.debug = open("debug.log", "rb") self.debug = open("debug.log", "rb")
self.monitor_in = open("monitor.pipe.in", "wb")
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")
@ -51,7 +61,11 @@ class Qemu:
self.timeout() self.timeout()
def kill(self): def kill(self):
os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM) if is_win32():
# FIXME: This is shit, isn't there anything better?
subprocess.Popen(f"TASKKILL /F /PID {self.popen.pid} /T", stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL)
else:
os.killpg(os.getpgid(self.popen.pid), signal.SIGTERM)
def failure(self): def failure(self):
self.kill() self.kill()
@ -64,32 +78,41 @@ class Qemu:
def wait(self, seconds = 0.25): def wait(self, seconds = 0.25):
time.sleep(seconds) time.sleep(seconds)
def send_keys(self, keys): def get_file_directory(path):
for key in keys.split(): path = path.replace("\\", "/")
self.send_monitor_command(f"sendkey {key}") if "/" in path:
folder = "/".join(path.split("/")[:-1])
if folder == "":
return "/" # It was a file in the root folder
return folder
else:
return "." # Just a filename, let's return current folder
def take_screenshot(self, fname): def run_qemu():
self.send_monitor_command(f"screendump {fname}") qemu_command = f"qemu-system-i386"
flags = ""
def send_monitor_command(self, command): flags += "-nographic " # Makes it faster
self.monitor_in.write(bytes(command + "\n", "utf-8")) flags += "-debugcon file:debug.log " # 0xe9 port output
self.monitor_in.flush() flags += "-L . " # IDK why it does not work without this
flags += "-m 128 "
def images_diff(self, i0, i1, expect=True): flags += "-drive format=raw,file=../../kolibri_test.img,index=0,if=floppy -boot a "
diff = bool(os.system(f"perceptualdiff {i0} {i1} > /dev/null")) flags += "-vga vmware "
if diff != expect: flags += "-net nic,model=rtl8139 -net user "
self.failure() flags += "-soundhw ac97 "
if is_win32():
qemu_full_path = shutil.which(qemu_command)
qemu_directory = get_file_directory(qemu_full_path)
flags += f"-L {qemu_directory} "
s = f"{qemu_command} {flags}"
if is_win32():
return subprocess.Popen(s, bufsize = 0, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL, shell = True, start_new_session = True)
else:
a = shlex.split(s)
return subprocess.Popen(a, bufsize = 0, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL, start_new_session = True)
def run(): def run():
if os.path.exists("debug.log"): if os.path.exists("debug.log"):
os.remove("debug.log") os.remove("debug.log")
if os.path.exists("monitor.pipe.in"): popen = run_qemu()
os.remove("monitor.pipe.in")
if os.path.exists("monitor.pipe.out"):
os.remove("monitor.pipe.out")
os.system("mkfifo monitor.pipe.in monitor.pipe.out")
s = f"qemu-system-i386 -nographic -monitor pipe:monitor.pipe -debugcon file:debug.log -L . -m 128 -drive format=raw,file=../../kolibri_test.img,index=0,if=floppy -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97"
a = shlex.split(s)
popen = subprocess.Popen(a, bufsize = 0, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL, stdin = subprocess.DEVNULL, start_new_session = True)
return Qemu(popen) return Qemu(popen)