Fix static variable names

Fixed static variable names according to the ESP-IDF C code formatting guide.

Refs #1085 and fixes #1103
This commit is contained in:
2025-09-04 18:20:51 +03:00
parent bf5e3a4426
commit 86cc29a33b
8 changed files with 210 additions and 210 deletions

View File

@@ -6,20 +6,20 @@
#include "test_common.h"
relay_chn_state_t states[CONFIG_RELAY_CHN_COUNT], expect_states[CONFIG_RELAY_CHN_COUNT];
relay_chn_direction_t directions[CONFIG_RELAY_CHN_COUNT], expect_directions[CONFIG_RELAY_CHN_COUNT];
static relay_chn_state_t s_states[CONFIG_RELAY_CHN_COUNT], s_expect_states[CONFIG_RELAY_CHN_COUNT];
static relay_chn_direction_t s_directions[CONFIG_RELAY_CHN_COUNT], s_expect_directions[CONFIG_RELAY_CHN_COUNT];
static void test_set_expected_state_all(relay_chn_state_t state)
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
expect_states[i] = state;
s_expect_states[i] = state;
}
}
static void test_set_expected_direction_all(relay_chn_direction_t direction)
{
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
expect_directions[i] = direction;
s_expect_directions[i] = direction;
}
}
@@ -231,24 +231,24 @@ TEST_CASE("Forward to Reverse transition with opposite inertia", "[relay_chn][co
// 1. Start in forward direction
relay_chn_run_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS)); // Short delay for state stabilization
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// 2. Issue reverse command
relay_chn_run_reverse_all();
// Immediately after the command, the motor should be stopped
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE_PENDING);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_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));
// Should now be in reverse state
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
}
// TEST_CASE: Test transition from reverse to forward with inertia and state checks
@@ -258,22 +258,22 @@ TEST_CASE("Reverse to Forward transition with opposite inertia", "[relay_chn][co
// 1. Start in reverse direction
relay_chn_run_reverse_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_REVERSE);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// 2. Issue forward command
relay_chn_run_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD_PENDING);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// Wait for inertia
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
}
// TEST_CASE: Test issuing the same run command while already running (no inertia expected)
@@ -283,18 +283,18 @@ TEST_CASE("Running in same direction does not incur inertia", "[relay_chn][core]
// 1. Start in forward direction
relay_chn_run_forward_all();
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// 2. Issue the same forward command again
relay_chn_run_forward_all();
// 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));
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
}
// ### Direction Flipping Tests
@@ -336,44 +336,44 @@ TEST_CASE("All channels direction can be flipped simultaneously", "[relay_chn][c
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
// 2. Verify all channels are flipped
TEST_ESP_OK(relay_chn_get_direction_all(directions));
TEST_ESP_OK(relay_chn_get_direction_all(s_directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_FLIPPED);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_directions, s_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));
// 4. Verify all channels are back to default
TEST_ESP_OK(relay_chn_get_direction_all(directions));
TEST_ESP_OK(relay_chn_get_direction_all(s_directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_DEFAULT);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_directions, s_directions, CONFIG_RELAY_CHN_COUNT);
}
TEST_CASE("Flipping a running channel stops it and flips direction", "[relay_chn][core][direction]")
{
// 1. Start channel running and verify state
relay_chn_run_forward_all();
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_FORWARD);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// 2. Flip the direction while running
relay_chn_flip_direction_all();
// 3. The channel should stop as part of the flip process
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_STOPPED);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
// 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_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_IDLE);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
TEST_ESP_OK(relay_chn_get_direction_all(directions));
TEST_ESP_OK(relay_chn_get_direction_all(s_directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_FLIPPED);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_directions, s_directions, CONFIG_RELAY_CHN_COUNT);
}
TEST_CASE("Direction flip handles invalid channel ID gracefully", "[relay_chn][core][direction]")
@@ -387,7 +387,7 @@ TEST_CASE("Direction flip handles invalid channel ID gracefully", "[relay_chn][c
TEST_CASE("get_state_all retrieves all channel states", "[relay_chn][core][batch]")
{
// 1. All should be IDLE initially
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ESP_OK(relay_chn_get_state_all(s_states));
test_set_expected_state_all(RELAY_CHN_STATE_IDLE);
// 2. Set some states
@@ -403,30 +403,30 @@ TEST_CASE("get_state_all retrieves all channel states", "[relay_chn][core][batch
// 3. Get all states and verify
for (uint8_t i = 0; i < CONFIG_RELAY_CHN_COUNT; i++) {
if (i % 2 == 0) {
expect_states[i] = RELAY_CHN_STATE_FORWARD;
s_expect_states[i] = RELAY_CHN_STATE_FORWARD;
} else {
expect_states[i] = RELAY_CHN_STATE_REVERSE;
s_expect_states[i] = RELAY_CHN_STATE_REVERSE;
}
}
TEST_ESP_OK(relay_chn_get_state_all(states));
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_states, states, CONFIG_RELAY_CHN_COUNT);
TEST_ESP_OK(relay_chn_get_state_all(s_states));
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_states, s_states, CONFIG_RELAY_CHN_COUNT);
}
TEST_CASE("get_direction_all retrieves all channel directions", "[relay_chn][core][direction][batch]")
{
// 1. All should be default initially
TEST_ESP_OK(relay_chn_get_direction_all(directions));
TEST_ESP_OK(relay_chn_get_direction_all(s_directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_DEFAULT);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_directions, s_directions, CONFIG_RELAY_CHN_COUNT);
// 2. Flip all
relay_chn_flip_direction_all();
vTaskDelay(pdMS_TO_TICKS(CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS + TEST_DELAY_MARGIN_MS));
// 3. Get all directions and verify
TEST_ESP_OK(relay_chn_get_direction_all(directions));
TEST_ESP_OK(relay_chn_get_direction_all(s_directions));
test_set_expected_direction_all(RELAY_CHN_DIRECTION_FLIPPED);
TEST_ASSERT_EQUAL_UINT_ARRAY(expect_directions, directions, CONFIG_RELAY_CHN_COUNT);
TEST_ASSERT_EQUAL_UINT_ARRAY(s_expect_directions, s_directions, CONFIG_RELAY_CHN_COUNT);
}
TEST_CASE("get_all functions handle NULL arguments", "[relay_chn][core][batch]")