]> granicus.if.org Git - esp-idf/commitdiff
Unit tests: If a test fails due to corrupting memory, don't print a misleading source...
authorAngus Gratton <angus@espressif.com>
Wed, 4 Oct 2017 05:00:38 +0000 (16:00 +1100)
committerAngus Gratton <gus@projectgus.com>
Tue, 17 Oct 2017 06:46:08 +0000 (14:46 +0800)
tools/unit-test-app/components/unity/unity_platform.c
tools/unit-test-app/sdkconfig

index 8e73fd525738b8e32d7b43025131231e8c1c2934..d204530dc088b649e80317de593bbeda6d843bba 100644 (file)
@@ -59,7 +59,7 @@ static void check_leak(size_t before_free, size_t after_free, const char *type)
            leaked < CRITICAL_LEAK_THRESHOLD ? "potential" : "critical",
            before_free, after_free, leaked);
     fflush(stdout);
-    TEST_ASSERT(leaked < CRITICAL_LEAK_THRESHOLD); /* fail the test if it leaks too much */
+    TEST_ASSERT_MESSAGE(leaked < CRITICAL_LEAK_THRESHOLD, "The test leaked too much memory");
 }
 
 /* tearDown runs after every test */
@@ -68,8 +68,12 @@ void tearDown(void)
     /* some FreeRTOS stuff is cleaned up by idle task */
     vTaskDelay(5);
 
+    /* We want the teardown to have this file in the printout if TEST_ASSERT fails */
+    const char *real_testfile = Unity.TestFile;
+    Unity.TestFile = __FILE__;
+
     /* check if unit test has caused heap corruption in any heap */
-    TEST_ASSERT( heap_caps_check_integrity(MALLOC_CAP_INVALID, true) );
+    TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap");
 
     /* check for leaks */
     size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
@@ -77,6 +81,8 @@ void tearDown(void)
 
     check_leak(before_free_8bit, after_free_8bit, "8BIT");
     check_leak(before_free_32bit, after_free_32bit, "32BIT");
+
+    Unity.TestFile = real_testfile; // go back to the real filename
 }
 
 void unity_putc(int c)
index 1d261c0a2187ac52dcfddf3745576836e9b38b33..6816f4cb0e9286549f940814c73b79c335a81dce 100644 (file)
@@ -302,7 +302,6 @@ CONFIG_LOG_COLORS=y
 #
 CONFIG_L2_TO_L3_COPY=
 CONFIG_LWIP_MAX_SOCKETS=4
-CONFIG_LWIP_THREAD_LOCAL_STORAGE_INDEX=0
 CONFIG_LWIP_SO_REUSE=
 CONFIG_LWIP_SO_RCVBUF=
 CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1