Select one of the symbols to view example projects that use it.
 
Outline
#include <stdio.h>
#include "unity.h"
#include "unity_test_utils.h"
s_allowed_leak_level
unity_utils_set_leak_level(size_t)
unity_utils_check_leak(unsigned int, unsigned int, const char *, unsigned int)
unity_utils_evaluate_leaks()
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/unity/unity_utils_memory.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <stdio.h> #include "unity.h" #include "unity_test_utils.h" static size_t s_allowed_leak_level; void unity_utils_set_leak_level(size_t leak_level) { s_allowed_leak_level = leak_level; }{ ... } void unity_utils_check_leak(unsigned int before_free, unsigned int after_free, const char *type, unsigned int threshold) { int free_delta = (int)after_free - (int)before_free; printf("MALLOC_CAP_%s usage: Free memory delta: %d Leak threshold: -%u \n", type, free_delta, threshold); if (free_delta > 0) { return; // free memory went up somehow }{...} unsigned int leaked = (size_t)(free_delta * -1); if (leaked > 0) { printf("MALLOC_CAP_%s %s leak: Before %u bytes free, After %u bytes free (delta %u)\n", type, leaked <= threshold ? "potential" : "critical", before_free, after_free, leaked); fflush(stdout); }{...} TEST_ASSERT_MESSAGE(leaked <= threshold, "The test leaked too much memory"); }{ ... } void unity_utils_evaluate_leaks(void) { unity_utils_evaluate_leaks_direct(s_allowed_leak_level); }{ ... }
Details