Specific `_*all` and `_*all_with` functions were implemented to make the API more concise and clean, and to replace the use of `RELAY_CHN_ID_ALL`, which caused confusion within the API. Refs #1085
157 lines
4.5 KiB
Bash
Executable File
157 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# ==== 1. Check ESP-IDF environment ====
|
|
if [[ -z "$IDF_PATH" ]]; then
|
|
echo "❌ ESP-IDF environment not found. Please source the export.sh file first:"
|
|
echo "'. $HOME/esp/esp-idf/export.sh' or wherever the ESP-IDF is installed"
|
|
exit 1
|
|
fi
|
|
|
|
# ==== 2. Valid Modes and Defaults ====
|
|
valid_test_tags=("core" "tilt" "listener" "all" "relay_chn" "nvs" "run_limit" "batch")
|
|
arg_tag="all" # Default to 'all' if no tag specified
|
|
arg_clean=false
|
|
arg_log=false
|
|
arg_dry_run=false
|
|
arg_sdkconfig_file=""
|
|
flag_file=false
|
|
|
|
print_help() {
|
|
echo "Usage: $0 -t <tags> [OPTIONS]"
|
|
echo ""
|
|
echo "This script builds and runs tests for the relay_chn component using QEMU."
|
|
echo ""
|
|
echo "Arguments:"
|
|
echo " -t, --tag [relay_chn|core|tilt|listener|nvs|run_limit|batch|all] Specify which test tag to run."
|
|
echo ""
|
|
echo " If no tag is specified, it defaults to 'all'."
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -f, --file <path> Specify a custom sdkconfig file to use for the build."
|
|
echo " Defaults to 'sdkconfig.defaults' if not provided."
|
|
echo " -c, --clean Perform a 'fullclean' before building the tests."
|
|
echo " -l, --log Log the test output to a timestamped file."
|
|
echo " -n, --dry-run Build the project without running qemu."
|
|
echo " -h, --help Show this help message and exit."
|
|
}
|
|
|
|
help() {
|
|
print_help
|
|
exit 0
|
|
}
|
|
|
|
usage() {
|
|
print_help
|
|
exit 1
|
|
}
|
|
|
|
# ==== 3. Argument Parsing ====
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--tag|-t)
|
|
arg_tag="$2"
|
|
shift 2
|
|
;;
|
|
--file|-f)
|
|
arg_sdkconfig_file="$2"
|
|
flag_file=true
|
|
shift 2
|
|
;;
|
|
--clean|-c)
|
|
arg_clean=true
|
|
shift
|
|
;;
|
|
--log|-l)
|
|
arg_log=true
|
|
shift
|
|
;;
|
|
--dry-run|-n)
|
|
arg_dry_run=true
|
|
shift
|
|
;;
|
|
--help|-h)
|
|
help
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# ==== 4. Validity Check ====
|
|
if [[ ! " ${valid_test_tags[*]} " =~ " $arg_tag " ]]; then
|
|
echo "❌ Invalid mode: '$arg_tag'"
|
|
usage
|
|
fi
|
|
|
|
# ==== 5. Resolve Paths and Switch to Working Directory ====
|
|
script_dir=$(dirname "$(readlink -f "$0")")
|
|
project_root=$(dirname "$script_dir")
|
|
|
|
echo "🔍 Searching for 'test_apps' directory in '$project_root'..."
|
|
test_apps_dir=$(find "$project_root" -type d -name "test_apps" | head -n 1)
|
|
|
|
if [[ -z "$test_apps_dir" || ! -d "$test_apps_dir" ]]; then
|
|
echo "❌ 'test_apps' directory not found within the project root: '$project_root'"
|
|
echo " Please ensure the script is in a 'scripts' directory and 'test_apps' is a sibling."
|
|
exit 1
|
|
fi
|
|
echo "✅ Found 'test_apps' at: $test_apps_dir"
|
|
|
|
if $flag_file; then
|
|
if [[ -z "$arg_sdkconfig_file" || ! -f "$arg_sdkconfig_file" ]]; then
|
|
echo "❌ Invalid or missing file: '$arg_sdkconfig_file'"
|
|
usage
|
|
fi
|
|
# Resolve to an absolute path to work correctly after changing directory
|
|
arg_sdkconfig_file=$(readlink -f "$arg_sdkconfig_file")
|
|
else
|
|
echo "⚠️ No SDK configuration file provided. Using default sdkconfig."
|
|
arg_sdkconfig_file="$test_apps_dir/sdkconfig.defaults"
|
|
fi
|
|
|
|
echo "🧪 Test mode: $arg_tag"
|
|
echo "🧹 Clean: $arg_clean | 📄 Log: $arg_log"
|
|
|
|
echo "📂 Changing to working directory: $test_apps_dir"
|
|
cd "$test_apps_dir" || exit 1
|
|
|
|
# ==== 6. Clean if requested ====
|
|
if $arg_clean; then
|
|
echo "🧹 Doing Fullclean..."
|
|
idf.py fullclean
|
|
rm sdkconfig
|
|
fi
|
|
|
|
# ==== 7. Building and Running Tests ====
|
|
# In some locales, we can get errors like: "Error: unknown opcode or format name 'wsr.IBREAKA1'"
|
|
# The 'LC_ALL=C' env variable is set to ensure consistent locale settings.
|
|
LC_ALL=C \
|
|
SDKCONFIG_DEFAULTS="$arg_sdkconfig_file" \
|
|
RELAY_CHN_UNITY_TEST_GROUP_TAG="$arg_tag" \
|
|
idf.py reconfigure build
|
|
|
|
echo "🚀 Running test with QEMU..."
|
|
|
|
if $arg_log; then
|
|
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
|
|
LOGFILE="test_log_${arg_tag}_$TIMESTAMP.txt"
|
|
if $arg_dry_run; then
|
|
echo "🔍 Dry run mode: Logging to $LOGFILE but not executing." | tee "$LOGFILE"
|
|
echo "Command: idf.py qemu" | tee "$LOGFILE"
|
|
else
|
|
echo "📜 Logging test output to: $LOGFILE"
|
|
idf.py qemu --qemu-extra-args "-no-reboot" | tee "$LOGFILE"
|
|
fi
|
|
else
|
|
if $arg_dry_run; then
|
|
echo "🔍 Dry run mode: Not executing idf.py qemu."
|
|
echo "Command: idf.py qemu"
|
|
else
|
|
echo "🚀 Running idf.py qemu..."
|
|
idf.py qemu --qemu-extra-args "-no-reboot"
|
|
fi
|
|
fi
|