From 0cd6b4e263e5a152616a16f158e8ebdb3b7646d7 Mon Sep 17 00:00:00 2001 From: ismail Date: Thu, 28 Aug 2025 09:30:43 +0300 Subject: [PATCH] Refactor and enhance reset_channels_to_idle_state - Refactor reset_channels_to_idle_state to reset_channels_to_defaults and enhance functionality with direction reset logic. This is because some tilt test cases were failing due to modified run limit values in some of the previous core test cases. See #1089-3. - A relay channel listener has been added to diagnose channel states during tests. Refs #1089 --- test_apps/main/test_app_main.c | 2 +- test_apps/main/test_common.c | 25 ++++++++++++++++++++++++- test_apps/main/test_common.h | 5 ++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/test_apps/main/test_app_main.c b/test_apps/main/test_app_main.c index 8400843..1f8d4f9 100644 --- a/test_apps/main/test_app_main.c +++ b/test_apps/main/test_app_main.c @@ -25,7 +25,7 @@ void setUp() void tearDown() { - reset_channels_to_idle_state(); + reset_channels_to_defaults(); } #if CONFIG_RELAY_CHN_ENABLE_NVS diff --git a/test_apps/main/test_common.c b/test_apps/main/test_common.c index 1dcdfad..d8fdb4d 100644 --- a/test_apps/main/test_common.c +++ b/test_apps/main/test_common.c @@ -32,17 +32,40 @@ const uint8_t gpio_map[] = {4, 5}; const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]); -void reset_channels_to_idle_state() +void reset_channels_to_defaults() { #if CONFIG_RELAY_CHN_COUNT > 1 relay_chn_stop_all(); +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT + relay_chn_set_run_limit_all_with(CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC); +#endif vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS)); for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) { TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(i)); + + // Reset directions + if (relay_chn_get_direction(i) != RELAY_CHN_DIRECTION_DEFAULT) { + relay_chn_flip_direction(i); + TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(i)); + } } #else relay_chn_stop(); +#if CONFIG_RELAY_CHN_ENABLE_RUN_LIMIT + relay_chn_set_run_limit(CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC); +#endif + + // Reset direction + if (relay_chn_get_direction() != RELAY_CHN_DIRECTION_DEFAULT) { + relay_chn_flip_direction(); + TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction()); + } 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()); #endif +} + +void test_state_listener(uint8_t id, relay_chn_state_t old_state, relay_chn_state_t new_state) +{ + ESP_LOGI(TEST_TAG, "test_state_listener: id: %d, old_state: %d, new_state: %d", id, old_state, new_state); } \ No newline at end of file diff --git a/test_apps/main/test_common.h b/test_apps/main/test_common.h index 1b9c94a..b2c1c55 100644 --- a/test_apps/main/test_common.h +++ b/test_apps/main/test_common.h @@ -18,4 +18,7 @@ extern const uint8_t gpio_count; #define TEST_DELAY_MARGIN_MS 50 // Reset channels to Idle state -void reset_channels_to_idle_state(void); \ No newline at end of file +void reset_channels_to_defaults(void); + +// Relay channel state listener for tests +void test_state_listener(uint8_t id, relay_chn_state_t old_state, relay_chn_state_t new_state); \ No newline at end of file