Skip to content

Commit 1299582

Browse files
lucasssvazpre-commit-ci-lite[bot]P-R-O-C-H-Y
authored
ci(performance): Add performance tests to CI (#9560)
* ci(performance): Add performance tests to CI * ci(req): Fix requirements * ci(pre-commit): Apply automatic fixes * ci(pre-commit): Increase maximum allowed complexity for python --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Jan Procházka <[email protected]>
1 parent c396834 commit 1299582

Some content is hidden

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

52 files changed

+8193
-57
lines changed

.flake8

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-python/.flake8
22
# See: https://flake8.pycqa.org/en/latest/user/configuration.html
3-
# The code style defined in this file is the official standardized style to be used in all Arduino tooling projects and
4-
# should not be modified.
53

64
[flake8]
75
doctests = True
86
# W503 and W504 are mutually exclusive. PEP 8 recommends line break before.
97
ignore = W503,E203
10-
max-complexity = 10
8+
max-complexity = 20
119
max-line-length = 120
1210
select = E,W,F,C,N

.github/scripts/sketch_utils.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
121121
fi
122122

123123
if [ -z "$fqbn" ]; then
124-
echo "No FQBN passed or unvalid chip: $target"
124+
echo "No FQBN passed or invalid chip: $target"
125125
exit 1
126126
fi
127127

@@ -139,7 +139,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
139139
echo "Skipping $sketchname for target $target"
140140
exit 0
141141
fi
142-
142+
143143
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
144144
if [ -n "$ARDUINO_BUILD_DIR" ]; then
145145
build_dir="$ARDUINO_BUILD_DIR"
@@ -177,7 +177,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
177177
--build-path "$build_dir" \
178178
$xtra_opts "${sketchdir}" \
179179
> $output_file
180-
180+
181181
exit_status=$?
182182
if [ $exit_status -ne 0 ]; then
183183
echo ""ERROR: Compilation failed with error code $exit_status""
@@ -198,11 +198,11 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
198198
# Extract the desired substring using sed
199199
lib_sketch_name=$(echo "$directory_path" | sed "s|$constant_part||")
200200
#append json file where key is fqbn, sketch name, sizes -> extracted values
201-
echo "{\"name\": \"$lib_sketch_name\",
201+
echo "{\"name\": \"$lib_sketch_name\",
202202
\"sizes\": [{
203-
\"flash_bytes\": $flash_bytes,
204-
\"flash_percentage\": $flash_percentage,
205-
\"ram_bytes\": $ram_bytes,
203+
\"flash_bytes\": $flash_bytes,
204+
\"flash_percentage\": $flash_percentage,
205+
\"ram_bytes\": $ram_bytes,
206206
\"ram_percentage\": $ram_percentage
207207
}]
208208
}," >> "$sizes_file"
@@ -365,6 +365,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
365365
start_index=$(( $chunk_index * $chunk_size ))
366366
if [ "$sketchcount" -le "$start_index" ]; then
367367
echo "Skipping job"
368+
touch ~/.build_skipped
368369
return 0
369370
fi
370371

@@ -386,7 +387,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
386387
if [ $log_compilation ]; then
387388
#echo board,target and start of sketches to sizes_file json
388389
echo "{ \"board\": \"$fqbn\",
389-
\"target\": \"$target\",
390+
\"target\": \"$target\",
390391
\"sketches\": [" >> "$sizes_file"
391392
fi
392393

.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

+32-9
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ function run_test() {
1515
fi
1616

1717
if [ $len -eq 1 ]; then
18-
# build_dir="tests/$sketchname/build"
18+
# build_dir="$sketchdir/build"
1919
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
20-
report_file="tests/$sketchname/$sketchname.xml"
20+
report_file="$sketchdir/$sketchname.xml"
2121
fi
2222

2323
for i in `seq 0 $(($len - 1))`
@@ -28,9 +28,9 @@ function run_test() {
2828
fi
2929

3030
if [ $len -ne 1 ]; then
31-
# build_dir="tests/$sketchname/build$i"
31+
# build_dir="$sketchdir/build$i"
3232
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
33-
report_file="tests/$sketchname/$sketchname$i.xml"
33+
report_file="$sketchdir/$sketchname$i.xml"
3434
fi
3535

3636
pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file
@@ -79,6 +79,10 @@ while [ ! -z "$1" ]; do
7979
echo "$USAGE"
8080
exit 0
8181
;;
82+
-type )
83+
shift
84+
test_type=$1
85+
;;
8286
* )
8387
break
8488
;;
@@ -88,21 +92,39 @@ done
8892

8993
source ${SCRIPTS_DIR}/install-arduino-ide.sh
9094

95+
# If sketch is provided and test type is not, test type is inferred from the sketch path
96+
if [[ $test_type == "all" ]] || [[ -z $test_type ]]; then
97+
if [ -n "$sketch" ]; then
98+
tmp_sketch_path=$(find tests -name $sketch.ino)
99+
test_type=$(basename $(dirname $(dirname "$tmp_sketch_path")))
100+
echo "Sketch $sketch test type: $test_type"
101+
test_folder="$PWD/tests/$test_type"
102+
else
103+
test_folder="$PWD/tests"
104+
fi
105+
else
106+
test_folder="$PWD/tests/$test_type"
107+
fi
108+
91109
if [ $chunk_run -eq 0 ]; then
92-
run_test $target $PWD/tests/$sketch/$sketch.ino $options $erase
110+
if [ -z $sketch ]; then
111+
echo "ERROR: Sketch name is required for single test run"
112+
exit 1
113+
fi
114+
run_test $target $test_folder/$sketch/$sketch.ino $options $erase
93115
else
94116
if [ "$chunk_max" -le 0 ]; then
95117
echo "ERROR: Chunks count must be positive number"
96-
return 1
118+
exit 1
97119
fi
98120

99121
if [ "$chunk_index" -ge "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
100122
echo "ERROR: Chunk index must be less than chunks count"
101-
return 1
123+
exit 1
102124
fi
103125

104126
set +e
105-
${COUNT_SKETCHES} $PWD/tests $target
127+
${COUNT_SKETCHES} $test_folder $target
106128
sketchcount=$?
107129
set -e
108130
sketches=$(cat sketches.txt)
@@ -123,7 +145,8 @@ else
123145
start_index=$(( $chunk_index * $chunk_size ))
124146
if [ "$sketchcount" -le "$start_index" ]; then
125147
echo "Skipping job"
126-
return 0
148+
touch ~/.test_skipped
149+
exit 0
127150
fi
128151

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

.github/workflows/hil.yml

+61-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
@@ -52,17 +69,21 @@ jobs:
5269
steps:
5370
- name: Checkout Repository
5471
uses: actions/checkout@v4
72+
5573
- name: Build sketches
5674
run: |
57-
bash .github/scripts/tests_build.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
75+
bash .github/scripts/tests_build.sh -c -type ${{ needs.gen_chunks.outputs.test_type }} -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
76+
5877
- name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts
5978
uses: actions/upload-artifact@v4
6079
with:
6180
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
62-
path: |
63-
~/.arduino/tests/*/build*.tmp/*.bin
64-
~/.arduino/tests/*/build*.tmp/*.json
6581
if-no-files-found: error
82+
path: |
83+
~/.build_skipped
84+
~/.arduino/tests/**/build*.tmp/*.bin
85+
~/.arduino/tests/**/build*.tmp/*.json
86+
6687
Test:
6788
needs: [gen_chunks, Build]
6889
name: ${{matrix.chip}}-Test#${{matrix.chunks}}
@@ -77,36 +98,49 @@ jobs:
7798
options: --privileged
7899

79100
steps:
80-
- name: Checkout repository
81-
uses: actions/checkout@v4
101+
- name: Checkout repository
102+
uses: actions/checkout@v4
82103

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/
104+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
105+
uses: actions/download-artifact@v4
106+
with:
107+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
108+
path: ~/
88109

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
110+
- name: Install dependencies
111+
run: |
112+
pip install -U pip
113+
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
114+
apt update && apt install -y -qq jq
94115
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
116+
- name: Run Tests
117+
run: |
118+
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
98119
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
120+
- name: Check if tests were skipped
121+
id: check-test-skipped
122+
run: |
123+
if [ -f ~/.test_skipped ]; then
124+
echo "skipped=true" >> $GITHUB_OUTPUT
125+
else
126+
echo "skipped=false" >> $GITHUB_OUTPUT
127+
fi
128+
129+
- name: Upload test result artifacts
130+
uses: actions/upload-artifact@v4
131+
if: ${{ always() && steps.check-test-skipped.outputs.skipped == 'false' }}
132+
with:
133+
name: test_results-${{matrix.chip}}-${{matrix.chunks}}
134+
if-no-files-found: error
135+
path: |
136+
tests/**/*.xml
137+
tests/**/result_*.json
105138
106139
event_file:
107140
name: "Event File"
108141
if: |
109142
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
143+
contains(github.event.pull_request.labels.*.name, 'perf_test') ||
110144
github.event_name == 'schedule'
111145
needs: Test
112146
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)