summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2024-08-08 22:41:26 +0700
committerGitHub <[email protected]>2024-08-08 22:41:26 +0700
commitdcd0f39b537f99c14d9a3dd291ab573cddeb47d5 (patch)
tree06c4f2d930c32c31dd3e283f7c0bec1e5f0be131 /test
parenta7d188832841cc5cbffdf433c07e4897f45c1088 (diff)
parente7e6fe7cd546c389cdafd1cab9dbf4d60791e70f (diff)
Merge pull request #2750 from hathach/fix-ch32v203-setup
rework fsdev driver, fix ch32v203 race condition and stability issue
Diffstat (limited to 'test')
-rw-r--r--test/hil/hil_test.py217
-rw-r--r--test/hil/rpi.json7
2 files changed, 116 insertions, 108 deletions
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index bdc48591e..b67520576 100644
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -34,14 +34,7 @@ import subprocess
import json
import glob
import platform
-
-# for RPI double reset
-if platform.machine() == 'aarch64':
- try:
- import gpiozero
- except ImportError:
- pass
-
+from multiprocessing import Pool
ENUM_TIMEOUT = 30
@@ -130,10 +123,11 @@ def run_cmd(cmd):
def flash_jlink(board, firmware):
script = ['halt', 'r', f'loadfile {firmware}.elf', 'r', 'go', 'exit']
- with open('flash.jlink', 'w') as f:
+ f_jlink = f'{board["name"]}_{os.path.basename(firmware)}.jlink'
+ with open(f_jlink, 'w') as f:
f.writelines(f'{s}\n' for s in script)
- ret = run_cmd(f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile flash.jlink')
- os.remove('flash.jlink')
+ ret = run_cmd(f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile {f_jlink}')
+ os.remove(f_jlink)
return ret
@@ -152,6 +146,42 @@ def flash_openocd(board, firmware):
return ret
+def flash_openocd_wch(board, firmware):
+ # Content of the wch-riscv.cfg file
+ cfg_content = """
+adapter driver wlinke
+adapter speed 6000
+transport select sdi
+
+wlink_set_address 0x00000000
+set _CHIPNAME wch_riscv
+sdi newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x00001
+
+set _TARGETNAME $_CHIPNAME.cpu
+
+target create $_TARGETNAME.0 wch_riscv -chain-position $_TARGETNAME
+$_TARGETNAME.0 configure -work-area-phys 0x20000000 -work-area-size 10000 -work-area-backup 1
+set _FLASHNAME $_CHIPNAME.flash
+
+flash bank $_FLASHNAME wch_riscv 0x00000000 0 0 0 $_TARGETNAME.0
+
+echo "Ready for Remote Connections"
+"""
+ f_wch = f"wch-riscv_{board['uid']}.cfg"
+ if not os.path.exists(f_wch):
+ with open(f_wch, 'w') as file:
+ file.write(cfg_content)
+
+ ret = run_cmd(f'openocd_wch -c "adapter serial {board["flasher_sn"]}" -f {f_wch} -c "program {firmware}.elf reset exit"')
+ return ret
+
+
+def flash_wlink_rs(board, firmware):
+ # wlink use index for probe selection and lacking usb serial support
+ ret = run_cmd(f'wlink flash {firmware}.elf')
+ return ret
+
+
def flash_esptool(board, firmware):
port = get_serial_dev(board["flasher_sn"], None, None, 0)
dir = os.path.dirname(f'{firmware}.bin')
@@ -165,38 +195,6 @@ def flash_esptool(board, firmware):
return ret
-def doublereset_with_rpi_gpio(pin):
- # Off = 0 = Reset
- nrst = gpiozero.LED(pin)
-
- nrst.off()
- time.sleep(0.1)
- nrst.on()
- time.sleep(0.1)
- nrst.off()
- time.sleep(0.1)
- nrst.on()
-
-
-def flash_bossac(board, firmware):
- # double reset to enter bootloader
- if platform.machine() == 'aarch64':
- doublereset_with_rpi_gpio(board["flasher_reset_pin"])
-
- port = get_serial_dev(board["uid"], board["flashser_vendor"], board["flasher_product"], 0)
- timeout = ENUM_TIMEOUT
- while timeout:
- if os.path.exists(port):
- break
- else:
- time.sleep(0.5)
- timeout = timeout - 0.5
- assert timeout, 'bossac bootloader is not available'
- # sleep a bit more for bootloader to be ready
- time.sleep(0.5)
- ret = run_cmd(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}.bin')
- return ret
-
# -------------------------------------------------------------
# Tests
# -------------------------------------------------------------
@@ -264,29 +262,30 @@ def test_dfu(id):
assert timeout, 'Device not available'
+ f_dfu0 = f'dfu0_{id}'
+ f_dfu1 = f'dfu1_{id}'
+
# Test upload
try:
- os.remove('dfu0')
- os.remove('dfu1')
+ os.remove(f_dfu0)
+ os.remove(f_dfu1)
except OSError:
pass
- ret = subprocess.run(f'dfu-util -S {id} -a 0 -U dfu0',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(f'dfu-util -S {id} -a 0 -U {f_dfu0}')
assert ret.returncode == 0, 'Upload failed'
- ret = subprocess.run(f'dfu-util -S {id} -a 1 -U dfu1',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(f'dfu-util -S {id} -a 1 -U {f_dfu1}')
assert ret.returncode == 0, 'Upload failed'
- with open('dfu0') as f:
+ with open(f_dfu0) as f:
assert 'Hello world from TinyUSB DFU! - Partition 0' in f.read(), 'Wrong uploaded data'
- with open('dfu1') as f:
+ with open(f_dfu1) as f:
assert 'Hello world from TinyUSB DFU! - Partition 1' in f.read(), 'Wrong uploaded data'
- os.remove('dfu0')
- os.remove('dfu1')
+ os.remove(f_dfu0)
+ os.remove(f_dfu1)
def test_dfu_runtime(id):
@@ -327,6 +326,61 @@ def test_hid_composite_freertos(id):
# -------------------------------------------------------------
# Main
# -------------------------------------------------------------
+# all possible tests: board_test is added last to disable board's usb
+all_tests = [
+ 'cdc_dual_ports',
+ 'cdc_msc',
+ 'cdc_msc_freertos',
+ 'dfu',
+ 'dfu_runtime',
+ 'hid_boot_interface',
+ 'board_test'
+]
+
+
+def test_board(item):
+ name = item['name']
+ flasher = item['flasher'].lower()
+
+ # default to all tests
+ if 'tests' in item:
+ test_list = item['tests'] + ['board_test']
+ else:
+ test_list = list(all_tests)
+
+ # remove skip_tests
+ if 'tests_skip' in item:
+ for skip in item['tests_skip']:
+ if skip in test_list:
+ test_list.remove(skip)
+
+ for test in test_list:
+ fw_dir = f'cmake-build/cmake-build-{name}/device/{test}'
+ if not os.path.exists(fw_dir):
+ fw_dir = f'examples/cmake-build-{name}/device/{test}'
+ fw_name = f'{fw_dir}/{test}'
+ print(f'{name:30} {test:20} ... ', end='')
+
+ if not os.path.exists(fw_dir):
+ print('Skip')
+ continue
+
+ # flash firmware. It may fail randomly, retry a few times
+ for i in range(3):
+ ret = globals()[f'flash_{flasher}'](item, fw_name)
+ if ret.returncode == 0:
+ break
+ else:
+ print(f'Flashing failed, retry {i+1}')
+ time.sleep(1)
+
+ assert ret.returncode == 0, 'Flash failed\n' + ret.stdout.decode()
+
+ # run test
+ globals()[f'test_{test}'](item['uid'])
+ print('OK')
+
+
def main():
"""
Hardware test on specified boards
@@ -345,66 +399,13 @@ def main():
with open(config_file) as f:
config = json.load(f)
- # all possible tests: board_test is added last to disable board's usb
- all_tests = [
- 'cdc_dual_ports',
- 'cdc_msc',
- 'cdc_msc_freertos',
- 'dfu',
- 'dfu_runtime',
- 'hid_boot_interface',
- 'board_test'
- ]
-
if len(boards) == 0:
config_boards = config['boards']
else:
config_boards = [e for e in config['boards'] if e['name'] in boards]
- for item in config_boards:
- name = item['name']
- print(f'Testing board:{name}')
- flasher = item['flasher'].lower()
-
- # default to all tests
- if 'tests' in item:
- test_list = item['tests'] + ['board_test']
- else:
- test_list = list(all_tests)
-
- # remove skip_tests
- if 'tests_skip' in item:
- for skip in item['tests_skip']:
- if skip in test_list:
- test_list.remove(skip)
-
- for test in test_list:
- fw_dir = f'cmake-build/cmake-build-{name}/device/{test}'
- if not os.path.exists(fw_dir):
- fw_dir = f'examples/cmake-build-{name}/device/{test}'
- fw_name = f'{fw_dir}/{test}'
- print(f' {test} ... ', end='')
- sys.stdout.flush()
-
- if not os.path.exists(fw_dir):
- print('Skip')
- continue
-
- # flash firmware. It may fail randomly, retry a few times
- for i in range(3):
- ret = globals()[f'flash_{flasher}'](item, fw_name)
- if ret.returncode == 0:
- break
- else:
- print(f'Flashing failed, retry {i+1}')
- time.sleep(1)
-
- assert ret.returncode == 0, 'Flash failed\n' + ret.stdout.decode()
-
- # run test
- globals()[f'test_{test}'](item['uid'])
-
- print('OK')
+ with Pool(processes=os.cpu_count()) as pool:
+ pool.map(test_board, config_boards)
if __name__ == '__main__':
diff --git a/test/hil/rpi.json b/test/hil/rpi.json
index 9520f30e2..fd00913f3 100644
--- a/test/hil/rpi.json
+++ b/test/hil/rpi.json
@@ -57,6 +57,13 @@
"flasher": "openocd",
"flasher_sn": "066FFF495087534867063844",
"flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg"
+ },
+ {
+ "name": "nanoch32v203",
+ "uid": "CDAB277B0FBC03E339E339E3",
+ "flasher": "openocd_wch",
+ "flasher_sn": "EBCA8F0670AF",
+ "flasher_args": ""
}
],
"boards-skip": [