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