Subversion Repositories Kolibri OS

Rev

Rev 9250 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9249 Boppan 1
#!/usr/bin/python3
2
# Copyright 2021 KolibriOS Team
3
# Copyright 2021 Nekos Team
4
# Published under MIT License
5
 
6
import os
7
import sys
8
from importlib.machinery import SourceFileLoader
9
import timeit
10
import urllib.request
11
import subprocess
12
 
13
sys.path.append('test')
14
import common
15
 
16
root_dir = os.getcwd()
17
tests = []
18
 
19
def log(s, end = "\n"):
20
    print(s, end = end, flush = True)
21
 
22
def execute(s, mute = False):
23
    mute = ">/dev/null" if mute else ""
24
    code = os.system(f"{s}{mute}")
25
    if code:
26
        print(f"Command returned {code}: \"{s}\"")
27
        exit(-1)
28
 
29
def stage(name, command, mute = False):
30
    print(f"{name}... ", end = "")
31
    execute(command, mute = mute)
32
    print("Done.")
33
 
34
if not os.path.exists("kolibri_test.img"):
35
    if len(sys.argv) == 1:
36
        execute("wget -q --show-progress http://builds.kolibrios.org/eng/data/data/kolibri.img -O kolibri_test.img")
37
    else:
38
        builds = sys.argv[1]
39
        execute(f"cp {builds}/data/data/kolibri.img kolibri_test.img")
40
 
41
# Remove old kernel (may fail if we removed it before so no check here)
42
os.system("mdel -i kolibri_test.img ::kernel.mnt > /dev/null")
43
 
44
# Check free space after kernel remove
45
free_clusters = int(subprocess.check_output("mdu -i kolibri_test.img :: -s", shell=True).split()[-1])
46
floppy_image_clusters = 2880
47
if floppy_image_clusters - free_clusters < 500:
48
    # Remove unuseful files from IMG if lesser than 500 sectors
49
    execute("mdeltree -i kolibri_test.img ::GAMES", mute = True)
50
    execute("mdeltree -i kolibri_test.img ::DEMOS", mute = True)
51
    execute("mdeltree -i kolibri_test.img ::3D", mute = True)
52
 
53
# Build kernel with debug output
54
stage("Building bootbios.bin.pretest",
55
      "fasm -m 65536 -dpretest_build=1 bootbios.asm bootbios.bin.pretest", mute = True)
56
 
57
stage("Building kernel.mnt.pretest",
58
      "fasm -m 65536 -dpretest_build=1 -ddebug_com_base=0xe9 kernel.asm kernel.mnt.pretest", mute = True)
59
 
60
# Put the kernel into IMG
61
execute("mcopy -D o -i kolibri_test.img kernel.mnt.pretest ::kernel.mnt", mute = True)
62
 
63
# Collect tests from test folder (not recursively yet)
64
for test_folder in os.listdir("test"):
65
    test_folder_path = f"test/{test_folder}"
66
    test_file = f"{test_folder_path}/test.py"
67
 
68
    if not os.path.isdir(test_folder_path):
69
        continue
70
 
71
    if os.path.exists(test_file):
72
        tests.append(test_folder_path)
73
 
74
# Execute each test
75
test_number = 1
76
for test in tests:
77
    test_dir = f"{root_dir}/{test}"
78
 
79
    os.chdir(test_dir)
80
    print(f"[{test_number}/{len(tests)}] {test}... ", end = "", flush=True)
81
    start = timeit.default_timer()
82
    try:
83
        SourceFileLoader("test", "test.py").load_module().run()
84
    except common.TestTimeoutException:
85
        result = "TIMEOUT"
86
    except common.TestFailureException:
87
        result = "FAILURE"
88
    else:
89
        result = "SUCCESS"
90
    finish = timeit.default_timer()
91
    print(f"{result} ({finish - start:.2f} seconds)")
92
    os.chdir(root_dir)
93
 
94
    test_number += 1
95