|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -echo -e "travis_fold:start:sketch_test_env_prepare" |
4 |
| -pip install pyserial |
| 3 | +CHUNK_INDEX=$1 |
| 4 | +CHUNKS_CNT=$2 |
| 5 | +if [ "$#" -lt 2 ]; then |
| 6 | + echo "Building all sketches" |
| 7 | + CHUNK_INDEX=0 |
| 8 | + CHUNKS_CNT=1 |
| 9 | +fi |
| 10 | +if [ "$CHUNKS_CNT" -le 0 ]; then |
| 11 | + echo "Chunks count must be positive number" |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | +if [ "$CHUNK_INDEX" -ge "$CHUNKS_CNT" ]; then |
| 15 | + echo "Chunk index must be less than chunks count" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +echo -e "travis_fold:start:prep_arduino_ide" |
| 20 | +# Install Arduino IDE |
5 | 21 | wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
|
6 | 22 | tar xf arduino.tar.xz
|
7 | 23 | mv arduino-nightly $HOME/arduino_ide
|
8 | 24 | mkdir -p $HOME/Arduino/libraries
|
| 25 | +mkdir -p $HOME/Arduino/hardware |
| 26 | +echo -e "travis_fold:end:prep_arduino_ide" |
| 27 | + |
| 28 | +echo -e "travis_fold:start:sketch_test_env_prepare" |
9 | 29 | cd $HOME/Arduino/libraries
|
10 | 30 | cp -rf $TRAVIS_BUILD_DIR AsyncTCP
|
11 |
| -cd $HOME/arduino_ide/hardware |
| 31 | +PLATFORM_EXAMPLES=$TRAVIS_BUILD_DIR/examples |
| 32 | + |
| 33 | +cd $HOME/Arduino/hardware |
| 34 | +pip install pyserial |
12 | 35 | mkdir espressif
|
13 | 36 | cd espressif
|
14 | 37 | git clone https://github.com/espressif/arduino-esp32.git esp32
|
15 | 38 | cd esp32
|
16 | 39 | git submodule update --init --recursive
|
17 | 40 | cd tools
|
18 | 41 | python get.py
|
19 |
| -cd $TRAVIS_BUILD_DIR |
20 |
| -export PATH="$HOME/arduino_ide:$HOME/arduino_ide/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin:$PATH" |
21 |
| -source travis/common.sh |
| 42 | +PLATFORM_FQBN="espressif:esp32:esp32" |
| 43 | +PLATFORM_SIZE_BIN=$HOME/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-size |
22 | 44 | echo -e "travis_fold:end:sketch_test_env_prepare"
|
23 | 45 |
|
24 |
| -echo -e "travis_fold:start:sketch_test" |
25 |
| -build_sketches $HOME/arduino_ide $HOME/Arduino/libraries/AsyncTCP/examples "-l $HOME/Arduino/libraries" |
| 46 | +cd $TRAVIS_BUILD_DIR |
| 47 | + |
| 48 | +ARDUINO_IDE_PATH=$HOME/arduino_ide |
| 49 | +ARDUINO_USR_PATH=$HOME/Arduino |
| 50 | +ARDUINO_BUILD_DIR=$HOME/build.tmp |
| 51 | +ARDUINO_CACHE_DIR=$HOME/cache.tmp |
| 52 | +ARDUINO_BUILD_CMD="$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 -hardware \"$ARDUINO_IDE_PATH/hardware\" -hardware \"$ARDUINO_USR_PATH/hardware\" -tools \"$ARDUINO_IDE_PATH/tools-builder\" -built-in-libraries \"$ARDUINO_IDE_PATH/libraries\" -libraries \"$ARDUINO_USR_PATH/libraries\" -fqbn=$PLATFORM_FQBN -warnings=\"all\" -build-cache \"$ARDUINO_CACHE_DIR\" -build-path \"$ARDUINO_BUILD_DIR\" -verbose" |
| 53 | + |
| 54 | +function print_size_info() |
| 55 | +{ |
| 56 | + elf_file=$1 |
| 57 | + |
| 58 | + if [ -z "$elf_file" ]; then |
| 59 | + printf "sketch iram0.text flash.text flash.rodata dram0.data dram0.bss dram flash\n" |
| 60 | + return 0 |
| 61 | + fi |
| 62 | + |
| 63 | + elf_name=$(basename $elf_file) |
| 64 | + sketch_name="${elf_name%.*}" |
| 65 | + declare -A segments |
| 66 | + while read -a tokens; do |
| 67 | + seg=${tokens[0]} |
| 68 | + seg=${seg//./} |
| 69 | + size=${tokens[1]} |
| 70 | + addr=${tokens[2]} |
| 71 | + if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then |
| 72 | + segments[$seg]=$size |
| 73 | + fi |
| 74 | + done < <($PLATFORM_SIZE_BIN --format=sysv $elf_file) |
| 75 | + |
| 76 | + total_ram=$((${segments[dram0data]} + ${segments[dram0bss]})) |
| 77 | + total_flash=$((${segments[iram0text]} + ${segments[flashtext]} + ${segments[dram0data]} + ${segments[flashrodata]})) |
| 78 | + printf "%-32s %-8d %-8d %-8d %-8d %-8d %-8d %-8d\n" $sketch_name ${segments[iram0text]} ${segments[flashtext]} ${segments[flashrodata]} ${segments[dram0data]} ${segments[dram0bss]} $total_ram $total_flash |
| 79 | + return 0 |
| 80 | +} |
| 81 | + |
| 82 | +function build_sketch() |
| 83 | +{ |
| 84 | + local sketch=$1 |
| 85 | + echo -e "\n------------ Building $sketch ------------\n"; |
| 86 | + rm -rf $ARDUINO_BUILD_DIR/* |
| 87 | + time ($ARDUINO_BUILD_CMD $sketch >build.log) |
| 88 | + local result=$? |
| 89 | + if [ $result -ne 0 ]; then |
| 90 | + echo "Build failed ($1)" |
| 91 | + echo "Build log:" |
| 92 | + cat build.log |
| 93 | + return $result |
| 94 | + fi |
| 95 | + rm build.log |
| 96 | + return 0 |
| 97 | +} |
| 98 | + |
| 99 | +function count_sketches() |
| 100 | +{ |
| 101 | + local sketches=$(find $PLATFORM_EXAMPLES -name *.ino) |
| 102 | + local sketchnum=0 |
| 103 | + rm -rf sketches.txt |
| 104 | + for sketch in $sketches; do |
| 105 | + local sketchdir=$(dirname $sketch) |
| 106 | + local sketchdirname=$(basename $sketchdir) |
| 107 | + local sketchname=$(basename $sketch) |
| 108 | + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then |
| 109 | + continue |
| 110 | + fi |
| 111 | + echo $sketch >> sketches.txt |
| 112 | + sketchnum=$(($sketchnum + 1)) |
| 113 | + done |
| 114 | + return $sketchnum |
| 115 | +} |
| 116 | + |
| 117 | +function build_sketches() |
| 118 | +{ |
| 119 | + mkdir -p $ARDUINO_BUILD_DIR |
| 120 | + mkdir -p $ARDUINO_CACHE_DIR |
| 121 | + mkdir -p $ARDUINO_USR_PATH/libraries |
| 122 | + mkdir -p $ARDUINO_USR_PATH/hardware |
| 123 | + |
| 124 | + local chunk_idex=$1 |
| 125 | + local chunks_num=$2 |
| 126 | + count_sketches |
| 127 | + local sketchcount=$? |
| 128 | + local sketches=$(cat sketches.txt) |
| 129 | + |
| 130 | + local chunk_size=$(( $sketchcount / $chunks_num )) |
| 131 | + local all_chunks=$(( $chunks_num * $chunk_size )) |
| 132 | + if [ "$all_chunks" -lt "$sketchcount" ]; then |
| 133 | + chunk_size=$(( $chunk_size + 1 )) |
| 134 | + fi |
| 135 | + |
| 136 | + local start_index=$(( $chunk_idex * $chunk_size )) |
| 137 | + if [ "$sketchcount" -le "$start_index" ]; then |
| 138 | + echo "Skipping job" |
| 139 | + return 0 |
| 140 | + fi |
| 141 | + |
| 142 | + local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) |
| 143 | + if [ "$end_index" -gt "$sketchcount" ]; then |
| 144 | + end_index=$sketchcount |
| 145 | + fi |
| 146 | + |
| 147 | + local start_num=$(( $start_index + 1 )) |
| 148 | + #echo -e "Sketches: \n$sketches\n" |
| 149 | + echo "Found $sketchcount Sketches"; |
| 150 | + echo "Chunk Count : $chunks_num" |
| 151 | + echo "Chunk Size : $chunk_size" |
| 152 | + echo "Start Sketch: $start_num" |
| 153 | + echo "End Sketch : $end_index" |
| 154 | + |
| 155 | + local sketchnum=0 |
| 156 | + print_size_info >size.log |
| 157 | + for sketch in $sketches; do |
| 158 | + local sketchdir=$(dirname $sketch) |
| 159 | + local sketchdirname=$(basename $sketchdir) |
| 160 | + local sketchname=$(basename $sketch) |
| 161 | + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then |
| 162 | + #echo "Skipping $sketch, beacause it is not the main sketch file"; |
| 163 | + continue |
| 164 | + fi; |
| 165 | + if [[ -f "$sketchdir/.test.skip" ]]; then |
| 166 | + #echo "Skipping $sketch marked"; |
| 167 | + continue |
| 168 | + fi |
| 169 | + sketchnum=$(($sketchnum + 1)) |
| 170 | + if [ "$sketchnum" -le "$start_index" ]; then |
| 171 | + #echo "Skipping $sketch index low" |
| 172 | + continue |
| 173 | + fi |
| 174 | + if [ "$sketchnum" -gt "$end_index" ]; then |
| 175 | + #echo "Skipping $sketch index high" |
| 176 | + continue |
| 177 | + fi |
| 178 | + build_sketch $sketch |
| 179 | + local result=$? |
| 180 | + if [ $result -ne 0 ]; then |
| 181 | + return $result |
| 182 | + fi |
| 183 | + print_size_info $ARDUINO_BUILD_DIR/*.elf >>size.log |
| 184 | + done |
| 185 | + return 0 |
| 186 | +} |
| 187 | + |
| 188 | +echo -e "travis_fold:start:test_arduino_ide" |
| 189 | +# Build Examples |
| 190 | +build_sketches $CHUNK_INDEX $CHUNKS_CNT |
26 | 191 | if [ $? -ne 0 ]; then exit 1; fi
|
27 |
| -echo -e "travis_fold:end:sketch_test" |
| 192 | +echo -e "travis_fold:end:test_arduino_ide" |
| 193 | + |
| 194 | +echo -e "travis_fold:start:size_report" |
| 195 | +cat size.log |
| 196 | +echo -e "travis_fold:end:size_report" |
0 commit comments