summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fuzz/net_fuzz.cc10
-rw-r--r--test/hil/hfp.json (renamed from test/hil/hil_hfp.json)0
-rw-r--r--test/hil/hil_test.py95
-rw-r--r--test/hil/pi4.json (renamed from test/hil/hil_pi4.json)20
-rw-r--r--test/unit-test/project.yml25
5 files changed, 77 insertions, 73 deletions
diff --git a/test/fuzz/net_fuzz.cc b/test/fuzz/net_fuzz.cc
index 63cd1ac98..468437b0c 100644
--- a/test/fuzz/net_fuzz.cc
+++ b/test/fuzz/net_fuzz.cc
@@ -69,14 +69,6 @@ void tud_network_init_cb(void) {
// TODO removed later since it is not part of tinyusb stack
uint8_t tud_network_mac_address[6] = {0};
-//------------- NCM -------------//
-
-// callback to client providing optional indication of internal state of network
-// driver
-void tud_network_link_state_cb(bool state) {
- (void)state;
- // NoOp.
-}
-}
+} // extern "C"
#endif
diff --git a/test/hil/hil_hfp.json b/test/hil/hfp.json
index e79a3cfc9..e79a3cfc9 100644
--- a/test/hil/hil_hfp.json
+++ b/test/hil/hfp.json
diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py
index 7c662aeea..c2699cc6f 100644
--- a/test/hil/hil_test.py
+++ b/test/hil/hil_test.py
@@ -25,20 +25,22 @@
# ACTION=="add", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", MODE="0666", PROGRAM="/bin/sh -c 'echo $$ID_SERIAL_SHORT | rev | cut -c -8 | rev'", SYMLINK+="ttyUSB_%c.%s{bInterfaceNumber}"
# ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ENV{ID_FS_USAGE}=="filesystem", MODE="0666", PROGRAM="/bin/sh -c 'echo $$ID_SERIAL_SHORT | rev | cut -c -8 | rev'", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media/blkUSB_%c.%s{bInterfaceNumber}"
+import argparse
import os
import sys
import time
-import click
import serial
import subprocess
import json
import glob
+import platform
# for RPI double reset
-try:
- import gpiozero
-except ImportError:
- pass
+if platform.machine() == 'aarch64':
+ try:
+ import gpiozero
+ except ImportError:
+ pass
ENUM_TIMEOUT = 10
@@ -111,27 +113,39 @@ def read_disk_file(id, fname):
# -------------------------------------------------------------
# Flashing firmware
# -------------------------------------------------------------
+def run_cmd(cmd):
+ # print(cmd)
+ r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ title = 'command error'
+ if r.returncode != 0:
+ # print build output if failed
+ if os.getenv('CI'):
+ print(f"::group::{title}")
+ print(r.stdout.decode("utf-8"))
+ print(f"::endgroup::")
+ else:
+ print(title)
+ print(r.stdout.decode("utf-8"))
+ return r
+
+
def flash_jlink(board, firmware):
- script = ['halt', 'r', f'loadfile {firmware}', 'r', 'go', 'exit']
+ script = ['halt', 'r', f'loadfile {firmware}.elf', 'r', 'go', 'exit']
with open('flash.jlink', 'w') as f:
f.writelines(f'{s}\n' for s in script)
- ret = subprocess.run(
- f'JLinkExe -USB {board["flasher_sn"]} {board["flasher_args"]} -if swd -JTAGConf -1,-1 -speed auto -NoGui 1 -ExitOnError 1 -CommandFile flash.jlink',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ 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')
return ret
def flash_openocd(board, firmware):
- ret = subprocess.run(
- f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware} reset exit"',
- shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ ret = run_cmd(f'openocd -c "adapter serial {board["flasher_sn"]}" {board["flasher_args"]} -c "program {firmware}.elf reset exit"')
return ret
def flash_esptool(board, firmware):
port = get_serial_dev(board["flasher_sn"], None, None, 0)
- dir = os.path.dirname(firmware)
+ dir = os.path.dirname(f'{firmware}.bin')
with open(f'{dir}/config.env') as f:
IDF_TARGET = json.load(f)['IDF_TARGET']
with open(f'{dir}/flash_args') as f:
@@ -154,9 +168,11 @@ def doublereset_with_rpi_gpio(board):
time.sleep(0.1)
led.on()
+
def flash_bossac(board, firmware):
# double reset to enter bootloader
- doublereset_with_rpi_gpio(board)
+ if platform.machine() == 'aarch64':
+ doublereset_with_rpi_gpio(board)
port = get_serial_dev(board["uid"], board["flashser_vendor"], board["flasher_product"], 0)
timeout = ENUM_TIMEOUT
@@ -169,8 +185,7 @@ def flash_bossac(board, firmware):
assert timeout, 'bossac bootloader is not available'
# sleep a bit more for bootloader to be ready
time.sleep(0.5)
- ret = subprocess.run(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}', shell=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ ret = run_cmd(f'bossac --port {port} {board["flasher_args"]} -U -i -R -e -w {firmware}.bin')
return ret
# -------------------------------------------------------------
@@ -303,13 +318,18 @@ def test_hid_composite_freertos(id):
# -------------------------------------------------------------
# Main
# -------------------------------------------------------------
[email protected]('config_file')
[email protected]('-b', '--board', multiple=True, default=None, help='Boards to test, all if not specified')
-def main(config_file, board):
+def main():
"""
Hardware test on specified boards
"""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('config_file', help='Configuration JSON file')
+ parser.add_argument('-b', '--board', action='append', default=[], help='Boards to test, all if not specified')
+ args = parser.parse_args()
+
+ config_file = args.config_file
+ boards = args.board
+
config_file = os.path.join(os.path.dirname(__file__), config_file)
with open(config_file) as f:
config = json.load(f)
@@ -319,13 +339,14 @@ def main(config_file, board):
'cdc_dual_ports', 'cdc_msc', 'dfu', 'dfu_runtime', 'hid_boot_interface',
]
- if len(board) == 0:
+ if len(boards) == 0:
config_boards = config['boards']
else:
- config_boards = [e for e in config['boards'] if e['name'] in board]
+ config_boards = [e for e in config['boards'] if e['name'] in boards]
for item in config_boards:
- print(f'Testing board:{item["name"]}')
+ name = item['name']
+ print(f'Testing board:{name}')
flasher = item['flasher'].lower()
# default to all tests
@@ -344,28 +365,18 @@ def main(config_file, board):
test_list.remove(skip)
for test in test_list:
- fw_list = [
- # cmake: esp32 & samd51 use .bin file
- f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.elf',
- f'cmake-build/cmake-build-{item["name"]}/device/{test}/{test}.bin',
- # make
- f'examples/device/{test}/_build/{item["name"]}/{test}.elf'
- ]
+ fw_name = f'cmake-build/cmake-build-{name}/device/{test}/{test}'
+ print(f' {test} ...', end='')
- fw = None
- for f in fw_list:
- if os.path.isfile(f):
- fw = f
+ # 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)
- if fw is None:
- print(f'Cannot find binary file for {test}')
- sys.exit(-1)
-
- print(f' {test} ...', end='')
-
- # flash firmware
- ret = globals()[f'flash_{flasher}'](item, fw)
assert ret.returncode == 0, 'Flash failed\n' + ret.stdout.decode()
# run test
diff --git a/test/hil/hil_pi4.json b/test/hil/pi4.json
index 17d9ff1fa..bdb8a5fa5 100644
--- a/test/hil/hil_pi4.json
+++ b/test/hil/pi4.json
@@ -8,16 +8,6 @@
"flasher_args": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 5000\""
},
{
- "name": "espressif_s3_devkitc",
- "uid": "7CDFA1E073CC",
- "tests": [
- "cdc_msc_freertos", "hid_composite_freertos"
- ],
- "flasher": "esptool",
- "flasher_sn": "461cb8d7decdeb119be9b506e93fd3f1",
- "flasher_args": "-b 1500000"
- },
- {
"name": "feather_nrf52840_express",
"uid": "1F0479CD0F764471",
"flasher": "jlink",
@@ -32,6 +22,16 @@
"flasher_product": "ItsyBitsy M4 Express",
"flasher_reset_pin": "2",
"flasher_args": "--offset 0x4000"
+ },
+ {
+ "name": "espressif_s3_devkitm",
+ "uid": "84F703C084E4",
+ "tests": [
+ "cdc_msc_freertos", "hid_composite_freertos"
+ ],
+ "flasher": "esptool",
+ "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1",
+ "flasher_args": "-b 1500000"
}
]
}
diff --git a/test/unit-test/project.yml b/test/unit-test/project.yml
index 562dbca09..7fbbabfe6 100644
--- a/test/unit-test/project.yml
+++ b/test/unit-test/project.yml
@@ -44,12 +44,13 @@
# in order to add common defines:
# 1) remove the trailing [] from the :common: section
# 2) add entries to the :common: section (e.g. :test: has TEST defined)
- :common: &common_defines
- - _UNITY_TEST_
+ :common: &common_defines []
:test:
- - *common_defines
+ - _UNITY_TEST_
+ #- *common_defines
:test_preprocess:
- - *common_defines
+ - _UNITY_TEST_
+ #- *common_defines
:cmock:
:mock_prefix: mock_
@@ -80,20 +81,20 @@
:tools:
:test_compiler:
- :executable: clang
- :name: 'clang compiler'
+ :executable: gcc
+ :name: 'gcc compiler'
:arguments:
- -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths
- -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths
- -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols
- - -fsanitize=address
+ #- -fsanitize=address
- -c ${1} #source code input file (Ruby method call param list sub)
- -o ${2} #object file output (Ruby method call param list sub)
:test_linker:
- :executable: clang
- :name: 'clang linker'
+ :executable: gcc
+ :name: 'gcc linker'
:arguments:
- - -fsanitize=address
+ #- -fsanitize=address
- ${1} #list of object files to link (Ruby method call param list sub)
- -o ${2} #executable file output (Ruby method call param list sub)
@@ -106,9 +107,9 @@
:flag: "${1}" # or "-L ${1}" for example
:common: &common_libraries []
:test:
- - *common_libraries
+ #- *common_libraries
:release:
- - *common_libraries
+ #- *common_libraries
:plugins:
:load_paths: