25
25
import re
26
26
import logging
27
27
28
+ BOLD = ("" , "" )
29
+ if os .name == 'posix' :
30
+ # primitive formatting on supported
31
+ # terminal via ANSI escape sequences:
32
+ BOLD = ('\033 [0m' , '\033 [1m' )
33
+
28
34
TEST_EXIT_PASSED = 0
29
35
TEST_EXIT_SKIPPED = 77
30
36
@@ -231,11 +237,6 @@ def main():
231
237
run_tests (test_list , config ["environment" ]["SRCDIR" ], config ["environment" ]["BUILDDIR" ], config ["environment" ]["EXEEXT" ], args .jobs , args .coverage , passon_args )
232
238
233
239
def run_tests (test_list , src_dir , build_dir , exeext , jobs = 1 , enable_coverage = False , args = []):
234
- BOLD = ("" ,"" )
235
- if os .name == 'posix' :
236
- # primitive formatting on supported
237
- # terminal via ANSI escape sequences:
238
- BOLD = ('\033 [0m' , '\033 [1m' )
239
240
240
241
#Set env vars
241
242
if "BITCOIND" not in os .environ :
@@ -258,42 +259,54 @@ def run_tests(test_list, src_dir, build_dir, exeext, jobs=1, enable_coverage=Fal
258
259
subprocess .check_output ([tests_dir + 'create_cache.py' ] + flags )
259
260
260
261
#Run Tests
261
- all_passed = True
262
- time_sum = 0
263
- time0 = time .time ()
264
-
265
262
job_queue = TestHandler (jobs , tests_dir , test_list , flags )
263
+ time0 = time .time ()
264
+ test_results = []
266
265
267
266
max_len_name = len (max (test_list , key = len ))
268
- results = " \n " + BOLD [ 1 ] + "%s | %s | %s \n \n " % ( "TEST" . ljust ( max_len_name ), "STATUS " , "DURATION" ) + BOLD [ 0 ]
267
+
269
268
for _ in range (len (test_list )):
270
- (name , stdout , stderr , status , duration ) = job_queue .get_next ()
271
- all_passed = all_passed and status != "Failed"
272
- time_sum += duration
273
-
274
- if status == "Passed" :
275
- logging .debug ("\n %s%s%s passed, Duration: %s s" % (BOLD [1 ], name , BOLD [0 ], duration ))
276
- elif status == "Skipped" :
277
- logging .debug ("\n %s%s%s skipped" % (BOLD [1 ], name , BOLD [0 ]))
269
+ test_result , stdout , stderr = job_queue .get_next ()
270
+ test_results .append (test_result )
271
+
272
+ if test_result .status == "Passed" :
273
+ logging .debug ("\n %s%s%s passed, Duration: %s s" % (BOLD [1 ], test_result .name , BOLD [0 ], test_result .time ))
274
+ elif test_result .status == "Skipped" :
275
+ logging .debug ("\n %s%s%s skipped" % (BOLD [1 ], test_result .name , BOLD [0 ]))
278
276
else :
279
- print ("\n %s%s%s failed, Duration: %s s\n " % (BOLD [1 ], name , BOLD [0 ], duration ))
277
+ print ("\n %s%s%s failed, Duration: %s s\n " % (BOLD [1 ], test_result . name , BOLD [0 ], test_result . time ))
280
278
print (BOLD [1 ] + 'stdout:\n ' + BOLD [0 ] + stdout + '\n ' )
281
279
print (BOLD [1 ] + 'stderr:\n ' + BOLD [0 ] + stderr + '\n ' )
282
280
283
- results += "%s | %s | %s s\n " % (name .ljust (max_len_name ), status .ljust (7 ), duration )
284
-
285
- results += BOLD [1 ] + "\n %s | %s | %s s (accumulated)" % ("ALL" .ljust (max_len_name ), str (all_passed ).ljust (7 ), time_sum ) + BOLD [0 ]
286
- print (results )
287
- print ("\n Runtime: %s s" % (int (time .time () - time0 )))
281
+ print_results (test_results , max_len_name , (int (time .time () - time0 )))
288
282
289
283
if coverage :
290
284
coverage .report_rpc_coverage ()
291
285
292
286
logging .debug ("Cleaning up coverage data" )
293
287
coverage .cleanup ()
294
288
289
+ all_passed = all (map (lambda test_result : test_result .status == "Passed" , test_results ))
290
+
295
291
sys .exit (not all_passed )
296
292
293
+ def print_results (test_results , max_len_name , runtime ):
294
+ results = "\n " + BOLD [1 ] + "%s | %s | %s\n \n " % ("TEST" .ljust (max_len_name ), "STATUS " , "DURATION" ) + BOLD [0 ]
295
+
296
+ test_results .sort (key = lambda result : result .name .lower ())
297
+ all_passed = True
298
+ time_sum = 0
299
+
300
+ for test_result in test_results :
301
+ all_passed = all_passed and test_result .status != "Failed"
302
+ time_sum += test_result .time
303
+ test_result .padding = max_len_name
304
+ results += str (test_result )
305
+
306
+ results += BOLD [1 ] + "\n %s | %s | %s s (accumulated) \n " % ("ALL" .ljust (max_len_name ), str (all_passed ).ljust (7 ), time_sum ) + BOLD [0 ]
307
+ results += "Runtime: %s s\n " % (runtime )
308
+ print (results )
309
+
297
310
class TestHandler :
298
311
"""
299
312
Trigger the testscrips passed in via the list.
@@ -348,9 +361,32 @@ def get_next(self):
348
361
status = "Failed"
349
362
self .num_running -= 1
350
363
self .jobs .remove (j )
351
- return name , stdout , stderr , status , int (time .time () - time0 )
364
+
365
+ return TestResult (name , status , int (time .time () - time0 )), stdout , stderr
352
366
print ('.' , end = '' , flush = True )
353
367
368
+ class TestResult ():
369
+ def __init__ (self , name , status , time ):
370
+ self .name = name
371
+ self .status = status
372
+ self .time = time
373
+ self .padding = 0
374
+
375
+ def __repr__ (self ):
376
+ COLOR = ("" , "" )
377
+ if os .name == 'posix' :
378
+ # primitive formatting on supported
379
+ # terminal via ANSI escape sequences:
380
+ if self .status == "Passed" :
381
+ COLOR = ('\033 [0m' , '\033 [0;34m' )
382
+ elif self .status == "Failed" :
383
+ COLOR = ('\033 [0m' , '\033 [0;31m' )
384
+ elif self .status == "Skipped" :
385
+ COLOR = ('\033 [0m' , '\033 [1;30m' )
386
+
387
+ return COLOR [1 ] + "%s | %s | %s s\n " % (self .name .ljust (self .padding ), self .status .ljust (7 ), self .time ) + COLOR [0 ]
388
+
389
+
354
390
def check_script_list (src_dir ):
355
391
"""Check scripts directory.
356
392
0 commit comments