55
55
56
56
class ProgressIndicator (object ):
57
57
58
- def __init__ (self , cases ):
58
+ def __init__ (self , cases , flaky_tests_mode ):
59
59
self .cases = cases
60
+ self .flaky_tests_mode = flaky_tests_mode
60
61
self .queue = Queue (len (cases ))
61
62
for case in cases :
62
63
self .queue .put_nowait (case )
@@ -234,13 +235,19 @@ def HasRun(self, output):
234
235
self ._done += 1
235
236
command = basename (output .command [- 1 ])
236
237
if output .UnexpectedOutput ():
237
- print 'not ok %i - %s' % (self ._done , command )
238
+ status_line = 'not ok %i - %s' % (self ._done , command )
239
+ if FLAKY in output .test .outcomes and self .flaky_tests_mode == "dontcare" :
240
+ status_line = status_line + " # TODO : Fix flaky test"
241
+ print status_line
238
242
for l in output .output .stderr .splitlines ():
239
243
print '#' + l
240
244
for l in output .output .stdout .splitlines ():
241
245
print '#' + l
242
246
else :
243
- print 'ok %i - %s' % (self ._done , command )
247
+ status_line = 'ok %i - %s' % (self ._done , command )
248
+ if FLAKY in output .test .outcomes :
249
+ status_line = status_line + " # TODO : Fix flaky test"
250
+ print status_line
244
251
245
252
duration = output .test .duration
246
253
@@ -258,8 +265,8 @@ def Done(self):
258
265
259
266
class CompactProgressIndicator (ProgressIndicator ):
260
267
261
- def __init__ (self , cases , templates ):
262
- super (CompactProgressIndicator , self ).__init__ (cases )
268
+ def __init__ (self , cases , flaky_tests_mode , templates ):
269
+ super (CompactProgressIndicator , self ).__init__ (cases , flaky_tests_mode )
263
270
self .templates = templates
264
271
self .last_status_length = 0
265
272
self .start_time = time .time ()
@@ -314,29 +321,29 @@ def PrintProgress(self, name):
314
321
315
322
class ColorProgressIndicator (CompactProgressIndicator ):
316
323
317
- def __init__ (self , cases ):
324
+ def __init__ (self , cases , flaky_tests_mode ):
318
325
templates = {
319
326
'status_line' : "[%(mins)02i:%(secs)02i|\033 [34m%%%(remaining) 4d\033 [0m|\033 [32m+%(passed) 4d\033 [0m|\033 [31m-%(failed) 4d\033 [0m]: %(test)s" ,
320
327
'stdout' : "\033 [1m%s\033 [0m" ,
321
328
'stderr' : "\033 [31m%s\033 [0m" ,
322
329
}
323
- super (ColorProgressIndicator , self ).__init__ (cases , templates )
330
+ super (ColorProgressIndicator , self ).__init__ (cases , flaky_tests_mode , templates )
324
331
325
332
def ClearLine (self , last_line_length ):
326
333
print "\033 [1K\r " ,
327
334
328
335
329
336
class MonochromeProgressIndicator (CompactProgressIndicator ):
330
337
331
- def __init__ (self , cases ):
338
+ def __init__ (self , cases , flaky_tests_mode ):
332
339
templates = {
333
340
'status_line' : "[%(mins)02i:%(secs)02i|%%%(remaining) 4d|+%(passed) 4d|-%(failed) 4d]: %(test)s" ,
334
341
'stdout' : '%s' ,
335
342
'stderr' : '%s' ,
336
343
'clear' : lambda last_line_length : ("\r " + (" " * last_line_length ) + "\r " ),
337
344
'max_length' : 78
338
345
}
339
- super (MonochromeProgressIndicator , self ).__init__ (cases , templates )
346
+ super (MonochromeProgressIndicator , self ).__init__ (cases , flaky_tests_mode , templates )
340
347
341
348
def ClearLine (self , last_line_length ):
342
349
print ("\r " + (" " * last_line_length ) + "\r " ),
@@ -738,8 +745,8 @@ def GetVmFlags(self, testcase, mode):
738
745
def GetTimeout (self , mode ):
739
746
return self .timeout * TIMEOUT_SCALEFACTOR [mode ]
740
747
741
- def RunTestCases (cases_to_run , progress , tasks ):
742
- progress = PROGRESS_INDICATORS [progress ](cases_to_run )
748
+ def RunTestCases (cases_to_run , progress , tasks , flaky_tests_mode ):
749
+ progress = PROGRESS_INDICATORS [progress ](cases_to_run , flaky_tests_mode )
743
750
return progress .Run (tasks )
744
751
745
752
@@ -763,6 +770,7 @@ def BuildRequirements(context, requirements, mode, scons_flags):
763
770
TIMEOUT = 'timeout'
764
771
CRASH = 'crash'
765
772
SLOW = 'slow'
773
+ FLAKY = 'flaky'
766
774
767
775
768
776
class Expression (object ):
@@ -1212,6 +1220,9 @@ def BuildOptions():
1212
1220
default = False , action = "store_true" )
1213
1221
result .add_option ("--cat" , help = "Print the source of the tests" ,
1214
1222
default = False , action = "store_true" )
1223
+ result .add_option ("--flaky-tests" ,
1224
+ help = "Regard tests marked as flaky (run|skip|dontcare)" ,
1225
+ default = "run" )
1215
1226
result .add_option ("--warn-unused" , help = "Report unused rules" ,
1216
1227
default = False , action = "store_true" )
1217
1228
result .add_option ("-j" , help = "The number of parallel tasks to run" ,
@@ -1258,6 +1269,13 @@ def ProcessOptions(options):
1258
1269
options .scons_flags .append ("arch=" + options .arch )
1259
1270
if options .snapshot :
1260
1271
options .scons_flags .append ("snapshot=on" )
1272
+ def CheckTestMode (name , option ):
1273
+ if not option in ["run" , "skip" , "dontcare" ]:
1274
+ print "Unknown %s mode %s" % (name , option )
1275
+ return False
1276
+ return True
1277
+ if not CheckTestMode ("--flaky-tests" , options .flaky_tests ):
1278
+ return False
1261
1279
return True
1262
1280
1263
1281
@@ -1450,15 +1468,16 @@ def wrap(processor):
1450
1468
1451
1469
result = None
1452
1470
def DoSkip (case ):
1453
- return SKIP in case .outcomes or SLOW in case .outcomes
1471
+ return (SKIP in case .outcomes or SLOW in case .outcomes or
1472
+ (FLAKY in case .outcomes and options .flaky_tests == "skip" ))
1454
1473
cases_to_run = [ c for c in all_cases if not DoSkip (c ) ]
1455
1474
if len (cases_to_run ) == 0 :
1456
1475
print "No tests to run."
1457
- return 0
1476
+ return 1
1458
1477
else :
1459
1478
try :
1460
1479
start = time .time ()
1461
- if RunTestCases (cases_to_run , options .progress , options .j ):
1480
+ if RunTestCases (cases_to_run , options .progress , options .j , options . flaky_tests ):
1462
1481
result = 0
1463
1482
else :
1464
1483
result = 1
0 commit comments