Skip to content

Commit f7386a5

Browse files
committed
ci(qemu): Add QEMU emulator to CI
1 parent cf44890 commit f7386a5

File tree

5 files changed

+110
-17
lines changed

5 files changed

+110
-17
lines changed

Diff for: .github/scripts/tests_run.sh

+30-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ function run_test() {
88
local sketchdir=$(dirname $sketch)
99
local sketchname=$(basename $sketchdir)
1010

11+
if [[ -f "$sketchdir/.skip.$platform" ]] || [[ -f "$sketchdir/.skip.$target" ]] || [[ -f "$sketchdir/.skip.$platform.$target" ]]; then
12+
echo "Skipping $sketchname test in $target for $platform"
13+
exit 0
14+
fi
15+
1116
if [ $options -eq 0 ] && [ -f $sketchdir/cfg.json ]; then
1217
len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
1318
else
@@ -33,7 +38,20 @@ function run_test() {
3338
report_file="tests/$sketchname/$sketchname$i.xml"
3439
fi
3540

36-
pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file
41+
if [ $platform == "qemu" ]; then
42+
extra_args="--embedded-services qemu --qemu-image-path $build_dir/$sketchname.ino.bin"
43+
44+
if [ $target == "esp32" ] || [ $target == "esp32s3" ]; then
45+
extra_args+=" --qemu-prog-path $QEMU_PATH/qemu-system-xtensa --qemu-cli-args \"-nographic -machine $target\""
46+
else
47+
extra_args+=" --qemu-prog-path $QEMU_PATH/qemu-system-riscv32 --qemu-cli-args \"-nographic -machine $target\""
48+
fi
49+
else
50+
extra_args="--embedded-services esp,arduino"
51+
fi
52+
53+
echo "pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args"
54+
pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args
3755
result=$?
3856
if [ $result -ne 0 ]; then
3957
return $result
@@ -44,6 +62,7 @@ function run_test() {
4462
SCRIPTS_DIR="./.github/scripts"
4563
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
4664

65+
platform="hardware"
4766
chunk_run=0
4867
options=0
4968
erase=0
@@ -53,6 +72,13 @@ while [ ! -z "$1" ]; do
5372
-c )
5473
chunk_run=1
5574
;;
75+
-q )
76+
if [ ! -d $QEMU_PATH ]; then
77+
echo "QEMU path $QEMU_PATH does not exist"
78+
exit 1
79+
fi
80+
platform="qemu"
81+
;;
5682
-o )
5783
options=1
5884
;;
@@ -86,7 +112,9 @@ while [ ! -z "$1" ]; do
86112
shift
87113
done
88114

89-
source ${SCRIPTS_DIR}/install-arduino-ide.sh
115+
if [ ! $platform == "qemu" ]; then
116+
source ${SCRIPTS_DIR}/install-arduino-ide.sh
117+
fi
90118

91119
if [ $chunk_run -eq 0 ]; then
92120
run_test $target $PWD/tests/$sketch/$sketch.ino $options $erase

Diff for: .github/workflows/hil.yml

+77-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run tests in hardware
1+
name: Run tests
22

33
on:
44
pull_request:
@@ -16,9 +16,7 @@ concurrency:
1616

1717
jobs:
1818
gen_chunks:
19-
if: |
20-
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
21-
(github.event_name == 'schedule' && github.repository == 'espressif/arduino-esp32')
19+
if: github.repository == 'espressif/arduino-esp32'
2220
name: Generate Chunks matrix
2321
runs-on: ubuntu-latest
2422
outputs:
@@ -41,7 +39,7 @@ jobs:
4139
CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $((sketches - 1))`)
4240
echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT
4341
44-
Build:
42+
build:
4543
needs: gen_chunks
4644
name: ${{matrix.chip}}-Build#${{matrix.chunks}}
4745
runs-on: ubuntu-latest
@@ -63,9 +61,77 @@ jobs:
6361
~/.arduino/tests/*/build*.tmp/*.bin
6462
~/.arduino/tests/*/build*.tmp/*.json
6563
if-no-files-found: error
66-
Test:
67-
needs: [gen_chunks, Build]
68-
name: ${{matrix.chip}}-Test#${{matrix.chunks}}
64+
65+
qemu-test:
66+
needs: [gen_chunks, build]
67+
name: ${{matrix.chip}}-QEMU_Test#${{matrix.chunks}}
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
chip: ['esp32', 'esp32c3'] # Currently only ESP32 and ESP32-C3 are supported by QEMU
72+
chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}}
73+
runs-on: ubuntu-latest
74+
env:
75+
QEMU_INSTALL_PATH: "$HOME"
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@v4
79+
80+
- name: Get QEMU version
81+
uses: pozetroninc/[email protected]
82+
id: get-qemu-version
83+
with:
84+
owner: espressif
85+
repo: qemu
86+
excludes: prerelease, draft
87+
88+
- name: Cache tools
89+
id: cache-linux
90+
uses: actions/cache@v4
91+
with:
92+
path: |
93+
~/qemu
94+
~/.cache/pip
95+
key: ${{ steps.get-qemu-version.outputs.release }}-${{ hashFiles('.github/workflows/hil.yml') }}
96+
97+
- name: Install python dependencies
98+
run: |
99+
pip install -U pip
100+
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
101+
102+
- name: Download QEMU
103+
if: steps.cache-linux.outputs.cache-hit != 'true'
104+
run: |
105+
cd ${{ env.QEMU_INSTALL_PATH }}
106+
underscore_release=$(echo ${{ steps.get-qemu-version.outputs.release }} | sed 's/\-/_/g')
107+
curl -L https://github.com/espressif/qemu/releases/download/${{ steps.get-qemu-version.outputs.release }}/qemu-riscv32-softmmu-${underscore_release}-x86_64-linux-gnu.tar.xz > qemu-riscv32.tar.xz
108+
curl -L https://github.com/espressif/qemu/releases/download/${{ steps.get-qemu-version.outputs.release }}/qemu-xtensa-softmmu-${underscore_release}-x86_64-linux-gnu.tar.xz > qemu-xtensa.tar.xz
109+
tar -xf qemu-riscv32.tar.xz
110+
tar -xf qemu-xtensa.tar.xz
111+
rm qemu-*
112+
echo "QEMU_PATH=${{ env.QEMU_INSTALL_PATH }}/qemu" >> $GITHUB_ENV
113+
114+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
115+
uses: actions/download-artifact@v4
116+
with:
117+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
118+
path: ~/.arduino/tests/
119+
120+
- name: Run Tests
121+
run: QEMU_PATH="${{env.QEMU_PATH}}" bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -q
122+
123+
- name: Upload test result artifacts
124+
uses: actions/upload-artifact@v4
125+
if: always()
126+
with:
127+
name: qemu_results-${{matrix.chip}}-${{matrix.chunks}}
128+
path: tests/*/*.xml
129+
130+
hardware-test:
131+
needs: [gen_chunks, build]
132+
name: ${{matrix.chip}}-Hardware_Test#${{matrix.chunks}}
133+
if: |
134+
contains(github.event.pull_request.labels.*.name, 'hil_test') || github.event_name == 'schedule'
69135
strategy:
70136
fail-fast: false
71137
matrix:
@@ -100,15 +166,13 @@ jobs:
100166
uses: actions/upload-artifact@v4
101167
if: always()
102168
with:
103-
name: test_results-${{matrix.chip}}-${{matrix.chunks}}
169+
name: hw_results-${{matrix.chip}}-${{matrix.chunks}}
104170
path: tests/*/*.xml
105171

106172
event_file:
107173
name: "Event File"
108-
if: |
109-
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
110-
github.event_name == 'schedule'
111-
needs: Test
174+
if: ${{ always() && !failure() && !cancelled() }}
175+
needs: [hardware-test, qemu-test]
112176
runs-on: ubuntu-latest
113177
steps:
114178
- name: Upload

Diff for: .github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Unit Test Results
22

33
on:
44
workflow_run:
5-
workflows: [Run tests in hardware]
5+
workflows: [Run tests]
66
branches-ignore: [master]
77

88
types:

Diff for: tests/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
addopts = --embedded-services esp,arduino
2+
addopts = --embedded-services esp,arduino,qemu
33

44
# log related
55
log_cli = True

Diff for: tests/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cryptography>=2.1.4
33
pytest-cov
44
pytest-embedded-serial-esp>=1.3.4
55
pytest-embedded-arduino>=1.3.4
6+
pytest-embedded-qemu>=1.3.4

0 commit comments

Comments
 (0)