|
1 | 1 | #!/bin/bash |
2 | 2 |
|
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 | +} |
6 | 26 |
|
7 | 27 | SCRIPTS_DIR="./.github/scripts" |
8 | 28 | COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count" |
9 | 29 |
|
10 | | -source ${SCRIPTS_DIR}/install-arduino-ide.sh |
| 30 | +chunk_run=0 |
| 31 | +options=0 |
11 | 32 |
|
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 |
20 | 67 |
|
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 |
33 | 69 |
|
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 |
39 | 72 | 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 |
45 | 77 |
|
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 |
51 | 82 |
|
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 |
54 | 89 |
|
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 |
0 commit comments