-
Notifications
You must be signed in to change notification settings - Fork 1
/
runtest.py
executable file
·297 lines (242 loc) · 10.2 KB
/
runtest.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import json
import sys
import os
import time
import subprocess
import mmap
import datetime
import platform
from checkgms_utils import *
from checkgms_stable import *
#global states
first = True
if "Windows" in platform.system():
rungms_path = "rungms.bat"
else:
rungms_path = "misc/automation/rungms"
codecoverage = []
def run_test(input_file):
global first
global rungms_path
global codecoverage
filenum = input_file[0]
input_file_path = input_file[1]
input_file_path = re.sub("(\*|\?| |!|\$|#|&|\"|\'|\(|\)|\||<|>|\\\|;)", r"\\\1", input_file_path)
short_input_file_path = input_file_path.split("/tests/", 1)[-1]
try:
rungms_path_tmp = run_arguments["path"]
if rungms_path_tmp == "":
rungms_path_tmp = rungms_path
if run_arguments["bwrap"] and "Windows" not in platform.system():
rungms_path_tmp = "bwrap --dev-bind / / --unshare-ipc " + rungms_path_tmp
run_command = rungms_path_tmp + " " + input_file_path + " " + run_arguments["version"] + " " + \
run_arguments["ncpus"]
if "Windows" in platform.system():
run_command = run_command + " > " + input_file_path.replace(".inp", ".log") + " 2>&1"
else:
run_command = run_command + " " + run_arguments["ncpus"] + \
" > " + input_file_path.replace(".inp", ".log") + " 2>&1"
if run_arguments["print_to_stdout"]:
run_command = rungms_path_tmp + " " + input_file_path + " " + run_arguments["version"] + " " + \
run_arguments["ncpus"]
if "Windows" not in platform.system():
run_command = run_command + " " + run_arguments["ncpus"]
if run_arguments["pre"]:
run_command = run_arguments["pre"] + " && " + run_command
if run_arguments["post"]:
run_command = run_command + " && " + run_arguments["post"]
# TODO: Use Python 3's pathlib to juggle Windows / Unix paths
if "Windows" in platform.system():
run_command=run_command.replace("/","\\")
if not run_arguments["coverage"]:
if not run_arguments["no_counter"]:
print(
c_box_small(
datetime.datetime.now().time()),
l_box_small("Running input file"),
file_progress(
filenum,
len(input_file_paths)),
short_input_file_path)
if run_arguments["stderr"]:
sys.stderr.write(
l_box_small("Running input file") +
" " +
file_progress(
filenum,
len(input_file_paths)) +
" " +
short_input_file_path +
"\n")
sys.stderr.flush()
if run_arguments["debug"] or run_arguments["dryrun"]:
print(run_command)
if not run_arguments["dryrun"]:
os.system(run_command)
time.sleep(2)
if run_arguments["coverage"]:
result = subprocess.run(
["tests/coverage"],
stdout=subprocess.PIPE).stdout.decode('utf-8')
lines = result.splitlines()
if first:
print(c_large("Test Input"), c_small("% Total Coverage"))
print(seperator(columns=83))
codecoverage.append(["Source Files"])
codecoverage.append(["Lines of Code"])
codecoverage.append([short_input_file_path])
for line in range(len(lines)):
if "File" in lines[line]:
sourcefile = lines[line].split("'")[-2]
coverage = lines[line + 1].split(":")[-1].split("%")[0]
linesofcode = lines[line + 1].split(" ")[-1]
if "No executable lines" in lines[line + 1]:
coverage = "0.00"
linesofcode = 0
if first:
codecoverage[0].append(sourcefile)
codecoverage[1].append(linesofcode)
codecoverage[-1].append(coverage)
if first:
codecoverage[0].append("Total")
loc_sum = 0
for loc in codecoverage[1][1:-1]:
loc_sum = loc_sum + int(loc)
codecoverage[1].append(loc_sum)
codecoverage[-1].append(lines[-1].split(":")[-1].split("%")[0])
if first:
first = False
if float(codecoverage[-1][-1]) > float(codecoverage[-2][-1]):
print(l_box_large(codecoverage[-1][0]),
r_small(codecoverage[-1][-1]))
else:
if float(codecoverage[-2][-1]) < 100.0:
print(l_box_large(
codecoverage[-1][0]), r_small(codecoverage[-1][-1]), c_small("X"))
else:
print(l_box_large(
codecoverage[-1][0]), r_small(codecoverage[-1][-1]))
# To permit a keyboard interrupt
except KeyboardInterrupt:
sys.exit(1)
except BaseException:
sys.exit(1)
if __name__ == '__main__':
input_files = []
total_coverage = 0
total_linesofcode = 0
run_arguments = parse_arguments(checkgms=False)
print(c_box("Run parameters"))
print(json.dumps(run_arguments, indent=2))
script_path = os.path.dirname(os.path.realpath(__file__))
threads_num = 0
try:
threads_num = int(run_arguments["threads"])
except ValueError:
print("\"threads\" flag requires integer value, but " +
run_arguments["threads"] + " is not an integer value!")
sys.exit(1)
if threads_num < 1:
print("Why are you thinking that zero threads can do something?")
sys.exit(1)
if threads_num > 1:
try:
import multiprocessing as mp
except ImportError:
print("Parallelization is not available with this python version!")
sys.exit(1)
if threads_num > 1 and run_arguments["coverage"]:
print("coverage run can not parallelized!")
sys.exit(1)
# Populate the input_file_paths array
input_file_paths = []
input_file_paths = get_input_file_paths(
filepath_string_match=run_arguments["filter_filepath"],
folder_string_match=run_arguments["filter_folder"],
file_string_match=run_arguments["filter_file"],
folder_string_skip=run_arguments["skip_folder"],
file_string_skip=run_arguments["skip_file"],
script_path=script_path)
# Loop through the input_file_paths array and validate
for filenum, input_file_path in enumerate(input_file_paths, start=1):
if ".inp" not in input_file_path[-4:]:
continue
short_input_file_path = input_file_path.split("/tests/", 1)[-1]
# Check if user wants to skip input if log file already exists
if run_arguments["skip_log"]:
if (os.path.isfile(input_file_path.replace('.inp', '.log'))):
print(
c_box_small(
datetime.datetime.now().time()),
l_box_small("Log file already exists!"),
file_progress(
filenum,
len(input_file_paths)),
short_input_file_path.replace('.inp', '.log'))
continue
# Search for prescence of "TRAVIS-CI SKIP"
with open(input_file_path, 'r', encoding="utf-8", errors='ignore') as opened_file:
parse_memory_map = mmap.mmap(
opened_file.fileno(), 0, access=mmap.ACCESS_READ)
if not run_arguments["no_skip"]:
regex_string = "TRAVIS-CI SKIP"
regex = re.compile(
str.encode(
regex_string,
'ascii'),
re.MULTILINE)
match = regex.search(parse_memory_map)
# If found then skip
if match:
if run_arguments["debug"]:
print(
l_box_small("Skipping input file"),
file_progress(
filenum,
len(input_file_paths)),
short_input_file_path)
continue
# If --test_type is passed in:
if "small" in run_arguments["test_type"]:
regex_string = "TRAVIS-CI SMALL"
elif "medium" in run_arguments["test_type"]:
regex_string = "TRAVIS-CI MEDIUM"
elif "large" in run_arguments["test_type"]:
regex_string = "TRAVIS-CI LARGE"
elif "msucc" in run_arguments["test_type"]:
regex_string = "TRAVIS-CI MSUCC"
if len(run_arguments["test_type"]) > 0:
regex = re.compile(
str.encode(
regex_string,
'ascii'),
re.MULTILINE)
match = regex.search(parse_memory_map)
if not match:
if run_arguments["debug"]:
print(
l_box_small("Skipping input file"),
file_progress(
filenum,
len(input_file_paths)),
short_input_file_path)
continue
input_files.append([filenum, input_file_path])
if threads_num == 1:
for input_file in input_files:
run_test(input_file)
else:
pool = mp.Pool(processes=threads_num)
pool.map(run_test, input_files, chunksize=1)
if run_arguments["coverage"]:
with open("tests/coverage.dat", "w") as coverage_file:
for row in codecoverage:
coverage_file.write(",".join([str(x) for x in row]))
coverage_file.write("\n")
pass
print(seperator(columns=83))
print(l_box_large("Total % Coverage"), r_small(codecoverage[-1][-1]))
print(l_box_large("Total Lines of Code"), r_small(codecoverage[1][-1]))