fix(esp_timer): enable dump overflow test on linux

This commit is contained in:
Renz Bagaporo
2026-08-27 09:16:02 +08:00
committed by BOT
parent 21c4f307de
commit abc386e154
2 changed files with 12 additions and 22 deletions
@@ -23,3 +23,12 @@ idf_component_register(SRCS ${srcs}
PRIV_INCLUDE_DIRS "../../private_include" "../include"
PRIV_REQUIRES cmock test_utils esp_timer spi_flash esp_psram esp_driver_gpio esp_pm
WHOLE_ARCHIVE)
if(CONFIG_IDF_TARGET_LINUX AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
# Linux host heap integrity checks are stubs, so use ASan to catch dump overflows.
set(asan_options -fsanitize=address -fno-omit-frame-pointer)
idf_component_get_property(esp_timer_lib esp_timer COMPONENT_LIB)
target_compile_options(${esp_timer_lib} PRIVATE ${asan_options})
target_compile_options(${COMPONENT_LIB} PRIVATE ${asan_options})
idf_build_set_property(LINK_OPTIONS -fsanitize=address APPEND)
endif()
@@ -6,6 +6,7 @@
#include "sdkconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>
@@ -506,27 +507,6 @@ 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];
for (int i = 0; i < NUM_TIMERS; ++i) {
char name[30];
snprintf(name, sizeof(name), "test_timer_number_%d", i);
esp_timer_create_args_t timer_args = {
.callback = &empty_cb,
.arg = NULL,
.name = name
};
TEST_ESP_OK(esp_timer_create(&timer_args, &timers[i]));
}
esp_timer_dump(stdout);
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,
@@ -566,7 +546,9 @@ TEST_CASE("Can dump esp_timer stats", "[esp_timer]")
fclose(stream);
TEST_ASSERT_NOT_NULL(strstr(dump_buf, "Timer stats:"));
TEST_ASSERT_NOT_NULL(strstr(dump_buf, "72057594037927935"));
#if !CONFIG_IDF_TARGET_LINUX
TEST_ASSERT_TRUE(heap_caps_check_integrity_all(true));
#endif
for (size_t i = 0; i < NUM_TIMERS; ++i) {
TEST_ESP_OK(esp_timer_stop(timers[i]));
@@ -576,7 +558,6 @@ TEST_CASE("Can dump esp_timer stats", "[esp_timer]")
for (size_t i = 0; i < INACTIVE_TIMER_COUNT; ++i) {
TEST_ESP_OK(esp_timer_delete(inactive_timers[i]));
}
#endif
}
typedef struct {