45
45
46
46
verbose = False
47
47
48
+ # -------------------------------------------------------------
49
+ # Path
50
+ # -------------------------------------------------------------
51
+ OPENCOD_ADI_PATH = f'{ os .getenv ("HOME" )} /app/openocd_adi'
52
+
48
53
# get usb serial by id
49
54
def get_serial_dev (id , vendor_str , product_str , ifnum ):
50
55
if vendor_str and product_str :
@@ -112,8 +117,8 @@ def read_disk_file(uid, lun, fname):
112
117
# -------------------------------------------------------------
113
118
# Flashing firmware
114
119
# -------------------------------------------------------------
115
- def run_cmd (cmd ):
116
- r = subprocess .run (cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
120
+ def run_cmd (cmd , cwd = None ):
121
+ r = subprocess .run (cmd , cwd = cwd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
117
122
if r .returncode != 0 :
118
123
title = f'COMMAND FAILED: { cmd } '
119
124
print ()
@@ -187,11 +192,7 @@ def flash_openocd_wch(board, firmware):
187
192
188
193
189
194
def flash_openocd_adi (board , firmware ):
190
- openocd_adi_script_path = f'{ os .getenv ("HOME" )} /app/openocd_adi/tcl'
191
- if not os .path .exists (openocd_adi_script_path ):
192
- openocd_adi_script_path = '/home/pi/openocd_adi/tcl'
193
-
194
- ret = run_cmd (f'openocd_adi -c "adapter serial { board ["flasher_sn" ]} " -s { openocd_adi_script_path } '
195
+ ret = run_cmd (f'{ OPENCOD_ADI_PATH } /src/openocd -c "adapter serial { board ["flasher_sn" ]} " -s { OPENCOD_ADI_PATH } /tcl '
195
196
f'{ board ["flasher_args" ]} -c "program { firmware } .elf reset exit"' )
196
197
return ret
197
198
@@ -203,14 +204,14 @@ def flash_wlink_rs(board, firmware):
203
204
204
205
def flash_esptool (board , firmware ):
205
206
port = get_serial_dev (board ["flasher_sn" ], None , None , 0 )
206
- dir = os .path .dirname (f'{ firmware } .bin' )
207
- with open (f'{ dir } /config.env' ) as f :
208
- IDF_TARGET = json .load (f )['IDF_TARGET' ]
209
- with open (f'{ dir } /flash_args' ) as f :
207
+ fw_dir = os .path .dirname (f'{ firmware } .bin' )
208
+ with open (f'{ fw_dir } /config.env' ) as f :
209
+ idf_target = json .load (f )['IDF_TARGET' ]
210
+ with open (f'{ fw_dir } /flash_args' ) as f :
210
211
flash_args = f .read ().strip ().replace ('\n ' , ' ' )
211
- command = (f'esptool.py --chip { IDF_TARGET } -p { port } { board ["flasher_args" ]} '
212
+ command = (f'esptool.py --chip { idf_target } -p { port } { board ["flasher_args" ]} '
212
213
f'--before=default_reset --after=hard_reset write_flash { flash_args } ' )
213
- ret = subprocess . run (command , shell = True , cwd = dir , stdout = subprocess . PIPE , stderr = subprocess . STDOUT )
214
+ ret = run_cmd (command , cwd = fw_dir )
214
215
return ret
215
216
216
217
@@ -305,8 +306,7 @@ def test_device_dfu(board):
305
306
# Wait device enum
306
307
timeout = ENUM_TIMEOUT
307
308
while timeout :
308
- ret = subprocess .run (f'dfu-util -l' ,
309
- shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
309
+ ret = run_cmd (f'dfu-util -l' )
310
310
stdout = ret .stdout .decode ()
311
311
if f'serial="{ uid } "' in stdout and 'Found DFU: [cafe:4000]' in stdout :
312
312
break
@@ -347,8 +347,7 @@ def test_device_dfu_runtime(board):
347
347
# Wait device enum
348
348
timeout = ENUM_TIMEOUT
349
349
while timeout :
350
- ret = subprocess .run (f'dfu-util -l' ,
351
- shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
350
+ ret = run_cmd (f'dfu-util -l' )
352
351
stdout = ret .stdout .decode ()
353
352
if f'serial="{ uid } "' in stdout and 'Found Runtime: [cafe:4000]' in stdout :
354
353
break
@@ -382,17 +381,18 @@ def test_device_hid_composite_freertos(id):
382
381
# -------------------------------------------------------------
383
382
# Main
384
383
# -------------------------------------------------------------
385
- # all possible tests: board_test is added last to disable board's usb
386
- all_tests = [
384
+ # device tests
385
+ device_tests = [
387
386
'device/cdc_dual_ports' ,
388
387
'device/cdc_msc' ,
389
388
'device/dfu' ,
390
389
'device/cdc_msc_freertos' , # don't test 2 cdc_msc next to each other
391
390
'device/dfu_runtime' ,
392
391
'device/hid_boot_interface' ,
392
+ ]
393
393
394
+ dual_tests = [
394
395
'dual/host_info_to_device_cdc' ,
395
- 'device/board_test'
396
396
]
397
397
398
398
@@ -401,17 +401,22 @@ def test_board(board):
401
401
flasher = board ['flasher' ].lower ()
402
402
403
403
# default to all tests
404
- test_list = list (all_tests )
404
+ test_list = list (device_tests )
405
405
406
406
if 'tests' in board :
407
407
board_tests = board ['tests' ]
408
408
if 'only' in board_tests :
409
- test_list = board_tests ['only' ] + [ 'device/board_test' ]
409
+ test_list = board_tests ['only' ]
410
410
if 'skip' in board_tests :
411
411
for skip in board_tests ['skip' ]:
412
412
if skip in test_list :
413
413
test_list .remove (skip )
414
414
print (f'{ name :25} { skip :30} ... Skip' )
415
+ if 'dual_attached' in board_tests :
416
+ test_list += dual_tests
417
+
418
+ # board_test is added last to disable board's usb
419
+ test_list .append ('device/board_test' )
415
420
416
421
err_count = 0
417
422
for test in test_list :
@@ -422,7 +427,7 @@ def test_board(board):
422
427
print (f'{ name :25} { test :30} ... ' , end = '' )
423
428
424
429
if not os .path .exists (fw_dir ):
425
- print ('Skip' )
430
+ print ('Skip (no binary) ' )
426
431
continue
427
432
428
433
# flash firmware. It may fail randomly, retry a few times
0 commit comments