mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_event: test that dispath order follows regisration order
This commit is contained in:
parent
a10901f44b
commit
a3664ad654
@ -74,6 +74,11 @@ typedef struct {
|
||||
SemaphoreHandle_t mutex;
|
||||
} simple_arg_t;
|
||||
|
||||
typedef struct {
|
||||
int *arr;
|
||||
int index;
|
||||
} ordered_data_t;
|
||||
|
||||
static BaseType_t s_test_core_id;
|
||||
static UBaseType_t s_test_priority;
|
||||
|
||||
@ -135,6 +140,13 @@ static void test_event_simple_handler(void* event_handler_arg, esp_event_base_t
|
||||
xSemaphoreGive(arg->mutex);
|
||||
}
|
||||
|
||||
static void test_event_ordered_dispatch(void* event_handler_arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
|
||||
{
|
||||
int *arg = (int*) event_handler_arg;
|
||||
ordered_data_t *data = *((ordered_data_t**) (event_data));
|
||||
|
||||
data->arr[data->index++] = *arg;
|
||||
}
|
||||
|
||||
static void test_event_performance_handler(void* event_handler_arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
|
||||
{
|
||||
@ -1036,6 +1048,60 @@ TEST_CASE("can create and delete loop from handler", "[event]")
|
||||
TEST_TEARDOWN();
|
||||
}
|
||||
|
||||
TEST_CASE("events are dispatched in the order they are registered", "[event]")
|
||||
{
|
||||
TEST_SETUP();
|
||||
|
||||
esp_event_loop_handle_t loop;
|
||||
esp_event_loop_args_t loop_args = test_event_get_default_loop_args();
|
||||
|
||||
loop_args.task_name = NULL;
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_create(&loop_args, &loop));
|
||||
|
||||
int id_arr[7];
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
id_arr[i] = i;
|
||||
}
|
||||
|
||||
int data_arr[12] = {0};
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base2, TEST_EVENT_BASE2_EV1, test_event_ordered_dispatch, id_arr + 0));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, test_event_ordered_dispatch, id_arr + 1));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, ESP_EVENT_ANY_ID, test_event_ordered_dispatch, id_arr + 2));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base2, TEST_EVENT_BASE2_EV2, test_event_ordered_dispatch, id_arr + 3));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV1, test_event_ordered_dispatch, id_arr + 4));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base2, ESP_EVENT_ANY_ID, test_event_ordered_dispatch, id_arr + 5));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV2, test_event_ordered_dispatch, id_arr + 6));
|
||||
|
||||
esp_event_dump(stdout);
|
||||
|
||||
ordered_data_t data = {
|
||||
.arr = data_arr,
|
||||
.index = 0
|
||||
};
|
||||
|
||||
ordered_data_t* dptr = &data;
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base2, TEST_EVENT_BASE1_EV2, &dptr, sizeof(dptr), portMAX_DELAY));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base1, TEST_EVENT_BASE1_EV1, &dptr, sizeof(dptr), portMAX_DELAY));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base1, TEST_EVENT_BASE1_EV2, &dptr, sizeof(dptr), portMAX_DELAY));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base2, TEST_EVENT_BASE1_EV1, &dptr, sizeof(dptr), portMAX_DELAY));
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_run(loop, pdMS_TO_TICKS(10)));
|
||||
|
||||
// Expected data executing the posts above
|
||||
int ref_arr[12] = {1, 3, 5, 1, 2, 4, 1, 2, 6, 0, 1, 5};
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
TEST_ASSERT_EQUAL(ref_arr[i], data_arr[i]);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_delete(loop));
|
||||
|
||||
TEST_TEARDOWN();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_EVENT_LOOP_PROFILING
|
||||
TEST_CASE("can dump event loop profile", "[event]")
|
||||
{
|
||||
@ -1060,6 +1126,7 @@ TEST_CASE("can dump event loop profile", "[event]")
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, test_event_simple_handler, &arg));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, ESP_EVENT_ANY_ID, test_event_simple_handler, &arg));
|
||||
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV1, test_event_simple_handler, &arg));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV2, test_event_simple_handler, &arg));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user