20
20
ERROR_RE = re .compile (r"(warning|error): .*" )
21
21
ERROR_CHECK_RE = re .compile (r"# COM: .*" )
22
22
OUTPUT_SKIPPED_RE = re .compile (r"(.text)" )
23
- COMMENT = {
24
- "asm" : "//" ,
25
- "dasm" : "#"
26
- }
23
+ COMMENT = {"asm" : "//" , "dasm" : "#" }
27
24
28
25
29
26
def invoke_tool (exe , cmd_args , testline , verbose = False ):
@@ -32,7 +29,7 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
32
29
else :
33
30
args = cmd_args
34
31
35
- cmd = " echo \" " + testline + " \" | " + exe + " " + args
32
+ cmd = ' echo "' + testline + '" | ' + exe + " " + args
36
33
if verbose :
37
34
print ("Command: " , cmd )
38
35
out = subprocess .check_output (cmd , shell = True )
@@ -44,68 +41,76 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
44
41
# and treat all others as tests
45
42
def isTestLine (input_line , mc_mode ):
46
43
# Skip comment lines
47
- if input_line .strip (' \t \r ' ).startswith (COMMENT [mc_mode ]):
44
+ if input_line .strip (" \t \r " ).startswith (COMMENT [mc_mode ]):
48
45
return False
49
- elif input_line .strip (' \t \r ' ) == '' :
46
+ elif input_line .strip (" \t \r " ) == "" :
50
47
return False
51
48
# skip any CHECK lines.
52
49
elif common .CHECK_RE .match (input_line ):
53
50
return False
54
51
return True
55
52
53
+
56
54
def hasErr (err ):
57
55
if err is None or len (err ) == 0 :
58
56
return False
59
57
if ERROR_RE .search (err ):
60
58
return True
61
59
return False
62
60
61
+
63
62
def getErrString (err ):
64
63
if err is None or len (err ) == 0 :
65
64
return ""
66
65
67
- lines = err .split (' \n ' )
66
+ lines = err .split (" \n " )
68
67
# take the first match
69
68
for line in lines :
70
69
s = ERROR_RE .search (line )
71
70
if s :
72
71
return s .group (0 )
73
72
return ""
74
73
74
+
75
75
def getOutputString (out ):
76
76
if out is None or len (out ) == 0 :
77
77
return ""
78
- lines = out .split (' \n ' )
78
+ lines = out .split (" \n " )
79
79
output = ""
80
80
81
81
for line in lines :
82
82
if OUTPUT_SKIPPED_RE .search (line ):
83
83
continue
84
- if line .strip (' \t ' ) == '' :
84
+ if line .strip (" \t " ) == "" :
85
85
continue
86
- output += line .lstrip (' \t ' )
86
+ output += line .lstrip (" \t " )
87
87
return output
88
88
89
+
89
90
def should_add_line_to_output (input_line , prefix_set , mc_mode ):
90
91
# special check line
91
- if mc_mode == ' dasm' and ERROR_CHECK_RE .search (input_line ):
92
+ if mc_mode == " dasm" and ERROR_CHECK_RE .search (input_line ):
92
93
return False
93
94
else :
94
- return common .should_add_line_to_output (input_line , prefix_set , comment_marker = COMMENT [mc_mode ])
95
+ return common .should_add_line_to_output (
96
+ input_line , prefix_set , comment_marker = COMMENT [mc_mode ]
97
+ )
95
98
96
99
97
100
def getStdCheckLine (prefix , output , mc_mode ):
98
- lines = output .split (' \n ' )
101
+ lines = output .split (" \n " )
99
102
output = ""
100
103
for line in lines :
101
- output += COMMENT [mc_mode ] + ' ' + prefix + ": " + line + ' \n '
104
+ output += COMMENT [mc_mode ] + " " + prefix + ": " + line + " \n "
102
105
return output
103
106
107
+
104
108
def getErrCheckLine (prefix , output , mc_mode ):
105
- if mc_mode == 'asm' :
106
- return COMMENT [mc_mode ] + ' ' + prefix + ": " + output + '\n '
107
- elif mc_mode == 'dasm' :
108
- return COMMENT [mc_mode ] + ' COM: ' + prefix + ": " + output + '\n '
109
+ if mc_mode == "asm" :
110
+ return COMMENT [mc_mode ] + " " + prefix + ": " + output + "\n "
111
+ elif mc_mode == "dasm" :
112
+ return COMMENT [mc_mode ] + " COM: " + prefix + ": " + output + "\n "
113
+
109
114
110
115
def main ():
111
116
parser = argparse .ArgumentParser (description = __doc__ )
@@ -132,9 +137,9 @@ def main():
132
137
for ti in common .itertests (
133
138
initial_args .tests , parser , script_name = "utils/" + script_name
134
139
):
135
- if ti .path .endswith ('.s' ):
140
+ if ti .path .endswith (".s" ):
136
141
mc_mode = "asm"
137
- elif ti .path .endswith (' .txt' ):
142
+ elif ti .path .endswith (" .txt" ):
138
143
mc_mode = "dasm"
139
144
else :
140
145
common .warn ("Expected .s and .txt, Skipping file : " , ti .path )
@@ -195,7 +200,6 @@ def main():
195
200
march_in_cmd ,
196
201
)
197
202
)
198
-
199
203
200
204
# find all test line from input
201
205
testlines = [l for l in ti .input_lines if isTestLine (l , mc_mode )]
@@ -232,7 +236,7 @@ def main():
232
236
raw_output [- 1 ].append (out )
233
237
234
238
common .debug ("Collect raw tool lines:" , str (len (raw_output [- 1 ])))
235
-
239
+
236
240
raw_prefixes .append (prefixes )
237
241
238
242
output_lines = []
@@ -255,7 +259,7 @@ def main():
255
259
o = getErrString (out )
256
260
else :
257
261
o = getOutputString (out )
258
-
262
+
259
263
prefixes = raw_prefixes [run_id ]
260
264
261
265
for p in prefixes :
@@ -273,7 +277,9 @@ def main():
273
277
# conflict, discard
274
278
p_dict [p ] = None , []
275
279
276
- p_dict_sorted = dict (sorted (p_dict .items (), key = lambda item : - len (item [1 ][1 ])))
280
+ p_dict_sorted = dict (
281
+ sorted (p_dict .items (), key = lambda item : - len (item [1 ][1 ]))
282
+ )
277
283
278
284
# prefix is selected and generated with most shared output lines
279
285
# each run_id can only be used once
@@ -299,7 +305,7 @@ def main():
299
305
else :
300
306
gen_prefix += getStdCheckLine (prefix , o , mc_mode )
301
307
302
- generated_prefixes .append (gen_prefix .rstrip (' \n ' ))
308
+ generated_prefixes .append (gen_prefix .rstrip (" \n " ))
303
309
304
310
# write output
305
311
prefix_id = 0
0 commit comments