mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 20:41:14 +00:00
refactor (test_utils)!: separate file for memory check functions
Memory check (leaks and heap tracing) functions for unit tests now have a separate file now and are renamed for more consistency. BREAKING CHANGE: renamed memory check function names which may be used in unit tests outside IDF.
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
@@ -20,6 +12,7 @@
|
||||
#include "esp_netif.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "memory_checks.h"
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
#include "esp_ipc.h"
|
||||
#include "esp_freertos_hooks.h"
|
||||
@@ -57,9 +50,9 @@ void test_case_uses_tcpip(void)
|
||||
printf("Note: esp_netif_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n");
|
||||
|
||||
// Reset the leak checker as LWIP allocates a lot of memory on first run
|
||||
unity_reset_leak_checks();
|
||||
test_utils_set_leak_level(0, TYPE_LEAK_CRITICAL, COMP_LEAK_GENERAL);
|
||||
test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_LWIP, TYPE_LEAK_CRITICAL, COMP_LEAK_LWIP);
|
||||
test_utils_record_free_mem();
|
||||
test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL);
|
||||
test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_LWIP, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_LWIP);
|
||||
}
|
||||
|
||||
// wait user to send "Enter" key or input parameter
|
||||
@@ -119,34 +112,6 @@ bool unity_util_convert_mac_from_string(const char* mac_str, uint8_t *mac_addr)
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t test_unity_leak_level[TYPE_LEAK_MAX][COMP_LEAK_ALL] = { 0 };
|
||||
|
||||
esp_err_t test_utils_set_leak_level(size_t leak_level, esp_type_leak_t type_of_leak, esp_comp_leak_t component)
|
||||
{
|
||||
if (type_of_leak >= TYPE_LEAK_MAX || component >= COMP_LEAK_ALL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
test_unity_leak_level[type_of_leak][component] = leak_level;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
size_t test_utils_get_leak_level(esp_type_leak_t type_of_leak, esp_comp_leak_t component)
|
||||
{
|
||||
size_t leak_level = 0;
|
||||
if (type_of_leak >= TYPE_LEAK_MAX || component > COMP_LEAK_ALL) {
|
||||
leak_level = 0;
|
||||
} else {
|
||||
if (component == COMP_LEAK_ALL) {
|
||||
for (int comp = 0; comp < COMP_LEAK_ALL; ++comp) {
|
||||
leak_level += test_unity_leak_level[type_of_leak][comp];
|
||||
}
|
||||
} else {
|
||||
leak_level = test_unity_leak_level[type_of_leak][component];
|
||||
}
|
||||
}
|
||||
return leak_level;
|
||||
}
|
||||
|
||||
#define EXHAUST_MEMORY_ENTRIES 100
|
||||
|
||||
struct test_utils_exhaust_memory_record_s {
|
||||
|
Reference in New Issue
Block a user