Refactor to remove redundant initialization and add NVS storage tests
- Removed unnecessary calls to relay_chn_create and g_is_component_initialized in multiple test cases across test_relay_chn_core_single.c, test_relay_chn_listener_multi.c, and test_relay_chn_listener_single.c. - Introduced new test files for NVS functionality: test_relay_chn_nvs_multi.c and test_relay_chn_nvs_single.c, covering initialization, direction setting, invalid parameters, and erase operations. - Updated partition table configuration to support NVS storage, including the addition of a new partition file part_nvs.csv. - Adjusted sdkconfig files to enable NVS support and configure custom partition settings for relay channels.
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
|
||||
// Helper function to prepare channel for tilt tests
|
||||
void prepare_channel_for_tilt(uint8_t chn_id, int initial_cmd) {
|
||||
// Ensure the channel reset tilt control
|
||||
relay_chn_tilt_stop(chn_id);
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
// Ensure the channel has had a 'last_run_cmd'
|
||||
if (initial_cmd == RELAY_CHN_CMD_FORWARD) {
|
||||
relay_chn_run_forward(chn_id);
|
||||
@@ -31,9 +35,6 @@ void prepare_channel_for_tilt(uint8_t chn_id, int initial_cmd) {
|
||||
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running forward first to set last_run_cmd
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
@@ -58,9 +59,6 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
|
||||
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running reverse first to set last_run_cmd
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
||||
|
||||
@@ -83,9 +81,6 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
|
||||
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running forward first to set last_run_cmd
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch)); // Ensure we are back to FREE
|
||||
@@ -102,9 +97,6 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
|
||||
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running reverse first to set last_run_cmd
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
||||
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(ch)); // Ensure we are back to FREE
|
||||
@@ -120,9 +112,6 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
|
||||
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
||||
@@ -142,9 +131,6 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
|
||||
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running reverse first to set last_run_cmd, then tilt
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_REVERSE);
|
||||
relay_chn_tilt_reverse(ch); // Go to tilt state
|
||||
@@ -163,9 +149,6 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
|
||||
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
||||
@@ -183,9 +166,6 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
|
||||
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]") {
|
||||
uint8_t ch = 0;
|
||||
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare channel by running forward first to set last_run_cmd, then tilt
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward(ch); // Go to tilt state
|
||||
@@ -203,9 +183,6 @@ TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_
|
||||
|
||||
TEST_CASE("tilt_forward with ID_ALL sets all channels to TILT_FORWARD", "[relay_chn][tilt][id_all]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// 1. Prepare all channels.
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_FORWARD);
|
||||
@@ -223,9 +200,6 @@ TEST_CASE("tilt_forward with ID_ALL sets all channels to TILT_FORWARD", "[relay_
|
||||
|
||||
TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_chn][tilt][id_all]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// 1. Prepare all channels.
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_REVERSE);
|
||||
@@ -243,9 +217,6 @@ TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_
|
||||
|
||||
TEST_CASE("tilt_stop with ID_ALL stops all tilting channels", "[relay_chn][tilt][id_all]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// 1. Prepare and start all channels tilting forward
|
||||
for (uint8_t i = 0; i < relay_chn_count; i++) {
|
||||
prepare_channel_for_tilt(i, RELAY_CHN_CMD_REVERSE);
|
||||
@@ -265,9 +236,6 @@ TEST_CASE("tilt_stop with ID_ALL stops all tilting channels", "[relay_chn][tilt]
|
||||
|
||||
TEST_CASE("tilt_auto with ID_ALL tilts channels based on last run direction", "[relay_chn][tilt][id_all]")
|
||||
{
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// This test requires at least 2 channels to demonstrate different behaviors
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(2, relay_chn_count, "Test requires at least 2 channels");
|
||||
|
||||
@@ -287,9 +255,6 @@ TEST_CASE("tilt_auto with ID_ALL tilts channels based on last run direction", "[
|
||||
// Test relay_chn_tilt_auto() chooses correct tilt direction
|
||||
TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][auto]") {
|
||||
uint8_t ch = 0;
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
// Prepare FORWARD
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_auto(ch);
|
||||
@@ -309,9 +274,6 @@ TEST_CASE("relay_chn_tilt_auto chooses correct direction", "[relay_chn][tilt][au
|
||||
TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivity]") {
|
||||
uint8_t ch = 0;
|
||||
uint8_t val = 0;
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
relay_chn_tilt_set_sensitivity(ch, 0);
|
||||
TEST_ESP_OK(relay_chn_tilt_get_sensitivity(ch, &val, 1));
|
||||
TEST_ASSERT_EQUAL_UINT8(0, val);
|
||||
@@ -336,9 +298,6 @@ 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_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][tilt][counter]") {
|
||||
uint8_t ch = 0;
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
|
||||
// Tilt forward 3 times
|
||||
@@ -372,9 +331,6 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
|
||||
// Test run command during TILT state
|
||||
TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][tilt][run-during-tilt]") {
|
||||
uint8_t ch = 0;
|
||||
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
|
||||
g_is_component_initialized = true;
|
||||
|
||||
prepare_channel_for_tilt(ch, RELAY_CHN_CMD_FORWARD);
|
||||
relay_chn_tilt_forward(ch);
|
||||
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
|
||||
|
||||
Reference in New Issue
Block a user