Skip to content

Commit

Permalink
Merge branch 'ci/tests_refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz committed May 15, 2024
2 parents 6adeca4 + a000fb6 commit bde5e31
Show file tree
Hide file tree
Showing 509 changed files with 1,406 additions and 474 deletions.
8 changes: 6 additions & 2 deletions .github/scripts/install-platformio-esp32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function count_sketches(){ # count_sketches <examples-path>
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
continue
fi
if [[ -f "$sketchdir/.test.skip" ]]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [[ "$is_target" == "false" ]]; then
continue
fi
echo $sketch >> sketches.txt
Expand Down Expand Up @@ -161,8 +163,10 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ "${sketchdirname}.ino" != "$sketchname" ] \
|| [ -f "$sketchdir/.test.skip" ]; then
|| [[ "$is_target" == "false" ]]; then
continue
fi
sketchnum=$(($sketchnum + 1))
Expand Down
47 changes: 32 additions & 15 deletions .github/scripts/sketch_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
done

xtra_opts=$*
len=0

if [ -z $sketchdir ]; then
echo "ERROR: Sketch directory not provided"
Expand All @@ -64,24 +65,28 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
# 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
if [ -z $options ] && [ -f $sketchdir/ci.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
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
if [ $len -gt 0 ]; then
fqbn=`jq -r --arg target $target '.fqbn[$target] | sort' $sketchdir/ci.json`
fi
fi

if [ ! -z $options ] || [ $len -eq 0 ]; then
# 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="FlashMode=dio,PSRAM=enabled,PartitionScheme=huge_app"
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="FlashMode=dio,PartitionScheme=huge_app"
esp32c3_opts="PartitionScheme=huge_app"
esp32c6_opts="PartitionScheme=huge_app"
esp32h2_opts="PartitionScheme=huge_app"

Expand Down Expand Up @@ -135,7 +140,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex

sketchname=$(basename $sketchdir)

if [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
else
is_target="true"
fi

if [[ "$is_target" == "false" ]]; then
echo "Skipping $sketchname for target $target"
exit 0
fi
Expand Down Expand Up @@ -270,12 +282,19 @@ function count_sketches(){ # count_sketches <path> [target]
local sketchname=$(basename $sketch)
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
continue
elif [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then
continue
else
echo $sketch >> sketches.txt
sketchnum=$(($sketchnum + 1))
elif [[ -n $target ]]; then
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
else
is_target="true"
fi
if [[ "$is_target" == "false" ]]; then
continue
fi
fi
echo $sketch >> sketches.txt
sketchnum=$(($sketchnum + 1))
done
return $sketchnum
}
Expand Down Expand Up @@ -339,7 +358,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
return 1
fi

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

Expand All @@ -364,8 +383,6 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
else
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
touch ~/.build_skipped
return 0
fi

Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/tests_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fi

if [ $chunk_build -eq 1 ]; then
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
args+=" -p $test_folder"
args+=" -p $test_folder -i 0 -m 1"
else
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh build"
args+=" -s $test_folder/$sketch"
Expand Down
41 changes: 30 additions & 11 deletions .github/scripts/tests_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ function run_test() {
local sketchdir=$(dirname $sketch)
local sketchname=$(basename $sketchdir)

if [[ -f "$sketchdir/.skip.$platform" ]] || [[ -f "$sketchdir/.skip.$target" ]] || [[ -f "$sketchdir/.skip.$platform.$target" ]]; then
# If the target or platform is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
selected_platform=$(jq -r --arg platform $platform '.platforms[$platform]' $sketchdir/ci.json)
else
is_target="true"
selected_platform="true"
fi

if [[ $is_target == "false" ]] || [[ $selected_platform == "false" ]]; then
echo "Skipping $sketchname test for $target, platform: $platform"
skipfile="$sketchdir/.test_skipped"
touch $skipfile
exit 0
return 0
fi

if [ $options -eq 0 ] && [ -f $sketchdir/cfg.json ]; then
len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
if [ $options -eq 0 ] && [ -f $sketchdir/ci.json ]; then
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
if [ $len -eq 0 ]; then
len=1
fi
else
len=1
fi
Expand All @@ -29,7 +39,18 @@ function run_test() {

for i in `seq 0 $(($len - 1))`
do
echo "Running test: $sketchname -- Config: $i"
fqbn="Default"

if [ $len -ne 1 ]; then
fqbn=`jq -r --arg target $target --argjson i $i '.fqbn[$target] | sort | .[$i]' $sketchdir/ci.json`
elif [ -f $sketchdir/ci.json ]; then
has_fqbn=`jq -r --arg target $target '.fqbn[$target]' $sketchdir/ci.json`
if [ "$has_fqbn" != "null" ]; then
fqbn=`jq -r --arg target $target '.fqbn[$target] | .[0]' $sketchdir/ci.json`
fi
fi

echo "Running test: $sketchname -- Config: $fqbn"
if [ $erase_flash -eq 1 ]; then
esptool.py -c $target erase_flash
fi
Expand Down Expand Up @@ -84,14 +105,14 @@ while [ ! -z "$1" ]; do
-c )
chunk_run=1
;;
-q )
-Q )
if [ ! -d $QEMU_PATH ]; then
echo "QEMU path $QEMU_PATH does not exist"
exit 1
fi
platform="qemu"
;;
-w )
-W )
shift
wokwi_timeout=$1
platform="wokwi"
Expand Down Expand Up @@ -189,8 +210,6 @@ else
else
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
touch $PWD/tests/.test_skipped
exit 0
fi

Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
workflow_call:
inputs:
chip:
required: true
type: string
type:
required: true
type: string
ref:
required: true
type: string

concurrency:
group: tests-build-${{ inputs.ref }}-${{ inputs.chip }}-${{ inputs.type }}
cancel-in-progress: true

jobs:
build-tests:
name: Build ${{ inputs.type }} tests for ${{ inputs.chip }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build sketches
run: |
bash .github/scripts/tests_build.sh -c -type ${{ inputs.type }} -t ${{ inputs.chip }}
- name: Upload ${{ inputs.chip }}-${{ inputs.type }} artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.chip }}-${{ inputs.type }}.artifacts
if-no-files-found: error
path: |
~/.build_skipped
~/.arduino/tests/**/build*.tmp/*.bin
~/.arduino/tests/**/build*.tmp/*.elf
~/.arduino/tests/**/build*.tmp/*.json
Loading

0 comments on commit bde5e31

Please sign in to comment.