Skip to content

Commit 140cb2f

Browse files
authored
Merge branch 'master' into ci/wokwi
2 parents ca03917 + 1299582 commit 140cb2f

Some content is hidden

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

63 files changed

+8450
-231
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
@@ -20,9 +20,9 @@ function run_test() {
2020
fi
2121

2222
if [ $len -eq 1 ]; then
23-
# build_dir="tests/$sketchname/build"
23+
# build_dir="$sketchdir/build"
2424
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
25-
report_file="tests/$sketchname/$sketchname.xml"
25+
report_file="$sketchdir/$sketchname.xml"
2626
fi
2727

2828
for i in `seq 0 $(($len - 1))`
@@ -33,9 +33,9 @@ function run_test() {
3333
fi
3434

3535
if [ $len -ne 1 ]; then
36-
# build_dir="tests/$sketchname/build$i"
36+
# build_dir="$sketchdir/build$i"
3737
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
38-
report_file="tests/$sketchname/$sketchname$i.xml"
38+
report_file="$sketchdir/$sketchname$i.xml"
3939
fi
4040

4141
if [ $platform == "wokwi" ]; then
@@ -100,6 +100,10 @@ while [ ! -z "$1" ]; do
100100
echo "$USAGE"
101101
exit 0
102102
;;
103+
-type )
104+
shift
105+
test_type=$1
106+
;;
103107
* )
104108
break
105109
;;
@@ -109,21 +113,39 @@ done
109113

110114
source ${SCRIPTS_DIR}/install-arduino-ide.sh
111115

116+
# If sketch is provided and test type is not, test type is inferred from the sketch path
117+
if [[ $test_type == "all" ]] || [[ -z $test_type ]]; then
118+
if [ -n "$sketch" ]; then
119+
tmp_sketch_path=$(find tests -name $sketch.ino)
120+
test_type=$(basename $(dirname $(dirname "$tmp_sketch_path")))
121+
echo "Sketch $sketch test type: $test_type"
122+
test_folder="$PWD/tests/$test_type"
123+
else
124+
test_folder="$PWD/tests"
125+
fi
126+
else
127+
test_folder="$PWD/tests/$test_type"
128+
fi
129+
112130
if [ $chunk_run -eq 0 ]; then
113-
run_test $target $PWD/tests/$sketch/$sketch.ino $options $erase
131+
if [ -z $sketch ]; then
132+
echo "ERROR: Sketch name is required for single test run"
133+
exit 1
134+
fi
135+
run_test $target $test_folder/$sketch/$sketch.ino $options $erase
114136
else
115137
if [ "$chunk_max" -le 0 ]; then
116138
echo "ERROR: Chunks count must be positive number"
117-
return 1
139+
exit 1
118140
fi
119141

120142
if [ "$chunk_index" -ge "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
121143
echo "ERROR: Chunk index must be less than chunks count"
122-
return 1
144+
exit 1
123145
fi
124146

125147
set +e
126-
${COUNT_SKETCHES} $PWD/tests $target
148+
${COUNT_SKETCHES} $test_folder $target
127149
sketchcount=$?
128150
set -e
129151
sketches=$(cat sketches.txt)
@@ -144,7 +166,8 @@ else
144166
start_index=$(( $chunk_index * $chunk_size ))
145167
if [ "$sketchcount" -le "$start_index" ]; then
146168
echo "Skipping job"
147-
return 0
169+
touch ~/.test_skipped
170+
exit 0
148171
fi
149172

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

.github/workflows/hil.yml

+61-36
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ concurrency:
2020
jobs:
2121
gen_chunks:
2222
if: |
23-
github.repository == 'espressif/arduino-esp32' &&
24-
( contains(github.event.pull_request.labels.*.name, 'run_tests') || github.event_name == 'schedule' )
23+
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
24+
contains(github.event.pull_request.labels.*.name, 'perf_test') ||
25+
(github.event_name == 'schedule' && github.repository == 'espressif/arduino-esp32')
2526
name: Generate Chunks matrix
2627
runs-on: ubuntu-latest
2728
outputs:
2829
chunks: ${{ steps.gen-chunks.outputs.chunks }}
30+
test_folder: ${{ steps.gen-chunks.outputs.test_folder }}
31+
test_type: ${{ steps.gen-chunks.outputs.test_type }}
2932
steps:
3033
- name: Checkout Repository
3134
uses: actions/checkout@v4
@@ -36,15 +39,29 @@ jobs:
3639
id: gen-chunks
3740
run: |
3841
set +e
39-
.github/scripts/sketch_utils.sh count tests
42+
if [ "${{contains(github.event.pull_request.labels.*.name, 'hil_test')}}" == "true" ] && \
43+
[ "${{contains(github.event.pull_request.labels.*.name, 'perf_test')}}" == "false" ]; then
44+
test_folder="tests/validation"
45+
test_type="validation"
46+
elif [ "${{contains(github.event.pull_request.labels.*.name, 'hil_test')}}" == "false" ] && \
47+
[ "${{contains(github.event.pull_request.labels.*.name, 'perf_test')}}" == "true" ]; then
48+
test_folder="tests/performance"
49+
test_type="performance"
50+
else
51+
test_folder="tests"
52+
test_type="all"
53+
fi
54+
.github/scripts/sketch_utils.sh count $test_folder
4055
sketches=$?
4156
if [[ $sketches -ge ${{env.MAX_CHUNKS}} ]]; then
4257
$sketches=${{env.MAX_CHUNKS}}
4358
fi
4459
set -e
4560
rm sketches.txt
4661
CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $((sketches - 1))`)
47-
echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT
62+
echo "chunks=${CHUNKS}" >> $GITHUB_OUTPUT
63+
echo "test_folder=${test_folder}" >> $GITHUB_OUTPUT
64+
echo "test_type=${test_type}" >> $GITHUB_OUTPUT
4865
4966
build:
5067
needs: gen_chunks
@@ -57,20 +74,20 @@ jobs:
5774
steps:
5875
- name: Checkout Repository
5976
uses: actions/checkout@v4
60-
with:
61-
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR
6277

6378
- name: Build sketches
6479
run: |
65-
bash .github/scripts/tests_build.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
80+
bash .github/scripts/tests_build.sh -c -type ${{ needs.gen_chunks.outputs.test_type }} -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
81+
6682
- name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts
6783
uses: actions/upload-artifact@v4
6884
with:
6985
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
70-
path: |
71-
~/.arduino/tests/*/build*.tmp/*.bin
72-
~/.arduino/tests/*/build*.tmp/*.json
7386
if-no-files-found: error
87+
path: |
88+
~/.build_skipped
89+
~/.arduino/tests/**/build*.tmp/*.bin
90+
~/.arduino/tests/**/build*.tmp/*.json
7491
7592
wokwi-test:
7693
needs: [gen_chunks, build]
@@ -98,11 +115,6 @@ jobs:
98115
run: |
99116
pip install -U pip
100117
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
101-
git clone https://github.com/P-R-O-C-H-Y/pytest-embedded.git
102-
cd pytest-embedded
103-
git checkout feature/wokwi-scenario-support
104-
pip install -e pytest-embedded-wokwi
105-
cd ..
106118
sudo apt update && sudo apt install -y -qq jq
107119
108120
- name: Run Tests
@@ -134,36 +146,49 @@ jobs:
134146
options: --privileged
135147

136148
steps:
137-
- name: Checkout repository
138-
uses: actions/checkout@v4
149+
- name: Checkout repository
150+
uses: actions/checkout@v4
139151

140-
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
141-
uses: actions/download-artifact@v4
142-
with:
143-
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
144-
path: ~/.arduino/tests/
152+
- name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts
153+
uses: actions/download-artifact@v4
154+
with:
155+
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
156+
path: ~/
157+
158+
- name: Install dependencies
159+
run: |
160+
pip install -U pip
161+
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
162+
apt update && apt install -y -qq jq
145163
146-
- name: Install dependencies
147-
run: |
148-
pip install -U pip
149-
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
150-
apt update && apt install -y -qq jq
164+
- name: Run Tests
165+
run: |
166+
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
151167
152-
- name: Run Tests
153-
run: |
154-
bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -e
168+
- name: Check if tests were skipped
169+
id: check-test-skipped
170+
run: |
171+
if [ -f ~/.test_skipped ]; then
172+
echo "skipped=true" >> $GITHUB_OUTPUT
173+
else
174+
echo "skipped=false" >> $GITHUB_OUTPUT
175+
fi
155176
156-
- name: Upload test result artifacts
157-
uses: actions/upload-artifact@v4
158-
if: always()
159-
with:
160-
name: hw_results-${{matrix.chip}}-${{matrix.chunks}}
161-
path: tests/*/*.xml
177+
- name: Upload test result artifacts
178+
uses: actions/upload-artifact@v4
179+
if: ${{ always() && steps.check-test-skipped.outputs.skipped == 'false' }}
180+
with:
181+
name: hw_results-${{matrix.chip}}-${{matrix.chunks}}
182+
if-no-files-found: error
183+
path: |
184+
tests/**/*.xml
185+
tests/**/result_*.json
162186
163187
event_file:
164188
name: "Event File"
165189
if: |
166190
contains(github.event.pull_request.labels.*.name, 'hil_test') ||
191+
contains(github.event.pull_request.labels.*.name, 'perf_test') ||
167192
github.event_name == 'schedule'
168193
needs: hardware-test
169194
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

0 commit comments

Comments
 (0)