|
cmocka
1.1.7
Unit testing library with mock support
|

Functions | |
| void * | test_malloc (size_t size) |
| Test function overriding malloc. | |
| void * | test_calloc (size_t nmemb, size_t size) |
| Test function overriding calloc. | |
| void * | test_realloc (void *ptr, size_t size) |
| Test function overriding realloc which detects buffer overruns and memoery leaks. | |
| void | test_free (void *ptr) |
| Test function overriding free(3). | |
Memory leaks, buffer overflows and underflows can be checked using cmocka.
To test for memory leaks, buffer overflows and underflows a module being tested by cmocka should replace calls to malloc(), calloc() and free() to test_malloc(), test_calloc() and test_free() respectively. Each time a block is deallocated using test_free() it is checked for corruption, if a corrupt block is found a test failure is signalled. All blocks allocated using the test_*() allocation functions are tracked by the cmocka library. When a test completes if any allocated blocks (memory leaks) remain they are reported and a test failure is signalled.
For simplicity cmocka currently executes all tests in one process. Therefore all test cases in a test application share a single address space which means memory corruption from a single test case could potentially cause the test application to exit prematurely.
| void * test_calloc | ( | size_t | nmemb, |
| size_t | size ) |
Test function overriding calloc.
The memory is set to zero.
| [in] | nmemb | The number of elements for an array to be allocated. |
| [in] | size | The size in bytes of each array element to allocate. |
| void test_free | ( | void * | ptr | ) |
Test function overriding free(3).
| [in] | ptr | The pointer to the memory space to free. |
| void * test_malloc | ( | size_t | size | ) |
Test function overriding malloc.
| [in] | size | The bytes which should be allocated. |
| void * test_realloc | ( | void * | ptr, |
| size_t | size ) |
Test function overriding realloc which detects buffer overruns and memoery leaks.
| [in] | ptr | The memory block which should be changed. |
| [in] | size | The bytes which should be allocated. |