2 Commits

Author SHA1 Message Date
0b75df35d1 Use build profiles instead of providing sdkconfig.defaults manually
ESP-IDF provides a more efficient way of handling and combining
multi-configurations for a project than the way currently used:
Build profiles.

So I switched to this method instead of providing the sdkconfig.defaults.*
files manually. This reduced the number of sdkconfig.defaults.* files
as well as the configuration parameters defined in them.

Refs #1085
2025-08-26 17:03:36 +03:00
da953846c9 Refactor function brackets
Refactor the brackets of the test case functions to align with ESP-IDF style.

Refs #1085
2025-08-26 15:19:09 +03:00
32 changed files with 157 additions and 217 deletions

View File

@@ -11,12 +11,12 @@ fi
# ==== 2. Valid Modes and Defaults ==== # ==== 2. Valid Modes and Defaults ====
valid_test_tags=("core" "tilt" "listener" "all" "relay_chn" "nvs" "run_limit" "batch") valid_test_tags=("core" "tilt" "listener" "all" "relay_chn" "nvs" "run_limit" "batch")
valid_test_profiles=("run_limit" "tilt" "nvs" "nvs_custom" "multi" "full_single" "full_multi")
arg_tag="all" # Default to 'all' if no tag specified arg_tag="all" # Default to 'all' if no tag specified
arg_profile="full_multi" # Default to 'full_multi' if no profile specified
arg_clean=false arg_clean=false
arg_log=false arg_log=false
arg_dry_run=false arg_dry_run=false
arg_sdkconfig_file=""
flag_file=false
print_help() { print_help() {
echo "Usage: $0 -t <tags> [OPTIONS]" echo "Usage: $0 -t <tags> [OPTIONS]"
@@ -28,6 +28,10 @@ print_help() {
echo "" echo ""
echo " If no tag is specified, it defaults to 'all'." echo " If no tag is specified, it defaults to 'all'."
echo "" echo ""
echo " -p, --profile [run_limit|tilt|nvs|nvs_custom|multi|full_single|full_multi] Specify which test tag to run."
echo ""
echo " If no profile is specified, it defaults to 'full_multi'."
echo ""
echo "Options:" echo "Options:"
echo " -f, --file <path> Specify a custom sdkconfig file to use for the build." echo " -f, --file <path> Specify a custom sdkconfig file to use for the build."
echo " Defaults to 'sdkconfig.defaults' if not provided." echo " Defaults to 'sdkconfig.defaults' if not provided."
@@ -54,9 +58,8 @@ while [[ $# -gt 0 ]]; do
arg_tag="$2" arg_tag="$2"
shift 2 shift 2
;; ;;
--file|-f) --profile|-p)
arg_sdkconfig_file="$2" arg_profile="$2"
flag_file=true
shift 2 shift 2
;; ;;
--clean|-c) --clean|-c)
@@ -86,6 +89,11 @@ if [[ ! " ${valid_test_tags[*]} " =~ " $arg_tag " ]]; then
usage usage
fi fi
if [[ ! " ${valid_test_profiles[*]} " =~ " $arg_profile " ]]; then
echo "❌ Invalid profile: '$arg_profile'"
usage
fi
# ==== 5. Resolve Paths and Switch to Working Directory ==== # ==== 5. Resolve Paths and Switch to Working Directory ====
script_dir=$(dirname "$(readlink -f "$0")") script_dir=$(dirname "$(readlink -f "$0")")
project_root=$(dirname "$script_dir") project_root=$(dirname "$script_dir")
@@ -98,21 +106,9 @@ if [[ -z "$test_apps_dir" || ! -d "$test_apps_dir" ]]; then
echo " Please ensure the script is in a 'scripts' directory and 'test_apps' is a sibling." echo " Please ensure the script is in a 'scripts' directory and 'test_apps' is a sibling."
exit 1 exit 1
fi fi
echo "✅ Found 'test_apps' at: $test_apps_dir" echo "✅ Found 'test_apps' at: $test_apps_dir"
echo "🧪 Test mode: $arg_tag | Profile: $arg_profile"
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 "🧹 Clean: $arg_clean | 📄 Log: $arg_log"
echo "📂 Changing to working directory: $test_apps_dir" echo "📂 Changing to working directory: $test_apps_dir"
@@ -129,15 +125,14 @@ fi
# In some locales, we can get errors like: "Error: unknown opcode or format name 'wsr.IBREAKA1'" # 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. # The 'LC_ALL=C' env variable is set to ensure consistent locale settings.
LC_ALL=C \ LC_ALL=C \
SDKCONFIG_DEFAULTS="$arg_sdkconfig_file" \
RELAY_CHN_UNITY_TEST_GROUP_TAG="$arg_tag" \ RELAY_CHN_UNITY_TEST_GROUP_TAG="$arg_tag" \
idf.py reconfigure build idf.py @profiles/"${arg_profile}" reconfigure build
echo "🚀 Running test with QEMU..." echo "🚀 Running test with QEMU..."
if $arg_log; then if $arg_log; then
TIMESTAMP=$(date +"%Y%m%d_%H%M%S") TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
LOGFILE="test_log_${arg_tag}_$TIMESTAMP.txt" LOGFILE="test_log_${arg_profile}_${arg_tag}_$TIMESTAMP.txt"
if $arg_dry_run; then if $arg_dry_run; then
echo "🔍 Dry run mode: Logging to $LOGFILE but not executing." | tee "$LOGFILE" echo "🔍 Dry run mode: Logging to $LOGFILE but not executing." | tee "$LOGFILE"
echo "Command: idf.py qemu" | tee "$LOGFILE" echo "Command: idf.py qemu" | tee "$LOGFILE"

View File

@@ -18,13 +18,16 @@ echo "🔍 Searching for 'test_apps' directory in '$project_root'..."
test_apps_dir=$(find "$project_root" -type d -name "test_apps" | head -n 1) test_apps_dir=$(find "$project_root" -type d -name "test_apps" | head -n 1)
echo "test_apps dir: ${test_apps_dir}" echo "test_apps dir: ${test_apps_dir}"
# Execute tests for all configs # Execute tests for all profiles
mapfile -t sdkcfg_files < <(find "$test_apps_dir" -maxdepth 1 -type f -name "sdkconfig.defaults*") mapfile -t profiles < <(find "${test_apps_dir}/profiles" -maxdepth 1 -type f)
for sdkcfg_file in "${sdkcfg_files[@]}"; do for profile in "${profiles[@]}"; do
echo "🔧 Running tests with config: $sdkcfg_file" # Get only the name of the profile file
"${script_dir}"/run_tests.sh -c -f "$sdkcfg_file" -t "$arg_tag" || { profile=$(basename "${profile}")
echo "❌ Tests failed with config: $sdkcfg_file"
echo "🔧 Running tests with profile: $profile"
"${script_dir}"/run_tests.sh -c -p "$profile" -t "$arg_tag" || {
echo "❌ Tests failed with profile: $profile"
exit 1 exit 1
} }
done done

View File

@@ -21,14 +21,16 @@ TEST_CASE("relay_chn_create handles invalid arguments", "[relay_chn][core]")
// --- Basic Functionality Tests --- // --- Basic Functionality Tests ---
// TEST_CASE: Test that relay channels initialize correctly to RELAY_CHN_STATE_IDLE // TEST_CASE: Test that relay channels initialize correctly to RELAY_CHN_STATE_IDLE
TEST_CASE("Relay channels initialize correctly to FREE state", "[relay_chn][core]") { TEST_CASE("Relay channels initialize correctly to FREE state", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i)); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i));
} }
} }
// TEST_CASE: Test that relays do nothing when an invlid channel id given // TEST_CASE: Test that relays do nothing when an invlid channel id given
TEST_CASE("Run forward does nothing if channel id is invalid", "[relay_chn][core]") { TEST_CASE("Run forward does nothing if channel id is invalid", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i; int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i;
relay_chn_run_forward(invalid_id); // relay_chn_run_forward returns void relay_chn_run_forward(invalid_id); // relay_chn_run_forward returns void
@@ -39,7 +41,8 @@ TEST_CASE("Run forward does nothing if channel id is invalid", "[relay_chn][core
} }
// TEST_CASE: Test that relays run in the forward direction and update their state // TEST_CASE: Test that relays run in the forward direction and update their state
TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]") { TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
relay_chn_run_forward(i); // relay_chn_run_forward returns void relay_chn_run_forward(i); // relay_chn_run_forward returns void
// Short delay for state to update // Short delay for state to update
@@ -49,7 +52,8 @@ TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]") {
} }
// TEST_CASE: Test that relays do nothing when an invlid channel id given // TEST_CASE: Test that relays do nothing when an invlid channel id given
TEST_CASE("Run reverse does nothing if channel id is invalid", "[relay_chn][core]") { TEST_CASE("Run reverse does nothing if channel id is invalid", "[relay_chn][core]")
{
// Verify that no valid channels were affected // Verify that no valid channels were affected
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i; int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i;
@@ -61,7 +65,8 @@ TEST_CASE("Run reverse does nothing if channel id is invalid", "[relay_chn][core
} }
// TEST_CASE: Test that relays run in the reverse direction and update their state // TEST_CASE: Test that relays run in the reverse direction and update their state
TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]") { TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
relay_chn_run_reverse(i); // relay_chn_run_reverse returns void relay_chn_run_reverse(i); // relay_chn_run_reverse returns void
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -111,7 +116,8 @@ TEST_CASE("stop_all stops all running channels", "[relay_chn][core][batch]")
// TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_IDLE // TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_IDLE
// This test also verifies the transition to FREE state after a STOP command. // This test also verifies the transition to FREE state after a STOP command.
TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn][core]") { TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
// First, run forward to test stopping and transitioning to FREE state // First, run forward to test stopping and transitioning to FREE state
relay_chn_run_forward(i); // relay_chn_run_forward returns void relay_chn_run_forward(i); // relay_chn_run_forward returns void
@@ -131,7 +137,8 @@ TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn][core]") {
} }
// TEST_CASE: Get state should return UNDEFINED when id is not valid // TEST_CASE: Get state should return UNDEFINED when id is not valid
TEST_CASE("Get state returns UNDEFINED when id is invalid", "[relay_chn][core]") { TEST_CASE("Get state returns UNDEFINED when id is invalid", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i; int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i;
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_UNDEFINED, relay_chn_get_state(invalid_id)); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_UNDEFINED, relay_chn_get_state(invalid_id));
@@ -146,7 +153,8 @@ TEST_CASE("Get state returns UNDEFINED when id is invalid", "[relay_chn][core]")
} }
// TEST_CASE: Get state string should return "UNKNOWN" when id is not valid // TEST_CASE: Get state string should return "UNKNOWN" when id is not valid
TEST_CASE("Get state string returns UNKNOWN when id is invalid", "[relay_chn][core]") { TEST_CASE("Get state string returns UNKNOWN when id is invalid", "[relay_chn][core]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i; int invalid_id = CONFIG_RELAY_CHN_COUNT * 2 + i;
TEST_ASSERT_EQUAL_STRING("UNKNOWN", relay_chn_get_state_str(invalid_id)); TEST_ASSERT_EQUAL_STRING("UNKNOWN", relay_chn_get_state_str(invalid_id));
@@ -161,7 +169,8 @@ TEST_CASE("Get state string returns UNKNOWN when id is invalid", "[relay_chn][co
} }
// TEST_CASE: Test independent operation of multiple relay channels // TEST_CASE: Test independent operation of multiple relay channels
TEST_CASE("Multiple channels can operate independently", "[relay_chn][core]") { TEST_CASE("Multiple channels can operate independently", "[relay_chn][core]")
{
if (CONFIG_RELAY_CHN_COUNT >= 2) { if (CONFIG_RELAY_CHN_COUNT >= 2) {
// Start Channel 0 in forward direction // Start Channel 0 in forward direction
relay_chn_run_forward(0); // relay_chn_run_forward returns void relay_chn_run_forward(0); // relay_chn_run_forward returns void
@@ -198,7 +207,8 @@ TEST_CASE("Multiple channels can operate independently", "[relay_chn][core]") {
// TEST_CASE: Test transition from forward to reverse with inertia and state checks // TEST_CASE: Test transition from forward to reverse with inertia and state checks
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][core][inertia]") { TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][core][inertia]")
{
uint8_t ch = 0; // Channel to test uint8_t ch = 0; // Channel to test
// 1. Start in forward direction // 1. Start in forward direction
@@ -219,7 +229,8 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
// TEST_CASE: Test transition from reverse to forward with inertia and state checks // TEST_CASE: Test transition from reverse to forward with inertia and state checks
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]") { TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]")
{
uint8_t ch = 0; uint8_t ch = 0;
// 1. Start in reverse direction // 1. Start in reverse direction
@@ -239,7 +250,8 @@ TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][co
// TEST_CASE: Test issuing the same run command while already running (no inertia expected) // TEST_CASE: Test issuing the same run command while already running (no inertia expected)
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core][inertia]") { TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core][inertia]")
{
uint8_t ch = 0; uint8_t ch = 0;
// 1. Start in forward direction // 1. Start in forward direction
@@ -257,7 +269,8 @@ TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core]
// TEST_CASE: Test transition from FREE state to running (no inertia expected) // TEST_CASE: Test transition from FREE state to running (no inertia expected)
// Scenario: RELAY_CHN_STATE_IDLE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_IDLE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("FREE to Running transition without inertia", "[relay_chn][core][inertia]") { TEST_CASE("FREE to Running transition without inertia", "[relay_chn][core][inertia]")
{
uint8_t ch = 0; uint8_t ch = 0;
// setUp() should have already brought the channel to FREE state // setUp() should have already brought the channel to FREE state

View File

@@ -21,12 +21,14 @@ TEST_CASE("relay_chn_create handles invalid arguments", "[relay_chn][core]")
// --- Basic Functionality Tests --- // --- Basic Functionality Tests ---
// TEST_CASE: Test that relay channels initialize correctly to RELAY_CHN_STATE_IDLE // TEST_CASE: Test that relay channels initialize correctly to RELAY_CHN_STATE_IDLE
TEST_CASE("Relay channels initialize correctly to IDLE state", "[relay_chn][core]") { TEST_CASE("Relay channels initialize correctly to IDLE state", "[relay_chn][core]")
{
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state());
} }
// TEST_CASE: Test that relays run in the forward direction and update their state // TEST_CASE: Test that relays run in the forward direction and update their state
TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]") { TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]")
{
relay_chn_run_forward(); relay_chn_run_forward();
// Short delay for state to update // Short delay for state to update
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -34,7 +36,8 @@ TEST_CASE("Relay channels run forward and update state", "[relay_chn][core]") {
} }
// TEST_CASE: Test that relays run in the reverse direction and update their state // TEST_CASE: Test that relays run in the reverse direction and update their state
TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]") { TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]")
{
relay_chn_run_reverse(); // relay_chn_run_reverse returns void relay_chn_run_reverse(); // relay_chn_run_reverse returns void
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state()); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
@@ -43,7 +46,8 @@ TEST_CASE("Relay channels run reverse and update state", "[relay_chn][core]") {
// TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_IDLE // TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_IDLE
// This test also verifies the transition to IDLE state after a STOP command. // This test also verifies the transition to IDLE state after a STOP command.
TEST_CASE("Relay channels stop and update to IDLE state", "[relay_chn][core]") { TEST_CASE("Relay channels stop and update to IDLE state", "[relay_chn][core]")
{
// First, run forward to test stopping and transitioning to IDLE state // First, run forward to test stopping and transitioning to IDLE state
relay_chn_run_forward(); relay_chn_run_forward();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -67,7 +71,8 @@ TEST_CASE("Relay channels stop and update to IDLE state", "[relay_chn][core]") {
// TEST_CASE: Test transition from forward to reverse with inertia and state checks // TEST_CASE: Test transition from forward to reverse with inertia and state checks
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][core][inertia]") { TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][core][inertia]")
{
// 1. Start in forward direction // 1. Start in forward direction
relay_chn_run_forward(); relay_chn_run_forward();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Short delay for state stabilization vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Short delay for state stabilization
@@ -86,7 +91,8 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
// TEST_CASE: Test transition from reverse to forward with inertia and state checks // TEST_CASE: Test transition from reverse to forward with inertia and state checks
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]") { TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]")
{
// 1. Start in reverse direction // 1. Start in reverse direction
relay_chn_run_reverse(); // relay_chn_run_reverse returns void relay_chn_run_reverse(); // relay_chn_run_reverse returns void
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -104,7 +110,8 @@ TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][co
// TEST_CASE: Test issuing the same run command while already running (no inertia expected) // TEST_CASE: Test issuing the same run command while already running (no inertia expected)
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core][inertia]") { TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core][inertia]")
{
// 1. Start in forward direction // 1. Start in forward direction
relay_chn_run_forward(); relay_chn_run_forward();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -120,7 +127,8 @@ TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core]
// TEST_CASE: Test transition from IDLE state to running (no inertia expected) // TEST_CASE: Test transition from IDLE state to running (no inertia expected)
// Scenario: RELAY_CHN_STATE_IDLE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_IDLE -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("IDLE to Running transition without inertia", "[relay_chn][core][inertia]") { TEST_CASE("IDLE to Running transition without inertia", "[relay_chn][core][inertia]")
{
// setUp() should have already brought the channel to IDLE state // setUp() should have already brought the channel to IDLE state
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state());

View File

@@ -35,7 +35,8 @@ static void test_listener_2(uint8_t chn_id, relay_chn_state_t old_state, relay_c
// ### Listener Functionality Tests // ### Listener Functionality Tests
TEST_CASE("Listener is called on state change", "[relay_chn][listener]") { TEST_CASE("Listener is called on state change", "[relay_chn][listener]")
{
uint8_t ch = 0; uint8_t ch = 0;
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
@@ -56,7 +57,8 @@ TEST_CASE("Listener is called on state change", "[relay_chn][listener]") {
relay_chn_unregister_listener(test_listener_1); relay_chn_unregister_listener(test_listener_1);
} }
TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]") { TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]")
{
uint8_t ch = 0; uint8_t ch = 0;
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
@@ -72,7 +74,8 @@ TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]") {
TEST_ASSERT_EQUAL(0, listener1_info.call_count); TEST_ASSERT_EQUAL(0, listener1_info.call_count);
} }
TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener]") { TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener]")
{
uint8_t ch = 0; uint8_t ch = 0;
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
reset_listener_info(&listener2_info); reset_listener_info(&listener2_info);
@@ -100,7 +103,8 @@ TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener
relay_chn_unregister_listener(test_listener_2); relay_chn_unregister_listener(test_listener_2);
} }
TEST_CASE("Listener registration handles invalid arguments and duplicates", "[relay_chn][listener]") { TEST_CASE("Listener registration handles invalid arguments and duplicates", "[relay_chn][listener]")
{
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
// 1. Registering a NULL listener should fail // 1. Registering a NULL listener should fail

View File

@@ -34,7 +34,8 @@ static void test_listener_2(uint8_t chn_id, relay_chn_state_t old_state, relay_c
// ### Listener Functionality Tests // ### Listener Functionality Tests
TEST_CASE("Listener is called on state change", "[relay_chn][listener]") { TEST_CASE("Listener is called on state change", "[relay_chn][listener]")
{
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
// 1. Register the listener // 1. Register the listener
@@ -53,7 +54,8 @@ TEST_CASE("Listener is called on state change", "[relay_chn][listener]") {
relay_chn_unregister_listener(test_listener_1); relay_chn_unregister_listener(test_listener_1);
} }
TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]") { TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]")
{
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
// 1. Register and then immediately unregister the listener // 1. Register and then immediately unregister the listener
@@ -68,7 +70,8 @@ TEST_CASE("Unregistered listener is not called", "[relay_chn][listener]") {
TEST_ASSERT_EQUAL(0, listener1_info.call_count); TEST_ASSERT_EQUAL(0, listener1_info.call_count);
} }
TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener]") { TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener]")
{
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
reset_listener_info(&listener2_info); reset_listener_info(&listener2_info);
@@ -95,7 +98,8 @@ TEST_CASE("Multiple listeners are called on state change", "[relay_chn][listener
relay_chn_unregister_listener(test_listener_2); relay_chn_unregister_listener(test_listener_2);
} }
TEST_CASE("Listener registration handles invalid arguments and duplicates", "[relay_chn][listener]") { TEST_CASE("Listener registration handles invalid arguments and duplicates", "[relay_chn][listener]")
{
reset_listener_info(&listener1_info); reset_listener_info(&listener1_info);
// 1. Registering a NULL listener should fail // 1. Registering a NULL listener should fail

View File

@@ -74,7 +74,8 @@ void prepare_all_channels_for_tilt(int initial_cmd) {
// TEST_CASE: Test transition from running forward to tilt forward // TEST_CASE: Test transition from running forward to tilt forward
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd // Prepare channel by running forward first to set last_run_cmd
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
@@ -96,7 +97,8 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from running reverse to tilt reverse // TEST_CASE: Test transition from running reverse to tilt reverse
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE // Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd // Prepare channel by running reverse first to set last_run_cmd
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
@@ -116,7 +118,8 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation) // TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD // Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]") { TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd // Prepare channel by running forward first to set last_run_cmd
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
@@ -129,7 +132,8 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation) // TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE // Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]") { TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd // Prepare channel by running reverse first to set last_run_cmd
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
@@ -141,7 +145,8 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run) // TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd, then tilt // Prepare channel by running forward first to set last_run_cmd, then tilt
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward_all(); // Go to tilt state relay_chn_tilt_forward_all(); // Go to tilt state
@@ -158,7 +163,8 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run) // TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd, then tilt // Prepare channel by running reverse first to set last_run_cmd, then tilt
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
relay_chn_tilt_reverse_all(); // Go to tilt state relay_chn_tilt_reverse_all(); // Go to tilt state
@@ -174,7 +180,8 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia) // TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd, then tilt // Prepare channel by running forward first to set last_run_cmd, then tilt
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward_all(); // Go to tilt state relay_chn_tilt_forward_all(); // Go to tilt state
@@ -189,7 +196,8 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself) // TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_tilt_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_tilt_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]")
{
// Prepare all channels by running forward first to set last_run_cmd, then tilt // Prepare all channels by running forward first to set last_run_cmd, then tilt
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward_all(); // Go to tilt state relay_chn_tilt_forward_all(); // Go to tilt state
@@ -271,7 +279,8 @@ TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_ch
} }
// Test relay_chn_tilt_auto() chooses correct tilt direction // Test relay_chn_tilt_auto() chooses correct tilt direction
TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]") { TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]")
{
// Prepare FORWARD // Prepare FORWARD
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_auto_all(); relay_chn_tilt_auto_all();
@@ -291,7 +300,8 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
} }
// Test sensitivity set/get // Test sensitivity set/get
TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]") { TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]")
{
uint8_t ch = 0; uint8_t ch = 0;
relay_chn_tilt_set_sensitivity(ch, 0); relay_chn_tilt_set_sensitivity(ch, 0);
TEST_ASSERT_EQUAL_UINT8(0, relay_chn_tilt_get_sensitivity(ch)); TEST_ASSERT_EQUAL_UINT8(0, relay_chn_tilt_get_sensitivity(ch));
@@ -313,7 +323,8 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi
} }
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails // Test tilt counter logic: forward x3, reverse x3, extra reverse fails
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]") { TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]")
{
// Tilt execution time at 100% sensitivity in milliseconds (10 + 90) // Tilt execution time at 100% sensitivity in milliseconds (10 + 90)
#define TEST_TILT_EXECUTION_TIME_MS 100 #define TEST_TILT_EXECUTION_TIME_MS 100
@@ -346,7 +357,8 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
} }
// Test run command during TILT state // Test run command during TILT state
TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]") { TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]")
{
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward_all(); relay_chn_tilt_forward_all();
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));

View File

@@ -32,7 +32,8 @@ void prepare_channel_for_tilt(int initial_cmd) {
// TEST_CASE: Test transition from running forward to tilt forward // TEST_CASE: Test transition from running forward to tilt forward
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD // Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd // Prepare channel by running forward first to set last_run_cmd
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
@@ -54,7 +55,8 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from running reverse to tilt reverse // TEST_CASE: Test transition from running reverse to tilt reverse
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE // Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd // Prepare channel by running reverse first to set last_run_cmd
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
@@ -74,7 +76,8 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation) // TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD // Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]") { TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd // Prepare channel by running forward first to set last_run_cmd
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
@@ -88,7 +91,8 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation) // TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE // Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]") { TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd // Prepare channel by running reverse first to set last_run_cmd
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
@@ -101,7 +105,8 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run) // TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd, then tilt // Prepare channel by running forward first to set last_run_cmd, then tilt
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward(); // Go to tilt state relay_chn_tilt_forward(); // Go to tilt state
@@ -118,7 +123,8 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run) // TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running reverse first to set last_run_cmd, then tilt // Prepare channel by running reverse first to set last_run_cmd, then tilt
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE); prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
relay_chn_tilt_reverse(); // Go to tilt state relay_chn_tilt_reverse(); // Go to tilt state
@@ -134,7 +140,8 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia) // TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd, then tilt // Prepare channel by running forward first to set last_run_cmd, then tilt
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward(); // Go to tilt state relay_chn_tilt_forward(); // Go to tilt state
@@ -149,7 +156,8 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself) // TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE // Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") { TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]")
{
// Prepare channel by running forward first to set last_run_cmd, then tilt // Prepare channel by running forward first to set last_run_cmd, then tilt
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward(); // Go to tilt state relay_chn_tilt_forward(); // Go to tilt state
@@ -164,7 +172,8 @@ TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_
} }
// Test relay_chn_tilt_auto() chooses correct tilt direction // Test relay_chn_tilt_auto() chooses correct tilt direction
TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]") { TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]")
{
// Prepare FORWARD // Prepare FORWARD
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_auto(); relay_chn_tilt_auto();
@@ -181,7 +190,8 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
} }
// Test sensitivity set/get // Test sensitivity set/get
TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]") { TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]")
{
relay_chn_tilt_set_sensitivity(0); relay_chn_tilt_set_sensitivity(0);
TEST_ASSERT_EQUAL_UINT8(0, relay_chn_tilt_get_sensitivity()); TEST_ASSERT_EQUAL_UINT8(0, relay_chn_tilt_get_sensitivity());
@@ -196,7 +206,8 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi
} }
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails // Test tilt counter logic: forward x3, reverse x3, extra reverse fails
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]") { TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]")
{
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
// Tilt forward 3 times // Tilt forward 3 times
@@ -228,7 +239,8 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
} }
// Test run command during TILT state // Test run command during TILT state
TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]") { TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]")
{
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward(); relay_chn_tilt_forward();
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));

View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.multi;sdkconfig.defaults.run_limit;sdkconfig.defaults.tilt;sdkconfig.defaults.nvs;sdkconfig.defaults.nvs_custom"

View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.run_limit;sdkconfig.defaults.tilt;sdkconfig.defaults.nvs;sdkconfig.defaults.nvs_custom"

1
test_apps/profiles/multi Normal file
View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.multi"

1
test_apps/profiles/nvs Normal file
View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.nvs"

View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.nvs;sdkconfig.defaults.nvs_custom"

View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.run_limit"

1
test_apps/profiles/tilt Normal file
View File

@@ -0,0 +1 @@
-DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.defaults.tilt"

View File

@@ -395,13 +395,13 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
# #
# Partition Table # Partition Table
# #
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set CONFIG_PARTITION_TABLE_SINGLE_APP=y
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set # CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
# CONFIG_PARTITION_TABLE_TWO_OTA is not set # CONFIG_PARTITION_TABLE_TWO_OTA is not set
# CONFIG_PARTITION_TABLE_TWO_OTA_LARGE is not set # CONFIG_PARTITION_TABLE_TWO_OTA_LARGE is not set
CONFIG_PARTITION_TABLE_CUSTOM=y # CONFIG_PARTITION_TABLE_CUSTOM is not set
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv" CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions/part_nvs.csv" CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000 CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table # end of Partition Table
@@ -1261,26 +1261,10 @@ CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
# #
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200 CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8 CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y # CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT is not set
CONFIG_RELAY_CHN_ENABLE_TILTING=y # CONFIG_RELAY_CHN_ENABLE_TILTING is not set
CONFIG_RELAY_CHN_ENABLE_NVS=y # CONFIG_RELAY_CHN_ENABLE_NVS is not set
# end of Relay Channel Driver Configuration # end of Relay Channel Driver Configuration
#
# Relay Channel NVS Storage Configuration
#
CONFIG_RELAY_CHN_NVS_NAMESPACE="relay_chn"
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION_NAME="app_data"
# end of Relay Channel NVS Storage Configuration
#
# Relay Channel Run Limit Configuration
#
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1
CONFIG_RELAY_CHN_RUN_LIMIT_MAX_SEC=600
CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC=60
# end of Relay Channel Run Limit Configuration
# end of Component config # end of Component config
# CONFIG_IDF_EXPERIMENTAL_FEATURES is not set # CONFIG_IDF_EXPERIMENTAL_FEATURES is not set

View File

@@ -1,7 +1 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8 CONFIG_RELAY_CHN_COUNT=8

View File

@@ -1,14 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Partition configuration
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv"
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_NVS=y
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y

View File

@@ -1,17 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Partition configuration
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv"
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1
CONFIG_RELAY_CHN_ENABLE_TILTING=y
CONFIG_RELAY_CHN_ENABLE_NVS=y
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y

View File

@@ -1,8 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_NVS=y

View File

@@ -1,9 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1

View File

@@ -1,8 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_COUNT=8
CONFIG_RELAY_CHN_ENABLE_TILTING=y

View File

@@ -0,0 +1 @@
CONFIG_RELAY_CHN_ENABLE_NVS=y

View File

@@ -0,0 +1,6 @@
# Partition configuration
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv"
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y

View File

@@ -0,0 +1,3 @@
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1

View File

@@ -1,13 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Partition configuration
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv"
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_ENABLE_NVS=y
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y

View File

@@ -1,16 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Partition configuration
CONFIG_PARTITION_TABLE_SINGLE_APP=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions/part_nvs.csv"
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1
CONFIG_RELAY_CHN_ENABLE_TILTING=y
CONFIG_RELAY_CHN_ENABLE_NVS=y
CONFIG_RELAY_CHN_NVS_CUSTOM_PARTITION=y

View File

@@ -1,7 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_ENABLE_NVS=y

View File

@@ -1,8 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT=y
CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC=1

View File

@@ -1,7 +0,0 @@
# Disable task WDT for tests
CONFIG_ESP_TASK_WDT_INIT=n
# Relay Channel Driver Default Configuration for Testing
# Keep this as short as possible for tests
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
CONFIG_RELAY_CHN_ENABLE_TILTING=y

View File

@@ -0,0 +1 @@
CONFIG_RELAY_CHN_ENABLE_TILTING=y