test: clean up "leaks" tags from most unit tests

This commit is contained in:
Ivan Grokhotkov 2019-04-15 21:07:38 +08:00
parent 1c21bc5c81
commit bb4f5617ab
10 changed files with 88 additions and 13 deletions

View File

@ -118,7 +118,7 @@ static void uart_config(uint32_t baud_rate, bool use_ref_tick)
uart_driver_install(UART_NUM1, BUF_SIZE * 2, BUF_SIZE * 2, 20, NULL, 0);
}
TEST_CASE("test uart get baud-rate","[uart]")
TEST_CASE("test uart get baud-rate", "[uart]")
{
uint32_t baud_rate1 = 0;
uint32_t baud_rate2 = 0;
@ -136,13 +136,13 @@ TEST_CASE("test uart get baud-rate","[uart]")
ESP_LOGI(UART_TAG, "get baud-rate test passed ....\n");
}
TEST_CASE("test uart tx data with break","[uart][leaks=2192]")
TEST_CASE("test uart tx data with break", "[uart]")
{
const int buf_len = 200;
const int send_len = 128;
const int brk_len = 10;
char *psend = (char *)malloc(buf_len);
TEST_ASSERT( psend != NULL);
TEST_ASSERT(psend != NULL);
memset(psend, '0', buf_len);
uart_config(UART_BAUD_115200, false);
printf("Uart%d send %d bytes with break\n", UART_NUM1, send_len);
@ -151,6 +151,7 @@ TEST_CASE("test uart tx data with break","[uart][leaks=2192]")
//If the code is running here, it means the test passed, otherwise it will crash due to the interrupt wdt timeout.
printf("Send data with break test passed\n");
free(psend);
uart_driver_delete(UART_NUM1);
}
// Calculate buffer checksum using tables

View File

@ -868,7 +868,7 @@ TEST_CASE("performance test - dedicated task", "[event]")
performance_test(true);
}
TEST_CASE("performance test - no dedicated task", "[event][leaks=2736]")
TEST_CASE("performance test - no dedicated task", "[event]")
{
performance_test(false);
}

View File

@ -44,6 +44,7 @@ static void test_phy_rtc_init(void)
//must run here, not blocking in above code
TEST_ASSERT(1);
nvs_flash_deinit();
}
static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
@ -77,7 +78,7 @@ static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
vTaskDelete(NULL);
}
TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled][leaks=1216]")
TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
{
semphr_done = xSemaphoreCreateCounting(1, 0);

View File

@ -69,7 +69,7 @@ TEST_CASE("(raw) can read file", "[fatfs]")
test_teardown();
}
TEST_CASE("(raw) can open maximum number of files", "[fatfs][leaks=2028]")
TEST_CASE("(raw) can open maximum number of files", "[fatfs]")
{
size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */
test_setup(max_files);

View File

@ -158,7 +158,7 @@ TEST_CASE("(SD) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs]
test_teardown();
}
TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][test_env=UT_T1_SDMODE][leaks=1264]")
TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][test_env=UT_T1_SDMODE]")
{
test_setup();
test_fatfs_concurrent("/sdcard/f");
@ -167,7 +167,7 @@ TEST_CASE("(SD) multiple tasks can use same volume", "[fatfs][test_env=UT_T1_SDM
static void speed_test(void* buf, size_t buf_size, size_t file_size, bool write);
TEST_CASE("(SD) write/read speed test", "[fatfs][sd][test_env=UT_T1_SDMODE][timeout=60][leaks=1080]")
TEST_CASE("(SD) write/read speed test", "[fatfs][sd][test_env=UT_T1_SDMODE][timeout=60]")
{
size_t heap_size;
HEAP_SIZE_CAPTURE(heap_size);

View File

@ -70,7 +70,7 @@ TEST_CASE("(WL) can read file", "[fatfs][wear_levelling]")
test_teardown();
}
TEST_CASE("(WL) can open maximum number of files", "[fatfs][wear_levelling][leaks=2460]")
TEST_CASE("(WL) can open maximum number of files", "[fatfs][wear_levelling]")
{
size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
@ -152,14 +152,14 @@ TEST_CASE("(WL) opendir, readdir, rewinddir, seekdir work as expected", "[fatfs]
test_teardown();
}
TEST_CASE("(WL) multiple tasks can use same volume", "[fatfs][wear_levelling][leaks=1340]")
TEST_CASE("(WL) multiple tasks can use same volume", "[fatfs][wear_levelling]")
{
test_setup();
test_fatfs_concurrent("/spiflash/f");
test_teardown();
}
TEST_CASE("(WL) write/read speed test", "[fatfs][wear_levelling][timeout=60][leaks=1156]")
TEST_CASE("(WL) write/read speed test", "[fatfs][wear_levelling][timeout=60]")
{
/* Erase partition before running the test to get consistent results */
const esp_partition_t* part = get_test_data_partition();

View File

@ -25,6 +25,11 @@
*/
void esp_reent_init(struct _reent* r);
/**
* Clean up some of lazily allocated buffers in REENT structures.
*/
void esp_reent_cleanup();
/**
* Function which sets up syscall table used by newlib functions in ROM.
*

View File

@ -13,6 +13,9 @@
// limitations under the License.
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/reent.h>
#include "esp_attr.h"
@ -42,3 +45,64 @@ void IRAM_ATTR esp_reent_init(struct _reent* r)
r->__sglue._niobs = 0;
r->__sglue._iobs = NULL;
}
/* only declared in private stdio header file, local.h */
extern void __sfp_lock_acquire();
extern void __sfp_lock_release();
void esp_reent_cleanup()
{
struct _reent* r = __getreent();
/* Clean up storage used by mprec functions */
if (r->_mp) {
if (_REENT_MP_FREELIST(r)) {
for (int i = 0; i < _Kmax; ++i) {
struct _Bigint *cur, *next;
next = _REENT_MP_FREELIST(r)[i];
while (next) {
cur = next;
next = next->_next;
free(cur);
}
}
}
free(_REENT_MP_FREELIST(r));
free(_REENT_MP_RESULT(r));
}
/* Clean up "glue" (lazily-allocated FILE objects) */
struct _glue* prev = &_GLOBAL_REENT->__sglue;
for (struct _glue* cur = _GLOBAL_REENT->__sglue._next; cur != NULL;) {
if (cur->_niobs == 0) {
cur = cur->_next;
continue;
}
bool has_open_files = false;
for (int i = 0; i < cur->_niobs; ++i) {
FILE* fp = &cur->_iobs[i];
if (fp->_flags != 0) {
has_open_files = true;
break;
}
}
if (has_open_files) {
prev = cur;
cur = cur->_next;
continue;
}
struct _glue* next = cur->_next;
prev->_next = next;
free(cur);
cur = next;
}
/* Clean up various other buffers */
free(r->_mp);
r->_mp = NULL;
free(r->_r48);
r->_r48 = NULL;
free(r->_localtime_buf);
r->_localtime_buf = NULL;
free(r->_asctime_buf);
r->_asctime_buf = NULL;
}

View File

@ -531,7 +531,7 @@ TEST_CASE("can read file", "[spiffs]")
test_teardown();
}
TEST_CASE("can open maximum number of files", "[spiffs][leaks=2244]")
TEST_CASE("can open maximum number of files", "[spiffs]")
{
size_t max_files = FOPEN_MAX - 3; /* account for stdin, stdout, stderr */
esp_vfs_spiffs_conf_t conf = {
@ -602,7 +602,7 @@ TEST_CASE("readdir with large number of files", "[spiffs][timeout=30]")
test_teardown();
}
TEST_CASE("multiple tasks can use same volume", "[spiffs][leaks=1128]")
TEST_CASE("multiple tasks can use same volume", "[spiffs]")
{
test_setup();
test_spiffs_concurrent("/spiffs/f");

View File

@ -19,6 +19,7 @@
#include "freertos/task.h"
#include "unity.h"
#include "test_utils.h"
#include "esp_newlib.h"
#ifdef CONFIG_HEAP_TRACING
#include "esp_heap_trace.h"
@ -121,6 +122,9 @@ 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();
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);
/* We want the teardown to have this file in the printout if TEST_ASSERT fails */