Skip to content

Commit e209acb

Browse files
authored
Migrate hil vm (#2822)
* migrate hil to new x64 VM instead of rpi * re-enable hil for s3
1 parent c8ab65f commit e209acb

File tree

5 files changed

+76
-71
lines changed

5 files changed

+76
-71
lines changed

.github/workflows/build_util.yml

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ on:
1616
required: false
1717
default: false
1818
type: boolean
19+
upload-artifacts:
20+
required: false
21+
default: false
22+
type: boolean
1923
os:
2024
required: false
2125
type: string
@@ -62,3 +66,17 @@ jobs:
6266
python tools/build.py -s ${{ inputs.build-system }} ${{ steps.setup-toolchain.outputs.build_option }} ${{ steps.set-one-per-family.outputs.build_option }} ${{ matrix.arg }}
6367
fi
6468
shell: bash
69+
70+
- name: Upload Artifacts for Hardware Testing
71+
if: ${{ inputs.upload-artifacts }}
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: ${{ matrix.arg }}
75+
path: |
76+
cmake-build/cmake-build-*/*/*/*.elf
77+
cmake-build/cmake-build-*/*/*/*.bin
78+
cmake-build/cmake-build-*/*/*/*.bin
79+
cmake-build/cmake-build-*/*/*/bootloader/bootloader.bin
80+
cmake-build/cmake-build-*/*/*/partition_table/partition-table.bin
81+
cmake-build/cmake-build-*/*/*/config.env
82+
cmake-build/cmake-build-*/*/*/flash_args

.github/workflows/hil_test.yml

+18-38
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ concurrency:
1818
cancel-in-progress: true
1919

2020
env:
21-
HIL_JSON: test/hil/rpi.json
21+
HIL_JSON: test/hil/tinyusb.json
2222

2323
jobs:
2424
set-matrix:
@@ -32,7 +32,10 @@ jobs:
3232
- name: Generate matrix json
3333
id: set-matrix-json
3434
run: |
35-
MATRIX_JSON=$(jq -c '{ "arm-gcc": [.boards[] | select(.flasher != "esptool" and .flasher != "openocd_wch") | .name] }' ${{ env.HIL_JSON }})
35+
MATRIX_ARMGCC=$(jq -c '{ "arm-gcc": { "family": [.boards[] | select(.flasher != "esptool" and .flasher != "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
36+
MATRIX_ESP=$(jq -c '{ "esp-idf": { "family": [.boards[] | select(.flasher == "esptool") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
37+
MATRIX_RISCV=$(jq -c '{ "riscv-gcc": { "family": [.boards[] | select(.flasher == "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
38+
MATRIX_JSON=$(jq -nc --argjson arm "$MATRIX_ARMGCC" --argjson esp "$MATRIX_ESP" --argjson riscv "$MATRIX_RISCV" '$arm + $esp + $riscv')
3639
echo "matrix=$MATRIX_JSON"
3740
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
3841
@@ -42,58 +45,35 @@ jobs:
4245
build:
4346
if: github.repository_owner == 'hathach'
4447
needs: set-matrix
45-
runs-on: ubuntu-latest
48+
uses: ./.github/workflows/build_util.yml
4649
strategy:
4750
fail-fast: false
4851
matrix:
49-
board: ${{ fromJSON(needs.set-matrix.outputs.json)['arm-gcc'] }}
50-
steps:
51-
- name: Checkout TinyUSB
52-
uses: actions/checkout@v4
53-
54-
- name: Setup arm-gcc toolchain
55-
uses: ./.github/actions/setup_toolchain
56-
with:
57-
toolchain: 'arm-gcc'
58-
59-
- name: Get Dependencies
60-
uses: ./.github/actions/get_deps
61-
with:
62-
arg: -b${{ matrix.board }}
63-
64-
- name: Build
65-
run: python tools/build.py -b${{ matrix.board }}
66-
67-
- name: Upload Artifacts for Hardware Testing
68-
uses: actions/upload-artifact@v4
69-
with:
70-
name: ${{ matrix.board }}
71-
path: |
72-
cmake-build/cmake-build-*/*/*/*.elf
73-
cmake-build/cmake-build-*/*/*/*.bin
52+
toolchain:
53+
- 'arm-gcc'
54+
- 'esp-idf'
55+
with:
56+
build-system: 'cmake'
57+
toolchain: ${{ matrix.toolchain }}
58+
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
59+
one-per-family: true
60+
upload-artifacts: true
7461

7562
# ---------------------------------------
7663
# Hardware in the loop (HIL)
77-
# self-hosted running on an RPI. For attached hardware checkout test/hil/rpi.json
64+
# self-hosted running on an VM. For attached hardware checkout test/hil/tinyusb.json
7865
# ---------------------------------------
79-
hil-rpi:
66+
hil-tinyusb:
8067
if: github.repository_owner == 'hathach'
8168
needs: build
82-
runs-on: [self-hosted, ARM64, rpi, hardware-in-the-loop]
69+
runs-on: [self-hosted, X64, hathach, hardware-in-the-loop]
8370
steps:
8471
- name: Clean workspace
8572
run: |
8673
echo "Cleaning up previous run"
8774
rm -rf "${{ github.workspace }}"
8875
mkdir -p "${{ github.workspace }}"
8976
90-
# USB bus on rpi is not stable, reset it before testing
91-
# - name: Reset USB bus
92-
# run: |
93-
# echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/unbind
94-
# sleep 5
95-
# echo "1-2" | sudo tee /sys/bus/usb/drivers/usb/bind
96-
9777
- name: Checkout TinyUSB
9878
uses: actions/checkout@v4
9979
with:

test/hil/hil_test.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545

4646
verbose = False
4747

48+
# -------------------------------------------------------------
49+
# Path
50+
# -------------------------------------------------------------
51+
OPENCOD_ADI_PATH = f'{os.getenv("HOME")}/app/openocd_adi'
52+
4853
# get usb serial by id
4954
def get_serial_dev(id, vendor_str, product_str, ifnum):
5055
if vendor_str and product_str:
@@ -112,8 +117,8 @@ def read_disk_file(uid, lun, fname):
112117
# -------------------------------------------------------------
113118
# Flashing firmware
114119
# -------------------------------------------------------------
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)
117122
if r.returncode != 0:
118123
title = f'COMMAND FAILED: {cmd}'
119124
print()
@@ -187,11 +192,7 @@ def flash_openocd_wch(board, firmware):
187192

188193

189194
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 '
195196
f'{board["flasher_args"]} -c "program {firmware}.elf reset exit"')
196197
return ret
197198

@@ -203,14 +204,14 @@ def flash_wlink_rs(board, firmware):
203204

204205
def flash_esptool(board, firmware):
205206
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:
210211
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"]} '
212213
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)
214215
return ret
215216

216217

@@ -305,8 +306,7 @@ def test_device_dfu(board):
305306
# Wait device enum
306307
timeout = ENUM_TIMEOUT
307308
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')
310310
stdout = ret.stdout.decode()
311311
if f'serial="{uid}"' in stdout and 'Found DFU: [cafe:4000]' in stdout:
312312
break
@@ -347,8 +347,7 @@ def test_device_dfu_runtime(board):
347347
# Wait device enum
348348
timeout = ENUM_TIMEOUT
349349
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')
352351
stdout = ret.stdout.decode()
353352
if f'serial="{uid}"' in stdout and 'Found Runtime: [cafe:4000]' in stdout:
354353
break
@@ -382,17 +381,18 @@ def test_device_hid_composite_freertos(id):
382381
# -------------------------------------------------------------
383382
# Main
384383
# -------------------------------------------------------------
385-
# all possible tests: board_test is added last to disable board's usb
386-
all_tests = [
384+
# device tests
385+
device_tests = [
387386
'device/cdc_dual_ports',
388387
'device/cdc_msc',
389388
'device/dfu',
390389
'device/cdc_msc_freertos', # don't test 2 cdc_msc next to each other
391390
'device/dfu_runtime',
392391
'device/hid_boot_interface',
392+
]
393393

394+
dual_tests = [
394395
'dual/host_info_to_device_cdc',
395-
'device/board_test'
396396
]
397397

398398

@@ -401,17 +401,22 @@ def test_board(board):
401401
flasher = board['flasher'].lower()
402402

403403
# default to all tests
404-
test_list = list(all_tests)
404+
test_list = list(device_tests)
405405

406406
if 'tests' in board:
407407
board_tests = board['tests']
408408
if 'only' in board_tests:
409-
test_list = board_tests['only'] + ['device/board_test']
409+
test_list = board_tests['only']
410410
if 'skip' in board_tests:
411411
for skip in board_tests['skip']:
412412
if skip in test_list:
413413
test_list.remove(skip)
414414
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')
415420

416421
err_count = 0
417422
for test in test_list:
@@ -422,7 +427,7 @@ def test_board(board):
422427
print(f'{name:25} {test:30} ... ', end='')
423428

424429
if not os.path.exists(fw_dir):
425-
print('Skip')
430+
print('Skip (no binary)')
426431
continue
427432

428433
# flash firmware. It may fail randomly, retry a few times

test/hil/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fs
2+
pyfatfs

test/hil/rpi.json renamed to test/hil/tinyusb.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
"flasher": "openocd",
7777
"flasher_sn": "066FFF495087534867063844",
7878
"flasher_args": "-f interface/stlink.cfg -f target/stm32g0x.cfg"
79+
},
80+
{
81+
"name": "espressif_s3_devkitm",
82+
"uid": "84F703C084E4",
83+
"tests": {
84+
"only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"]
85+
},
86+
"flasher": "esptool",
87+
"flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1",
88+
"flasher_args": "-b 921600"
7989
}
8090
],
8191
"boards-skip": [
@@ -92,16 +102,6 @@
92102
"flasher": "openocd_wch",
93103
"flasher_sn": "EBCA8F0670AF",
94104
"flasher_args": ""
95-
},
96-
{
97-
"name": "espressif_s3_devkitm",
98-
"uid": "84F703C084E4",
99-
"tests": {
100-
"only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"]
101-
},
102-
"flasher": "esptool",
103-
"flasher_sn": "3ea619acd1cdeb11a0a0b806e93fd3f1",
104-
"flasher_args": "-b 921600"
105105
}
106106
]
107107
}

0 commit comments

Comments
 (0)