@@ -47,6 +47,7 @@ def usage():
47
47
print ( ' --context <> The context to use for test configuration' )
48
48
print ( ' --repeat <#> Repeat each test <#> times' )
49
49
print ( ' --config <> Ignore test configurations; use the one provided' )
50
+ print ( ' --device <> Run only on the specified devices; ignore any test that does not match (implies --live)' )
50
51
print ( ' --no-reset Do not try to reset any devices, with or without Acroname' )
51
52
print ( ' --acroname-reset If acroname is available, reset the acroname itself' )
52
53
print ( ' --rslog Enable LibRS logging (LOG_DEBUG etc.) to console in each test' )
@@ -77,7 +78,7 @@ def usage():
77
78
opts , args = getopt .getopt ( sys .argv [1 :], 'hvqr:st:' ,
78
79
longopts = ['help' , 'verbose' , 'debug' , 'quiet' , 'regex=' , 'stdout' , 'tag=' , 'list-tags' ,
79
80
'list-tests' , 'no-exceptions' , 'context=' , 'repeat=' , 'config=' , 'no-reset' , 'acroname-reset' ,
80
- 'rslog' , 'skip-disconnected' , 'live' , 'not-live' ] )
81
+ 'rslog' , 'skip-disconnected' , 'live' , 'not-live' , 'device=' ] )
81
82
except getopt .GetoptError as err :
82
83
log .e ( err ) # something like "option -a not recognized"
83
84
usage ()
@@ -90,6 +91,7 @@ def usage():
90
91
context = []
91
92
repeat = 1
92
93
forced_configurations = None
94
+ device_set = None
93
95
no_reset = False
94
96
acroname_reset = False
95
97
skip_disconnected = False
@@ -124,6 +126,12 @@ def usage():
124
126
repeat = int (arg )
125
127
elif opt == '--config' :
126
128
forced_configurations = [[arg ]]
129
+ elif opt == '--device' :
130
+ if only_not_live :
131
+ log .e ( "--device and --not-live are mutually exclusive" )
132
+ usage ()
133
+ only_live = True
134
+ device_set = arg .split ()
127
135
elif opt == '--no-reset' :
128
136
no_reset = True
129
137
elif opt == '--acroname-reset' :
@@ -237,16 +245,20 @@ def find_build_dir( dir ):
237
245
os .environ ["PYTHONPATH" ] += os .pathsep + dir
238
246
239
247
240
- def configuration_str ( configuration , repetition = 1 , retry = 0 , sns = None , prefix = '' , suffix = '' ):
248
+ def serial_numbers_to_string ( sns ):
249
+ return ' ' .join ( [f'{ devices .get (sn ).name } _{ sn } ' for sn in sns ] )
250
+
251
+
252
+ def configuration_str ( configuration , repetition = 0 , retry = 0 , sns = None , prefix = '' , suffix = '' ):
241
253
""" Return a string repr (with a prefix and/or suffix) of the configuration or '' if it's None """
242
254
s = ''
243
255
if configuration is not None :
244
256
s += '[' + ' ' .join ( configuration )
245
257
if sns is not None :
246
- s += ' -> ' + ' ' . join ( [ f' { devices . get ( sn ). name } _ { sn } ' for sn in sns ] )
258
+ s += ' -> ' + serial_numbers_to_string ( sns )
247
259
s += ']'
248
260
elif sns is not None :
249
- s += '[' + ' ' . join ( [ f' { devices . get ( sn ). name } _ { sn } ' for sn in sns ] ) + ']'
261
+ s += '[' + serial_numbers_to_string ( sns ) + ']'
250
262
if repetition :
251
263
s += '[' + str (repetition + 1 ) + ']'
252
264
if retry :
@@ -379,11 +391,14 @@ def devices_by_test_config( test, exceptions ):
379
391
380
392
:param test: The test (of class type Test) we're interested in
381
393
"""
382
- global forced_configurations
394
+ global forced_configurations , device_set
383
395
for configuration in ( forced_configurations or test .config .configurations ):
384
396
try :
385
- for serial_numbers in devices .by_configuration ( configuration , exceptions ):
386
- yield configuration , serial_numbers
397
+ for serial_numbers in devices .by_configuration ( configuration , exceptions , device_set ):
398
+ if not serial_numbers :
399
+ log .d ( 'configuration:' , configuration_str ( configuration ), 'has no matching device; ignoring' )
400
+ else :
401
+ yield configuration , serial_numbers
387
402
except RuntimeError as e :
388
403
if devices .acroname :
389
404
log .e ( log .red + test .name + log .reset + ': ' + str ( e ) )
@@ -462,6 +477,17 @@ def test_wrapper( test, configuration=None, repetition=1, sns=None ):
462
477
finally :
463
478
log .debug_unindent ()
464
479
#
480
+ if device_set is not None :
481
+ sns = set () # convert the list of specs to a list of serial numbers
482
+ ignored_list = list ()
483
+ for spec in device_set :
484
+ included_devices = [sn for sn in devices .by_spec ( spec , ignored_list )]
485
+ if not included_devices :
486
+ log .f ( f'No match for --device "{ spec } "' )
487
+ sns .update ( included_devices )
488
+ device_set = sns
489
+ log .d ( f'ignoring devices other than: { serial_numbers_to_string ( device_set )} ' )
490
+ #
465
491
log .progress ()
466
492
#
467
493
# Automatically detect github actions based on environment variable
@@ -543,7 +569,7 @@ def test_wrapper( test, configuration=None, repetition=1, sns=None ):
543
569
for configuration , serial_numbers in devices_by_test_config ( test , exceptions ):
544
570
for repetition in range (repeat ):
545
571
try :
546
- log .d ( 'configuration:' , configuration )
572
+ log .d ( 'configuration:' , configuration_str ( configuration , repetition , sns = serial_numbers ) )
547
573
log .debug_indent ()
548
574
if not no_reset :
549
575
devices .enable_only ( serial_numbers , recycle = True )
0 commit comments