-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
Copy pathtests_run.sh
executable file
·265 lines (236 loc) · 7.56 KB
/
tests_run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
function run_test() {
local target=$1
local sketch=$2
local options=$3
local erase_flash=$4
local sketchdir=$(dirname $sketch)
local sketchname=$(basename $sketchdir)
local result=0
local error=0
# If the target or platform is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
selected_platform=$(jq -r --arg platform $platform '.platforms[$platform]' $sketchdir/ci.json)
else
is_target="true"
selected_platform="true"
fi
if [[ $is_target == "false" ]] || [[ $selected_platform == "false" ]]; then
printf "\033[93mSkipping $sketchname test for $target, platform: $platform\033[0m\n"
printf "\n\n\n"
return 0
fi
if [ $options -eq 0 ] && [ -f $sketchdir/ci.json ]; then
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
if [ $len -eq 0 ]; then
len=1
fi
else
len=1
fi
if [ $len -eq 1 ]; then
# build_dir="$sketchdir/build"
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
report_file="$sketchdir/$target/$sketchname.xml"
fi
for i in `seq 0 $(($len - 1))`
do
fqbn="Default"
if [ $len -ne 1 ]; then
fqbn=`jq -r --arg target $target --argjson i $i '.fqbn[$target] | sort | .[$i]' $sketchdir/ci.json`
elif [ -f $sketchdir/ci.json ]; then
has_fqbn=`jq -r --arg target $target '.fqbn[$target]' $sketchdir/ci.json`
if [ "$has_fqbn" != "null" ]; then
fqbn=`jq -r --arg target $target '.fqbn[$target] | .[0]' $sketchdir/ci.json`
fi
fi
printf "\033[95mRunning test: $sketchname -- Config: $fqbn\033[0m\n"
if [ $erase_flash -eq 1 ]; then
esptool.py -c $target erase_flash
fi
if [ $len -ne 1 ]; then
# build_dir="$sketchdir/build$i"
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
report_file="$sketchdir/$target/$sketchname$i.xml"
fi
if [ $platform == "wokwi" ]; then
extra_args="--target $target --embedded-services arduino,wokwi --wokwi-timeout=$wokwi_timeout"
if [[ -f "$sketchdir/scenario.yaml" ]]; then
extra_args+=" --wokwi-scenario $sketchdir/scenario.yaml"
fi
if [[ -f "$sketchdir/diagram.$target.json" ]]; then
extra_args+=" --wokwi-diagram $sketchdir/diagram.$target.json"
fi
elif [ $platform == "qemu" ]; then
PATH=$HOME/qemu/bin:$PATH
extra_args="--embedded-services qemu --qemu-image-path $build_dir/$sketchname.ino.merged.bin"
if [ $target == "esp32" ] || [ $target == "esp32s3" ]; then
extra_args+=" --qemu-prog-path qemu-system-xtensa --qemu-cli-args=\"-machine $target -m 4M -nographic\""
elif [ $target == "esp32c3" ]; then
extra_args+=" --qemu-prog-path qemu-system-riscv32 --qemu-cli-args=\"-machine $target -icount 3 -nographic\""
else
printf "\033[91mUnsupported QEMU target: $target\033[0m\n"
exit 1
fi
else
extra_args="--embedded-services esp,arduino"
fi
result=0
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
printf "\n"
if [ $result -ne 0 ]; then
result=0
printf "\033[95mRetrying test: $sketchname -- Config: $i\033[0m\n"
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
printf "\n"
if [ $result -ne 0 ]; then
printf "\033[91mFailed test: $sketchname -- Config: $i\033[0m\n\n"
error=$result
fi
fi
done
return $error
}
SCRIPTS_DIR="./.github/scripts"
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
platform="hardware"
wokwi_timeout=60000
chunk_run=0
options=0
erase=0
while [ ! -z "$1" ]; do
case $1 in
-c )
chunk_run=1
;;
-Q )
if [ ! -d $QEMU_PATH ]; then
echo "QEMU path $QEMU_PATH does not exist"
exit 1
fi
platform="qemu"
;;
-W )
shift
wokwi_timeout=$1
if [[ -z $WOKWI_CLI_TOKEN ]]; then
echo "Wokwi CLI token is not set"
exit 1
fi
platform="wokwi"
;;
-o )
options=1
;;
-s )
shift
sketch=$1
;;
-t )
shift
target=$1
;;
-i )
shift
chunk_index=$1
;;
-m )
shift
chunk_max=$1
;;
-e )
erase=1
;;
-h )
echo "$USAGE"
exit 0
;;
-type )
shift
test_type=$1
;;
* )
break
;;
esac
shift
done
if [ ! $platform == "qemu" ]; then
source ${SCRIPTS_DIR}/install-arduino-ide.sh
fi
# If sketch is provided and test type is not, test type is inferred from the sketch path
if [[ $test_type == "all" ]] || [[ -z $test_type ]]; then
if [ -n "$sketch" ]; then
tmp_sketch_path=$(find tests -name $sketch.ino)
test_type=$(basename $(dirname $(dirname "$tmp_sketch_path")))
echo "Sketch $sketch test type: $test_type"
test_folder="$PWD/tests/$test_type"
else
test_folder="$PWD/tests"
fi
else
test_folder="$PWD/tests/$test_type"
fi
if [ $chunk_run -eq 0 ]; then
if [ -z $sketch ]; then
echo "ERROR: Sketch name is required for single test run"
exit 1
fi
run_test $target $test_folder/$sketch/$sketch.ino $options $erase
exit $?
else
if [ "$chunk_max" -le 0 ]; then
echo "ERROR: Chunks count must be positive number"
exit 1
fi
if [ "$chunk_index" -ge "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
echo "ERROR: Chunk index must be less than chunks count"
exit 1
fi
set +e
${COUNT_SKETCHES} $test_folder $target
sketchcount=$?
set -e
sketches=$(cat sketches.txt)
rm -rf sketches.txt
chunk_size=$(( $sketchcount / $chunk_max ))
all_chunks=$(( $chunk_max * $chunk_size ))
if [ "$all_chunks" -lt "$sketchcount" ]; then
chunk_size=$(( $chunk_size + 1 ))
fi
start_index=0
end_index=0
if [ "$chunk_index" -ge "$chunk_max" ]; then
start_index=$chunk_index
end_index=$sketchcount
else
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
exit 0
fi
end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))
if [ "$end_index" -gt "$sketchcount" ]; then
end_index=$sketchcount
fi
fi
start_num=$(( $start_index + 1 ))
sketchnum=0
error=0
for sketch in $sketches; do
sketchnum=$(($sketchnum + 1))
if [ "$sketchnum" -le "$start_index" ] \
|| [ "$sketchnum" -gt "$end_index" ]; then
continue
fi
printf "\033[95mSketch Index $(($sketchnum - 1))\033[0m\n"
exit_code=0
run_test $target $sketch $options $erase || exit_code=$?
if [ $exit_code -ne 0 ]; then
error=$exit_code
fi
done
exit $error
fi