41
41
42
42
import sys
43
43
import json
44
+ import optparse
45
+ import pprint
44
46
from prettytable import PrettyTable
45
47
from serial import Serial
46
48
51
53
52
54
ROOT = abspath (join (dirname (__file__ ), ".." ))
53
55
sys .path .insert (0 , ROOT )
56
+ # Imports related to mbed build pi
54
57
from workspace_tools .build_api import build_project , build_mbed_libs
55
58
from workspace_tools .paths import BUILD_DIR
56
59
from workspace_tools .targets import TARGET_MAP
60
63
ROOT = abspath (join (dirname (__file__ ), ".." ))
61
64
sys .path .insert (0 , ROOT )
62
65
66
+ # Imports related to mbed build pi
63
67
from workspace_tools .utils import delete_dir_files
64
68
from workspace_tools .settings import MUTs
65
69
@@ -77,7 +81,9 @@ def reset(self, mcu_name, serial,
77
81
"""
78
82
if sleep_before_reset > 0 :
79
83
sleep (sleep_before_reset )
80
- verbose_msg = "Reset::cmd(sendBreak)"
84
+ if verbose :
85
+ verbose_msg = "Reset::cmd(sendBreak)"
86
+ # Reset type decision
81
87
if mcu_name .startswith ('NRF51822' ): # Nordic
82
88
call (["nrfjprog" , "-r" ])
83
89
verbose_msg = "Reset::cmd(nrfjprog)"
@@ -86,6 +92,7 @@ def reset(self, mcu_name, serial,
86
92
verbose_msg = "Reset::cmd(ST-LINK_CLI.exe)"
87
93
else :
88
94
serial .sendBreak ()
95
+
89
96
if sleep_before_reset > 0 :
90
97
sleep (sleep_after_reset )
91
98
if verbose :
@@ -97,6 +104,7 @@ def flush_serial(self, serial):
97
104
serial .flushOutput ()
98
105
99
106
def is_peripherals_available (self , target , peripherals = None ):
107
+ """ Checks if specified target should run specific peripheral test case."""
100
108
if peripherals is not None :
101
109
peripherals = set (peripherals )
102
110
@@ -114,7 +122,7 @@ def is_peripherals_available(self, target, peripherals=None):
114
122
return False
115
123
116
124
def run_host_test (self , name , target_name , disk , port ,
117
- duration , extra_serial , verbose = True ):
125
+ duration , extra_serial , verbose = False ):
118
126
"""
119
127
Functions resets target and grabs by timeouted pooling test log
120
128
via serial port.
@@ -246,25 +254,54 @@ def shape_test_request(mcu, image_path, test_id, duration=10):
246
254
247
255
248
256
if __name__ == '__main__' :
249
- start = time ()
250
- single_test = SingleTestRunner ()
257
+ # Command line options
258
+ parser = optparse .OptionParser ()
259
+ parser .add_option ('-i' , '--tests' ,
260
+ dest = 'test_spec_filename' ,
261
+ metavar = "FILE" ,
262
+ help = 'Points to file with test specification' )
263
+
264
+ parser .add_option ('-s' , '--suppress-summary' ,
265
+ dest = 'suppress_summary' ,
266
+ default = False ,
267
+ action = "store_true" ,
268
+ help = 'Suppresses display of wellformatted table with test results' )
269
+
270
+ parser .add_option ('-v' , '--verbose' ,
271
+ dest = 'verbose' ,
272
+ default = False ,
273
+ action = "store_true" ,
274
+ help = 'Verbose mode (pronts some extra information)' )
275
+
276
+ parser .epilog = "Example: singletest.py -i test_spec.json"
277
+ (opts , args ) = parser .parse_args ()
251
278
252
279
# Below list tells script which targets and their toolchain(s)
253
280
# should be covered by the test scenario
254
- test_spec = {
255
- "targets" : {
256
- # "KL25Z": ["ARM", "GCC_ARM"],
257
- # "LPC1768": ["ARM", "GCC_ARM", "GCC_CR", "GCC_CS", "IAR"],
258
- # "LPC11U24": ["uARM"]
259
- # "UBLOX_C027": ["IAR"]
260
- # "NRF51822": ["ARM"]
261
- # "NUCLEO_F103RB": ["ARM"],
262
- # "LPC2368": ["ARM"],
263
- # "LPC812": ["uARM"],
264
- # "LPC1549": ["uARM"]
265
- "LPC4088" : ["ARM" ] # , "GCC_CR", "GCC_ARM"
266
- }
267
- }
281
+ test_spec = None
282
+
283
+ # Open file with test specification
284
+ if opts .test_spec_filename :
285
+ try :
286
+ with open (opts .test_spec_filename ) as data_file :
287
+ try :
288
+ test_spec = json .load (data_file )
289
+ except ValueError as json_error_msg :
290
+ test_spec = None
291
+ print "Error: %s" % (json_error_msg )
292
+ except IOError as fileopen_error_msg :
293
+ print "Error: %s" % (fileopen_error_msg )
294
+ if opts .verbose and test_spec :
295
+ pp = pprint .PrettyPrinter (indent = 4 )
296
+ pp .pprint (test_spec )
297
+
298
+ if test_spec is None :
299
+ parser .print_help ()
300
+ exit (- 1 )
301
+
302
+ # Magic happens here... ;)
303
+ start = time ()
304
+ single_test = SingleTestRunner ()
268
305
269
306
clean = test_spec .get ('clean' , False )
270
307
test_ids = test_spec .get ('test_ids' , [])
@@ -287,7 +324,8 @@ def shape_test_request(mcu, image_path, test_id, duration=10):
287
324
288
325
if test .automated and test .is_supported (target , toolchain ):
289
326
if not single_test .is_peripherals_available (target , test .peripherals ):
290
- print "TargetTest::%s::TestSkipped(%s)" % (target , "," .join (test .peripherals ))
327
+ if opts .verbose :
328
+ print "TargetTest::%s::TestSkipped(%s)" % (target , "," .join (test .peripherals ))
291
329
continue
292
330
293
331
test_result = {
@@ -296,7 +334,7 @@ def shape_test_request(mcu, image_path, test_id, duration=10):
296
334
'test_id' : test_id ,
297
335
}
298
336
299
- path = build_project (test .source_dir , join (build_dir , test_id ), T , toolchain , test .dependencies , clean = clean , verbose = False )
337
+ path = build_project (test .source_dir , join (build_dir , test_id ), T , toolchain , test .dependencies , clean = clean , verbose = opts . verbose )
300
338
301
339
if target .startswith ('NRF51822' ): # Nordic:
302
340
#Convert bin to Hex and Program nrf chip via jlink
@@ -314,19 +352,21 @@ def shape_test_request(mcu, image_path, test_id, duration=10):
314
352
315
353
elapsed_time = time () - start
316
354
317
- print
318
- print "Test summary:"
319
- # Pretty table package is used to print results
320
- pt = PrettyTable (["Result" , "Target" , "Toolchain" , "Test ID" , "Test Description" ,
321
- "Elapsed Time (sec)" , "Timeout (sec)" ])
322
- pt .align ["Result" ] = "l" # Left align
323
- pt .align ["Target" ] = "l" # Left align
324
- pt .align ["Toolchain" ] = "l" # Left align
325
- pt .align ["Test ID" ] = "l" # Left align
326
- pt .align ["Test Description" ] = "l" # Left align
327
- pt .padding_width = 1 # One space between column edges and contents (default)
328
-
329
- for test in test_summary :
330
- pt .add_row (test )
331
- print pt
355
+ # Human readable summary
356
+ if not opts .suppress_summary :
357
+ print
358
+ print "Test summary:"
359
+ # Pretty table package is used to print results
360
+ pt = PrettyTable (["Result" , "Target" , "Toolchain" , "Test ID" , "Test Description" ,
361
+ "Elapsed Time (sec)" , "Timeout (sec)" ])
362
+ pt .align ["Result" ] = "l" # Left align
363
+ pt .align ["Target" ] = "l" # Left align
364
+ pt .align ["Toolchain" ] = "l" # Left align
365
+ pt .align ["Test ID" ] = "l" # Left align
366
+ pt .align ["Test Description" ] = "l" # Left align
367
+ pt .padding_width = 1 # One space between column edges and contents (default)
368
+
369
+ for test in test_summary :
370
+ pt .add_row (test )
371
+ print pt
332
372
print "Completed in %d sec" % (time () - start )
0 commit comments