diff --git a/.github/workflows/build_util.yml b/.github/workflows/build_util.yml index ff98aef2d4..294d181409 100644 --- a/.github/workflows/build_util.yml +++ b/.github/workflows/build_util.yml @@ -16,6 +16,10 @@ on: required: false default: false type: boolean + upload-artifacts: + required: false + default: false + type: boolean os: required: false type: string @@ -62,3 +66,17 @@ jobs: python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ steps.set-one-per-family.outputs.build_option }} ${{ matrix.arg }} fi shell: bash + + - name: Upload Artifacts for Hardware Testing + if: ${{ inputs.upload-artifacts }} + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.arg }} + path: | + cmake-build/cmake-build-*/*/*/*.elf + cmake-build/cmake-build-*/*/*/*.bin + cmake-build/cmake-build-*/*/*/*.bin + cmake-build/cmake-build-*/*/*/bootloader/bootloader.bin + cmake-build/cmake-build-*/*/*/partition_table/partition-table.bin + cmake-build/cmake-build-*/*/*/config.env + cmake-build/cmake-build-*/*/*/flash_args diff --git a/.github/workflows/hil_test.yml b/.github/workflows/hil_test.yml index 087374be25..6ece44922e 100644 --- a/.github/workflows/hil_test.yml +++ b/.github/workflows/hil_test.yml @@ -18,7 +18,7 @@ concurrency: cancel-in-progress: true env: - HIL_JSON: test/hil/rpi.json + HIL_JSON: test/hil/tinyusb.json jobs: set-matrix: @@ -32,7 +32,10 @@ jobs: - name: Generate matrix json id: set-matrix-json run: | - MATRIX_JSON=$(jq -c '{ "arm-gcc": [.boards[] | select(.flasher != "esptool" and .flasher != "openocd_wch") | .name] }' ${{ env.HIL_JSON }}) + MATRIX_ARMGCC=$(jq -c '{ "arm-gcc": { "family": [.boards[] | select(.flasher != "esptool" and .flasher != "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}") + MATRIX_ESP=$(jq -c '{ "esp-idf": { "family": [.boards[] | select(.flasher == "esptool") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}") + MATRIX_RISCV=$(jq -c '{ "riscv-gcc": { "family": [.boards[] | select(.flasher == "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}") + MATRIX_JSON=$(jq -nc --argjson arm "$MATRIX_ARMGCC" --argjson esp "$MATRIX_ESP" --argjson riscv "$MATRIX_RISCV" '$arm + $esp + $riscv') echo "matrix=$MATRIX_JSON" echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT @@ -42,44 +45,28 @@ jobs: build: if: github.repository_owner == 'hathach' needs: set-matrix - runs-on: ubuntu-latest + uses: ./.github/workflows/build_util.yml strategy: fail-fast: false matrix: - board: ${{ fromJSON(needs.set-matrix.outputs.json)['arm-gcc'] }} - steps: - - name: Checkout TinyUSB - uses: actions/checkout@v4 - - - name: Setup arm-gcc toolchain - uses: ./.github/actions/setup_toolchain - with: - toolchain: 'arm-gcc' - - - name: Get Dependencies - uses: ./.github/actions/get_deps - with: - arg: -b${{ matrix.board }} - - - name: Build - run: python tools/build.py -b${{ matrix.board }} - - - name: Upload Artifacts for Hardware Testing - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.board }} - path: | - cmake-build/cmake-build-*/*/*/*.elf - cmake-build/cmake-build-*/*/*/*.bin + toolchain: + - 'arm-gcc' + - 'esp-idf' + with: + build-system: 'cmake' + toolchain: ${{ matrix.toolchain }} + build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }} + one-per-family: true + upload-artifacts: true # --------------------------------------- # Hardware in the loop (HIL) - # self-hosted running on an RPI. For attached hardware checkout test/hil/rpi.json + # self-hosted running on an VM. For attached hardware checkout test/hil/tinyusb.json # --------------------------------------- - hil-rpi: + hil-tinyusb: if: github.repository_owner == 'hathach' needs: build - runs-on: [self-hosted, ARM64, rpi, hardware-in-the-loop] + runs-on: [self-hosted, X64, hathach, hardware-in-the-loop] steps: - name: Clean workspace run: | @@ -87,13 +74,6 @@ jobs: rm -rf "${{ github.workspace }}" mkdir -p "${{ github.workspace }}" - # USB bus on rpi is not stable, reset it before testing -# - name: Reset USB bus -# run: | -# echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/unbind -# sleep 5 -# echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/bind - - name: Checkout TinyUSB uses: actions/checkout@v4 with: diff --git a/test/hil/hil_test.py b/test/hil/hil_test.py index ec28328d47..2d14220c51 100644 --- a/test/hil/hil_test.py +++ b/test/hil/hil_test.py @@ -45,6 +45,11 @@ verbose = False +# ------------------------------------------------------------- +# Path +# ------------------------------------------------------------- +OPENCOD_ADI_PATH = f'{os.getenv("HOME")}/app/openocd_adi' + # get usb serial by id def get_serial_dev(id, vendor_str, product_str, ifnum): if vendor_str and product_str: @@ -112,8 +117,8 @@ def read_disk_file(uid, lun, fname): # ------------------------------------------------------------- # Flashing firmware # ------------------------------------------------------------- -def run_cmd(cmd): - r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) +def run_cmd(cmd, cwd=None): + r = subprocess.run(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if r.returncode != 0: title = f'COMMAND FAILED: {cmd}' print() @@ -187,11 +192,7 @@ def flash_openocd_wch(board, firmware): def flash_openocd_adi(board, firmware): - openocd_adi_script_path = f'{os.getenv("HOME")}/app/openocd_adi/tcl' - if not os.path.exists(openocd_adi_script_path): - openocd_adi_script_path = '/home/pi/openocd_adi/tcl' - - ret = run_cmd(f'openocd_adi -c "adapter serial {board["flasher_sn"]}" -s {openocd_adi_script_path} ' + ret = run_cmd(f'{OPENCOD_ADI_PATH}/src/openocd -c "adapter serial {board["flasher_sn"]}" -s {OPENCOD_ADI_PATH}/tcl ' f'{board["flasher_args"]} -c "program {firmware}.elf reset exit"') return ret @@ -203,14 +204,14 @@ def flash_wlink_rs(board, firmware): def flash_esptool(board, firmware): port = get_serial_dev(board["flasher_sn"], None, None, 0) - 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: + fw_dir = os.path.dirname(f'{firmware}.bin') + with open(f'{fw_dir}/config.env') as f: + idf_target = json.load(f)['IDF_TARGET'] + with open(f'{fw_dir}/flash_args') as f: flash_args = f.read().strip().replace('\n', ' ') - command = (f'esptool.py --chip {IDF_TARGET} -p {port} {board["flasher_args"]} ' + command = (f'esptool.py --chip {idf_target} -p {port} {board["flasher_args"]} ' f'--before=default_reset --after=hard_reset write_flash {flash_args}') - ret = subprocess.run(command, shell=True, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = run_cmd(command, cwd=fw_dir) return ret @@ -305,8 +306,7 @@ def test_device_dfu(board): # Wait device enum timeout = ENUM_TIMEOUT while timeout: - ret = subprocess.run(f'dfu-util -l', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = run_cmd(f'dfu-util -l') stdout = ret.stdout.decode() if f'serial="{uid}"' in stdout and 'Found DFU: [cafe:4000]' in stdout: break @@ -347,8 +347,7 @@ def test_device_dfu_runtime(board): # Wait device enum timeout = ENUM_TIMEOUT while timeout: - ret = subprocess.run(f'dfu-util -l', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + ret = run_cmd(f'dfu-util -l') stdout = ret.stdout.decode() if f'serial="{uid}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout: break @@ -382,17 +381,18 @@ def test_device_hid_composite_freertos(id): # ------------------------------------------------------------- # Main # ------------------------------------------------------------- -# all possible tests: board_test is added last to disable board's usb -all_tests = [ +# device tests +device_tests = [ 'device/cdc_dual_ports', 'device/cdc_msc', 'device/dfu', 'device/cdc_msc_freertos', # don't test 2 cdc_msc next to each other 'device/dfu_runtime', 'device/hid_boot_interface', +] +dual_tests = [ 'dual/host_info_to_device_cdc', - 'device/board_test' ] @@ -401,17 +401,22 @@ def test_board(board): flasher = board['flasher'].lower() # default to all tests - test_list = list(all_tests) + test_list = list(device_tests) if 'tests' in board: board_tests = board['tests'] if 'only' in board_tests: - test_list = board_tests['only'] + ['device/board_test'] + test_list = board_tests['only'] if 'skip' in board_tests: for skip in board_tests['skip']: if skip in test_list: test_list.remove(skip) print(f'{name:25} {skip:30} ... Skip') + if 'dual_attached' in board_tests: + test_list += dual_tests + + # board_test is added last to disable board's usb + test_list.append('device/board_test') err_count = 0 for test in test_list: @@ -422,7 +427,7 @@ def test_board(board): print(f'{name:25} {test:30} ... ', end='') if not os.path.exists(fw_dir): - print('Skip') + print('Skip (no binary)') continue # flash firmware. It may fail randomly, retry a few times diff --git a/test/hil/requirements.txt b/test/hil/requirements.txt new file mode 100644 index 0000000000..c33980c9da --- /dev/null +++ b/test/hil/requirements.txt @@ -0,0 +1,2 @@ +fs +pyfatfs diff --git a/test/hil/rpi.json b/test/hil/tinyusb.json similarity index 100% rename from test/hil/rpi.json rename to test/hil/tinyusb.json index 672e857fdf..fcd004c6d0 100644 --- a/test/hil/rpi.json +++ b/test/hil/tinyusb.json @@ -76,6 +76,16 @@ "flasher": "openocd", "flasher_sn": "066FFF495087534867063844", "flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg" + }, + { + "name": "espressif_s3_devkitm", + "uid": "84F703C084E4", + "tests": { + "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] + }, + "flasher": "esptool", + "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1", + "flasher_args": "-b 921600" } ], "boards-skip": [ @@ -92,16 +102,6 @@ "flasher": "openocd_wch", "flasher_sn": "EBCA8F0670AF", "flasher_args": "" - }, - { - "name": "espressif_s3_devkitm", - "uid": "84F703C084E4", - "tests": { - "only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"] - }, - "flasher": "esptool", - "flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1", - "flasher_args": "-b 921600" } ] }