Subversion Repositories Kolibri OS

Rev

Rev 9397 | Rev 9412 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9397 Rev 9409
Line 16... Line 16...
16
sys.path.append('test')
16
sys.path.append('test')
17
import common
17
import common
Line 18... Line 18...
18
 
18
 
Line -... Line 19...
-
 
19
use_umka = False
19
use_umka = False
20
 
20
 
21
 
Line -... Line 22...
-
 
22
def log(s, end="\n"):
21
def log(s, end = "\n"):
23
    print(s, end=end, flush=True)
22
    print(s, end = end, flush = True)
24
 
23
 
25
 
24
def execute(s, mute = False):
26
def execute(s, mute=False):
25
    mute = ">/dev/null" if mute else ""
27
    mute = ">/dev/null" if mute else ""
26
    code = os.system(f"{s}{mute}")
28
    code = os.system(f"{s}{mute}")
Line -... Line 29...
-
 
29
    if code:
27
    if code:
30
        print(f"Command returned {code}: \"{s}\"")
28
        print(f"Command returned {code}: \"{s}\"")
31
        exit(-1)
29
        exit(-1)
32
 
30
 
33
 
Line -... Line 34...
-
 
34
def stage(name, command, mute=False):
31
def stage(name, command, mute = False):
35
    print(f"{name}... ", end="")
32
    print(f"{name}... ", end = "")
36
    execute(command, mute=mute)
33
    execute(command, mute = mute)
37
    print("Done.")
34
    print("Done.")
38
 
Line -... Line 39...
-
 
39
 
35
 
40
def download(link, path):
36
def download(link, path):
41
    log(f"Downloading {path}... ", end="")
37
    log(f"Downloading {path}... ", end = "")
42
    urllib.request.urlretrieve(link, path)
-
 
43
    log("Done.")
Line 38... Line 44...
38
    urllib.request.urlretrieve(link, path)
44
 
39
    log("Done.")
45
 
40
 
46
def tool_exists(name):
41
def tool_exists(name):
47
    assert(type(name) == str)
Line 67... Line 73...
67
                max_package_name_len = len(package)
73
                max_package_name_len = len(package)
68
            if len(name) > max_name_len:
74
            if len(name) > max_name_len:
69
                max_name_len = len(name)
75
                max_name_len = len(name)
Line 70... Line 76...
70
 
76
 
-
 
77
        def draw_row(name, package):
71
        def draw_row(name, package):
78
            log((f" | {name.ljust(max_name_len)}" +
Line 72... Line 79...
72
            log(f" | {name.ljust(max_name_len)} | {package.ljust(max_package_name_len)} |")
79
                 f" | {package.ljust(max_package_name_len)} |"))
73
 
80
 
Line 74... Line 81...
74
        def draw_line():
81
        def draw_line():
Line 80... Line 87...
80
        for name, package in not_exists:
87
        for name, package in not_exists:
81
            draw_row(name, package)
88
            draw_row(name, package)
82
        draw_line()
89
        draw_line()
83
        exit()
90
        exit()
Line -... Line 91...
-
 
91
 
84
 
92
 
85
def prepare_test_img():
93
def prepare_test_img():
86
    # TODO: Always recompile the kernel (after build system is done?)
94
    # TODO: Always recompile the kernel (after build system is done?)
87
    # Get IMG
95
    # Get IMG
88
    if not os.path.exists("kolibri_test.img"):
96
    if not os.path.exists("kolibri_test.img"):
89
        if len(sys.argv) == 1:
97
        if len(sys.argv) == 1:
-
 
98
            download("http://builds.kolibrios.org/eng/data/data/kolibri.img",
90
            download("http://builds.kolibrios.org/eng/data/data/kolibri.img", "kolibri_test.img")
99
                     "kolibri_test.img")
91
        else:
100
        else:
92
            builds_eng = sys.argv[1]
101
            builds_eng = sys.argv[1]
Line 93... Line 102...
93
            execute(f"cp {builds_eng}/data/data/kolibri.img kolibri_test.img")
102
            execute(f"cp {builds_eng}/data/data/kolibri.img kolibri_test.img")
Line 106... Line 115...
106
    if not os.path.exists("kernel.mnt.pretest"):
115
    if not os.path.exists("kernel.mnt.pretest"):
107
        if len(sys.argv) == 1:
116
        if len(sys.argv) == 1:
108
            with open("lang.inc", "w") as lang_inc:
117
            with open("lang.inc", "w") as lang_inc:
109
                lang_inc.write("lang fix en\n")
118
                lang_inc.write("lang fix en\n")
110
            execute("fasm bootbios.asm bootbios.bin.pretest -dpretest_build=1")
119
            execute("fasm bootbios.asm bootbios.bin.pretest -dpretest_build=1")
-
 
120
            command = "fasm "
111
            execute("fasm -m 65536 kernel.asm kernel.mnt.pretest -dpretest_build=1 -ddebug_com_base=0xe9")
121
            command += "-dpretest_build=1 -ddebug_com_base=0xe9 "
-
 
122
            command += "-m 65536 "
-
 
123
            command += "kernel.asm kernel.mnt.pretest"
-
 
124
            execute(command)
112
        else:
125
        else:
113
            builds_eng = sys.argv[1]
126
            builds_eng = sys.argv[1]
-
 
127
            kernel_mnt_pretest_subpath = "data/kernel/trunk/kernel.mnt.pretest"
-
 
128
            kernel_mnt_pretest = f"{builds_eng}/{kernel_mnt_pretest_subpath}"
114
            execute(f"cp {builds_eng}/data/kernel/trunk/kernel.mnt.pretest kernel.mnt.pretest", mute = True)
129
            execute(f"cp {kernel_mnt_pretest} kernel.mnt.pretest", mute=True)
Line 115... Line 130...
115
    
130
 
116
    # Put the kernel into IMG
131
    # Put the kernel into IMG
117
    with open("kernel.mnt.pretest", "rb") as kernel_mnt_pretest:
132
    with open("kernel.mnt.pretest", "rb") as kernel_mnt_pretest:
118
        kernel_mnt_pretest_data = kernel_mnt_pretest.read()
133
        kernel_mnt_pretest_data = kernel_mnt_pretest.read()
119
    img.add_file_path("KERNEL.MNT", kernel_mnt_pretest_data)
134
    img.add_file_path("KERNEL.MNT", kernel_mnt_pretest_data)
Line -... Line 135...
-
 
135
    img.save("kolibri_test.img")
120
    img.save("kolibri_test.img")
136
 
121
 
137
 
Line 122... Line 138...
122
def collect_tests():
138
def collect_tests():
123
    tests = []
139
    tests = []
Line 132... Line 148...
132
 
148
 
133
        if os.path.exists(test_file):
149
        if os.path.exists(test_file):
134
            tests.append(test_folder_path)
150
            tests.append(test_folder_path)
Line -... Line 151...
-
 
151
    return tests
135
    return tests
152
 
136
 
153
 
137
def run_tests_serially_thread(test, root_dir):
154
def run_tests_serially_thread(test, root_dir):
138
    test_number = 1
155
    test_number = 1
Line 139... Line 156...
139
    for test in tests:
156
    for test in tests:
140
        test_dir = f"{root_dir}/{test}"
157
        test_dir = f"{root_dir}/{test}"
141
    
158
 
-
 
159
        print(f"[{test_number}/{len(tests)}] {test}... ", end="", flush=True)
142
        print(f"[{test_number}/{len(tests)}] {test}... ", end = "", flush=True)
160
        start = timeit.default_timer()
143
        start = timeit.default_timer()
161
        try:
144
        try:
162
            loader = SourceFileLoader("test", f"{test_dir}/test.py")
145
            SourceFileLoader("test", f"{test_dir}/test.py").load_module().run(root_dir, test_dir)
163
            loader.load_module().run(root_dir, test_dir)
146
        except common.TestTimeoutException:
164
        except common.TestTimeoutException:
147
            result = "TIMEOUT"
165
            result = "TIMEOUT"
Line 152... Line 170...
152
        finish = timeit.default_timer()
170
        finish = timeit.default_timer()
153
        print(f"{result} ({finish - start:.2f} seconds)")
171
        print(f"{result} ({finish - start:.2f} seconds)")
Line 154... Line 172...
154
    
172
 
Line -... Line 173...
-
 
173
        test_number += 1
155
        test_number += 1
174
 
156
 
175
 
157
def run_tests_serially(tests, root_dir):
176
def run_tests_serially(tests, root_dir):
158
    thread = Thread(target = run_tests_serially_thread, args = (tests, root_dir))
177
    thread = Thread(target=run_tests_serially_thread, args=(tests, root_dir))
Line -... Line 178...
-
 
178
    thread.start()
159
    thread.start()
179
    return thread
160
    return thread
180
 
161
 
181
 
-
 
182
def build_umka_asm(object_output_dir):
-
 
183
    umka_o = f"{object_output_dir}/umka.o"
-
 
184
    kolibri_kernel_trunk_runtests_py = os.path.abspath(__file__)
162
def build_umka_asm(object_output_dir):
185
    kolibri_kernel_trunk = os.path.dirname(kolibri_kernel_trunk_runtests_py)
-
 
186
    kolibri_kernel = os.path.dirname(kolibri_kernel_trunk)
163
    umka_o = f"{object_output_dir}/umka.o"
187
    kolibrios_folder = os.path.dirname(kolibri_kernel)
164
    kolibrios_folder = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
188
    env = os.environ
165
    env = os.environ
189
    libcrash = "programs/develop/libraries/libcrash/hash"
-
 
190
    env["INCLUDE"] = ""
-
 
191
    env["INCLUDE"] += f"{kolibrios_folder}/kernel/trunk;"
166
    env["INCLUDE"] = ""
192
    env["INCLUDE"] += f"{kolibrios_folder}/{libcrash}"
-
 
193
    command = "fasm "
-
 
194
    command += "-dUEFI=1 -dextended_primary_loader=1 -dUMKA=1 "
167
    env["INCLUDE"] += f"{kolibrios_folder}/kernel/trunk;"
195
    command += "umka/umka.asm umka/build/umka.o -s umka/build/umka.fas "
168
    env["INCLUDE"] += f"{kolibrios_folder}/programs/develop/libraries/libcrash/hash"
196
    command += "-m 2000000 "
Line -... Line 197...
-
 
197
    stdout = subprocess.check_output(command, shell=True, env=env)
169
    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)
198
    print(stdout)
170
    print(stdout)
199
    return umka_o
171
    return umka_o
200
 
172
 
201
 
173
def cc(src, obj, include_path):
202
def cc(src, obj, include_path):
174
    command = "clang "
203
    command = "clang "
175
    command += "-Wno-everything -std=c11 -g -O0 -fno-pie -m32 -c "
204
    command += "-Wno-everything -std=c11 -g -O0 -fno-pie -m32 -masm=intel -c "
Line -... Line 205...
-
 
205
    command += "-D_FILE_OFFSET_BITS=64 -DNDEBUG -D_POSIX_C_SOURCE=200809L "
176
    command += "-D_FILE_OFFSET_BITS=64 -DNDEBUG -masm=intel -D_POSIX_C_SOURCE=200809L "
206
    command += f"-I {include_path} {src} -o {obj}"
177
    command += f"-I {include_path} {src} -o {obj}"
207
    if os.system(command) != 0:
-
 
208
        exit()
178
    if os.system(command) != 0:
209
 
179
        exit()
210
 
180
 
211
def link(objects):
181
def link(objects):
212
    command = "clang "
Line -... Line 213...
-
 
213
    command += "-Wno-everything "
182
    command = "clang "
214
    command += "-no-pie -m32 -o umka_shell -static -T umka/umka.ld "
183
    command += "-Wno-everything -no-pie -m32 -o umka_shell -static -T umka/umka.ld "
215
    command += " ".join(objects)
184
    command += " ".join(objects)
216
    if os.system(command) != 0:
Line 185... Line 217...
185
    if os.system(command) != 0:
217
        exit()
Line 202... Line 234...
202
        "linux/pci.c",
234
        "linux/pci.c",
203
        "linux/thread.c",
235
        "linux/thread.c",
204
        "util.c",
236
        "util.c",
205
    ]
237
    ]
Line -... Line 238...
-
 
238
 
206
 
239
    src_obj_pairs = [
-
 
240
        (f"umka/{source}", f"umka/{source}.o") for source in c_sources
Line 207... Line 241...
207
    src_obj_pairs = [ (f"umka/{source}", f"umka/{source}.o") for source in c_sources ]
241
    ]
208
 
242
 
Line 209... Line 243...
209
    for src, obj in src_obj_pairs:
243
    for src, obj in src_obj_pairs:
Line 241... Line 275...
241
    prepare_test_img()
275
    prepare_test_img()
242
    build_umka()
276
    build_umka()
243
    tests = collect_tests()
277
    tests = collect_tests()
244
    serial_executor_thread = run_tests_serially(tests, root_dir)
278
    serial_executor_thread = run_tests_serially(tests, root_dir)
245
    serial_executor_thread.join()
279
    serial_executor_thread.join()
246
-