Skip to content

Commit 449fe9b

Browse files
committed
ci(performance): Add performance tests to CI
1 parent cf44890 commit 449fe9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+8229
-44
lines changed

.github/scripts/tests_build.sh

+25-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
USAGE="
44
USAGE:
5-
${0} -c <chunk_build_opts>
6-
Example: ${0} -c -t esp32 -i 0 -m 15
5+
${0} -c -type <test_type> <chunk_build_opts>
6+
Example: ${0} -c -type validation -t esp32 -i 0 -m 15
77
${0} -s sketch_name <build_opts>
88
Example: ${0} -s hello_world -t esp32
99
${0} -clean
1010
Remove build and test generated files
1111
"
1212

1313
function clean(){
14-
rm -rf tests/*/build*/
1514
rm -rf tests/.pytest_cache
16-
rm -rf tests/*/__pycache__/
17-
rm -rf tests/*/*.xml
15+
find tests/ -type d -name 'build*' -exec rm -rf "{}" \+
16+
find tests/ -type d -name '__pycache__' -exec rm -rf "{}" \+
17+
find tests/ -name '*.xml' -exec rm -rf "{}" \+
18+
find tests/ -name 'result_*.json' -exec rm -rf "{}" \+
1819
}
1920

2021
SCRIPTS_DIR="./.github/scripts"
@@ -35,6 +36,10 @@ while [ ! -z "$1" ]; do
3536
echo "$USAGE"
3637
exit 0
3738
;;
39+
-type )
40+
shift
41+
test_type=$1
42+
;;
3843
-clean )
3944
clean
4045
exit 0
@@ -52,12 +57,25 @@ source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh
5257

5358
args="-ai $ARDUINO_IDE_PATH -au $ARDUINO_USR_PATH"
5459

60+
if [[ $test_type == "all" ]] || [[ -z $test_type ]]; then
61+
if [ -n "$sketch" ]; then
62+
tmp_sketch_path=$(find tests -name $sketch.ino)
63+
test_type=$(basename $(dirname $(dirname "$tmp_sketch_path")))
64+
echo "Sketch $sketch test type: $test_type"
65+
test_folder="$PWD/tests/$test_type"
66+
else
67+
test_folder="$PWD/tests"
68+
fi
69+
else
70+
test_folder="$PWD/tests/$test_type"
71+
fi
72+
5573
if [ $chunk_build -eq 1 ]; then
5674
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
57-
args+=" -p $PWD/tests"
75+
args+=" -p $test_folder"
5876
else
5977
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh build"
60-
args+=" -s $PWD/tests/$sketch"
78+
args+=" -s $test_folder/$sketch"
6179
fi
6280

6381
${BUILD_CMD} ${args} $*

.github/scripts/tests_run.sh

+36-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ function run_test() {
88
local sketchdir=$(dirname $sketch)
99
local sketchname=$(basename $sketchdir)
1010

11+
if [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then
12+
echo "Skipping $sketchname for target $target"
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
1419
len=1
1520
fi
1621

1722
if [ $len -eq 1 ]; then
18-
# build_dir="tests/$sketchname/build"
23+
# build_dir="$sketchdir/build"
1924
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
20-
report_file="tests/$sketchname/$sketchname.xml"
25+
report_file="$sketchdir/$sketchname.xml"
2126
fi
2227

2328
for i in `seq 0 $(($len - 1))`
@@ -28,9 +33,9 @@ function run_test() {
2833
fi
2934

3035
if [ $len -ne 1 ]; then
31-
# build_dir="tests/$sketchname/build$i"
36+
# build_dir="$sketchdir/build$i"
3237
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
33-
report_file="tests/$sketchname/$sketchname$i.xml"
38+
report_file="$sketchdir/$sketchname$i.xml"
3439
fi
3540

3641
pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file
@@ -79,6 +84,10 @@ while [ ! -z "$1" ]; do
7984
echo "$USAGE"
8085
exit 0
8186
;;
87+
-type )
88+
shift
89+
test_type=$1
90+
;;
8291
* )
8392
break
8493
;;
@@ -88,21 +97,39 @@ done
8897

8998
source ${SCRIPTS_DIR}/install-arduino-ide.sh
9099

100+
# If sketch is provided and test type is not, test type is inferred from the sketch path
101+
if [[ $test_type == "all" ]] || [[ -z $test_type ]]; then
102+
if [ -n "$sketch" ]; then
103+
tmp_sketch_path=$(find tests -name $sketch.ino)
104+
test_type=$(basename $(dirname $(dirname "$tmp_sketch_path")))
105+
echo "Sketch $sketch test type: $test_type"
106+
test_folder="$PWD/tests/$test_type"
107+
else
108+
test_folder="$PWD/tests"
109+
fi
110+
else
111+
test_folder="$PWD/tests/$test_type"
112+
fi
113+
91114
if [ $chunk_run -eq 0 ]; then
92-
run_test $target $PWD/tests/$sketch/$sketch.ino $options $erase
115+
if [ -z $sketch ]; then
116+
echo "ERROR: Sketch name is required for single test run"
117+
exit 1
118+
fi
119+
run_test $target $test_folder/$sketch/$sketch.ino $options $erase
93120
else
94121
if [ "$chunk_max" -le 0 ]; then
95122
echo "ERROR: Chunks count must be positive number"
96-
return 1
123+
exit 1
97124
fi
98125

99126
if [ "$chunk_index" -ge "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
100127
echo "ERROR: Chunk index must be less than chunks count"
101-
return 1
128+
exit 1
102129
fi
103130

104131
set +e
105-
${COUNT_SKETCHES} $PWD/tests $target
132+
${COUNT_SKETCHES} $test_folder $target
106133
sketchcount=$?
107134
set -e
108135
sketches=$(cat sketches.txt)
@@ -123,7 +150,7 @@ else
123150
start_index=$(( $chunk_index * $chunk_size ))
124151
if [ "$sketchcount" -le "$start_index" ]; then
125152
echo "Skipping job"
126-
return 0
153+
exit 0
127154
fi
128155

129156
end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))

.github/workflows/hil.yml

+56-27
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ jobs:
1818
gen_chunks:
1919
if: |
2020
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
21+
contains(github.event.pull_request.labels.*.name, 'perf_test') ||
2122
(github.event_name == 'schedule' && github.repository == 'espressif/arduino-esp32')
2223
name: Generate Chunks matrix
2324
runs-on: ubuntu-latest
2425
outputs:
2526
chunks: ${{ steps.gen-chunks.outputs.chunks }}
27+
test_folder: ${{ steps.gen-chunks.outputs.test_folder }}
28+
test_type: ${{ steps.gen-chunks.outputs.test_type }}
2629
steps:
2730
- name: Checkout Repository
2831
uses: actions/checkout@v4
@@ -31,15 +34,29 @@ jobs:
3134
id: gen-chunks
3235
run: |
3336
set +e
34-
.github/scripts/sketch_utils.sh count tests
37+
if [ "${{contains(github.event.pull_request.labels.*.name, 'hil_test')}}" == "true" ] && \
38+
[ "${{contains(github.event.pull_request.labels.*.name, 'perf_test')}}" == "false" ]; then
39+
test_folder="tests/validation"
40+
test_type="validation"
41+
elif [ "${{contains(github.event.pull_request.labels.*.name, 'hil_test')}}" == "false" ] && \
42+
[ "${{contains(github.event.pull_request.labels.*.name, 'perf_test')}}" == "true" ]; then
43+
test_folder="tests/performance"
44+
test_type="performance"
45+
else
46+
test_folder="tests"
47+
test_type="all"
48+
fi
49+
.github/scripts/sketch_utils.sh count $test_folder
3550
sketches=$?
3651
if [[ $sketches -ge ${{env.MAX_CHUNKS}} ]]; then
3752
$sketches=${{env.MAX_CHUNKS}}
3853
fi
3954
set -e
4055
rm sketches.txt
4156
CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $((sketches - 1))`)
42-
echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT
57+
echo "chunks=${CHUNKS}" >> $GITHUB_OUTPUT
58+
echo "test_folder=${test_folder}" >> $GITHUB_OUTPUT
59+
echo "test_type=${test_type}" >> $GITHUB_OUTPUT
4360
4461
Build:
4562
needs: gen_chunks
@@ -54,15 +71,15 @@ jobs:
5471
uses: actions/checkout@v4
5572
- name: Build sketches
5673
run: |
57-
bash .github/scripts/tests_build.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
74+
bash .github/scripts/tests_build.sh -c -type ${{ needs.gen_chunks.outputs.test_type }} -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
5875
- name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts
5976
uses: actions/upload-artifact@v4
6077
with:
6178
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
6279
path: |
63-
~/.arduino/tests/*/build*.tmp/*.bin
64-
~/.arduino/tests/*/build*.tmp/*.json
65-
if-no-files-found: error
80+
~/.arduino/tests/**/build*.tmp/*.bin
81+
~/.arduino/tests/**/build*.tmp/*.json
82+
6683
Test:
6784
needs: [gen_chunks, Build]
6885
name: ${{matrix.chip}}-Test#${{matrix.chunks}}
@@ -77,36 +94,48 @@ jobs:
7794
options: --privileged
7895

7996
steps:
80-
- name: Checkout repository
81-
uses: actions/checkout@v4
97+
- name: Checkout repository
98+
uses: actions/checkout@v4
8299

83-
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
84-
uses: actions/download-artifact@v4
85-
with:
86-
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
87-
path: ~/.arduino/tests/
100+
- name: Check if test artifacts are available
101+
id: check-artifact
102+
uses: LIT-Protocol/artifact-exists-action@v0
103+
with:
104+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
105+
106+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
107+
uses: actions/download-artifact@v4
108+
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
109+
with:
110+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
111+
path: ~/.arduino/tests/
88112

89-
- name: Install dependencies
90-
run: |
91-
pip install -U pip
92-
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
93-
apt update && apt install -y -qq jq
113+
- name: Install dependencies
114+
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
115+
run: |
116+
pip install -U pip
117+
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
118+
apt update && apt install -y -qq jq
94119
95-
- name: Run Tests
96-
run: |
97-
bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -e
120+
- name: Run Tests
121+
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
122+
run: |
123+
bash .github/scripts/tests_run.sh -c -type ${{ needs.gen_chunks.outputs.test_type }} -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -e
98124
99-
- name: Upload test result artifacts
100-
uses: actions/upload-artifact@v4
101-
if: always()
102-
with:
103-
name: test_results-${{matrix.chip}}-${{matrix.chunks}}
104-
path: tests/*/*.xml
125+
- name: Upload test result artifacts
126+
uses: actions/upload-artifact@v4
127+
if: ${{ always() && steps.check-artifact.outputs.exists == 'true' }}
128+
with:
129+
name: test_results-${{matrix.chip}}-${{matrix.chunks}}
130+
path: |
131+
tests/**/*.xml
132+
tests/**/result_*.json
105133
106134
event_file:
107135
name: "Event File"
108136
if: |
109137
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
138+
contains(github.event.pull_request.labels.*.name, 'perf_test') ||
110139
github.event_name == 'schedule'
111140
needs: Test
112141
runs-on: ubuntu-latest

.pre-commit-config.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
exclude: ".github/.*"
1+
exclude: |
2+
(?x)(
3+
^\.github\/|
4+
^tests\/performance\/coremark\/.*\.[ch]$
5+
)
26
37
default_language_version:
48
# force all unspecified python hooks to run python3

tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build*/
22
__pycache__/
33
*.xml
4+
result_*.json

0 commit comments

Comments
 (0)