From 6f07e0797d812d5963a6784f0a008fb55c81c2cb Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 4 Oct 2017 16:00:38 +1100 Subject: [PATCH] Unit tests: If a test fails due to corrupting memory, don't print a misleading source file name --- tools/unit-test-app/components/unity/unity_platform.c | 10 ++++++++-- tools/unit-test-app/sdkconfig | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/unit-test-app/components/unity/unity_platform.c b/tools/unit-test-app/components/unity/unity_platform.c index 8e73fd5257..d204530dc0 100644 --- a/tools/unit-test-app/components/unity/unity_platform.c +++ b/tools/unit-test-app/components/unity/unity_platform.c @@ -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) diff --git a/tools/unit-test-app/sdkconfig b/tools/unit-test-app/sdkconfig index 1d261c0a21..6816f4cb0e 100644 --- a/tools/unit-test-app/sdkconfig +++ b/tools/unit-test-app/sdkconfig @@ -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 -- 2.40.0