General code and comment cleanup

This commit is contained in:
2025-09-04 16:59:00 +03:00
parent 7244b57061
commit bf5e3a4426
25 changed files with 213 additions and 218 deletions

View File

@@ -23,9 +23,9 @@
#define RELAY_CHN_UNITY_TEST_GROUP_TAG "relay_chn"
#endif
void setUp()
void setUp()
{
}
void tearDown()
@@ -75,7 +75,7 @@ static void test_nvs_flash_deinit(void)
}
#endif
void app_main(void)
void app_main(void)
{
#if CONFIG_RELAY_CHN_ENABLE_NVS
// Init NVS once for all tests
@@ -109,6 +109,6 @@ void app_main(void)
#endif
ESP_LOGI(TEST_TAG, "All tests complete.");
esp_restart(); // Restart to invoke qemu exit
}

View File

@@ -91,7 +91,7 @@ TEST_CASE("Run reverse does nothing if channel id is invalid", "[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++) {
relay_chn_run_reverse(i); // relay_chn_run_reverse returns void
relay_chn_run_reverse(i);
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(i));
}
@@ -148,7 +148,7 @@ TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn][core]")
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(i));
// Now, issue the stop command
relay_chn_stop(i); // relay_chn_stop returns void
relay_chn_stop(i);
// Immediately after stop, state should be STOPPED
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(i));
@@ -201,19 +201,19 @@ TEST_CASE("Multiple channels can operate independently", "[relay_chn][core]")
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(1)); // Other channel should not be affected
// Start Channel 1 in reverse direction
relay_chn_run_reverse(1); // relay_chn_run_reverse returns void
relay_chn_run_reverse(1);
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(0));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(1));
// Stop Channel 0 and wait for it to become FREE
relay_chn_stop(0); // relay_chn_stop returns void
relay_chn_stop(0);
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(0));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(1)); // Other channel should continue running
// Stop Channel 1 and wait for it to become FREE
relay_chn_stop(1); // relay_chn_stop returns void
relay_chn_stop(1);
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(0));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state(1));
@@ -236,15 +236,15 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
// 2. Issue reverse command
relay_chn_run_reverse_all(); // relay_chn_run_reverse returns void
relay_chn_run_reverse_all();
// Immediately after the command, the motor should be stopped
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE_PENDING);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
// Wait for the inertia period (after which the reverse command will be dispatched)
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));
// Should now be in reverse state
TEST_ESP_OK(relay_chn_get_state_all(states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE);
@@ -256,7 +256,7 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]")
{
// 1. Start in reverse direction
relay_chn_run_reverse_all(); // relay_chn_run_reverse returns void
relay_chn_run_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE);
@@ -305,7 +305,7 @@ TEST_CASE("Direction can be flipped for each channel independently", "[relay_chn
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(i));
}
// 2. Flip the direction
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
relay_chn_flip_direction(i);
@@ -339,7 +339,7 @@ TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][c
TEST_ESP_OK(relay_chn_get_direction_all(directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_FLIPPED);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
// 3. Flip all back
relay_chn_flip_direction_all();
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
@@ -366,7 +366,7 @@ TEST_CASE("Flipping a running channel stops it and flips direction", "[relay_chn
// 4. Wait for the flip inertia to pass, after which it should be idle and FLIPPED
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
test_set_expected_state_all(RELAY_CHN_STATE_IDLE);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
@@ -452,7 +452,7 @@ TEST_CASE("Test run limit initialization", "[relay_chn][run_limit]")
}
}
TEST_CASE("Test run limit setting boundaries", "[relay_chn][run_limit]")
TEST_CASE("Test run limit setting boundaries", "[relay_chn][run_limit]")
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
// Test minimum boundary
@@ -482,7 +482,7 @@ TEST_CASE("Test run limit stops channel after timeout", "[relay_chn][run_limit]"
// Check running forward
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(i));
}
// Wait for run limit timeout
vTaskDelay(pdMS_TO_TICKS(TEST_SHORT_RUN_LIMIT_SEC * 1000 + TEST_DELAY_MARGIN_MS));
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
@@ -498,25 +498,25 @@ TEST_CASE("Test run limit reset on direction change and time out finally", "[rel
// Wait for the NVS module task to process operations
vTaskDelay(300 / portTICK_PERIOD_MS); // Wait 1 second
#endif
// Start running forward
relay_chn_run_forward_all();
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait 1 second
// Change direction before timeout
relay_chn_run_reverse_all();
// Wait for the inertia period (after which the reverse command will be dispatched)
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(i));
}
// Timer should time out and stop the channel after the run limit time
vTaskDelay(pdMS_TO_TICKS(TEST_SHORT_RUN_LIMIT_SEC * 1000 + TEST_DELAY_MARGIN_MS));
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state(i));
}
@@ -527,11 +527,11 @@ TEST_CASE("Test run limit persistence across stop/start", "[relay_chn][run_limit
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
// Set initial run limit
relay_chn_set_run_limit(i, TEST_RUN_LIMIT_SEC);
// Stop and start channel
relay_chn_stop(i);
relay_chn_run_forward(i);
// Run limit should persist
TEST_ASSERT_EQUAL(TEST_RUN_LIMIT_SEC, relay_chn_get_run_limit(i));
}

View File

@@ -44,7 +44,7 @@ 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("Relay channels run reverse and update state", "[relay_chn][core]")
{
relay_chn_run_reverse(); // relay_chn_run_reverse returns void
relay_chn_run_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
}
@@ -60,7 +60,7 @@ TEST_CASE("Relay channels stop and update to IDLE state", "[relay_chn][core]")
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
// Now, issue the stop command
relay_chn_stop(); // relay_chn_stop returns void
relay_chn_stop();
// Immediately after stop, state should be STOPPED
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
@@ -85,13 +85,13 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
// 2. Issue reverse command
relay_chn_run_reverse(); // relay_chn_run_reverse returns void
relay_chn_run_reverse();
// Immediately after the command, the motor should be stopped
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE_PENDING, relay_chn_get_state());
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE_PENDING, relay_chn_get_state());
// Wait for the inertia period (after which the reverse command will be dispatched)
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));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state()); // Should now be in reverse state
}
@@ -100,7 +100,7 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][core][inertia]")
{
// 1. Start in reverse direction
relay_chn_run_reverse(); // relay_chn_run_reverse returns void
relay_chn_run_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
@@ -127,7 +127,7 @@ TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core]
relay_chn_run_forward();
// As per the code, is_direction_opposite_to_current_motion should return false, so no inertia.
// Just a short delay to check state remains the same.
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
}
@@ -177,7 +177,7 @@ TEST_CASE("Flipping a running channel stops it and flips direction", "[relay_chn
// 2. Flip the direction while running
relay_chn_flip_direction();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Give time for events to process
// 3. The channel should stop as part of the flip process
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
@@ -197,7 +197,7 @@ TEST_CASE("Test run limit initialization", "[relay_chn][run_limit]")
TEST_ASSERT_EQUAL(CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC, relay_chn_get_run_limit());
}
TEST_CASE("Test run limit setting boundaries", "[relay_chn][run_limit]")
TEST_CASE("Test run limit setting boundaries", "[relay_chn][run_limit]")
{
// Test minimum boundary
relay_chn_set_run_limit(CONFIG_RELAY_CHN_RUN_LIMIT_MIN_SEC - 1);
@@ -216,11 +216,11 @@ TEST_CASE("Test run limit stops channel after timeout", "[relay_chn][run_limit]"
{
// Set a short run limit for testing
relay_chn_set_run_limit(TEST_SHORT_RUN_LIMIT_SEC);
// Start running forward
relay_chn_run_forward();
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
// Wait for run limit timeout
vTaskDelay(pdMS_TO_TICKS(TEST_SHORT_RUN_LIMIT_SEC * 1000 + TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
@@ -230,22 +230,22 @@ TEST_CASE("Test run limit reset on direction change and time out finally", "[rel
{
// Set a short run limit
relay_chn_set_run_limit(TEST_SHORT_RUN_LIMIT_SEC);
// Start running forward
relay_chn_run_forward();
vTaskDelay(1000 / portTICK_PERIOD_MS); // Wait 1 second
// Change direction before timeout
relay_chn_run_reverse();
// Wait for the inertia period (after which the reverse command will be dispatched)
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
// Timer should time out and stop the channel after the run limit time
vTaskDelay(pdMS_TO_TICKS(TEST_SHORT_RUN_LIMIT_SEC * 1000 + TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
}
@@ -253,11 +253,11 @@ TEST_CASE("Test run limit persistence across stop/start", "[relay_chn][run_limit
{
// Set initial run limit
relay_chn_set_run_limit(TEST_RUN_LIMIT_SEC);
// Stop and start channel
relay_chn_stop();
relay_chn_run_forward();
// Run limit should persist
TEST_ASSERT_EQUAL(TEST_RUN_LIMIT_SEC, relay_chn_get_run_limit());
}

View File

@@ -17,7 +17,7 @@ TEST_CASE("Test direction setting and getting", "[relay_chn][nvs]")
{
// Test all channels
relay_chn_direction_t dir, expect;
for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) {
dir = channel % 2 == 0 ? RELAY_CHN_DIRECTION_DEFAULT : RELAY_CHN_DIRECTION_FLIPPED;
TEST_ESP_OK(relay_chn_nvs_set_direction(channel, dir));
@@ -25,7 +25,7 @@ TEST_CASE("Test direction setting and getting", "[relay_chn][nvs]")
// Wait for the batch commit timeout to ensure the value is written
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS));
for (int channel = 0; channel < CONFIG_RELAY_CHN_COUNT; channel++) {
expect = channel % 2 == 0 ? RELAY_CHN_DIRECTION_DEFAULT : RELAY_CHN_DIRECTION_FLIPPED;
TEST_ESP_OK(relay_chn_nvs_get_direction(channel, &dir, RELAY_CHN_DIRECTION_DEFAULT));
@@ -138,7 +138,7 @@ TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]")
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
test_sensitivities[i] = 70 + i; // e.g., 70, 71, 72...
}
// 1. Set all values first
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(i, test_sensitivities[i]));
@@ -161,7 +161,7 @@ TEST_CASE("Test tilt counter operations", "[relay_chn][nvs][tilt]")
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
test_counts[i] = 100 + i; // e.g., 100, 101, 102...
}
// 1. Set all values first
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
TEST_ESP_OK(relay_chn_nvs_set_tilt_count(i, test_counts[i]));

View File

@@ -21,7 +21,7 @@ TEST_CASE("Test direction setting and getting", "[relay_chn][nvs]")
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS)); // Allow NVS task to write and commit
TEST_ESP_OK(relay_chn_nvs_get_direction(0, &dir, RELAY_CHN_DIRECTION_DEFAULT));
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, dir);
// Test channel 1
TEST_ESP_OK(relay_chn_nvs_set_direction(0, RELAY_CHN_DIRECTION_FLIPPED));
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS)); // Allow NVS task to write and commit
@@ -83,7 +83,7 @@ TEST_CASE("Test run limit setting and getting", "[relay_chn][nvs][run_limit]")
{
const uint16_t run_limit_sec = 32;
TEST_ESP_OK(relay_chn_nvs_set_run_limit(0, run_limit_sec));
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS)); // Allow NVS task to write and commit
uint16_t run_limit_read;
TEST_ESP_OK(relay_chn_nvs_get_run_limit(0, &run_limit_read, CONFIG_RELAY_CHN_RUN_LIMIT_DEFAULT_SEC));
@@ -96,7 +96,7 @@ TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]")
{
const uint8_t test_sensitivity = 75;
TEST_ESP_OK(relay_chn_nvs_set_tilt_sensitivity(0, test_sensitivity));
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS)); // Allow NVS task to write and commit
uint8_t sensitivity;
TEST_ESP_OK(relay_chn_nvs_get_tilt_sensitivity(0, &sensitivity, 0));
@@ -106,10 +106,10 @@ TEST_CASE("Test sensitivity setting and getting", "[relay_chn][nvs][tilt]")
TEST_CASE("Test tilt counter operations", "[relay_chn][nvs][tilt]")
{
const uint16_t tilt_count = 100;
// Test setting counters
TEST_ESP_OK(relay_chn_nvs_set_tilt_count(0, tilt_count));
vTaskDelay(pdMS_TO_TICKS(TEST_NVS_TASK_TIME_OUT_MS)); // Allow NVS task to write and commit
uint16_t tilt_count_read;
TEST_ESP_OK(relay_chn_nvs_get_tilt_count(0, &tilt_count_read, 0));

View File

@@ -30,7 +30,7 @@ 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'
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
if (i % 2 == 0) {
@@ -39,7 +39,7 @@ void prepare_channels_for_tilt_with_mixed_runs() {
relay_chn_run_reverse(i);
}
}
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));
@@ -60,11 +60,11 @@ void prepare_all_channels_for_tilt(int initial_cmd) {
break;
}
}
if (not_idle) {
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
}
// Ensure the channel has had a 'last_run_cmd'
if (initial_cmd == RELAY_CHN_CMD_FORWARD) {
relay_chn_run_forward_all();
@@ -74,7 +74,7 @@ void prepare_all_channels_for_tilt(int initial_cmd) {
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);
}
@@ -86,15 +86,15 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
// 1. Start in forward direction
relay_chn_run_forward_all();
relay_chn_run_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD);
// 2. Issue tilt forward command
relay_chn_tilt_forward_all();
relay_chn_tilt_forward_all();
// After tilt command, it should immediately stop and then trigger inertia.
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_STOPPED);
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_STOPPED);
// Wait for the inertia period (after which the tilt command will be dispatched)
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS));
@@ -109,12 +109,12 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
// 1. Start in reverse direction
relay_chn_run_reverse_all();
relay_chn_run_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
// 2. Issue tilt reverse command
relay_chn_tilt_reverse_all();
relay_chn_tilt_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_STOPPED);
@@ -130,9 +130,9 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
// Issue tilt forward command
relay_chn_tilt_forward_all();
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));
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
}
@@ -144,7 +144,7 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
prepare_all_channels_for_tilt(RELAY_CHN_CMD_REVERSE);
// Issue tilt reverse command
relay_chn_tilt_reverse_all();
relay_chn_tilt_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
}
@@ -160,7 +160,7 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
// 2. Issue run forward command
relay_chn_run_forward_all();
relay_chn_run_forward_all();
// From Tilt to Run in the same logical name but in the opposite direction, inertia is expected.
check_all_channels_for_state(RELAY_CHN_STATE_FORWARD_PENDING);
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
@@ -178,7 +178,7 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
check_all_channels_for_state(RELAY_CHN_STATE_TILT_REVERSE);
// 2. Issue run reverse command
relay_chn_run_reverse_all();
relay_chn_run_reverse_all();
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);
@@ -195,7 +195,7 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
check_all_channels_for_state(RELAY_CHN_STATE_TILT_FORWARD);
// 2. Issue run reverse command (opposite direction)
relay_chn_run_reverse_all();
relay_chn_run_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
check_all_channels_for_state(RELAY_CHN_STATE_REVERSE);
}
@@ -251,7 +251,7 @@ TEST_CASE("tilt_stop_all stops all tilting channels", "[relay_chn][tilt][batch]"
{
// 1. Prepare and start all channels tilting forward
prepare_all_channels_for_tilt(RELAY_CHN_CMD_FORWARD);
relay_chn_tilt_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
@@ -279,7 +279,7 @@ TEST_CASE("tilt_auto_all tilts channels based on last run direction", "[relay_ch
for (int i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
relay_chn_state_t state = i % 2 == 0 ?
RELAY_CHN_STATE_TILT_FORWARD : RELAY_CHN_STATE_TILT_REVERSE;
TEST_ASSERT_EQUAL(state, relay_chn_get_state(i));
}
}
@@ -319,11 +319,11 @@ TEST_CASE("relay_chn_tilt_set_sensitivity and get", "[relay_chn][tilt][sensitivi
TEST_ASSERT_EQUAL_UINT8(100, relay_chn_tilt_get_sensitivity(ch));
// Set all channels
relay_chn_tilt_set_sensitivity_all_with(42);
uint8_t vals[CONFIG_RELAY_CHN_COUNT] = {0};
uint8_t expect[CONFIG_RELAY_CHN_COUNT];
memset(expect, 42, CONFIG_RELAY_CHN_COUNT);
TEST_ESP_OK(relay_chn_tilt_get_sensitivity_all(vals));
TEST_ASSERT_EQUAL_UINT8_ARRAY(expect, vals, CONFIG_RELAY_CHN_COUNT);
}
@@ -371,7 +371,6 @@ TEST_CASE("relay_chn_tilt_set_sensitivity functions handle upper boundary", "[re
// 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

View File

@@ -44,15 +44,15 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
// 1. Start in forward direction
relay_chn_run_forward();
relay_chn_run_forward();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
// 2. Issue tilt forward command
relay_chn_tilt_forward();
relay_chn_tilt_forward();
// After tilt command, it should immediately stop and then trigger inertia.
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
// Wait for the inertia period (after which the tilt command will be dispatched)
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
@@ -67,12 +67,12 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
prepare_channel_for_tilt(RELAY_CHN_CMD_REVERSE);
// 1. Start in reverse direction
relay_chn_run_reverse();
relay_chn_run_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
// 2. Issue tilt reverse command
relay_chn_tilt_reverse();
relay_chn_tilt_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_STOPPED, relay_chn_get_state());
@@ -89,9 +89,9 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
// Issue tilt forward command
relay_chn_tilt_forward();
relay_chn_tilt_forward();
// From FREE state, tilt command should still incur the inertia due to the internal timer logic
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
}
@@ -104,7 +104,7 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state()); // Ensure we are back to FREE
// Issue tilt reverse command
relay_chn_tilt_reverse();
relay_chn_tilt_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
}
@@ -120,7 +120,7 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
// 2. Issue run forward command
relay_chn_run_forward();
relay_chn_run_forward();
// From Tilt to Run in the same logical name but in the opposite direction, inertia is expected.
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD_PENDING, relay_chn_get_state());
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
@@ -138,7 +138,7 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
// 2. Issue run reverse command
relay_chn_run_reverse();
relay_chn_run_reverse();
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE_PENDING, relay_chn_get_state());
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
@@ -155,7 +155,7 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
// 2. Issue run reverse command (opposite direction)
relay_chn_run_reverse();
relay_chn_run_reverse();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
}