From 97f9a36b2d7df1853dd7cc884f31f8786410cf11 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Mon, 13 Jul 2026 15:20:57 +0900 Subject: [PATCH] fix(esp_timer): add target test for long dump lines --- .../esp_timer/test_apps/main/test_esp_timer.c | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/components/esp_timer/test_apps/main/test_esp_timer.c b/components/esp_timer/test_apps/main/test_esp_timer.c index fce31680b9e..6b670aeaf81 100644 --- a/components/esp_timer/test_apps/main/test_esp_timer.c +++ b/components/esp_timer/test_apps/main/test_esp_timer.c @@ -506,6 +506,7 @@ TEST_CASE("Can dump esp_timer stats", "[esp_timer]") overflow the internal string buffer if the length calculation is not correct. */ +#if CONFIG_IDF_TARGET_LINUX const int NUM_TIMERS = 200; esp_timer_handle_t timers[NUM_TIMERS]; @@ -525,6 +526,57 @@ TEST_CASE("Can dump esp_timer stats", "[esp_timer]") for (int i = 0; i < NUM_TIMERS; ++i) { TEST_ESP_OK(esp_timer_delete(timers[i])); } +#else + enum { + INACTIVE_TIMER_COUNT = 64, + NUM_TIMERS = 256, + }; + const uint64_t long_period = (1ULL << 56) - 1; + const uint64_t long_alarm = (uint64_t)esp_timer_get_time() + 1000000000000ULL; + /* Keep large test buffers off the Unity task stack on smaller targets. */ + static esp_timer_handle_t inactive_timers[INACTIVE_TIMER_COUNT]; + static char inactive_names[INACTIVE_TIMER_COUNT][30]; + static esp_timer_handle_t timers[NUM_TIMERS]; + + for (size_t i = 0; i < INACTIVE_TIMER_COUNT; ++i) { + snprintf(inactive_names[i], sizeof(inactive_names[i]), "test_timer_number_%zu", i); + const esp_timer_create_args_t timer_args = { + .callback = &empty_cb, + .arg = NULL, + .name = inactive_names[i], + }; + TEST_ESP_OK(esp_timer_create(&timer_args, &inactive_timers[i])); + } + + for (size_t i = 0; i < NUM_TIMERS; ++i) { + const esp_timer_create_args_t timer_args = { + .callback = &empty_cb, + .name = "dump_long_line_timer", + }; + TEST_ESP_OK(esp_timer_create(&timer_args, &timers[i])); + TEST_ESP_OK(esp_timer_start_periodic_at(timers[i], long_period, long_alarm + i)); + } + + static char dump_buf[4096]; + memset(dump_buf, 0, sizeof(dump_buf)); + FILE* stream = fmemopen(dump_buf, sizeof(dump_buf) - 1, "w+"); + TEST_ASSERT_NOT_NULL(stream); + TEST_ESP_OK(esp_timer_dump(stream)); + fflush(stream); + fclose(stream); + TEST_ASSERT_NOT_NULL(strstr(dump_buf, "Timer stats:")); + TEST_ASSERT_NOT_NULL(strstr(dump_buf, "72057594037927935")); + TEST_ASSERT_TRUE(heap_caps_check_integrity_all(true)); + + for (size_t i = 0; i < NUM_TIMERS; ++i) { + TEST_ESP_OK(esp_timer_stop(timers[i])); + TEST_ESP_OK(esp_timer_delete(timers[i])); + } + + for (size_t i = 0; i < INACTIVE_TIMER_COUNT; ++i) { + TEST_ESP_OK(esp_timer_delete(inactive_timers[i])); + } +#endif } typedef struct {