mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
fix: memory leaks check added
This commit is contained in:
committed by
Mahavir Jain
parent
146f101289
commit
317eeddce4
@@ -5,7 +5,34 @@
|
|||||||
*/
|
*/
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "test_utils.h"
|
#include "unity.h"
|
||||||
|
#include "memory_checks.h"
|
||||||
|
|
||||||
|
/* setUp runs before every test */
|
||||||
|
void setUp(void)
|
||||||
|
{
|
||||||
|
test_utils_record_free_mem();
|
||||||
|
test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL);
|
||||||
|
test_utils_set_leak_level(CONFIG_UNITY_WARN_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL);
|
||||||
|
test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_LWIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tearDown runs after every test */
|
||||||
|
void tearDown(void)
|
||||||
|
{
|
||||||
|
/* some FreeRTOS stuff is cleaned up by idle task */
|
||||||
|
vTaskDelay(5);
|
||||||
|
|
||||||
|
/* clean up some of the newlib's lazy allocations */
|
||||||
|
esp_reent_cleanup();
|
||||||
|
|
||||||
|
/* check if unit test has caused heap corruption in any heap */
|
||||||
|
TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap");
|
||||||
|
|
||||||
|
test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
|
||||||
|
test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void test_task(void *pvParameters)
|
static void test_task(void *pvParameters)
|
||||||
{
|
{
|
||||||
@@ -15,5 +42,5 @@ static void test_task(void *pvParameters)
|
|||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
xTaskCreatePinnedToCore(test_task, "testTask", UNITY_FREERTOS_STACK_SIZE, NULL, UNITY_FREERTOS_PRIORITY, NULL, UNITY_FREERTOS_CPU);
|
xTaskCreatePinnedToCore(test_task, "testTask", CONFIG_UNITY_FREERTOS_STACK_SIZE, NULL, CONFIG_UNITY_FREERTOS_PRIORITY, NULL, CONFIG_UNITY_FREERTOS_CPU);
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,11 @@ static void check_leak(size_t before_free,
|
|||||||
if (leaked <= warn_threshold) {
|
if (leaked <= warn_threshold) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
printf("The test leaked more memory than warn threshold: Leaked: %d Warn threshold: -%u \n",
|
||||||
|
leaked,
|
||||||
|
warn_threshold);
|
||||||
|
}
|
||||||
|
|
||||||
printf("MALLOC_CAP_%s %s leak: Before %u bytes free, After %u bytes free (delta %u)\n",
|
printf("MALLOC_CAP_%s %s leak: Before %u bytes free, After %u bytes free (delta %u)\n",
|
||||||
type,
|
type,
|
||||||
|
Reference in New Issue
Block a user