Skip to content

Commit 7dcaadc

Browse files
committed
Add test workflow and necessary scripts.
Signed-off-by: Abdelatif Guettouche <[email protected]>
1 parent b0c28db commit 7dcaadc

File tree

11 files changed

+240
-0
lines changed

11 files changed

+240
-0
lines changed

Diff for: .github/scripts/tests_build.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
target=$1
4+
chunk_index=$2
5+
chunk_max=$3
6+
7+
if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
8+
chunk_index=$chunk_max
9+
fi
10+
11+
case "$target" in
12+
"esp32") fqbn="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app"
13+
;;
14+
"esp32s2") fqbn="espressif:esp32:esp32s2:PSRAM=enabled,PartitionScheme=huge_app"
15+
;;
16+
"esp32c3") fqbn="espressif:esp32:esp32c3:PartitionScheme=huge_app"
17+
;;
18+
esac
19+
20+
if [ -z $fqbn ]; then
21+
echo "Unvalid chip $1"
22+
exit 0
23+
fi
24+
25+
SCRIPTS_DIR="./.github/scripts"
26+
BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
27+
28+
source ${SCRIPTS_DIR}/install-arduino-ide.sh
29+
source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh
30+
31+
args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH"
32+
args+=" \"$fqbn\" $target $PWD/tests $chunk_index $chunk_max"
33+
${BUILD_SKETCHES} ${args}
34+

Diff for: .github/scripts/tests_run.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
target=$1
4+
chunk_idex=$2
5+
chunks_num=$3
6+
7+
SCRIPTS_DIR="./.github/scripts"
8+
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
9+
10+
source ${SCRIPTS_DIR}/install-arduino-ide.sh
11+
12+
if [ "$chunks_num" -le 0 ]; then
13+
echo "ERROR: Chunks count must be positive number"
14+
return 1
15+
fi
16+
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
17+
echo "ERROR: Chunk index must be less than chunks count"
18+
return 1
19+
fi
20+
21+
set +e
22+
${COUNT_SKETCHES} $PWD/tests $target
23+
sketchcount=$?
24+
set -e
25+
sketches=$(cat sketches.txt)
26+
rm -rf sketches.txt
27+
28+
chunk_size=$(( $sketchcount / $chunks_num ))
29+
all_chunks=$(( $chunks_num * $chunk_size ))
30+
if [ "$all_chunks" -lt "$sketchcount" ]; then
31+
chunk_size=$(( $chunk_size + 1 ))
32+
fi
33+
34+
start_index=0
35+
end_index=0
36+
if [ "$chunk_idex" -ge "$chunks_num" ]; then
37+
start_index=$chunk_idex
38+
end_index=$sketchcount
39+
else
40+
start_index=$(( $chunk_idex * $chunk_size ))
41+
if [ "$sketchcount" -le "$start_index" ]; then
42+
echo "Skipping job"
43+
return 0
44+
fi
45+
46+
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
47+
if [ "$end_index" -gt "$sketchcount" ]; then
48+
end_index=$sketchcount
49+
fi
50+
fi
51+
52+
start_num=$(( $start_index + 1 ))
53+
sketchnum=0
54+
55+
for sketch in $sketches; do
56+
sketchdir=$(dirname $sketch)
57+
sketchdirname=$(basename $sketchdir)
58+
sketchname=$(basename $sketch)
59+
sketchnum=$(($sketchnum + 1))
60+
if [ "$sketchnum" -le "$start_index" ] \
61+
|| [ "$sketchnum" -gt "$end_index" ]; then
62+
continue
63+
fi
64+
echo ""
65+
echo "Test for Sketch Index $(($sketchnum - 1)) - $sketchdirname"
66+
pytest tests -k test_$sketchdirname
67+
result=$?
68+
if [ $result -ne 0 ]; then
69+
return $result
70+
fi
71+
done

Diff for: .github/workflows/hil.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Run tests in hardware
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, labeled]
6+
7+
# schedule:
8+
# - cron: '0 2 * * *'
9+
10+
env:
11+
MAX_CHUNKS: 15
12+
13+
concurrency:
14+
group: hil-${{github.event.pull_request.number || github.ref}}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
Build:
19+
if: contains(github.event.pull_request.labels.*.name, 'hil_test')
20+
name: ${{matrix.chip}}-Build#${{matrix.chunks}}
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
chip: ['esp32', 'esp32s2', 'esp32c3']
25+
chunks: [0, 1, 2, 3]
26+
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@v2
30+
31+
- name: Build sketches
32+
run: |
33+
bash .github/scripts/tests_build.sh ${{matrix.chip}} ${{matrix.chunks}} ${{env.MAX_CHUNKS}}
34+
- name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts
35+
uses: actions/upload-artifact@v2
36+
with:
37+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
38+
path: |
39+
tests/*/build/*.bin
40+
tests/*/build/*.json
41+
Test:
42+
needs: Build
43+
name: ${{matrix.chip}}-Test#${{matrix.chunks}}
44+
runs-on: ESP32
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
chip: ['esp32', 'esp32s2', 'esp32c3']
49+
chunks: [0, 1, 2, 3]
50+
container:
51+
image: python:3.10.1-bullseye
52+
options: --privileged
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v2
57+
58+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
59+
uses: actions/download-artifact@v2
60+
with:
61+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
62+
path: tests/
63+
64+
- name: Check Artifacts
65+
run: |
66+
ls -R tests
67+
cat tests/*/build/build.options.json
68+
69+
- name: Install dependencies
70+
run: |
71+
pip install -U pip
72+
pip install -r tests/requirements.txt
73+
74+
- name: Run Tests
75+
run: |
76+
bash .github/scripts/tests_run.sh ${{matrix.chip}} ${{matrix.chunks}} ${{env.MAX_CHUNKS}}

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ boards.sloeber.txt
2222
# Ignore docs build (Sphinx)
2323
docs/build
2424
docs/source/_build
25+
26+
# Test log files
27+
*.log

Diff for: tests/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
__pycache__/

Diff for: tests/hello_world/hello_world.ino

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void setup(){
2+
// Open serial communications and wait for port to open:
3+
Serial.begin(115200);
4+
while (!Serial) {
5+
;
6+
}
7+
8+
Serial.println("Hello Arduino!");
9+
}
10+
11+
void loop(){
12+
}

Diff for: tests/hello_world/test_hello_world.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_hello_world(dut):
2+
dut.expect('Hello Arduino!')

Diff for: tests/pytest.ini

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[pytest]
2+
addopts = --embedded-services esp,arduino
3+
4+
# log related
5+
log_cli = True
6+
log_cli_level = INFO
7+
log_cli_format = %(asctime)s %(levelname)s %(message)s
8+
log_cli_date_format = %Y-%m-%d %H:%M:%S
9+
10+
log_file = test.log
11+
log_file_level = INFO
12+
log_file_format = %(asctime)s %(levelname)s %(message)s
13+
log_file_date_format = %Y-%m-%d %H:%M:%S

Diff for: tests/requirements.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pyserial>=3.0
2+
esptool>=3.1
3+
pytest-cov
4+
cryptography<3.4; platform_machine == "armv7l"
5+
6+
pytest>=6.2.0
7+
pexpect>=4.4
8+
9+
pytest-embedded>=0.5.1
10+
pytest-embedded-serial>=0.5.1
11+
pytest-embedded-serial-esp>=0.5.1
12+
pytest-embedded-arduino>=0.5.1
13+

Diff for: tests/serial/serial.ino

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void setup(){
2+
// Open serial communications and wait for port to open:
3+
Serial.begin(115200);
4+
while (!Serial) {
5+
;
6+
}
7+
8+
Serial.println("Hello Serial!");
9+
}
10+
11+
void loop(){
12+
}

Diff for: tests/serial/test_serial.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_serial(dut):
2+
dut.expect('Hello Serial!')

0 commit comments

Comments
 (0)