|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -echo -e "travis_fold:start:sketch_test_env_prepare" |
4 | | -pip install pyserial |
| 3 | +PLATFORM=$1 |
| 4 | +CHUNK_INDEX=$2 |
| 5 | +CHUNKS_CNT=$3 |
| 6 | +if [ "$#" -lt 3 ]; then |
| 7 | + echo "Building all sketches" |
| 8 | + CHUNK_INDEX=0 |
| 9 | + CHUNKS_CNT=1 |
| 10 | +fi |
| 11 | +if [ "$CHUNKS_CNT" -le 0 ]; then |
| 12 | + echo "Chunks count must be positive number" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | +if [ "$CHUNK_INDEX" -ge "$CHUNKS_CNT" ]; then |
| 16 | + echo "Chunk index must be less than chunks count" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +if [ $PLATFORM == "esp32" ]; then |
| 21 | + echo "BUILDING ESP32 EXAMPLES" |
| 22 | +elif [ $PLATFORM == "esp8266" ]; then |
| 23 | + echo "BUILDING ESP8266 EXAMPLES" |
| 24 | +else |
| 25 | + echo "UNKNOWN PLATFORM $PLATFORM" |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +echo -e "travis_fold:start:prep_arduino_ide" |
| 30 | +# Install Arduino IDE |
5 | 31 | wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz |
6 | 32 | tar xf arduino.tar.xz |
7 | 33 | mv arduino-nightly $HOME/arduino_ide |
8 | 34 | mkdir -p $HOME/Arduino/libraries |
| 35 | +mkdir -p $HOME/Arduino/hardware |
| 36 | +echo -e "travis_fold:end:prep_arduino_ide" |
| 37 | + |
| 38 | +echo -e "travis_fold:start:sketch_test_env_prepare" |
9 | 39 | cd $HOME/Arduino/libraries |
10 | 40 | cp -rf $TRAVIS_BUILD_DIR ESPAsyncWebServer |
11 | 41 | git clone https://github.com/bblanchon/ArduinoJson |
12 | | -git clone https://github.com/me-no-dev/AsyncTCP |
13 | | -cd $HOME/arduino_ide/hardware |
14 | | -mkdir espressif |
15 | | -cd espressif |
16 | | -git clone https://github.com/espressif/arduino-esp32.git esp32 |
17 | | -cd esp32 |
18 | | -git submodule update --init --recursive |
19 | | -cd tools |
20 | | -python get.py |
21 | | -cd $TRAVIS_BUILD_DIR |
22 | | -export PATH="$HOME/arduino_ide:$HOME/arduino_ide/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin:$PATH" |
23 | | -source travis/common.sh |
| 42 | +#wget https://github.com/bblanchon/ArduinoJson/releases/download/v6.11.0/ArduinoJson-v6.11.0.zip && unzip ArduinoJson-v6.11.0.zip |
| 43 | +PLATFORM_EXAMPLES=$TRAVIS_BUILD_DIR/examples |
| 44 | + |
| 45 | +if [ $PLATFORM == "esp32" ]; then |
| 46 | + # ESP32 |
| 47 | + cd $HOME/Arduino/libraries |
| 48 | + git clone https://github.com/me-no-dev/AsyncTCP |
| 49 | + cd $HOME/Arduino/hardware |
| 50 | + pip install pyserial |
| 51 | + mkdir espressif |
| 52 | + cd espressif |
| 53 | + git clone https://github.com/espressif/arduino-esp32.git esp32 |
| 54 | + cd esp32 |
| 55 | + git submodule update --init --recursive |
| 56 | + cd tools |
| 57 | + python get.py |
| 58 | + PLATFORM_FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none" |
| 59 | + PLATFORM_SIZE_BIN=$HOME/Arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-size |
| 60 | +elif [ $PLATFORM == "esp8266" ]; then |
| 61 | + # ESP8266 |
| 62 | + cd $HOME/Arduino/libraries |
| 63 | + git clone https://github.com/me-no-dev/ESPAsyncTCP |
| 64 | + cd $HOME/Arduino/hardware |
| 65 | + mkdir esp8266com |
| 66 | + cd esp8266com |
| 67 | + git clone https://github.com/esp8266/Arduino.git esp8266 |
| 68 | + cd esp8266 |
| 69 | + git submodule update --init --recursive |
| 70 | + cd tools |
| 71 | + python get.py |
| 72 | + PLATFORM_FQBN="esp8266com:esp8266:generic:xtal=80,FlashFreq=40,FlashMode=qio,baud=921600,eesz=4M1M,ip=lm2f,ResetMethod=nodemcu" |
| 73 | + PLATFORM_SIZE_BIN=$HOME/Arduino/hardware/esp8266com/esp8266/tools/xtensa-lx106-elf/bin/xtensa-lx106-elf-size |
| 74 | +fi |
24 | 75 | echo -e "travis_fold:end:sketch_test_env_prepare" |
25 | 76 |
|
26 | | -echo -e "travis_fold:start:sketch_test" |
27 | | -build_sketches $HOME/arduino_ide $HOME/Arduino/libraries/ESPAsyncWebServer/examples "-l $HOME/Arduino/libraries" |
| 77 | +cd $TRAVIS_BUILD_DIR |
| 78 | + |
| 79 | +ARDUINO_IDE_PATH=$HOME/arduino_ide |
| 80 | +ARDUINO_USR_PATH=$HOME/Arduino |
| 81 | +ARDUINO_BUILD_DIR=$HOME/build.tmp |
| 82 | +ARDUINO_CACHE_DIR=$HOME/cache.tmp |
| 83 | +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" |
| 84 | + |
| 85 | +function print_size_info() |
| 86 | +{ |
| 87 | + elf_file=$1 |
| 88 | + |
| 89 | + if [ -z "$elf_file" ]; then |
| 90 | + if [ $PLATFORM == "esp32" ]; then |
| 91 | + printf "sketch iram0.text flash.text flash.rodata dram0.data dram0.bss dram flash\n" |
| 92 | + elif [ $PLATFORM == "esp8266" ]; then |
| 93 | + printf "sketch data rodata bss text irom0.text dram flash\n" |
| 94 | + fi |
| 95 | + return 0 |
| 96 | + fi |
| 97 | + |
| 98 | + elf_name=$(basename $elf_file) |
| 99 | + sketch_name="${elf_name%.*}" |
| 100 | + declare -A segments |
| 101 | + while read -a tokens; do |
| 102 | + seg=${tokens[0]} |
| 103 | + seg=${seg//./} |
| 104 | + size=${tokens[1]} |
| 105 | + addr=${tokens[2]} |
| 106 | + if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then |
| 107 | + segments[$seg]=$size |
| 108 | + fi |
| 109 | + done < <($PLATFORM_SIZE_BIN --format=sysv $elf_file) |
| 110 | + |
| 111 | + if [ $PLATFORM == "esp32" ]; then |
| 112 | + total_ram=$((${segments[dram0data]} + ${segments[dram0bss]})) |
| 113 | + total_flash=$((${segments[iram0text]} + ${segments[flashtext]} + ${segments[dram0data]} + ${segments[flashrodata]})) |
| 114 | + 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 |
| 115 | + elif [ $PLATFORM == "esp8266" ]; then |
| 116 | + total_ram=$((${segments[data]} + ${segments[rodata]} + ${segments[bss]})) |
| 117 | + total_flash=$((${segments[data]} + ${segments[rodata]} + ${segments[text]} + ${segments[irom0text]})) |
| 118 | + 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 |
| 119 | + fi |
| 120 | + return 0 |
| 121 | +} |
| 122 | + |
| 123 | +function build_sketch() |
| 124 | +{ |
| 125 | + local sketch=$1 |
| 126 | + echo -e "\n------------ Building $sketch ------------\n"; |
| 127 | + rm -rf $ARDUINO_BUILD_DIR/* |
| 128 | + time ($ARDUINO_BUILD_CMD $sketch >build.log) |
| 129 | + local result=$? |
| 130 | + if [ $result -ne 0 ]; then |
| 131 | + echo "Build failed ($1)" |
| 132 | + echo "Build log:" |
| 133 | + cat build.log |
| 134 | + return $result |
| 135 | + fi |
| 136 | + rm build.log |
| 137 | + return 0 |
| 138 | +} |
| 139 | + |
| 140 | +function count_sketches() |
| 141 | +{ |
| 142 | + local sketches=$(find $PLATFORM_EXAMPLES -name *.ino) |
| 143 | + local sketchnum=0 |
| 144 | + rm -rf sketches.txt |
| 145 | + for sketch in $sketches; do |
| 146 | + local sketchdir=$(dirname $sketch) |
| 147 | + local sketchdirname=$(basename $sketchdir) |
| 148 | + local sketchname=$(basename $sketch) |
| 149 | + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then |
| 150 | + continue |
| 151 | + fi |
| 152 | + echo $sketch >> sketches.txt |
| 153 | + sketchnum=$(($sketchnum + 1)) |
| 154 | + done |
| 155 | + return $sketchnum |
| 156 | +} |
| 157 | + |
| 158 | +function build_sketches() |
| 159 | +{ |
| 160 | + mkdir -p $ARDUINO_BUILD_DIR |
| 161 | + mkdir -p $ARDUINO_CACHE_DIR |
| 162 | + mkdir -p $ARDUINO_USR_PATH/libraries |
| 163 | + mkdir -p $ARDUINO_USR_PATH/hardware |
| 164 | + |
| 165 | + local chunk_idex=$1 |
| 166 | + local chunks_num=$2 |
| 167 | + count_sketches |
| 168 | + local sketchcount=$? |
| 169 | + local sketches=$(cat sketches.txt) |
| 170 | + |
| 171 | + local chunk_size=$(( $sketchcount / $chunks_num )) |
| 172 | + local all_chunks=$(( $chunks_num * $chunk_size )) |
| 173 | + if [ "$all_chunks" -lt "$sketchcount" ]; then |
| 174 | + chunk_size=$(( $chunk_size + 1 )) |
| 175 | + fi |
| 176 | + |
| 177 | + local start_index=$(( $chunk_idex * $chunk_size )) |
| 178 | + if [ "$sketchcount" -le "$start_index" ]; then |
| 179 | + echo "Skipping job" |
| 180 | + return 0 |
| 181 | + fi |
| 182 | + |
| 183 | + local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size )) |
| 184 | + if [ "$end_index" -gt "$sketchcount" ]; then |
| 185 | + end_index=$sketchcount |
| 186 | + fi |
| 187 | + |
| 188 | + local start_num=$(( $start_index + 1 )) |
| 189 | + #echo -e "Sketches: \n$sketches\n" |
| 190 | + echo "Found $sketchcount Sketches"; |
| 191 | + echo "Chunk Count : $chunks_num" |
| 192 | + echo "Chunk Size : $chunk_size" |
| 193 | + echo "Start Sketch: $start_num" |
| 194 | + echo "End Sketch : $end_index" |
| 195 | + |
| 196 | + local sketchnum=0 |
| 197 | + print_size_info >size.log |
| 198 | + for sketch in $sketches; do |
| 199 | + local sketchdir=$(dirname $sketch) |
| 200 | + local sketchdirname=$(basename $sketchdir) |
| 201 | + local sketchname=$(basename $sketch) |
| 202 | + if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then |
| 203 | + #echo "Skipping $sketch, beacause it is not the main sketch file"; |
| 204 | + continue |
| 205 | + fi; |
| 206 | + if [[ -f "$sketchdir/.test.skip" ]]; then |
| 207 | + #echo "Skipping $sketch marked"; |
| 208 | + continue |
| 209 | + fi |
| 210 | + sketchnum=$(($sketchnum + 1)) |
| 211 | + if [ "$sketchnum" -le "$start_index" ]; then |
| 212 | + #echo "Skipping $sketch index low" |
| 213 | + continue |
| 214 | + fi |
| 215 | + if [ "$sketchnum" -gt "$end_index" ]; then |
| 216 | + #echo "Skipping $sketch index high" |
| 217 | + continue |
| 218 | + fi |
| 219 | + build_sketch $sketch |
| 220 | + local result=$? |
| 221 | + if [ $result -ne 0 ]; then |
| 222 | + return $result |
| 223 | + fi |
| 224 | + print_size_info $ARDUINO_BUILD_DIR/*.elf >>size.log |
| 225 | + done |
| 226 | + return 0 |
| 227 | +} |
| 228 | + |
| 229 | +echo -e "travis_fold:start:test_arduino_ide" |
| 230 | +# Build Examples |
| 231 | +build_sketches $CHUNK_INDEX $CHUNKS_CNT |
28 | 232 | if [ $? -ne 0 ]; then exit 1; fi |
29 | | -echo -e "travis_fold:end:sketch_test" |
| 233 | +echo -e "travis_fold:end:test_arduino_ide" |
| 234 | + |
| 235 | +echo -e "travis_fold:start:size_report" |
| 236 | +cat size.log |
| 237 | +echo -e "travis_fold:end:size_report" |
0 commit comments