Subversion Repositories Kolibri OS

Rev

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

Rev 9342 Rev 9387
Line 14... Line 14...
14
import filecmp
14
import filecmp
Line 15... Line 15...
15
 
15
 
16
sys.path.append('test')
16
sys.path.append('test')
Line 17... Line -...
17
import common
-
 
18
 
-
 
19
enable_umka = True
17
import common
20
 
18
 
Line 21... Line 19...
21
def log(s, end = "\n"):
19
def log(s, end = "\n"):
22
    print(s, end = end, flush = True)
20
    print(s, end = end, flush = True)
Line 132... Line 130...
132
 
130
 
133
        if os.path.exists(test_file):
131
        if os.path.exists(test_file):
134
            tests.append(test_folder_path)
132
            tests.append(test_folder_path)
Line 135... Line -...
135
    return tests
-
 
136
 
-
 
137
def collect_umka_tests():
-
 
138
    tests = []
-
 
139
 
-
 
140
    for test_file in os.listdir("umka/test"):
-
 
141
        test_file_path = f"umka/test/{test_file}"
-
 
142
        if not test_file.endswith(".t"):
-
 
143
            continue
-
 
144
        if not os.path.isfile(test_file_path):
-
 
145
            continue
-
 
146
        tests.append(test_file_path)
-
 
147
    return tests
133
    return tests
148
 
134
 
149
def run_tests_serially_thread(test, root_dir):
135
def run_tests_serially_thread(test, root_dir):
150
    test_number = 1
136
    test_number = 1
Line 169... Line 155...
169
def run_tests_serially(tests, root_dir):
155
def run_tests_serially(tests, root_dir):
170
    thread = Thread(target = run_tests_serially_thread, args = (tests, root_dir))
156
    thread = Thread(target = run_tests_serially_thread, args = (tests, root_dir))
171
    thread.start()
157
    thread.start()
172
    return thread
158
    return thread
Line 173... Line -...
173
 
-
 
174
def gcc(fin, fout):
-
 
175
    flags = "-m32 -std=c11 -g -O0 -fno-pie -w"
-
 
176
    defines = "-D_FILE_OFFSET_BITS=64 -DNDEBUG -D_POSIX_C_SOURCE=200809L"
-
 
177
    include = "-Iumka -Iumka/linux"
-
 
178
    command = f"clang {flags} {defines} {include} -c {fin} -o {fout}"
-
 
179
    print(command)
-
 
180
    os.system(command)
-
 
181
 
-
 
182
def build_umka_asm():
-
 
183
    include = "INCLUDE=\"../../programs/develop/libraries/libcrash/hash\""
-
 
184
    flags = "-dUEFI=1 -dextended_primary_loader=1 -dUMKA=1"
-
 
185
    files = "umka/umka.asm umka/build/umka.o -s umka/build/umka.fas"
-
 
186
    memory = "-m 2000000"
-
 
187
    command = f"{include} fasm {flags} {files} {memory}"
-
 
188
    if sys.platform != "win32":
-
 
189
        print(command)
-
 
190
        os.system(command)
-
 
191
    else:
-
 
192
        my_env = os.environ.copy()
-
 
193
        my_env["INCLUDE"] = "../../programs/develop/libraries/libcrash/hash"
-
 
194
        print(subprocess.check_output(f"fasm {flags} {files} {memory} -dwin32=1", shell = True, env = my_env))
-
 
195
 
-
 
196
def build_umka():
-
 
197
    if not enable_umka:
-
 
198
        return
-
 
199
    if os.path.exists("umka_shell.exe"):
-
 
200
        return
-
 
201
    os.makedirs("umka/build/linux", exist_ok = True)
-
 
202
    os.makedirs("umka/build/win32", exist_ok = True)
-
 
203
    sources = [ "umka_shell.c", 
-
 
204
                "shell.c",
-
 
205
                "vdisk.c",
-
 
206
                "lodepng.c",
-
 
207
                "getopt.c" ]
-
 
208
    if sys.platform == "win32":
-
 
209
        sources += [ "win32/pci.c", "win32/thread.c" ]
-
 
210
    else:
-
 
211
        sources += [ "linux/pci.c", "linux/thread.c" ]
-
 
212
    sources = [f"umka/{f}" for f in sources]
-
 
213
    objects = []
-
 
214
    for source in sources:
-
 
215
        object_path = source.replace("umka/", "umka/build/")
-
 
216
        object_path = f"{object_path}.o"
-
 
217
        gcc(source, object_path)
-
 
218
        objects.append(object_path)
-
 
219
    build_umka_asm()
-
 
220
    objects.append("umka/build/umka.o")
-
 
221
    objects = " ".join(objects)
-
 
222
    if sys.platform != "win32":
-
 
223
        ld_script = "-T umka/umka.ld"
-
 
224
    else:
-
 
225
        ld_script = ""
-
 
226
    command = f"clang -m32 -fno-pie -o umka_shell.exe -static {ld_script} {objects}"
-
 
227
    print(command)
-
 
228
    os.system(command)
-
 
229
    if not os.path.exists("umka_shell.exe"):
-
 
230
        print("Could't compile umka_shell.exe")
-
 
231
        exit()
-
 
232
 
-
 
233
def create_relocated(root_dir, fname):
-
 
234
    with open(fname, "rb") as f:
-
 
235
        contents = f.read()
-
 
236
    new_contents = contents.replace(b"../img", bytes(f"{root_dir}/umka/img", "ascii"))
-
 
237
    new_contents = new_contents.replace(b"chess_image.rgb", bytes(f"{root_dir}/umka/test/chess_image.rgb", "ascii"))
-
 
238
    outname = f"{fname}.o" # .o extension just to avoid indexing of the file
-
 
239
    with open(outname, "wb") as f:
-
 
240
        f.write(new_contents)
-
 
241
    return outname
-
 
242
 
-
 
243
def run_umka_test(root_dir, test_file_path):
-
 
244
    test = create_relocated(root_dir, test_file_path)
-
 
245
    ref_log = create_relocated(root_dir, f"{test_file_path[:-2]}.ref.log")
-
 
246
    out_log = f"{test_file_path[:-2]}.out.log"
-
 
247
    if sys.platform != "win32":
-
 
248
        prefix = "./"
-
 
249
    else:
-
 
250
        prefix = ""
-
 
251
    os.system(f"{prefix}umka_shell.exe < {test} > {out_log}")
-
 
252
    if sys.platform == "win32":
-
 
253
        with open(out_log, "rb") as f:
-
 
254
            contents = f.read()
-
 
255
        contents_no_crlf = contents.replace(b"\r\n", b"\n")
-
 
256
        with open(out_log, "wb") as f:
-
 
257
            f.write(contents_no_crlf)
-
 
258
    if not filecmp.cmp(ref_log, out_log):
-
 
259
        print(f"FAILURE: {test_file_path}\n", end = "")
-
 
260
    else:
-
 
261
        print(f"SUCCESS: {test_file_path}\n", end = "")
-
 
262
 
159
 
263
if __name__ == "__main__":
160
if __name__ == "__main__":
Line 264... Line 161...
264
    root_dir = os.getcwd()
161
    root_dir = os.getcwd()
265
 
162
 
266
    # Check available tools
163
    # Check available tools
267
    tools = (("qemu-system-i386", "qemu-system-x86"),
164
    tools = (("qemu-system-i386", "qemu-system-x86"),
Line 268... Line 165...
268
             ("fasm", "fasm"))
165
             ("fasm", "fasm"))
269
    check_tools(tools)
-
 
270
    
166
    check_tools(tools)
271
    prepare_test_img()
-
 
272
    build_umka()
167
    
273
    tests = collect_tests()
-
 
274
    umka_tests = collect_umka_tests()
-
 
275
    serial_executor_thread = run_tests_serially(tests, root_dir)
-
 
276
    if enable_umka:
168
    prepare_test_img()