mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-14 08:47:45 -04:00
Add unity memory extension, fake_assert, and enable -fsanitize=address (#506)
* Enable libunitymemory extension to track dynamic memory usage during unit tests * Use UnityMemory in timers_utest.c * Add fake_assert.h to allow mocking of configASSERT calls * Add .editorconfig to make github show indentation correctly * Add unity memory and fake_assert to queue_utest.c * Add -fsanitize=address CFLAG when running unit tests * Define mtCOVERAGE_TEST_MARKER macro to include mtCOVERAGE_TEST_MARKER lines in coverage figures * Add additional memory check / protection CFLAGS for CMock tests * Fix out of bounds array access in list_utest.c * Move the fake_assert.h include to the top of FreeRTOSConfig.h
This commit is contained in:
parent
c4d8002634
commit
570ae6bb52
11 changed files with 151 additions and 59 deletions
|
@ -36,23 +36,24 @@
|
|||
|
||||
/* Test includes. */
|
||||
#include "unity.h"
|
||||
#include "unity_memory.h"
|
||||
|
||||
/* Mock includes. */
|
||||
#include "mock_task.h"
|
||||
#include "mock_list.h"
|
||||
#include "mock_fake_assert.h"
|
||||
|
||||
/* ============================ GLOBAL VARIABLES =========================== */
|
||||
static uint16_t usMallocFreeCalls = 0;
|
||||
|
||||
/* ========================== CALLBACK FUNCTIONS =========================== */
|
||||
|
||||
void * pvPortMalloc( size_t xSize )
|
||||
{
|
||||
return malloc( xSize );
|
||||
return unity_malloc( xSize );
|
||||
}
|
||||
void vPortFree( void * pv )
|
||||
{
|
||||
return free( pv );
|
||||
return unity_free( pv );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -60,15 +61,16 @@ void vPortFree( void * pv )
|
|||
******************************************************************************/
|
||||
void setUp( void )
|
||||
{
|
||||
vFakeAssert_Ignore();
|
||||
|
||||
/* Track calls to malloc / free */
|
||||
UnityMalloc_StartTest();
|
||||
}
|
||||
|
||||
/*! called before each testcase */
|
||||
void tearDown( void )
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE( 0, usMallocFreeCalls,
|
||||
"free is not called the same number of times as malloc,"
|
||||
"you might have a memory leak!!" );
|
||||
usMallocFreeCalls = 0;
|
||||
UnityMalloc_EndTest();
|
||||
}
|
||||
|
||||
/*! called at the beginning of the whole suite */
|
||||
|
@ -92,4 +94,5 @@ void test_xQueueCreate_Success( void )
|
|||
QueueHandle_t xQueue = xQueueCreate( 1, 1 );
|
||||
|
||||
TEST_ASSERT_NOT_EQUAL( NULL, xQueue );
|
||||
vQueueDelete(xQueue);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue