Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add options. #6916

Merged
merged 14 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions .github/scripts/on-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ function build(){
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
local BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"

local args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH"
local args="-ai $ARDUINO_IDE_PATH -au $ARDUINO_USR_PATH"

args+=" \"$fqbn\""
args+=" -t $target -fqbn $fqbn"

if [ "$OS_IS_LINUX" == "1" ]; then
args+=" $target"
args+=" $ARDUINO_ESP32_PATH/libraries"
args+=" $chunk_index $chunks_cnt"
args+=" -p $ARDUINO_ESP32_PATH/libraries"
args+=" -i $chunk_index -m $chunks_cnt"
${BUILD_SKETCHES} ${args}
else
if [ "$OS_IS_WINDOWS" == "1" ]; then
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
-prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
args+=" ${win_opts}"
fi

for sketch in ${sketches}; do
${BUILD_SKETCH} ${args} ${sketch}
args+=" -s $(dirname $sketch)"
if [ "$OS_IS_WINDOWS" == "1" ]; then
local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
-prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
args+=" ${win_opts}"
fi
${BUILD_SKETCH} ${args}
done
fi
}
Expand Down Expand Up @@ -82,7 +81,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
else
source ${SCRIPTS_DIR}/install-platformio-esp32.sh
# PlatformIO ESP32 Test
Expand Down
269 changes: 200 additions & 69 deletions .github/scripts/sketch_utils.sh
Original file line number Diff line number Diff line change
@@ -1,43 +1,142 @@
#!/bin/bash

function build_sketch(){ # build_sketch <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]
if [ "$#" -lt 4 ]; then
echo "ERROR: Illegal number of parameters"
echo "USAGE: ${0} build <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]"
return 1
function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
while [ ! -z "$1" ]; do
case "$1" in
-ai )
shift
ide_path=$1
;;
-au )
shift
user_path=$1
;;
-t )
shift
target=$1
;;
-fqbn )
shift
fqbn=$1
;;
-o )
shift
options=$1
;;
-s )
shift
sketchdir=$1
;;
* )
break
;;
esac
shift
done

xtra_opts=$*

if [ -z $sketchdir ]; then
echo "ERROR: Sketch directory not provided"
echo "$USAGE"
exit 1
fi

local ide_path=$1
local usr_path=$2
local fqbn=$3
local sketch=$4
local xtra_opts=$5
local win_opts=$6
# No FQBN was passed, try to get it from other options

if [ -z $fqbn ]; then
if [ -z $target ]; then
echo "ERROR: Unspecified chip"
echo "$USAGE"
exit 1
fi

# The options are either stored in the test directory, for a per test
# customization or passed as parameters. Command line options take
# precedence. Note that the following logic also falls to the default
# parameters if no arguments were passed and no file was found.

if [ -z $options ] && [ -f $sketchdir/cfg.json ]; then
# The config file could contain multiple FQBNs for one chip. If
# that's the case we build one time for every FQBN.

len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
fqbn=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn' $sketchdir/cfg.json`
else
# Since we are passing options, we will end up with only one FQBN to
# build.

len=1

# Default FQBN options if none were passed in the command line.

esp32_opts="PSRAM=enabled,PartitionScheme=huge_app"
esp32s2_opts="PSRAM=enabled,PartitionScheme=huge_app"
esp32s3_opts="PSRAM=opi,USBMode=default,PartitionScheme=huge_app"
esp32c3_opts="PartitionScheme=huge_app"

# Select the common part of the FQBN based on the target. The rest will be
# appended depending on the passed options.

case "$target" in
"esp32")
fqbn="espressif:esp32:esp32:${options:-$esp32_opts}"
;;
"esp32s2")
fqbn="espressif:esp32:esp32s2:${options:-$esp32s2_opts}"
;;
"esp32c3")
fqbn="espressif:esp32:esp32c3:${options:-$esp32c3_opts}"
;;
"esp32s3")
fqbn="espressif:esp32:esp32s3:${options:-$esp32s3_opts}"
;;
esac

# Make it look like a JSON array.

fqbn="[\"$fqbn\"]"
fi
else
# An FQBN was passed. Make it look like a JSON array.

len=1
fqbn="[\"$fqbn\"]"
fi

if [ -z "$fqbn" ]; then
echo "No FQBN passed or unvalid chip: $target"
exit 1
fi

ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
if [ -z "$ARDUINO_BUILD_DIR" ]; then
build_dir="$(dirname $sketch)/build"
build_dir="$sketchdir/build"
else
build_dir="$ARDUINO_BUILD_DIR"
fi

echo $sketch

rm -rf "$build_dir"
mkdir -p "$build_dir"
mkdir -p "$ARDUINO_CACHE_DIR"
$ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
-fqbn=$fqbn \
-warnings="all" \
-tools "$ide_path/tools-builder" \
-tools "$ide_path/tools" \
-built-in-libraries "$ide_path/libraries" \
-hardware "$ide_path/hardware" \
-hardware "$usr_path/hardware" \
-libraries "$usr_path/libraries" \
-build-cache "$ARDUINO_CACHE_DIR" \
-build-path "$build_dir" \
$win_opts $xtra_opts "$sketch"
for i in `seq 0 $(($len - 1))`
do
rm -rf "$build_dir$i"
mkdir -p "$build_dir$i"
currfqbn=`echo $fqbn | jq -r --argjson i $i '.[$i]'`
sketchname=$(basename $sketchdir)
echo "Building $sketchname with FQBN=$currfqbn"
$ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
-fqbn=\"$currfqbn\" \
-warnings="all" \
-tools "$ide_path/tools-builder" \
-tools "$ide_path/tools" \
-built-in-libraries "$ide_path/libraries" \
-hardware "$ide_path/hardware" \
-hardware "$user_path/hardware" \
-libraries "$user_path/libraries" \
-build-cache "$ARDUINO_CACHE_DIR" \
-build-path "$build_dir$i" \
$xtra_opts "${sketchdir}/${sketchname}.ino"
done
}

function count_sketches(){ # count_sketches <path> [target]
Expand Down Expand Up @@ -73,29 +172,63 @@ function count_sketches(){ # count_sketches <path> [target]
return $sketchnum
}

function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <target> <path> <chunk> <total-chunks> [extra-options]
local ide_path=$1
local usr_path=$2
local fqbn=$3
local target=$4
local path=$5
local chunk_idex=$6
local chunks_num=$7
local xtra_opts=$8

if [ "$#" -lt 7 ]; then
echo "ERROR: Illegal number of parameters"
echo "USAGE: ${0} chunk_build <ide_path> <user_path> <fqbn> <target> <path> [<chunk> <total-chunks>] [extra-options]"
return 1
function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <path> <chunk> <total-chunks> [extra-options]

local args=""
while [ ! -z "$1" ]; do
case $1 in
-ai )
shift
ide_path=$1
;;
-au )
shift
user_path=$1
;;
-t )
shift
target=$1
args+=" -t $target"
;;
-fqbn )
shift
fqbn=$1
args+=" -fqbn $fqbn"
;;
-p )
shift
path=$1
;;
-i )
shift
chunk_index=$1
;;
-m )
shift
chunk_max=$1
;;
* )
break
;;
esac
shift
done

local xtra_opts=$*

if [ -z $chunk_index ] || [ -z $chunk_max ]; then
echo "ERROR: Invalid chunk paramters"
echo "$USAGE"
exit 1
fi

if [ "$chunks_num" -le 0 ]; then
if [ "$chunk_max" -le 0 ]; then
echo "ERROR: Chunks count must be positive number"
return 1
fi
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
echo "ERROR: Chunk index must be less than chunks count"
return 1

if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
chunk_index=$chunk_max
fi

set +e
Expand All @@ -105,51 +238,52 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <targe
local sketches=$(cat sketches.txt)
rm -rf sketches.txt

local chunk_size=$(( $sketchcount / $chunks_num ))
local all_chunks=$(( $chunks_num * $chunk_size ))
local chunk_size=$(( $sketchcount / $chunk_max ))
local all_chunks=$(( $chunk_max * $chunk_size ))
if [ "$all_chunks" -lt "$sketchcount" ]; then
chunk_size=$(( $chunk_size + 1 ))
fi

local start_index=0
local end_index=0
if [ "$chunk_idex" -ge "$chunks_num" ]; then
start_index=$chunk_idex
if [ "$chunk_index" -ge "$chunk_max" ]; then
start_index=$chunk_index
end_index=$sketchcount
else
start_index=$(( $chunk_idex * $chunk_size ))
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
return 0
fi

end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))
if [ "$end_index" -gt "$sketchcount" ]; then
end_index=$sketchcount
fi
fi

local start_num=$(( $start_index + 1 ))
echo "Found $sketchcount Sketches for target '$target'";
echo "Chunk Index : $chunk_idex"
echo "Chunk Count : $chunks_num"
echo "Chunk Index : $chunk_index"
echo "Chunk Count : $chunk_max"
echo "Chunk Size : $chunk_size"
echo "Start Sketch: $start_num"
echo "End Sketch : $end_index"

local sketchnum=0
args+=" -ai $ide_path -au $user_path"
for sketch in $sketches; do
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
sketchnum=$(($sketchnum + 1))
if [ "$sketchnum" -le "$start_index" ] \
|| [ "$sketchnum" -gt "$end_index" ]; then
continue
fi
echo ""
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
build_sketch "$ide_path" "$usr_path" "$fqbn" "$sketch" "$xtra_opts"
args+=" -s $sketchdir $xtra_opts"
build_sketch $args
local result=$?
if [ $result -ne 0 ]; then
return $result
Expand All @@ -169,24 +303,21 @@ Available commands:
cmd=$1
shift
if [ -z $cmd ]; then
echo "ERROR: No command supplied"
echo "$USAGE"
exit 2
echo "ERROR: No command supplied"
echo "$USAGE"
exit 2
fi

case "$cmd" in
"count")
count_sketches $*
"count") count_sketches $*
;;
"build")
build_sketch $*
"build") build_sketch $*
;;
"chunk_build")
build_sketches $*
"chunk_build") build_sketches $*
;;
*)
echo "ERROR: Unrecognized command"
echo "$USAGE"
exit 2
*)
echo "ERROR: Unrecognized command"
echo "$USAGE"
exit 2
esac

Loading