-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
153 lines (131 loc) · 5.34 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from utils import *
from pat import pat
from utils import precompile
# import progressbar
import time
from concurrent.futures import ThreadPoolExecutor, wait
import sqlite3
import threading
thread_mutex = threading.Lock()
failed = []
pass_num = 0
times = []
def test_single(n_thread, times, jar, test_file, project_dir, ignores=None, main="Main", package="", main_path="."):
if not os.path.exists("temp"):
os.mkdir("temp")
if ignores is None:
ignores = []
precompile(project_dir, main, main_path, jar)
# print("Testing... Please wait.")
# test_data_folder = os.path.join(project_dir, "test_data")
p_list = []
with ThreadPoolExecutor(n_thread) as executor:
for i in range(times):
child = executor.submit(pat_thread, test_file, package + main, jar, False if times > 1 else True)
p_list.append(child)
# if pat(test_data_in, package + main, jar, timeout):
# pass_num += 1
# print("Passed: {}".format(test_data_in))
wait(p_list)
# for p in p_list:
# print(p.done())
#
time.sleep(0.01)
global pass_num
if len(failed) != 0:
print("\033[1;33mAC {}/{}\033[0m".format(pass_num, times))
print("\033[1;31mFailed:", failed)
else:
print("\033[1;32mAC {}/{}\033[0m".format(pass_num, times))
conn.commit()
def test(n_thread, number, jar, test_data_folder, project_dir, ignores=None, main="Main", package="", main_path="."):
global times
times = []
global failed
failed = []
global pass_num
pass_num = 0
print(project_dir)
if not os.path.exists("temp"):
os.mkdir("temp")
if ignores is None:
ignores = []
precompile(project_dir, main, main_path, jar)
# print("Testing... Please wait.")
# test_data_folder = os.path.join(project_dir, "test_data")
test_data_paths = get_paths_recursively(test_data_folder)
test_data_in_paths = list(filter(lambda path: path.split('.')[-1] == "in", test_data_paths))
random.shuffle(test_data_in_paths)
if number != -1:
test_data_in_paths = test_data_in_paths[:number]
p_list = []
with ThreadPoolExecutor(n_thread) as executor:
for i, test_data_in in enumerate(test_data_in_paths):
if test_data_in.split("\\")[-1].split(".")[0] in ignores:
continue
child = executor.submit(pat_thread, test_data_in, package + main, jar)
p_list.append(child)
# if pat(test_data_in, package + main, jar, timeout):
# pass_num += 1
# print("Passed: {}".format(test_data_in))
wait(p_list)
# for p in p_list:
# print(p.done())
#
time.sleep(0.01)
if len(failed) != 0:
print("\033[1;33mAC {}/{}\033[0m".format(pass_num, len(test_data_in_paths)))
print("\033[1;31mFailed:", failed)
else:
print("\033[1;32mAC {}/{}\033[0m".format(pass_num, len(test_data_in_paths)))
best_time, _ = datacheck(test_data_folder)
average_time = sum(times) / len(times)
print("\033[1;32mAverage Time: {}, Best Average Time: {}\033[0m".format(average_time, best_time))
update_time(test_data_folder, average_time)
conn.commit()
for p in p_list:
if p.result() is not None:
print(p.result())
def pat_thread(test_data_in, class_path, jar, prt=False):
global failed
global pass_num
global times
print("\033[1;37mTesting: {}\033[0m".format(test_data_in))
result = pat(test_data_in, class_path, jar, prt)
thread_mutex.acquire()
if result[0] is True:
pass_num += 1
# print(test_data_in)
update_time(test_data_in, result[1])
times.append(result[1])
else:
failed.append(test_data_in)
thread_mutex.release()
# from test import test, test_single
# import sys
# from config import *
#
# if __name__ == "__main__":
# # cfg.EPS = 0.1
# jar = ";".join([
# r".",
# r"temp",
# r"C:\Study\OO\homework\unit2\elevator-input-hw2-1.3-jar-with-dependencies.jar",
# r"C:\Study\OO\homework\unit2\timable-output-1.0-raw-jar-with-dependencies.jar",
# ])
# n_thread = 64 # thread number of evaluator
# number = -1
# test_data = r"test_data\auto"
#
# # test_single(n_thread, 1, jar, r"test_data\manual\x.in", r"C:\Study\OO\homework\unit2\oo_course_2019_16191051_homework_6", [], "Main", "", ".")
# test(n_thread, number, jar, test_data, r"C:\Study\OO\homework\unit2\oo_course_2019_16191051_homework_6", [], "Main", "", ".")
#
#
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Saber", [], "Test", "", ".") # passed
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Lancer", [], "Main", "", ".") # passed
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Archer", [], "Excutor", "", ".") # passed
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Rider", [], "Main", "", ".") # passed
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Assassin", [], "FoolMain", "foolthread.", r".\foolthread") # ConcurrentModificationException
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Berserker", [], "Scheduler", "", ".") # passed
# # test(n_thread, jar, test_data, r"C:\Study\OO\others\homework_5\Alterego", [], "Main", "s.homework1.", r".\s\homework1") # passed
#