2018-07-13 23:42:15 -05:00
|
|
|
#!/usr/bin/env bash
|
2018-10-08 23:03:53 -05:00
|
|
|
#
|
|
|
|
# run_tests
|
|
|
|
#
|
2018-07-13 23:42:15 -05:00
|
|
|
export PATH="$PATH:$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
|
|
|
|
export PATH="$PATH:./buildroot/bin"
|
|
|
|
|
|
|
|
# exit on first failure
|
|
|
|
set -e
|
|
|
|
|
2018-09-02 03:27:39 -05:00
|
|
|
exec_test () {
|
2018-10-02 04:25:46 -05:00
|
|
|
printf "\n\033[0;32m[Test $2] \033[0m$3...\n"
|
2020-11-17 20:04:28 -06:00
|
|
|
# Check to see if we should skip tests
|
|
|
|
if [[ -n "$4" ]] ; then
|
|
|
|
if [[ ! "$3" =~ $4 ]] ; then
|
|
|
|
printf "\033[1;33mSkipped\033[0m\n"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ -z "$VERBOSE_PLATFORMIO" ]] ; then
|
|
|
|
silent="--silent"
|
|
|
|
else
|
|
|
|
silent=""
|
|
|
|
fi
|
|
|
|
if platformio run --project-dir $1 -e $2 $silent; then
|
2018-07-13 23:42:15 -05:00
|
|
|
printf "\033[0;32mPassed\033[0m\n"
|
|
|
|
return 0
|
|
|
|
else
|
2020-11-17 20:04:28 -06:00
|
|
|
if [[ -n $GIT_RESET_HARD ]]; then
|
|
|
|
git reset --hard HEAD
|
|
|
|
else
|
|
|
|
restore_configs
|
|
|
|
fi
|
2018-07-13 23:42:15 -05:00
|
|
|
printf "\033[0;31mFailed!\033[0m\n"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
export -f exec_test
|
|
|
|
|
2018-09-02 03:27:39 -05:00
|
|
|
printf "Running \033[0;32m$2\033[0m Tests\n"
|
|
|
|
|
2018-08-24 18:53:24 -05:00
|
|
|
if [[ $2 = "ALL" ]]; then
|
2018-07-13 23:42:15 -05:00
|
|
|
dir_list=("$(dirname "${BASH_SOURCE[0]}")"/*)
|
2018-10-08 23:03:53 -05:00
|
|
|
declare -a tests=(${dir_list[@]/*run_tests/})
|
2018-07-13 23:42:15 -05:00
|
|
|
for f in "${tests[@]}"; do
|
2019-02-22 19:09:10 -06:00
|
|
|
testenv=$(basename $f | cut -d"-" -f1)
|
2018-07-13 23:42:15 -05:00
|
|
|
printf "Running \033[0;32m$f\033[0m Tests\n"
|
|
|
|
exec_test $1 "$testenv --target clean" "Setup Build Environment"
|
2020-11-17 20:04:28 -06:00
|
|
|
if [[ $GIT_RESET_HARD == "true" ]]; then
|
|
|
|
git reset --hard HEAD
|
|
|
|
else
|
|
|
|
restore_configs
|
|
|
|
fi
|
2018-07-13 23:42:15 -05:00
|
|
|
done
|
|
|
|
else
|
|
|
|
exec_test $1 "$2 --target clean" "Setup Build Environment"
|
2020-11-17 20:04:28 -06:00
|
|
|
test_name="$3"
|
|
|
|
# If the test name is 1 or 2 digits, treat it as an index
|
|
|
|
if [[ "$test_name" =~ ^[0-9][0-9]?$ ]] ; then
|
|
|
|
# Find the test name that corresponds to that index
|
|
|
|
test_name="$(cat buildroot/tests/$2-tests | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")"
|
|
|
|
if [[ -z "$test_name" ]] ; then
|
|
|
|
# Fail if none matches
|
|
|
|
printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2-tests\n"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
printf "\033[0;32mMatching test \033[0m#$3\033[0;32m: '\033[0m$test_name\033[0;32m'\n"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
$2-tests $1 $2 "$test_name"
|
|
|
|
if [[ $GIT_RESET_HARD == "true" ]]; then
|
|
|
|
git reset --hard HEAD
|
|
|
|
else
|
|
|
|
restore_configs
|
|
|
|
fi
|
2018-07-13 23:42:15 -05:00
|
|
|
fi
|
|
|
|
printf "\033[0;32mAll tests completed successfully\033[0m\n"
|