[KERNEL][TEST][runtests.py] Conform PEP8 except import

git-svn-id: svn://kolibrios.org@9409 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Magomed Kostoev (mkostoevr) 2021-12-07 20:02:15 +00:00
parent 6aea287961
commit 0954251dbc

View File

@ -18,29 +18,35 @@ import common
use_umka = False use_umka = False
def log(s, end = "\n"):
print(s, end = end, flush = True)
def execute(s, mute = False): def log(s, end="\n"):
print(s, end=end, flush=True)
def execute(s, mute=False):
mute = ">/dev/null" if mute else "" mute = ">/dev/null" if mute else ""
code = os.system(f"{s}{mute}") code = os.system(f"{s}{mute}")
if code: if code:
print(f"Command returned {code}: \"{s}\"") print(f"Command returned {code}: \"{s}\"")
exit(-1) exit(-1)
def stage(name, command, mute = False):
print(f"{name}... ", end = "") def stage(name, command, mute=False):
execute(command, mute = mute) print(f"{name}... ", end="")
execute(command, mute=mute)
print("Done.") print("Done.")
def download(link, path): def download(link, path):
log(f"Downloading {path}... ", end = "") log(f"Downloading {path}... ", end="")
urllib.request.urlretrieve(link, path) urllib.request.urlretrieve(link, path)
log("Done.") log("Done.")
def tool_exists(name): def tool_exists(name):
assert(type(name) == str) assert(type(name) == str)
return which(name) != None return which(name) is not None
def check_tools(tools): def check_tools(tools):
assert(type(tools) == tuple) assert(type(tools) == tuple)
@ -69,7 +75,8 @@ def check_tools(tools):
max_name_len = len(name) max_name_len = len(name)
def draw_row(name, package): def draw_row(name, package):
log(f" | {name.ljust(max_name_len)} | {package.ljust(max_package_name_len)} |") log((f" | {name.ljust(max_name_len)}" +
f" | {package.ljust(max_package_name_len)} |"))
def draw_line(): def draw_line():
log(f" +-{'-' * max_name_len}-+-{'-' * max_package_name_len}-+") log(f" +-{'-' * max_name_len}-+-{'-' * max_package_name_len}-+")
@ -82,12 +89,14 @@ def check_tools(tools):
draw_line() draw_line()
exit() exit()
def prepare_test_img(): def prepare_test_img():
# TODO: Always recompile the kernel (after build system is done?) # TODO: Always recompile the kernel (after build system is done?)
# Get IMG # Get IMG
if not os.path.exists("kolibri_test.img"): if not os.path.exists("kolibri_test.img"):
if len(sys.argv) == 1: if len(sys.argv) == 1:
download("http://builds.kolibrios.org/eng/data/data/kolibri.img", "kolibri_test.img") download("http://builds.kolibrios.org/eng/data/data/kolibri.img",
"kolibri_test.img")
else: else:
builds_eng = sys.argv[1] builds_eng = sys.argv[1]
execute(f"cp {builds_eng}/data/data/kolibri.img kolibri_test.img") execute(f"cp {builds_eng}/data/data/kolibri.img kolibri_test.img")
@ -108,10 +117,16 @@ def prepare_test_img():
with open("lang.inc", "w") as lang_inc: with open("lang.inc", "w") as lang_inc:
lang_inc.write("lang fix en\n") lang_inc.write("lang fix en\n")
execute("fasm bootbios.asm bootbios.bin.pretest -dpretest_build=1") execute("fasm bootbios.asm bootbios.bin.pretest -dpretest_build=1")
execute("fasm -m 65536 kernel.asm kernel.mnt.pretest -dpretest_build=1 -ddebug_com_base=0xe9") command = "fasm "
command += "-dpretest_build=1 -ddebug_com_base=0xe9 "
command += "-m 65536 "
command += "kernel.asm kernel.mnt.pretest"
execute(command)
else: else:
builds_eng = sys.argv[1] builds_eng = sys.argv[1]
execute(f"cp {builds_eng}/data/kernel/trunk/kernel.mnt.pretest kernel.mnt.pretest", mute = True) kernel_mnt_pretest_subpath = "data/kernel/trunk/kernel.mnt.pretest"
kernel_mnt_pretest = f"{builds_eng}/{kernel_mnt_pretest_subpath}"
execute(f"cp {kernel_mnt_pretest} kernel.mnt.pretest", mute=True)
# Put the kernel into IMG # Put the kernel into IMG
with open("kernel.mnt.pretest", "rb") as kernel_mnt_pretest: with open("kernel.mnt.pretest", "rb") as kernel_mnt_pretest:
@ -119,6 +134,7 @@ def prepare_test_img():
img.add_file_path("KERNEL.MNT", kernel_mnt_pretest_data) img.add_file_path("KERNEL.MNT", kernel_mnt_pretest_data)
img.save("kolibri_test.img") img.save("kolibri_test.img")
def collect_tests(): def collect_tests():
tests = [] tests = []
@ -134,15 +150,17 @@ def collect_tests():
tests.append(test_folder_path) tests.append(test_folder_path)
return tests return tests
def run_tests_serially_thread(test, root_dir): def run_tests_serially_thread(test, root_dir):
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}"
print(f"[{test_number}/{len(tests)}] {test}... ", end = "", flush=True) print(f"[{test_number}/{len(tests)}] {test}... ", end="", flush=True)
start = timeit.default_timer() start = timeit.default_timer()
try: try:
SourceFileLoader("test", f"{test_dir}/test.py").load_module().run(root_dir, test_dir) loader = SourceFileLoader("test", f"{test_dir}/test.py")
loader.load_module().run(root_dir, test_dir)
except common.TestTimeoutException: except common.TestTimeoutException:
result = "TIMEOUT" result = "TIMEOUT"
except common.TestFailureException: except common.TestFailureException:
@ -154,42 +172,56 @@ def run_tests_serially_thread(test, root_dir):
test_number += 1 test_number += 1
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))
thread.start() thread.start()
return thread return thread
def build_umka_asm(object_output_dir): def build_umka_asm(object_output_dir):
umka_o = f"{object_output_dir}/umka.o" umka_o = f"{object_output_dir}/umka.o"
kolibrios_folder = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) kolibri_kernel_trunk_runtests_py = os.path.abspath(__file__)
kolibri_kernel_trunk = os.path.dirname(kolibri_kernel_trunk_runtests_py)
kolibri_kernel = os.path.dirname(kolibri_kernel_trunk)
kolibrios_folder = os.path.dirname(kolibri_kernel)
env = os.environ env = os.environ
libcrash = "programs/develop/libraries/libcrash/hash"
env["INCLUDE"] = "" env["INCLUDE"] = ""
env["INCLUDE"] += f"{kolibrios_folder}/kernel/trunk;" env["INCLUDE"] += f"{kolibrios_folder}/kernel/trunk;"
env["INCLUDE"] += f"{kolibrios_folder}/programs/develop/libraries/libcrash/hash" env["INCLUDE"] += f"{kolibrios_folder}/{libcrash}"
stdout = subprocess.check_output(f"fasm -dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 umka/umka.asm umka/build/umka.o -s umka/build/umka.fas -m 2000000", shell = True, env = env) command = "fasm "
command += "-dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 "
command += "umka/umka.asm umka/build/umka.o -s umka/build/umka.fas "
command += "-m 2000000 "
stdout = subprocess.check_output(command, shell=True, env=env)
print(stdout) print(stdout)
return umka_o return umka_o
def cc(src, obj, include_path): def cc(src, obj, include_path):
command = "clang " command = "clang "
command += "-Wno-everything -std=c11 -g -O0 -fno-pie -m32 -c " command += "-Wno-everything -std=c11 -g -O0 -fno-pie -m32 -masm=intel -c "
command += "-D_FILE_OFFSET_BITS=64 -DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L " command += "-D_FILE_OFFSET_BITS=64 -DNDEBUG -D_POSIX_C_SOURCE=200809L "
command += f"-I {include_path} {src} -o {obj}" command += f"-I {include_path} {src} -o {obj}"
if os.system(command) != 0: if os.system(command) != 0:
exit() exit()
def link(objects): def link(objects):
command = "clang " command = "clang "
command += "-Wno-everything -no-pie -m32 -o umka_shell -static -T umka/umka.ld " command += "-Wno-everything "
command += "-no-pie -m32 -o umka_shell -static -T umka/umka.ld "
command += " ".join(objects) command += " ".join(objects)
if os.system(command) != 0: if os.system(command) != 0:
exit() exit()
def build_umka(): def build_umka():
if not use_umka: if not use_umka:
return return
os.makedirs("umka/build", exist_ok = True) os.makedirs("umka/build", exist_ok=True)
c_sources = [ c_sources = [
"umka_shell.c", "umka_shell.c",
@ -204,18 +236,20 @@ def build_umka():
"util.c", "util.c",
] ]
src_obj_pairs = [ (f"umka/{source}", f"umka/{source}.o") for source in c_sources ] src_obj_pairs = [
(f"umka/{source}", f"umka/{source}.o") for source in c_sources
]
for src, obj in src_obj_pairs: for src, obj in src_obj_pairs:
cc(src, obj, "umka/linux") cc(src, obj, "umka/linux")
umka_o = build_umka_asm("umka/build") umka_o = build_umka_asm("umka/build")
objects = [ obj for src, obj in src_obj_pairs ] + [ umka_o ] objects = [obj for src, obj in src_obj_pairs] + [umka_o]
link(objects) link(objects)
os.chdir("umka/test") os.chdir("umka/test")
for test in [ t for t in os.listdir(".") if t.endswith(".t") ]: for test in [t for t in os.listdir(".") if t.endswith(".t")]:
out_log = f"{test[:-2]}.out.log" out_log = f"{test[:-2]}.out.log"
ref_log = f"{test[:-2]}.ref.log" ref_log = f"{test[:-2]}.ref.log"
cmd_umka = f"../../umka_shell < {test} > {out_log}" cmd_umka = f"../../umka_shell < {test} > {out_log}"
@ -243,4 +277,3 @@ if __name__ == "__main__":
tests = collect_tests() tests = collect_tests()
serial_executor_thread = run_tests_serially(tests, root_dir) serial_executor_thread = run_tests_serially(tests, root_dir)
serial_executor_thread.join() serial_executor_thread.join()