Refactor and improve unit tests

- Refactored and improved NVS tests to accomodate latest changes in NVS module. See #1098
- Improved channel reset function that is called from `tearDown` to minimize public API calls that trigger a chain of internal calls that involve NVS and timer operations.
- Fixed test case bugs that make some test cases to fail.

Refs #1096, #1098
This commit is contained in:
2025-09-04 15:06:17 +03:00
parent 2c9ee40ff4
commit 639533cbb6
6 changed files with 164 additions and 159 deletions

View File

@@ -362,25 +362,26 @@ TEST_CASE("tilt counter logic: forward and reverse consumption", "[relay_chn][ti
relay_chn_tilt_set_sensitivity_all_with(100); // Set sentivity to max for fastest execution
// Tilt forward 3 times
for (int i = 0; i < 3; ++i) {
relay_chn_tilt_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
relay_chn_tilt_stop_all();
}
relay_chn_tilt_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3 + TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
// Stop tilt on all channels
relay_chn_tilt_stop_all();
#if CONFIG_RELAY_CHN_ENABLE_NVS
// Tilt stop should save the latest tilt count to the NVS
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS + 300));
#else
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
#endif
// Now tilt reverse 3 times (should succeed)
for (int i = 0; i < 3; ++i) {
relay_chn_tilt_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
relay_chn_tilt_stop_all();
}
// Extra reverse tilt should fail (counter exhausted)
relay_chn_tilt_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3 + TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
// One more reverse tilt should fail (counter exhausted)
vTaskDelay(pdMS_TO_TICKS(TEST_TILT_EXECUTION_TIME_MS * 3));
// Should not enter TILT_REVERSE, should remain IDLE
check_all_channels_for_state(RELAY_CHN_STATE_IDLE);
}