Compare commits
9 Commits
c718a1380f
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e92e0477b | |||
| fafc23591a | |||
|
497f45e336
|
|||
|
95ca976bc6
|
|||
|
300f9a1317
|
|||
|
5440440c4d
|
|||
|
8416187d86
|
|||
|
9f45a2310d
|
|||
|
a1ff54b6e9
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -59,6 +59,7 @@ tools/test_apps/**/sdkconfig.old
|
||||
# autogenerated config files
|
||||
sdkconfig
|
||||
test_apps/sdkconfig
|
||||
test_apps/sdkconfig.old
|
||||
|
||||
TEST_LOGS/
|
||||
build_summary_*.xml
|
||||
|
||||
@@ -130,7 +130,7 @@ dependencies:
|
||||
# Add as a custom component from git repository
|
||||
relay_chn:
|
||||
git: https://git.kozmotronik.com.tr/KozmotronikTech/relay_chn.git
|
||||
version: '>=0.5.0'
|
||||
version: '>=1.0.0'
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
name: relay_chn
|
||||
version: "0.5.0"
|
||||
description: "Custom component for relay channel control"
|
||||
version: "1.0.0"
|
||||
description: "Relay channel driver for bipolar motors."
|
||||
license: "MIT"
|
||||
url: "https://git.kozmotronik.com.tr/KozmotronikTech/relay_chn"
|
||||
repository: "https://git.kozmotronik.com.tr/KozmotronikTech/relay_chn.git"
|
||||
dependencies:
|
||||
idf: ">=5.0"
|
||||
examples:
|
||||
- path: examples/relay_chn_single
|
||||
- path: examples/relay_chn_multi
|
||||
files:
|
||||
use_gitignore: true
|
||||
@@ -98,8 +98,7 @@ fi
|
||||
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)
|
||||
test_apps_dir="${project_root}/test_apps"
|
||||
|
||||
if [[ -z "$test_apps_dir" || ! -d "$test_apps_dir" ]]; then
|
||||
echo "❌ 'test_apps' directory not found within the project root: '$project_root'"
|
||||
@@ -107,7 +106,7 @@ if [[ -z "$test_apps_dir" || ! -d "$test_apps_dir" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Found 'test_apps' at: $test_apps_dir"
|
||||
echo "⏳ Current time is: $(date +"%Y-%m-%d %H:%M:%S")"
|
||||
echo "🧪 Test mode: $arg_tag | Profile: $arg_profile"
|
||||
echo "🧹 Clean: $arg_clean | 📄 Log: $arg_log"
|
||||
|
||||
|
||||
@@ -14,10 +14,15 @@ project_root=$(dirname "$script_dir")
|
||||
echo "Script dir: ${script_dir}"
|
||||
echo "Project root: ${project_root}"
|
||||
|
||||
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="${project_root}/test_apps"
|
||||
echo "test_apps dir: ${test_apps_dir}"
|
||||
|
||||
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
|
||||
|
||||
# Execute tests for all profiles
|
||||
mapfile -t profiles < <(find "${test_apps_dir}/profiles" -maxdepth 1 -type f)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "relay_chn_nvs.h"
|
||||
#endif
|
||||
|
||||
static const char *TAG = "RELAY_CHN_CTL";
|
||||
static const char *TAG __attribute__((unused)) = "RELAY_CHN_CTL";
|
||||
|
||||
static relay_chn_ctl_t s_chn_ctl;
|
||||
|
||||
|
||||
@@ -21,14 +21,13 @@
|
||||
void check_all_channels_for_state(relay_chn_state_t state)
|
||||
{
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
// ESP_LOGI(TEST_TAG, "Checking channel %d for state %d", i, state);
|
||||
TEST_ASSERT_EQUAL(state, relay_chn_get_state(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to prepare channel for tilt tests
|
||||
void prepare_channels_for_tilt_with_mixed_runs() {
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// Ensure the channel has had a 'last_run_cmd'
|
||||
@@ -40,16 +39,19 @@ void prepare_channels_for_tilt_with_mixed_runs() {
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
||||
relay_chn_stop_all(); // Stop it to set last_run_cmd but return to FREE for next test
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
relay_chn_state_t expect_state;
|
||||
if (i % 2 == 0) {
|
||||
expect_state = RELAY_CHN_STATE_FORWARD;
|
||||
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
||||
expect_state = RELAY_CHN_STATE_REVERSE;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(expect_state, relay_chn_get_state(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to prepare channel for tilt tests
|
||||
void prepare_all_channels_for_tilt(int initial_cmd) {
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// If the channels are not IDLE yet, wait more
|
||||
@@ -64,6 +66,8 @@ void prepare_all_channels_for_tilt(int initial_cmd) {
|
||||
if (not_idle) {
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
|
||||
}
|
||||
// Ensure all channels are IDLE
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||
|
||||
// Ensure the channel has had a 'last_run_cmd'
|
||||
if (initial_cmd == RELAY_CHN_CMD_FORWARD) {
|
||||
@@ -71,20 +75,17 @@ void prepare_all_channels_for_tilt(int initial_cmd) {
|
||||
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
||||
relay_chn_run_reverse_all();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
||||
relay_chn_stop_all(); // Stop all to set last_run_cmd but return to FREE for next test
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||
relay_chn_state_t expect_state = initial_cmd == RELAY_CHN_CMD_FORWARD
|
||||
? RELAY_CHN_STATE_FORWARD : RELAY_CHN_STATE_REVERSE;
|
||||
check_all_channels_for_state(expect_state);
|
||||
ESP_LOGI(TEST_TAG, "All channels prepared for tilt test");
|
||||
}
|
||||
|
||||
// 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
|
||||
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_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
// 1. Start in forward direction
|
||||
relay_chn_run_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
@@ -99,15 +100,15 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
|
||||
// Wait for the inertia period (after which the tilt command will be dispatched)
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// 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
|
||||
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_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
|
||||
// 1. Start in reverse direction
|
||||
relay_chn_run_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
@@ -120,6 +121,9 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
|
||||
@@ -128,12 +132,19 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
|
||||
{
|
||||
// Prepare channel by running forward first to set last_run_cmd
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_stop_all(); // Stop to trigger IDLE
|
||||
// Wait for the channel to transition to IDLE
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE); // Ensure we are back to IDLE
|
||||
|
||||
// Issue tilt forward command
|
||||
relay_chn_tilt_forward_all();
|
||||
// From FREE state, tilt command should still incur the inertia due to the internal timer logic
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
|
||||
@@ -142,11 +153,18 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
|
||||
{
|
||||
// Prepare channel by running reverse first to set last_run_cmd
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
relay_chn_stop_all(); // Stop to trigger IDLE
|
||||
// Wait for the channel to transition to IDLE
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE); // Ensure we are back to IDLE
|
||||
|
||||
// Issue tilt reverse command
|
||||
relay_chn_tilt_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
|
||||
@@ -165,6 +183,9 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD_PENDING);
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
|
||||
@@ -182,6 +203,9 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE_PENDING);
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
|
||||
@@ -198,6 +222,9 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
|
||||
relay_chn_run_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
|
||||
@@ -228,10 +255,14 @@ TEST_CASE("tilt_forward_all sets all channels to TILT_FORWARD", "[relay_chn][til
|
||||
|
||||
// 2. Issue tilt forward to all channels
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE doesn't have stop-inertia
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// 3. Verify all channels are tilting forward
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("tilt_reverse_all sets all channels to TILT_REVERSE", "[relay_chn][tilt][batch]")
|
||||
@@ -241,10 +272,14 @@ TEST_CASE("tilt_reverse_all sets all channels to TILT_REVERSE", "[relay_chn][til
|
||||
|
||||
// 2. Issue tilt reverse to all channels
|
||||
relay_chn_tilt_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// 3. Verify all channels are tilting reverse
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]")
|
||||
@@ -253,7 +288,10 @@ TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]"
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
// 3. Verify all channels are tilting forward
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// 2. Stop tilting on all channels
|
||||
relay_chn_tilt_stop_all();
|
||||
@@ -265,15 +303,13 @@ TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]"
|
||||
|
||||
TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_chn][tilt][batch]")
|
||||
{
|
||||
// This test requires at least 2 channels to demonstrate different behaviors
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(2, CONFIG_RELAY_CHN_COUNT, "Test requires at least 2 channels");
|
||||
|
||||
// 1. Prepare channel 0 with last run FORWARD and channel 1 with last run REVERSE
|
||||
prepare_channels_for_tilt_with_mixed_runs();
|
||||
|
||||
// 2. Issue auto tilt command to all channels
|
||||
relay_chn_tilt_auto_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Tilt from FREE state is dispatched immediately
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// 3. Verify even channels tilt forward (last run was forward) and odd channels tilt reverse (last run was reverse)
|
||||
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
|
||||
@@ -282,6 +318,9 @@ TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_ch
|
||||
|
||||
TEST_ASSERT_EQUAL(state, relay_chn_get_state(i));
|
||||
}
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// Test relay_chn_tilt_auto() chooses correct tilt direction
|
||||
@@ -290,19 +329,24 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
|
||||
// Prepare FORWARD
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_auto_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
// Verify all tilt forward
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
|
||||
// Prepare REVERSE
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
relay_chn_tilt_auto_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
// Verify all tilt reverse
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop_all();
|
||||
}
|
||||
|
||||
// Test sensitivity set/get
|
||||
@@ -375,7 +419,14 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
|
||||
#define TEST_TILT_EXECUTION_TIME_MS 100
|
||||
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
relay_chn_tilt_set_sensitivity_all_with(100); // Set sentivity to max for fastest execution
|
||||
// Ensure sensitivities are set correctly
|
||||
uint8_t sensitivities[CONFIG_RELAY_CHN_COUNT];
|
||||
uint8_t expect[CONFIG_RELAY_CHN_COUNT];
|
||||
memset(expect, 100, CONFIG_RELAY_CHN_COUNT);
|
||||
relay_chn_tilt_get_sensitivity_all(sensitivities);
|
||||
TEST_ASSERT_EQUAL_UINT8_ARRAY(expect, sensitivities, CONFIG_RELAY_CHN_COUNT);
|
||||
|
||||
// Tilt forward 3 times
|
||||
relay_chn_tilt_forward_all();
|
||||
@@ -393,12 +444,12 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
|
||||
|
||||
// Now tilt reverse 3 times (should succeed)
|
||||
relay_chn_tilt_reverse_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3 + TEST_DELAY_MARGIN_MS));
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
|
||||
|
||||
// One more reverse tilt should fail (counter exhausted)
|
||||
// Let it execute 2 at least, or more
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3));
|
||||
// Should not enter TILT_REVERSE, should remain IDLE
|
||||
|
||||
// More reverse tilt should fail (counter exhausted)
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
|
||||
}
|
||||
|
||||
@@ -423,12 +474,12 @@ TEST_CASE("run_all command during active tilt cycle stops tilt", "[relay_chn][ti
|
||||
// Set a known sensitivity for predictable timing.
|
||||
// For sensitivity=50, move_time=30ms, pause_time=270ms.
|
||||
relay_chn_tilt_set_sensitivity_all_with(50);
|
||||
const uint32_t move_time_ms = 30;
|
||||
|
||||
// --- Test interrupting during MOVE step ---
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(move_time_ms / 2)); // Wait for half of the move time
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Interrupt with run_reverse_all while in the MOVE part of the cycle
|
||||
@@ -438,9 +489,12 @@ TEST_CASE("run_all command during active tilt cycle stops tilt", "[relay_chn][ti
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
|
||||
|
||||
// --- Test interrupting during PAUSE step ---
|
||||
relay_chn_stop_all(); // Stop the reverse runs
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward_all();
|
||||
vTaskDelay(pdMS_TO_TICKS(move_time_ms + TEST_DELAY_MARGIN_MS)); // Wait past MOVE, into PAUSE
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); // Wait past MOVE, into PAUSE
|
||||
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
|
||||
|
||||
// Interrupt with run_forward_all while in the PAUSE part of the cycle
|
||||
|
||||
@@ -30,19 +30,15 @@ void prepare_channel_for_tilt(int initial_cmd) {
|
||||
} else { // Assuming initial_cmd is RELAY_CHN_CMD_REVERSE
|
||||
relay_chn_run_reverse();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Allow command to process
|
||||
relay_chn_stop(); // Stop it to set last_run_cmd but return to FREE for next test
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state());
|
||||
relay_chn_state_t expect_state = initial_cmd == RELAY_CHN_CMD_FORWARD ? RELAY_CHN_STATE_FORWARD : RELAY_CHN_STATE_REVERSE;
|
||||
TEST_ASSERT_EQUAL(expect_state, relay_chn_get_state());
|
||||
}
|
||||
|
||||
// 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
|
||||
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_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
// 1. Start in forward direction
|
||||
relay_chn_run_forward();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
@@ -63,9 +59,6 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
|
||||
// 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]")
|
||||
{
|
||||
// Prepare channel by running reverse first to set last_run_cmd
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
|
||||
// 1. Start in reverse direction
|
||||
relay_chn_run_reverse();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
@@ -86,6 +79,9 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
|
||||
{
|
||||
// Prepare channel by running forward first to set last_run_cmd
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_stop(); // Stop to trigger IDLE
|
||||
// Wait for the channel to transition to IDLE
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
|
||||
|
||||
// Issue tilt forward command
|
||||
@@ -101,6 +97,9 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
|
||||
{
|
||||
// Prepare channel by running reverse first to set last_run_cmd
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
relay_chn_stop(); // Stop to trigger IDLE
|
||||
// Wait for the channel to transition to IDLE
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
|
||||
|
||||
// Issue tilt reverse command
|
||||
@@ -183,7 +182,8 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
|
||||
// Prepare FORWARD
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_auto();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
||||
relay_chn_tilt_stop();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
@@ -191,7 +191,8 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
|
||||
// Prepare REVERSE
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
|
||||
relay_chn_tilt_auto();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
||||
}
|
||||
|
||||
@@ -237,31 +238,25 @@ TEST_CASE("relay_chn_tilt_set_sensitivity handles upper boundary", "[relay_chn][
|
||||
// Test tilt counter logic: forward x3, reverse x3, extra reverse fails
|
||||
TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]")
|
||||
{
|
||||
// Tilt execution time at 100% sensitivity in milliseconds (10 + 90)
|
||||
#define TEST_TILT_EXECUTION_TIME_MS 100
|
||||
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
// Tilt forward 3 times
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
relay_chn_tilt_forward();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3 + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
||||
relay_chn_tilt_stop();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
}
|
||||
|
||||
// Now tilt reverse 3 times (should succeed)
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
relay_chn_tilt_reverse();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
if (i < 3) {
|
||||
// Let it execute one time
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
||||
relay_chn_tilt_stop();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
}
|
||||
}
|
||||
// Let it execute 2 at least, or more
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3));
|
||||
|
||||
// Extra reverse tilt should fail (counter exhausted)
|
||||
relay_chn_tilt_reverse();
|
||||
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
||||
// Should not enter TILT_REVERSE, should remain FREE or STOPPED
|
||||
relay_chn_state_t state = relay_chn_get_state();
|
||||
TEST_ASSERT(state != RELAY_CHN_STATE_TILT_REVERSE);
|
||||
@@ -289,12 +284,12 @@ TEST_CASE("run command during active tilt cycle stops tilt", "[relay_chn][tilt][
|
||||
// Set a known sensitivity for predictable timing.
|
||||
// For sensitivity=50, move_time=30ms, pause_time=270ms.
|
||||
relay_chn_tilt_set_sensitivity(50);
|
||||
const uint32_t move_time_ms = 30;
|
||||
|
||||
// --- Test interrupting during MOVE step ---
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward();
|
||||
vTaskDelay(pdMS_TO_TICKS(move_time_ms / 2)); // Wait for half of the move time
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
||||
|
||||
// Interrupt with run_reverse while in the MOVE part of the cycle
|
||||
@@ -304,9 +299,14 @@ TEST_CASE("run command during active tilt cycle stops tilt", "[relay_chn][tilt][
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
||||
|
||||
// --- Test interrupting during PAUSE step ---
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_stop(); // Stop the reverse run
|
||||
// Wait the channel to be IDLE
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
|
||||
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD); // Prepare channel again
|
||||
relay_chn_tilt_forward();
|
||||
vTaskDelay(pdMS_TO_TICKS(move_time_ms + TEST_DELAY_MARGIN_MS)); // Wait past MOVE, into PAUSE
|
||||
// Should incur inertia timer
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
||||
|
||||
// Interrupt with run_forward while in the PAUSE part of the cycle
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Disable task WDT for tests
|
||||
CONFIG_ESP_TASK_WDT_INIT=n
|
||||
|
||||
CONFIG_LOG_MAXIMUM_LEVEL_DEBUG=y
|
||||
CONFIG_LOG_MAXIMUM_LEVEL=4
|
||||
|
||||
# Relay Channel Driver Default Configuration for Testing
|
||||
# Keep this as short as possible for tests
|
||||
CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS=200
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user