]> granicus.if.org Git - esp-idf/commitdiff
unit tests: If heap tracing is enabled in sdkconfig, leak trace each test
authorAngus Gratton <angus@espressif.com>
Wed, 4 Oct 2017 06:30:10 +0000 (17:30 +1100)
committerAngus Gratton <gus@projectgus.com>
Tue, 17 Oct 2017 07:29:25 +0000 (15:29 +0800)
components/pthread/test/test_pthread_cxx.cpp
tools/unit-test-app/components/unity/unity_platform.c
tools/unit-test-app/sdkconfig

index ced961d09fa10e4b7eba087365c84f4fbc59be34..d207c11611603d18c03fb2bb4ffae08133bd58cf 100644 (file)
@@ -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)
index d204530dc088b649e80317de593bbeda6d843bba..7b96ae4f34b6911af93a5c243b0fcb73e60323c6 100644 (file)
@@ -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);
 
index 6816f4cb0e9286549f940814c73b79c335a81dce..d9315630ba30a60627483521295e9d56d79c9a88 100644 (file)
@@ -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