This repository has been archived by the owner on May 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
115 lines (103 loc) · 3.57 KB
/
test.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import sys
import subprocess
import time
class Color:
CLEAR = "\033[0m"
RED = "\033[1m\033[31m"
GREEN = "\033[1m\033[32m"
BLUE = "\033[1m\033[34m"
def make():
test_files = sorted(os.listdir("./test/"))
f = open("test/expect.txt", "w")
for idx, test_file in enumerate(test_files):
if test_file == "expect.txt":
continue
f.write(f"{test_file} {expects[idx]}\n")
f.close()
def test_compile():
print(f"{Color.GREEN}++++++++++++++++test-votalile++++++++++++++++{Color.CLEAR}")
f = open("test/expect.txt", "r")
content = f.read()
cases = {}
cases = {
line.split()[0]: int(line.split()[1])
for line in content.split("\n")
if len(line) > 0
}
for filename, expect in cases.items():
fn = f"test/{filename}"
f = open(fn)
p = subprocess.Popen(f"./target/debug/depth {fn} --run", shell=True)
exit_status = p.wait()
if exit_status != expect:
print(
f"[{filename}]{f.read()} => {Color.RED}{expect} expected but got {exit_status}{Color.CLEAR}"
)
sys.exit(1)
else:
print(f"[{filename}] => {Color.BLUE}{expect}{Color.CLEAR}")
print(f"{Color.GREEN}All Test Passed.{Color.CLEAR}")
def test_optimize1():
print(f"{Color.GREEN}++++++++++++++++test-optimize1++++++++++++++++{Color.CLEAR}")
f = open("test/expect.txt", "r")
content = f.read()
cases = {}
cases = {
line.split()[0]: int(line.split()[1])
for line in content.split("\n")
if len(line) > 0
}
for filename, expect in cases.items():
fn = f"test/{filename}"
f = open(fn)
p = subprocess.Popen(f"./target/debug/depth {fn} --Opt1 ; ./a.out", shell=True)
exit_status = p.wait()
if exit_status != expect:
print(
f"[{filename}]{f.read()} => {Color.RED}{expect} expected but got {exit_status}{Color.CLEAR}"
)
sys.exit(1)
else:
print(f"[{filename}] => {Color.BLUE}{expect}{Color.CLEAR}")
print(f"{Color.GREEN}All Test Passed.{Color.CLEAR}")
def test_llvm():
print(f"{Color.GREEN}++++++++++++++++test-llvm++++++++++++++++{Color.CLEAR}")
f = open("test/expect.txt", "r")
content = f.read()
cases = {}
cases = {
line.split()[0]: int(line.split()[1])
for line in content.split("\n")
if len(line) > 0
}
for filename, expect in cases.items():
fn = f"test/{filename}"
f = open(fn)
p = subprocess.Popen(
f"./target/debug/depth {fn} --emit-llvm > d.ll ; clang d.ll; ./a.out",
shell=True,
)
exit_status = p.wait()
if exit_status != expect:
print(
f"[{filename}]{f.read()} => {Color.RED}{expect} expected but got {exit_status}{Color.CLEAR}"
)
sys.exit(1)
else:
print(f"[{filename}] => {Color.BLUE}{expect}{Color.CLEAR}")
print(f"{Color.GREEN}All Test Passed.{Color.CLEAR}")
if __name__ == "__main__":
start = time.time()
test_compile()
compile_time = time.time() - start
print(f"test-volatile time -> {Color.BLUE}{round(compile_time,2)}{Color.CLEAR}s")
# start = time.time()
# test_optimize1()
# compile_time = time.time() - start
# print(f"test-optimize1 time -> {Color.BLUE}{round(compile_time,2)}{Color.CLEAR}s")
start = time.time()
test_llvm()
compile_time = time.time() - start
print(f"test-llvm time -> {Color.BLUE}{round(compile_time,2)}{Color.CLEAR}s")
# make()