-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
89 lines (73 loc) · 2.24 KB
/
run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
import subprocess
import sys
tests_dir = "external/riscv-tests/isa"
emulator = "./build/riscv-emulator"
passed = 0
failed = 0
def run_test(file_path, file_name, do_jit):
global passed
global failed
print(" " * 40, end='\r')
print(f"Running {file_name}", end='\r')
# Emulate test
with open(os.devnull, 'w') as devnull:
try:
if do_jit:
result = subprocess.run([emulator, "--test", "--jit", "--image", file_path], stdout=devnull, stderr=devnull)
else:
result = subprocess.run([emulator, "--test", "--image", file_path], stdout=devnull, stderr=devnull)
except KeyboardInterrupt:
print("Running " + file_name)
exit()
print(" " * 40, end='\r')
# Check the return status
if result.returncode == 0:
passed += 1
return True
else:
failed += 1
return False
def pad(name):
amount = 30
return name + (amount-len(name)) * " "
def main():
tests = []
# Buid list of tests
for file_name in os.listdir(tests_dir):
# Ignore "non-tests"
if file_name[-3:] != "bin":
continue
file_path = os.path.join(tests_dir, file_name)
if os.path.isfile(file_path):
tests.append({
"name": file_path,
"display_name": pad(file_path.replace(tests_dir + "/", "")),
"jit": False
})
# Duplicate tests for JIT
for test in tests:
if test["jit"] == False:
tests.append({
"name": test["name"],
"display_name": test["display_name"],
"passed": False,
"jit": True
})
for test in tests:
if run_test(test["name"], test["display_name"], test["jit"]):
test["passed"] = True
else:
test["passed"] = False
# Display
print()
print("Test Name\t Passed")
print("-" * 34)
for test in tests:
status = "✅" if test["passed"] else "❌"
if test["jit"]:
status += " (JIT)"
print(f"{test['display_name']}\t{status}")
print(f"\n\tPassed {passed}/{passed + failed}")
if __name__ == "__main__":
main()