Skip to content

Commit f21829a

Browse files
Add initial HIL testing (#596)
* feat: Initial HIL test * ci: Use esp-hal example instead of themplate * ci: Expand the matrix to cover all targets * feat: Update ESPFLASH_PORT * feat: Check that it flashed properly * feat: Add asserts to the board-info check * ci: Enable other targets * ci: Update flash test * ci: Avoid building espflash on self-hosted-runner * feat: Add non-interactive mode for monitoring * ci: Add erase/read flash test * ci: Add save-image/write-bintest * chore: Code cleanup * ci: Enable C2 * chore: Code cleanup * ci: Update esp32c2 hosted runner name * ci: Avoid building test apps * docs: Update changelog
1 parent 14befdc commit f21829a

File tree

18 files changed

+259
-73
lines changed

18 files changed

+259
-73
lines changed

.github/actions/setup-target/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ runs:
6060
if: inputs.target == 'x86_64-unknown-linux-gnu' || inputs.target == 'x86_64-unknown-linux-musl'
6161
shell: bash
6262
run: |
63-
sudo apt-get update && sudo apt-get install musl-tools libudev-dev
63+
sudo apt-get update && sudo apt-get -y install musl-tools libudev-dev pkg-config
6464
6565
- name: Set environment variables
6666
if: inputs.arch != 'x86_64'

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ on:
44
pull_request:
55
branches:
66
- main
7+
paths-ignore:
8+
- "**/hil.yml"
9+
- "**/*.md"
710
push:
11+
paths-ignore:
12+
- "**/hil.yml"
13+
- "**/*.md"
814
workflow_dispatch:
915

1016
env:

.github/workflows/hil.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: HIL
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "**/ci.yml"
9+
- "**/*.md"
10+
push:
11+
paths-ignore:
12+
- "**/ci.yml"
13+
- "**/*.md"
14+
workflow_dispatch:
15+
16+
env:
17+
CARGO_TERM_COLOR: always
18+
19+
# Cancel any currently running workflows from the same PR, branch, or
20+
# tag when a new workflow is triggered.
21+
#
22+
# https://stackoverflow.com/a/66336834
23+
concurrency:
24+
cancel-in-progress: true
25+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
26+
27+
28+
jobs:
29+
build-espflash:
30+
name: Build espflash
31+
runs-on: ubuntu-20.04
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: ./.github/actions/setup-target
36+
with:
37+
arch: x86_64
38+
target: x86_64-unknown-linux-gnu
39+
40+
- name: Build espflash
41+
run: cargo build --release
42+
working-directory: espflash
43+
44+
- uses: actions/upload-artifact@v3
45+
with:
46+
name: espflash
47+
path: target/release/espflash
48+
if-no-files-found: error
49+
50+
run-target:
51+
name: ${{ matrix.board.mcu }}${{ matrix.board.freq }}
52+
if: ${{ github.repository_owner == 'esp-rs' }}
53+
needs: build-espflash
54+
runs-on: [self-hosted, linux, x64, "${{ matrix.board.mcu }}${{ matrix.board.freq }}" ]
55+
strategy:
56+
matrix:
57+
board:
58+
- mcu: esp32
59+
- mcu: esp32c2
60+
freq: -26mhz
61+
flag: -x 26mhz
62+
- mcu: esp32c3
63+
- mcu: esp32c6
64+
- mcu: esp32h2
65+
- mcu: esp32s2
66+
- mcu: esp32s3
67+
fail-fast: false
68+
steps:
69+
- uses: actions/checkout@v4
70+
- uses: actions/download-artifact@v3
71+
with:
72+
name: espflash
73+
path: espflash_app
74+
75+
- run: chmod +x espflash_app/espflash
76+
77+
- name: board-info test
78+
env:
79+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
80+
shell: bash
81+
run: |
82+
result=$(espflash_app/espflash board-info)
83+
echo "$result"
84+
if [[ $? -ne 0 || ! "$result" =~ "esp32" ]]; then
85+
exit 1
86+
fi
87+
88+
- name: flash test
89+
env:
90+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
91+
ESPFLASH_APP: espflash/resources/apps/${{ matrix.board.mcu }}
92+
shell: bash
93+
run: |
94+
result=$(espflash_app/espflash flash ${{ env.ESPFLASH_APP }} 2>&1)
95+
echo "$result"
96+
if [[ ! $result =~ "Flashing has completed!" ]]; then
97+
exit 1
98+
fi
99+
100+
- name: monitor test
101+
env:
102+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
103+
shell: bash
104+
run: |
105+
result=$(timeout 5s espflash_app/espflash monitor --non-interactive || true)
106+
echo "$result"
107+
if ! echo "$result" | grep -q "Hello world!"; then
108+
exit 1
109+
fi
110+
111+
- name: erase/read flash test
112+
env:
113+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
114+
run: |
115+
result=$(espflash_app/espflash erase-flash 2>&1)
116+
echo "$result"
117+
if [[ ! $result =~ "Flash has been erased!" ]]; then
118+
exit 1
119+
fi
120+
result=$(espflash_app/espflash read-flash 0 0x200 flash_content.bin 2>&1)
121+
echo "$result"
122+
if [[ ! $result =~ "Flash content successfully read and written to" ]]; then
123+
exit 1
124+
fi
125+
echo "Checking if flash is empty"
126+
if hexdump -v -e '/1 "%02x"' "flash_content.bin" | grep -qv '^ff*$'; then
127+
exit 1
128+
fi
129+
echo "Flash is empty!"
130+
131+
- name: save-image/write-bin test
132+
env:
133+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
134+
ESPFLASH_APP: espflash/resources/apps/${{ matrix.board.mcu }}
135+
run: |
136+
result=$(espflash_app/espflash save-image --merge --chip ${{ matrix.board.mcu }} ${{ matrix.board.flag }} ${{ env.ESPFLASH_APP }} app.bin 2>&1)
137+
echo "$result"
138+
if [[ ! $result =~ "Image successfully saved!" ]]; then
139+
exit 1
140+
fi
141+
echo "Writting binary"
142+
result=$(espflash_app/espflash write-bin 0x0 app.bin 2>&1)
143+
echo "$result"
144+
if [[ ! $result =~ "Binary successfully written to flash!" ]]; then
145+
exit 1
146+
fi
147+
echo "Monitoring..."
148+
result=$(timeout 5s espflash_app/espflash monitor --non-interactive || true)
149+
echo "$result"
150+
if ! echo "$result" | grep -q "Hello world!"; then
151+
exit 1
152+
fi
153+
154+

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
- Add CI check to verify that CHANGELOG is updated (#560)
3939
- Add `--before` and `--after` reset arguments (#561)
4040
- Add `read-flash` command (#558)
41+
- Add HIL testing (#596)
4142

4243
### Fixed
4344

0 commit comments

Comments
 (0)