• Home
Name Date Size #Lines LOC

..--

src/22-Mar-2025-274203

test/22-Mar-2025-529437

readme.mdD22-Mar-20252.2 KiB4328

readme.md

1# Unity Memory
2
3This Framework is an optional add-on to Unity.
4By including unity.h and then unity_memory.h, you have the added ability to track malloc and free calls.
5This addon requires that the stdlib functions be overridden by its own defines.
6These defines will still malloc / realloc / free etc, but will also track the calls in order to ensure that you don't have any memory leaks in your programs.
7
8Note that this is only useful in situations where a unit is in charge of both the allocation and deallocation of memory.
9When it is not symmetric, unit testing can report a number of false failures.
10A more advanced runtime tool is required to track complete system memory handling.
11
12## Module API
13
14### `UnityMalloc_StartTest` and `UnityMalloc_EndTest`
15
16These must be called at the beginning and end of each test.
17For simplicity, they can be added to `setUp` and `tearDown` in order to do their job.
18When using the test runner generator scripts, these will be automatically added to the runner whenever unity_memory.h is included.
19
20### `UnityMalloc_MakeMallocFailAfterCount`
21
22This can be called from the tests themselves.
23Passing this function a number will force the reference counter to start keeping track of malloc calls.
24During that test, if the number of malloc calls exceeds the number given, malloc will immediately start returning `NULL`.
25This allows you to test error conditions.
26Think of it as a simplified mock.
27
28## Configuration
29
30### `UNITY_MALLOC` and `UNITY_FREE`
31
32By default, this module tries to use the real stdlib `malloc` and `free` internally.
33If you would prefer it to use something else, like FreeRTOS's `pvPortMalloc` and `pvPortFree`, then you can use these defines to make it so.
34
35### `UNITY_EXCLUDE_STDLIB_MALLOC`
36
37If you would like this library to ignore stdlib or other heap engines completely, and manage the memory on its own, then define this. All memory will be handled internally (and at likely lower overhead).
38Note that this is not a very featureful memory manager, but is sufficient for most testing purposes.
39
40### `UNITY_INTERNAL_HEAP_SIZE_BYTES`
41
42When using the built-in memory manager (see `UNITY_EXCLUDE_STDLIB_MALLOC`) this define allows you to set the heap size this library will use to manage the memory.
43