Skip to content

Commit 6f3c96d

Browse files
Improve HIL (#754)
* ci: Use job.env to avoid duplications * ci: Add erase-region, hold-in-reset, reset and checksum-md5 tests * ci: Use bash scripts * cI: Update workflow * feat: Udpate testing elfs * test: Read 0x2000 bytes of flash * docs: Add TODOs for issue #697 * fix: Typo Co-authored-by: Jesse Braham <[email protected]> * docs: Improve the todo comment --------- Co-authored-by: Jesse Braham <[email protected]>
1 parent ad1cb9f commit 6f3c96d

18 files changed

+154
-83
lines changed

.github/workflows/hil.yml

+32-83
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ jobs:
3232
runs-on: ubuntu-20.04
3333
steps:
3434
- uses: actions/checkout@v4
35-
if: github.event_name != 'workflow_dispatch'
36-
37-
- uses: actions/checkout@v4
38-
if: github.event_name == 'workflow_dispatch'
3935
with:
40-
repository: ${{ github.event.inputs.repository }}
41-
ref: ${{ github.event.inputs.branch }}
36+
repository: ${{ github.event.inputs.repository || github.repository }}
37+
ref: ${{ github.event.inputs.branch || github.ref }}
4238

4339
- uses: ./.github/actions/setup-target
4440
with:
@@ -57,15 +53,9 @@ jobs:
5753

5854
run-target:
5955
name: ${{ matrix.board.mcu }}${{ matrix.board.freq }}
60-
if: ${{ github.repository_owner == 'esp-rs' }}
56+
if: github.repository_owner == 'esp-rs'
6157
needs: build-espflash
62-
runs-on:
63-
[
64-
self-hosted,
65-
linux,
66-
x64,
67-
"${{ matrix.board.mcu }}${{ matrix.board.freq }}",
68-
]
58+
runs-on: [self-hosted, linux, x64, "${{ matrix.board.mcu }}${{ matrix.board.freq }}"]
6959
strategy:
7060
matrix:
7161
board:
@@ -79,88 +69,47 @@ jobs:
7969
- mcu: esp32s2
8070
- mcu: esp32s3
8171
fail-fast: false
72+
env:
73+
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
74+
ESPFLASH_APP: espflash/tests/data/${{ matrix.board.mcu }}
8275
steps:
8376
- uses: actions/checkout@v4
77+
8478
- uses: actions/download-artifact@v4
8579
with:
8680
name: espflash
8781
path: espflash_app
8882

89-
- run: chmod +x espflash_app/espflash
83+
- name: Set up espflash binary
84+
run: |
85+
chmod +x espflash_app/espflash
86+
echo "$PWD/espflash_app" >> "$GITHUB_PATH"
9087
9188
- name: board-info test
92-
env:
93-
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
94-
shell: bash
95-
run: |
96-
result=$(espflash_app/espflash board-info)
97-
echo "$result"
98-
if [[ $? -ne 0 || ! "$result" =~ "esp32" ]]; then
99-
exit 1
100-
fi
89+
run: bash espflash/tests/scripts/board-info.sh
10190

10291
- name: flash test
103-
env:
104-
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
105-
ESPFLASH_APP: espflash/tests/data/${{ matrix.board.mcu }}
106-
shell: bash
107-
run: |
108-
result=$(espflash_app/espflash flash --no-skip ${{ env.ESPFLASH_APP }} 2>&1)
109-
echo "$result"
110-
if [[ ! $result =~ "Flashing has completed!" ]]; then
111-
exit 1
112-
fi
92+
run: bash espflash/tests/scripts/flash.sh ${{ env.ESPFLASH_APP }}
11393

11494
- name: monitor test
115-
env:
116-
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
117-
shell: bash
118-
run: |
119-
result=$(timeout 5s espflash_app/espflash monitor --non-interactive || true)
120-
echo "$result"
121-
if ! echo "$result" | grep -q "Hello world!"; then
122-
exit 1
123-
fi
124-
125-
- name: erase/read flash test
126-
env:
127-
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
128-
run: |
129-
result=$(espflash_app/espflash erase-flash 2>&1)
130-
echo "$result"
131-
if [[ ! $result =~ "Flash has been erased!" ]]; then
132-
exit 1
133-
fi
134-
result=$(espflash_app/espflash read-flash 0 0x200 flash_content.bin 2>&1)
135-
echo "$result"
136-
if [[ ! $result =~ "Flash content successfully read and written to" ]]; then
137-
exit 1
138-
fi
139-
echo "Checking if flash is empty"
140-
if hexdump -v -e '/1 "%02x"' "flash_content.bin" | grep -qv '^ff*$'; then
141-
exit 1
142-
fi
143-
echo "Flash is empty!"
95+
run: bash espflash/tests/scripts/monitor.sh
96+
97+
- name: erase-flash test
98+
run: bash espflash/tests/scripts/erase-flash.sh
14499

145100
- name: save-image/write-bin test
146-
env:
147-
ESPFLASH_PORT: /dev/serial_ports/${{ matrix.board.mcu }}
148-
ESPFLASH_APP: espflash/tests/data/${{ matrix.board.mcu }}
149101
run: |
150-
result=$(espflash_app/espflash save-image --merge --chip ${{ matrix.board.mcu }} ${{ matrix.board.flag }} ${{ env.ESPFLASH_APP }} app.bin 2>&1)
151-
echo "$result"
152-
if [[ ! $result =~ "Image successfully saved!" ]]; then
153-
exit 1
154-
fi
155-
echo "Writting binary"
156-
result=$(espflash_app/espflash write-bin 0x0 app.bin 2>&1)
157-
echo "$result"
158-
if [[ ! $result =~ "Binary successfully written to flash!" ]]; then
159-
exit 1
160-
fi
161-
echo "Monitoring..."
162-
result=$(timeout 5s espflash_app/espflash monitor --non-interactive || true)
163-
echo "$result"
164-
if ! echo "$result" | grep -q "Hello world!"; then
165-
exit 1
166-
fi
102+
bash espflash/tests/scripts/save-image_write-bin.sh ${{ matrix.board.mcu }} ${{ env.ESPFLASH_APP }}
103+
bash espflash/tests/scripts/monitor.sh
104+
105+
- name: erase-region test
106+
run: bash espflash/tests/scripts/erase-region.sh
107+
108+
- name: hold-in-reset test
109+
run: bash espflash/tests/scripts/hold-in-reset.sh
110+
111+
- name: reset test
112+
run: bash espflash/tests/scripts/reset.sh
113+
114+
- name: checksum-md5 test
115+
run: bash espflash/tests/scripts/checksum-md5.sh

espflash/tests/data/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The elf files under this folder have been generated using `[email protected]`:
2+
3+
```
4+
esp-generate --chip=$CHIP --headless $CHIP
5+
cd $CHIP
6+
cargo build --release
7+
```

espflash/tests/data/esp32

-1.06 MB
Binary file not shown.

espflash/tests/data/esp32c2

-2.38 MB
Binary file not shown.

espflash/tests/data/esp32c3

-2.66 MB
Binary file not shown.

espflash/tests/data/esp32c6

-2.98 MB
Binary file not shown.

espflash/tests/data/esp32h2

-2.89 MB
Binary file not shown.

espflash/tests/data/esp32s2

-1.09 MB
Binary file not shown.

espflash/tests/data/esp32s3

-1.27 MB
Binary file not shown.

espflash/tests/scripts/board-info.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash board-info)
4+
echo "$result"
5+
if [[ $? -ne 0 || ! "$result" =~ "esp32" ]]; then
6+
exit 1
7+
fi
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash erase-flash 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Flash has been erased!" ]]; then
6+
exit 1
7+
fi
8+
result=$(espflash checksum-md5 --address 0x1000 --length 0x100 2>&1)
9+
echo "$result"
10+
if [[ ! $result =~ "0x827f263ef9fb63d05499d14fcef32f60" ]]; then
11+
exit 1
12+
fi

espflash/tests/scripts/erase-flash.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash erase-flash 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Flash has been erased!" ]]; then
6+
exit 1
7+
fi
8+
# TODO: Once https://github.com/esp-rs/espflash/issues/697 is resolved this should read a larger portion of flash
9+
result=$(espflash read-flash 0 0x200 flash_content.bin 2>&1)
10+
echo "$result"
11+
if [[ ! $result =~ "Flash content successfully read and written to" ]]; then
12+
exit 1
13+
fi
14+
echo "Checking if flash is empty"
15+
if hexdump -v -e '/1 "%02x"' "flash_content.bin" | grep -qv '^ff*$'; then
16+
exit 1
17+
fi
18+
echo "Flash is empty!"
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash erase-region 0x1000 0x1000 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Erasing region at" ]]; then
6+
exit 1
7+
fi
8+
# TODO: Once https://github.com/esp-rs/espflash/issues/697 is resolved we should look like:
9+
# https://github.com/esp-rs/espflash/pull/754/commits/288eced61e7b21deface52a67e2f023b388ce6ed#diff-083bacee91d55c6adddc9dcd306da31db24e33591d5453e819999552995b85b7R8-R23
10+
11+
# Check first 0x1000 bytes are FF
12+
result=$(espflash read-flash 0x1000 0x200 flash_content.bin 2>&1)
13+
echo "$result"
14+
if [[ ! $result =~ "Flash content successfully read and written to" ]]; then
15+
exit 1
16+
fi
17+
if hexdump -v -e '/1 "%02x"' "flash_content.bin" | grep -qv '^ff*$'; then
18+
exit 1
19+
fi
20+
# Check next 0x1000 bytes contain some non-FF bytes
21+
result=$(espflash read-flash 0x2000 0x200 flash_content.bin 2>&1)
22+
echo "$result"
23+
if [[ ! $result =~ "Flash content successfully read and written to" ]]; then
24+
echo "This region should be empty (FF)"
25+
exit 1
26+
fi
27+
if ! hexdump -v -e '/1 "%02x"' "flash_content.bin" | grep -q '[0-e]'; then
28+
echo "This region should contain some non-FF bytes"
29+
exit 1
30+
fi
31+
echo "Flash contents verified!"

espflash/tests/scripts/flash.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash flash --no-skip $1 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Flashing has completed!" ]]; then
6+
exit 1
7+
fi
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash hold-in-reset 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Holding target device in reset" ]]; then
6+
exit 1
7+
fi

espflash/tests/scripts/monitor.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Monitoring..."
4+
result=$(timeout 5s espflash monitor --non-interactive || true)
5+
echo "$result"
6+
if ! echo "$result" | grep -q "Hello world!"; then
7+
exit 1
8+
fi

espflash/tests/scripts/reset.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
result=$(espflash reset 2>&1)
4+
echo "$result"
5+
if [[ ! $result =~ "Resetting target device" ]]; then
6+
exit 1
7+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# if $1 is esp32c2, create an variable that contains `-x 26mhz`
4+
if [[ $1 == "esp32c2" ]]; then
5+
freq="-x 26mhz"
6+
fi
7+
8+
result=$(espflash save-image --merge --chip $1 $freq $2 app.bin 2>&1)
9+
echo "$result"
10+
if [[ ! $result =~ "Image successfully saved!" ]]; then
11+
exit 1
12+
fi
13+
echo "Writing binary"
14+
result=$(espflash write-bin 0x0 app.bin 2>&1)
15+
echo "$result"
16+
if [[ ! $result =~ "Binary successfully written to flash!" ]]; then
17+
exit 1
18+
fi

0 commit comments

Comments
 (0)