release-0.5.0 #31

Merged
ismail merged 19 commits from release-0.5.0 into main 2025-07-23 16:48:19 +02:00
Showing only changes of commit a9a8169710 - Show all commits

View File

@@ -123,6 +123,56 @@ TEST_CASE("Relay channels run reverse and update state", "[relay_chn]") {
} }
} }
// ### Broadcast Command (RELAY_CHN_ID_ALL) Tests
TEST_CASE("run_forward with ID_ALL sets all channels to FORWARD", "[relay_chn][all]")
{
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
g_is_component_initialized = true;
relay_chn_run_forward(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state(i));
}
}
TEST_CASE("run_reverse with ID_ALL sets all channels to REVERSE", "[relay_chn][all]")
{
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
g_is_component_initialized = true;
relay_chn_run_reverse(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state(i));
}
}
TEST_CASE("stop with ID_ALL stops all running channels", "[relay_chn][all]")
{
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
g_is_component_initialized = true;
// 1. Start all channels forward to ensure they are in a known running state
relay_chn_run_forward(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
// 2. Stop all channels using the broadcast command
relay_chn_stop(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
// 3. Verify all channels have transitioned to the FREE state
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FREE, relay_chn_get_state(i));
}
}
// TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_FREE // TEST_CASE: Test that relays stop and transition to RELAY_CHN_STATE_FREE
// This test also verifies the transition to FREE state after a STOP command. // This test also verifies the transition to FREE state after a STOP command.
TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn]") { TEST_CASE("Relay channels stop and update to FREE state", "[relay_chn]") {
@@ -638,6 +688,91 @@ TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FREE, relay_chn_get_state(ch)); TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FREE, relay_chn_get_state(ch));
} }
// ### Tilt Broadcast Command (RELAY_CHN_ID_ALL) Tests
TEST_CASE("tilt_forward with ID_ALL sets all channels to TILT_FORWARD", "[relay_chn][tilt][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);
}
// 2. Issue tilt forward to all channels
relay_chn_tilt_forward(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms)); // Tilt from FREE doesn't have stop-inertia
// 3. Verify all channels are tilting forward
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(i));
}
}
TEST_CASE("tilt_reverse with ID_ALL sets all channels to TILT_REVERSE", "[relay_chn][tilt][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);
}
// 2. Issue tilt reverse to all channels
relay_chn_tilt_reverse(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
// 3. Verify all channels are tilting reverse
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(i));
}
}
TEST_CASE("tilt_stop with ID_ALL stops all tilting channels", "[relay_chn][tilt][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);
}
relay_chn_tilt_forward(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms));
// 2. Stop tilting on all channels
relay_chn_tilt_stop(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(opposite_inertia_ms + test_delay_margin_ms));
// 3. Verify all channels are free
for (uint8_t i = 0; i < relay_chn_count; i++) {
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FREE, relay_chn_get_state(i));
}
}
TEST_CASE("tilt_auto with ID_ALL tilts channels based on last run direction", "[relay_chn][tilt][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");
// 1. Prepare channel 0 with last run FORWARD and channel 1 with last run REVERSE
prepare_channel_for_tilt(0, RELAY_CHN_CMD_FORWARD);
prepare_channel_for_tilt(1, RELAY_CHN_CMD_REVERSE);
// 2. Issue auto tilt command to all channels
relay_chn_tilt_auto(RELAY_CHN_ID_ALL);
vTaskDelay(pdMS_TO_TICKS(test_delay_margin_ms)); // Tilt from FREE state is dispatched immediately
// 3. Verify channel 0 tilts forward (last run was forward) and channel 1 tilts reverse (last run was reverse)
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state(0));
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state(1));
}
#else // CONFIG_RELAY_CHN_ENABLE_TILTING == 0 #else // CONFIG_RELAY_CHN_ENABLE_TILTING == 0
// If tilt functionality is disabled, these tests are skipped. // If tilt functionality is disabled, these tests are skipped.
// A dummy test case is added to indicate this in the test output. // A dummy test case is added to indicate this in the test output.
@@ -673,7 +808,7 @@ TEST_CASE("Single channel direction can be flipped", "[relay_chn][direction]")
TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(ch)); TEST_ASSERT_EQUAL(RELAY_CHN_DIRECTION_DEFAULT, relay_chn_get_direction(ch));
} }
TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][direction]") TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][direction][all]")
{ {
TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count)); TEST_ESP_OK(relay_chn_create(gpio_map, gpio_count));
g_is_component_initialized = true; g_is_component_initialized = true;