diff --git a/components/pthread/test/test_pthread_cxx.cpp b/components/pthread/test/test_pthread_cxx.cpp index ced961d09..d207c1161 100644 --- a/components/pthread/test/test_pthread_cxx.cpp +++ b/components/pthread/test/test_pthread_cxx.cpp @@ -85,6 +85,8 @@ TEST_CASE("pthread C++", "[pthread]") std::cout << "Join thread " << std::hex << t4.get_id() << std::endl; t4.join(); } + + global_sp.reset(); // avoid reported leak } static void task_test_sandbox(void *arg) diff --git a/tools/unit-test-app/components/unity/unity_platform.c b/tools/unit-test-app/components/unity/unity_platform.c index d204530dc..7b96ae4f3 100644 --- a/tools/unit-test-app/components/unity/unity_platform.c +++ b/tools/unit-test-app/components/unity/unity_platform.c @@ -10,6 +10,7 @@ #include "esp_log.h" #include "soc/cpu.h" #include "esp_heap_caps.h" +#include "esp_heap_trace.h" #include "test_utils.h" #define unity_printf ets_printf @@ -37,11 +38,26 @@ const size_t CRITICAL_LEAK_THRESHOLD = 4096; /* setUp runs before every test */ void setUp(void) { +// If heap tracing is enabled in kconfig, leak trace the test +#ifdef CONFIG_HEAP_TRACING + const size_t num_heap_records = 80; + static heap_trace_record_t *record_buffer; + if (!record_buffer) { + record_buffer = malloc(sizeof(heap_trace_record_t) * num_heap_records); + assert(record_buffer); + heap_trace_init_standalone(record_buffer, num_heap_records); + } +#endif + printf("%s", ""); /* sneakily lazy-allocate the reent structure for this test task */ get_test_data_partition(); /* allocate persistent partition table structures */ before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); + +#ifdef CONFIG_HEAP_TRACING + heap_trace_start(HEAP_TRACE_LEAKS); +#endif } static void check_leak(size_t before_free, size_t after_free, const char *type) @@ -76,6 +92,10 @@ void tearDown(void) TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap"); /* check for leaks */ +#ifdef CONFIG_HEAP_TRACING + heap_trace_stop(); + heap_trace_dump(); +#endif size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); diff --git a/tools/unit-test-app/sdkconfig b/tools/unit-test-app/sdkconfig index 6816f4cb0..d9315630b 100644 --- a/tools/unit-test-app/sdkconfig +++ b/tools/unit-test-app/sdkconfig @@ -91,6 +91,7 @@ CONFIG_OPTIMIZATION_LEVEL_RELEASE= CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y CONFIG_OPTIMIZATION_ASSERTIONS_SILENT= CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED= +CONFIG_CXX_EXCEPTIONS= # # Component config @@ -277,8 +278,7 @@ CONFIG_FREERTOS_DEBUG_INTERNALS= CONFIG_HEAP_POISONING_DISABLED= CONFIG_HEAP_POISONING_LIGHT= CONFIG_HEAP_POISONING_COMPREHENSIVE=y -CONFIG_HEAP_TRACING=y -CONFIG_HEAP_TRACING_STACK_DEPTH=2 +CONFIG_HEAP_TRACING= # # libsodium