9
9
import sys
10
10
import argparse
11
11
12
+ run_tests_module = __import__ ("run-tests" )
13
+
12
14
sys .path .append ("../tools" )
13
15
import pyboard
14
16
@@ -133,14 +135,15 @@ def detect_architecture(target):
133
135
return platform , arch , None
134
136
135
137
136
- def run_tests (target_truth , target , args , stats , resolved_arch ):
138
+ def run_tests (target_truth , target , args , resolved_arch ):
137
139
global injected_import_hook_code
138
140
139
141
prelude = ""
140
142
if args .begin :
141
143
prelude = args .begin .read ()
142
144
injected_import_hook_code = injected_import_hook_code .replace ("{import_prelude}" , prelude )
143
145
146
+ test_results = []
144
147
for test_file in args .files :
145
148
# Find supported test
146
149
test_file_basename = os .path .basename (test_file )
@@ -195,17 +198,18 @@ def run_tests(target_truth, target, args, stats, resolved_arch):
195
198
result = "pass"
196
199
197
200
# Accumulate statistics
198
- stats ["total" ] += 1
199
201
if result == "pass" :
200
- stats [ "pass" ] += 1
202
+ test_results . append (( test_file , "pass" , "" ))
201
203
elif result == "SKIP" :
202
- stats [ "skip" ] += 1
204
+ test_results . append (( test_file , "skip" , "" ))
203
205
else :
204
- stats [ "fail" ] += 1
206
+ test_results . append (( test_file , "fail" , "" ))
205
207
206
208
# Print result
207
209
print ("{:4} {}{}" .format (result , test_file , extra ))
208
210
211
+ return test_results
212
+
209
213
210
214
def main ():
211
215
cmd_parser = argparse .ArgumentParser (
@@ -227,6 +231,12 @@ def main():
227
231
default = None ,
228
232
help = "prologue python file to execute before module import" ,
229
233
)
234
+ cmd_parser .add_argument (
235
+ "-r" ,
236
+ "--result-dir" ,
237
+ default = run_tests_module .base_path ("results" ),
238
+ help = "directory for test results" ,
239
+ )
230
240
cmd_parser .add_argument ("files" , nargs = "*" , help = "input test files" )
231
241
args = cmd_parser .parse_args ()
232
242
@@ -251,20 +261,14 @@ def main():
251
261
print ("platform={} " .format (target_platform ), end = "" )
252
262
print ("arch={}" .format (target_arch ))
253
263
254
- stats = {"total" : 0 , "pass" : 0 , "fail" : 0 , "skip" : 0 }
255
- run_tests (target_truth , target , args , stats , target_arch )
264
+ os .makedirs (args .result_dir , exist_ok = True )
265
+ test_results = run_tests (target_truth , target , args , target_arch )
266
+ res = run_tests_module .create_test_report (args , test_results )
256
267
257
268
target .close ()
258
269
target_truth .close ()
259
270
260
- print ("{} tests performed" .format (stats ["total" ]))
261
- print ("{} tests passed" .format (stats ["pass" ]))
262
- if stats ["fail" ]:
263
- print ("{} tests failed" .format (stats ["fail" ]))
264
- if stats ["skip" ]:
265
- print ("{} tests skipped" .format (stats ["skip" ]))
266
-
267
- if stats ["fail" ]:
271
+ if not res :
268
272
sys .exit (1 )
269
273
270
274
0 commit comments