27
27
28
28
import argparse
29
29
import os
30
+ import re
30
31
import sys
31
32
import time
32
33
import serial
@@ -212,14 +213,39 @@ def flash_uniflash(board, firmware):
212
213
213
214
214
215
# -------------------------------------------------------------
215
- # Tests
216
+ # Tests: dual
216
217
# -------------------------------------------------------------
217
- def test_board_test (board ):
218
+
219
+ def test_dual_host_info_to_device_cdc (board ):
220
+ uid = board ['uid' ]
221
+ declared_devs = [f'{ d ["vid_pid" ]} _{ d ["serial" ]} ' for d in board ['tests' ]['dual_attached' ]]
222
+
223
+ port = get_serial_dev (uid , 'TinyUSB' , "TinyUSB_Device" , 0 )
224
+ ser = open_serial_dev (port )
225
+ # read from cdc, first line should contain vid/pid and serial
226
+ data = ser .read (1000 )
227
+ lines = data .decode ('utf-8' ).splitlines ()
228
+ enum_dev_sn = []
229
+ for l in lines :
230
+ vid_pid_sn = re .search (r'ID ([0-9a-fA-F]+):([0-9a-fA-F]+) SN (\w+)' , l )
231
+ if vid_pid_sn :
232
+ print (f'\r \n { l } ' , end = '' )
233
+ enum_dev_sn .append (f'{ vid_pid_sn .group (1 )} _{ vid_pid_sn .group (2 )} _{ vid_pid_sn .group (3 )} ' )
234
+
235
+ assert (set (declared_devs ) == set (enum_dev_sn )), \
236
+ f'Enumerated devices { enum_dev_sn } not match with declared { declared_devs } '
237
+ return 0
238
+
239
+
240
+ # -------------------------------------------------------------
241
+ # Tests: device
242
+ # -------------------------------------------------------------
243
+ def test_device_board_test (board ):
218
244
# Dummy test
219
245
pass
220
246
221
247
222
- def test_cdc_dual_ports (board ):
248
+ def test_device_cdc_dual_ports (board ):
223
249
uid = board ['uid' ]
224
250
port1 = get_serial_dev (uid , 'TinyUSB' , "TinyUSB_Device" , 0 )
225
251
port2 = get_serial_dev (uid , 'TinyUSB' , "TinyUSB_Device" , 2 )
@@ -241,7 +267,7 @@ def test_cdc_dual_ports(board):
241
267
assert ser2 .read (100 ) == str2 .upper (), 'Port2 wrong data'
242
268
243
269
244
- def test_cdc_msc (board ):
270
+ def test_device_cdc_msc (board ):
245
271
uid = board ['uid' ]
246
272
# Echo test
247
273
port = get_serial_dev (uid , 'TinyUSB' , "TinyUSB_Device" , 0 )
@@ -262,11 +288,11 @@ def test_cdc_msc(board):
262
288
assert data == readme , 'MSC wrong data'
263
289
264
290
265
- def test_cdc_msc_freertos (board ):
266
- test_cdc_msc (board )
291
+ def test_device_cdc_msc_freertos (board ):
292
+ test_device_cdc_msc (board )
267
293
268
294
269
- def test_dfu (board ):
295
+ def test_device_dfu (board ):
270
296
uid = board ['uid' ]
271
297
272
298
# Wait device enum
@@ -308,7 +334,7 @@ def test_dfu(board):
308
334
os .remove (f_dfu1 )
309
335
310
336
311
- def test_dfu_runtime (board ):
337
+ def test_device_dfu_runtime (board ):
312
338
uid = board ['uid' ]
313
339
314
340
# Wait device enum
@@ -325,7 +351,7 @@ def test_dfu_runtime(board):
325
351
assert timeout , 'Device not available'
326
352
327
353
328
- def test_hid_boot_interface (board ):
354
+ def test_device_hid_boot_interface (board ):
329
355
uid = board ['uid' ]
330
356
kbd = get_hid_dev (uid , 'TinyUSB' , 'TinyUSB_Device' , 'event-kbd' )
331
357
mouse1 = get_hid_dev (uid , 'TinyUSB' , 'TinyUSB_Device' , 'if01-event-mouse' )
@@ -341,7 +367,7 @@ def test_hid_boot_interface(board):
341
367
assert timeout , 'HID device not available'
342
368
343
369
344
- def test_hid_composite_freertos (id ):
370
+ def test_device_hid_composite_freertos (id ):
345
371
# TODO implement later
346
372
pass
347
373
@@ -351,13 +377,15 @@ def test_hid_composite_freertos(id):
351
377
# -------------------------------------------------------------
352
378
# all possible tests: board_test is added last to disable board's usb
353
379
all_tests = [
354
- 'cdc_dual_ports' ,
355
- 'cdc_msc' ,
356
- 'dfu' ,
357
- 'cdc_msc_freertos' , # dont test 2 cdc_msc next to each other, since they have same vid/pid. Can be confused by host
358
- 'dfu_runtime' ,
359
- 'hid_boot_interface' ,
360
- 'board_test'
380
+ 'device/cdc_dual_ports' ,
381
+ 'device/cdc_msc' ,
382
+ 'device/dfu' ,
383
+ 'device/cdc_msc_freertos' , # don't test 2 cdc_msc next to each other
384
+ 'device/dfu_runtime' ,
385
+ 'device/hid_boot_interface' ,
386
+
387
+ 'dual/host_info_to_device_cdc' ,
388
+ 'device/board_test'
361
389
]
362
390
363
391
@@ -366,23 +394,23 @@ def test_board(board):
366
394
flasher = board ['flasher' ].lower ()
367
395
368
396
# default to all tests
369
- if 'tests' in board :
370
- test_list = board ['tests' ] + ['board_test' ]
371
- else :
372
- test_list = list (all_tests )
397
+ test_list = list (all_tests )
373
398
374
- # remove skip_tests
375
- if 'tests_skip' in board :
376
- for skip in board ['tests_skip' ]:
377
- if skip in test_list :
378
- test_list .remove (skip )
399
+ if 'tests' in board :
400
+ board_tests = board ['tests' ]
401
+ if 'only' in board_tests :
402
+ test_list = board_tests ['only' ] + ['device/board_test' ]
403
+ if 'skip' in board_tests :
404
+ for skip in board_tests ['skip' ]:
405
+ if skip in test_list :
406
+ test_list .remove (skip )
379
407
380
408
err_count = 0
381
409
for test in test_list :
382
- fw_dir = f'cmake-build/cmake-build-{ name } /device/ { test } '
410
+ fw_dir = f'cmake-build/cmake-build-{ name } /{ test } '
383
411
if not os .path .exists (fw_dir ):
384
- fw_dir = f'examples/cmake-build-{ name } /device/ { test } '
385
- fw_name = f'{ fw_dir } /{ test } '
412
+ fw_dir = f'examples/cmake-build-{ name } /{ test } '
413
+ fw_name = f'{ fw_dir } /{ os . path . basename ( test ) } '
386
414
print (f'{ name :30} { test :20} ... ' , end = '' )
387
415
388
416
if not os .path .exists (fw_dir ):
@@ -400,7 +428,7 @@ def test_board(board):
400
428
401
429
if ret .returncode == 0 :
402
430
try :
403
- ret = globals ()[f'test_{ test } ' ](board )
431
+ ret = globals ()[f'test_{ test . replace ( "/" , "_" ) } ' ](board )
404
432
print ('OK' )
405
433
except Exception as e :
406
434
err_count += 1
@@ -409,7 +437,6 @@ def test_board(board):
409
437
else :
410
438
err_count += 1
411
439
print ('Flash failed' )
412
-
413
440
return err_count
414
441
415
442
0 commit comments