mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(esp_event): Fix event loop profiling in handler_execute function
handler_execute function is looking to match the handler only in the list of loop events but does not look in the base event handler list nor the id event handler list. So unless the event handler is registered to be triggered for all event bases and all event ids of an event loop, its profiling fields (invoked and time) are not updated when it is called. This commit updates the search for the matching handler to also look in base event list and ID event list. Closes https://github.com/espressif/esp-idf/issues/15041
This commit is contained in:
@@ -1597,3 +1597,49 @@ TEST_CASE("default event loop: registering event handler instance without instan
|
||||
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
}
|
||||
|
||||
#if CONFIG_ESP_EVENT_LOOP_PROFILING
|
||||
static void handler_all(void* arg, esp_event_base_t event_base, int32_t event_id, void* data)
|
||||
{
|
||||
printf("Event received: base=%s, id=%" PRId32 ", data=%p\n", event_base, event_id, data);
|
||||
}
|
||||
|
||||
static void handler_base(void* arg, esp_event_base_t event_base, int32_t event_id, void* data)
|
||||
{
|
||||
printf("Event received: base=%s, id=%" PRId32 ", data=%p\n", event_base, event_id, data);
|
||||
}
|
||||
|
||||
static void handler_id(void* arg, esp_event_base_t event_base, int32_t event_id, void* data)
|
||||
{
|
||||
printf("Event received: base=%s, id=%" PRId32 ", data=%p\n", event_base, event_id, data);
|
||||
}
|
||||
|
||||
TEST_CASE("profiling reports valid values", "[event][default]")
|
||||
{
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
|
||||
/* register handler for event base 1 and event id 1 */
|
||||
TEST_ESP_OK(esp_event_handler_register(s_test_base1, TEST_EVENT_BASE1_EV1, handler_id, NULL));
|
||||
|
||||
/* register handler for event base 1 and all event ids */
|
||||
TEST_ESP_OK(esp_event_handler_register(s_test_base1, ESP_EVENT_ANY_ID, handler_base, NULL));
|
||||
|
||||
/* register handler for all event bases and all event ids */
|
||||
TEST_ESP_OK(esp_event_handler_register(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, handler_all, NULL));
|
||||
|
||||
/* post an event on event base 1, event id 1 */
|
||||
TEST_ESP_OK(esp_event_post(s_test_base1, TEST_EVENT_BASE1_EV1, NULL, 0, pdMS_TO_TICKS(1000)));
|
||||
|
||||
/* post an event 1 from base 1 and check the dump.
|
||||
* - 3 handlers invoked, exec time is not 0 */
|
||||
esp_event_dump(stdout);
|
||||
|
||||
/* unregister handlers */
|
||||
TEST_ESP_OK(esp_event_handler_unregister(ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, handler_all));
|
||||
TEST_ESP_OK(esp_event_handler_unregister(s_test_base1, ESP_EVENT_ANY_ID, handler_base));
|
||||
TEST_ESP_OK(esp_event_handler_unregister(s_test_base1, TEST_EVENT_BASE1_EV1, handler_id));
|
||||
|
||||
/* delete loop */
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
}
|
||||
#endif // CONFIG_ESP_EVENT_LOOP_PROFILING
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
@@ -29,3 +29,15 @@ def test_esp_event_posix_simulator(dut: Dut) -> None:
|
||||
dut.expect_exact('Press ENTER to see the list of tests.')
|
||||
dut.write('*')
|
||||
dut.expect(r'\d{2} Tests 0 Failures 0 Ignored', timeout=120)
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.generic
|
||||
def test_esp_event_profiling(dut: Dut) -> None:
|
||||
dut.expect_exact('Press ENTER to see the list of tests.')
|
||||
dut.write('"profiling reports valid values"')
|
||||
# look for all references of handlers invoked at least 1 time
|
||||
# with an execution time superior to 0 us
|
||||
matches = dut.expect(r'HANDLER .+ inv:[1-9][0-9]{0,} time:[1-9][0-9]{0,} us', timeout=2)
|
||||
matches_arr = matches.group().split(b'\r\n')
|
||||
assert (len(matches_arr) == 3)
|
||||
|
||||
Reference in New Issue
Block a user