Skip to content

Commit 28ed0a4

Browse files
committed
tests/: Run multiple tests if the build contained multiple
configurations. Signed-off-by: Abdelatif Guettouche <[email protected]>
1 parent 818c195 commit 28ed0a4

File tree

4 files changed

+122
-62
lines changed

4 files changed

+122
-62
lines changed

Diff for: .github/scripts/tests_run.sh

+116-57
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,129 @@
11
#!/bin/bash
22

3-
target=$1
4-
chunk_idex=$2
5-
chunks_num=$3
3+
function run_test() {
4+
local target=$1
5+
local sketch=$2
6+
local options=$3
7+
local sketchdir=$(dirname $sketch)
8+
local sketchdirname=$(basename $sketchdir)
9+
10+
if [ $options -eq 0 ] && [ -f $sketchdir/cfg.json ]; then
11+
len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
12+
else
13+
len=1
14+
fi
15+
16+
for i in `seq 0 $(($len - 1))`
17+
do
18+
echo "Running test: $sketchdirname -- Config: $i"
19+
pytest tests --build-dir tests/$sketchdirname/build$i -k test_$sketchdirname --junit-xml=tests/$sketchdirname/$sketchdirname$i.xml
20+
result=$?
21+
if [ $result -ne 0 ]; then
22+
return $result
23+
fi
24+
done
25+
}
626

727
SCRIPTS_DIR="./.github/scripts"
828
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
929

10-
source ${SCRIPTS_DIR}/install-arduino-ide.sh
30+
chunk_run=0
31+
options=0
1132

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
33+
while [ ! -z "$1" ]; do
34+
case $1 in
35+
-c )
36+
chunk_run=1
37+
;;
38+
-o )
39+
options=1
40+
;;
41+
-s )
42+
shift
43+
sketch=$1
44+
;;
45+
-t )
46+
shift
47+
target=$1
48+
;;
49+
-i )
50+
shift
51+
chunk_index=$1
52+
;;
53+
-m )
54+
shift
55+
chunk_max=$1
56+
;;
57+
-h )
58+
echo "$USAGE"
59+
exit 0
60+
;;
61+
* )
62+
break
63+
;;
64+
esac
65+
shift
66+
done
2067

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
68+
source ${SCRIPTS_DIR}/install-arduino-ide.sh
3369

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
70+
if [ $chunk_run -eq 0 ]; then
71+
run_test $target $PWD/tests/$sketch/$sketch.ino $options
3972
else
40-
start_index=$(( $chunk_idex * $chunk_size ))
41-
if [ "$sketchcount" -le "$start_index" ]; then
42-
echo "Skipping job"
43-
return 0
44-
fi
73+
if [ "$chunk_max" -le 0 ]; then
74+
echo "ERROR: Chunks count must be positive number"
75+
return 1
76+
fi
4577

46-
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
47-
if [ "$end_index" -gt "$sketchcount" ]; then
48-
end_index=$sketchcount
49-
fi
50-
fi
78+
if [ "$chunk_index" -ge "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
79+
echo "ERROR: Chunk index must be less than chunks count"
80+
return 1
81+
fi
5182

52-
start_num=$(( $start_index + 1 ))
53-
sketchnum=0
83+
set +e
84+
${COUNT_SKETCHES} $PWD/tests $target
85+
sketchcount=$?
86+
set -e
87+
sketches=$(cat sketches.txt)
88+
rm -rf sketches.txt
5489

55-
for sketch in $sketches; do
56-
sketchdir=$(dirname $sketch)
57-
sketchdirname=$(basename $sketchdir)
58-
sketchnum=$(($sketchnum + 1))
59-
if [ "$sketchnum" -le "$start_index" ] \
60-
|| [ "$sketchnum" -gt "$end_index" ]; then
61-
continue
62-
fi
63-
echo ""
64-
echo "Test for Sketch Index $(($sketchnum - 1)) - $sketchdirname"
65-
pytest tests -k test_$sketchdirname --junit-xml=tests/$sketchdirname/$sketchdirname.xml
66-
result=$?
67-
if [ $result -ne 0 ]; then
68-
return $result
69-
fi
70-
done
90+
chunk_size=$(( $sketchcount / $chunk_max ))
91+
all_chunks=$(( $chunk_max * $chunk_size ))
92+
if [ "$all_chunks" -lt "$sketchcount" ]; then
93+
chunk_size=$(( $chunk_size + 1 ))
94+
fi
95+
96+
start_index=0
97+
end_index=0
98+
if [ "$chunk_index" -ge "$chunk_max" ]; then
99+
start_index=$chunk_index
100+
end_index=$sketchcount
101+
else
102+
start_index=$(( $chunk_index * $chunk_size ))
103+
if [ "$sketchcount" -le "$start_index" ]; then
104+
echo "Skipping job"
105+
return 0
106+
fi
107+
108+
end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))
109+
if [ "$end_index" -gt "$sketchcount" ]; then
110+
end_index=$sketchcount
111+
fi
112+
fi
113+
114+
start_num=$(( $start_index + 1 ))
115+
sketchnum=0
116+
117+
for sketch in $sketches; do
118+
119+
sketchnum=$(($sketchnum + 1))
120+
if [ "$sketchnum" -le "$start_index" ] \
121+
|| [ "$sketchnum" -gt "$end_index" ]; then
122+
continue
123+
fi
124+
echo ""
125+
echo "Sketch Index $(($sketchnum - 1))"
126+
127+
run_test $target $sketch
128+
done
129+
fi

Diff for: .github/workflows/hil.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ jobs:
5656

5757
- name: Build sketches
5858
run: |
59-
bash .github/scripts/tests_build.sh -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
59+
bash .github/scripts/tests_build.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
6060
- name: Upload ${{matrix.chip}}-${{matrix.chunks}} artifacts
6161
uses: actions/upload-artifact@v2
6262
with:
6363
name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts
6464
path: |
65-
tests/*/build/*.bin
66-
tests/*/build/*.json
65+
tests/*/build*/*.bin
66+
tests/*/build*/*.json
6767
Test:
6868
needs: [gen_chunks, Build]
6969
name: ${{matrix.chip}}-Test#${{matrix.chunks}}
@@ -99,7 +99,7 @@ jobs:
9999
100100
- name: Run Tests
101101
run: |
102-
bash .github/scripts/tests_run.sh ${{matrix.chip}} ${{matrix.chunks}} ${{env.MAX_CHUNKS}}
102+
bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}}
103103
104104
- name: Upload test result artifacts
105105
uses: actions/upload-artifact@v2

Diff for: tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build*/
22
__pycache__/
3+
*.xml

Diff for: tests/democfg/test_democfg.py

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

0 commit comments

Comments
 (0)