Add unit tests for GetStaticBuffer functions (#964)

Add unit tests for the various ...GetStaticBuffer() functions added in
https://github.com/FreeRTOS/FreeRTOS-Kernel/pull/641.
---------

Co-authored-by: Paul Bartell <pbartell@amazon.com>
pull/973/head
Darian 2 years ago committed by GitHub
parent c8c1c12765
commit e7d31258f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,38 +123,30 @@ typedef unsigned long UBaseType_t;
/*-----------------------------------------------------------*/
#define portSAVE_CONTEXT()
#define portYIELD() vFakePortYield()
#define portYIELD_WITHIN_API() vFakePortYieldWithinAPI()
#define portYIELD_FROM_ISR() vFakePortYieldFromISR()
#define portYIELD() vFakePortYield()
#define portYIELD_WITHIN_API() vFakePortYieldWithinAPI()
#define portYIELD_FROM_ISR() vFakePortYieldFromISR()
/* Critical section handling. */
#define portDISABLE_INTERRUPTS() vFakePortDisableInterrupts()
#define portENABLE_INTERRUPTS() vFakePortEnableInterrupts()
#define portDISABLE_INTERRUPTS() vFakePortDisableInterrupts()
#define portENABLE_INTERRUPTS() vFakePortEnableInterrupts()
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) \
vFakePortClearInterruptMaskFromISR( x )
#define portSET_INTERRUPT_MASK_FROM_ISR() \
ulFakePortSetInterruptMaskFromISR()
#define portSET_INTERRUPT_MASK() ulFakePortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK( x ) vFakePortClearInterruptMask( x )
#define portSET_INTERRUPT_MASK() ulFakePortSetInterruptMask()
#define portCLEAR_INTERRUPT_MASK( x ) vFakePortClearInterruptMask( x )
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() \
vFakePortAssertIfInterruptPriorityInvalid()
#define portENTER_CRITICAL() vFakePortEnterCriticalSection()
#define portEXIT_CRITICAL() vFakePortExitCriticalSection()
#define portENTER_CRITICAL() vFakePortEnterCriticalSection()
#define portEXIT_CRITICAL() vFakePortExitCriticalSection()
#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) \
vPortCurrentTaskDying( ( pvTaskToDelete ), ( pxPendYield ) )
#define portSETUP_TCB( pxTCB ) portSetupTCB_CB( pxTCB );
#define portASSERT_IF_IN_ISR() vFakePortAssertIfISR();
static uint8_t ucPortCountLeadingZeros( uint32_t ulBitmap )
{
uint8_t ucReturn;
ucReturn = __builtin_clz( ulBitmap );
return ucReturn;
}
#define portSETUP_TCB( pxTCB ) portSetupTCB_CB( pxTCB );
#define portASSERT_IF_IN_ISR() vFakePortAssertIfISR();
#define ucPortCountLeadingZeros( ulBitmap ) ( ( uint8_t ) __builtin_clz( ulBitmap ) )
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) \
( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )

@ -37,6 +37,7 @@
/* Test includes. */
#include "unity.h"
#include "unity_memory.h"
#include "CException.h"
/* Mock includes. */
#include "mock_task.h"
@ -48,10 +49,37 @@
/* =========================== DEFINES CONSTANTS ========================== */
#define BIT_0 ( 1 << 0 )
#define BIT_2 ( 1 << 2 )
#define BIT_4 ( 1 << 4 )
#define ALL_SYNC_BITS ( BIT_0 | BIT_2 | BIT_4 )
#define BIT_0 ( 1 << 0 )
#define BIT_2 ( 1 << 2 )
#define BIT_4 ( 1 << 4 )
#define ALL_SYNC_BITS ( BIT_0 | BIT_2 | BIT_4 )
/**
* @brief CException code for when a configASSERT should be intercepted.
*/
#define configASSERT_E 0xAA101
/**
* @brief Expect a configASSERT from the function called.
* Break out of the called function when this occurs.
* @details Use this macro when the call passed in as a parameter is expected
* to cause invalid memory access.
*/
#define EXPECT_ASSERT_BREAK( call ) \
do \
{ \
shouldAbortOnAssertion = true; \
CEXCEPTION_T e = CEXCEPTION_NONE; \
Try \
{ \
call; \
TEST_FAIL_MESSAGE( "Expected Assert!" ); \
} \
Catch( e ) \
{ \
TEST_ASSERT_EQUAL( configASSERT_E, e ); \
} \
} while( 0 )
/* =========================== GLOBAL VARIABLES =========================== */
@ -64,6 +92,16 @@ static List_t * pxListTemp = &xListTemp;
static ListItem_t xListItemDummy = { 0 };
static ListItem_t * pxListItem_HasTaskBlockOnBit0 = &xListItemDummy;
/**
* @brief Global counter for the number of assertions in code.
*/
static int assertionFailed = 0;
/**
* @brief Flag which denotes if test need to abort on assertion.
*/
static BaseType_t shouldAbortOnAssertion;
/* =========================== EXTERN VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
@ -77,6 +115,22 @@ void vPortFree( void * pv )
return unity_free( pv );
}
static void vFakeAssertStub( bool x,
char * file,
int line,
int cmock_num_calls )
{
if( !x )
{
assertionFailed++;
if( shouldAbortOnAssertion == pdTRUE )
{
Throw( configASSERT_E );
}
}
}
/* ============================ Unity Fixtures ============================ */
/*! called before each testcase */
void setUp( void )
@ -91,12 +145,14 @@ void setUp( void )
pxListItem_HasTaskBlockOnBit0->xItemValue = BIT_0;
vFakeAssert_Ignore();
vFakeAssert_StubWithCallback( vFakeAssertStub );
vFakePortEnterCriticalSection_Ignore();
vFakePortExitCriticalSection_Ignore();
ulFakePortSetInterruptMaskFromISR_IgnoreAndReturn( 0U );
vFakePortClearInterruptMaskFromISR_Ignore();
vTaskSuspendAll_Ignore();
/* Track calls to malloc / free */
UnityMalloc_StartTest();
}
@ -105,6 +161,8 @@ void setUp( void )
void tearDown( void )
{
UnityMalloc_EndTest();
mock_fake_assert_Verify();
mock_fake_assert_Destroy();
}
/*! called at the beginning of the whole suite */
@ -118,6 +176,12 @@ int suiteTearDown( int numFailures )
return numFailures;
}
static void validate_and_clear_assertions( void )
{
TEST_ASSERT_EQUAL( 1, assertionFailed );
assertionFailed = 0;
}
/* =========================== Static Functions =========================== */
@ -134,7 +198,6 @@ void test_xEventGroupDynamicCreateAndDelete_Success( void )
vListInitialise_IgnoreArg_pxList();
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
/* Expectation of Function: vEventGroupDelete */
vTaskSuspendAll_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
vTaskRemoveFromUnorderedEventList_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
@ -175,7 +238,6 @@ void test_xEventGroupStaticCreate_Success( void )
vListInitialise_Ignore();
/* Expectation of Function: vEventGroupDelete */
vTaskSuspendAll_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
vTaskRemoveFromUnorderedEventList_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
@ -221,7 +283,6 @@ void test_xEventGroupSetBits_NoTaskBlockedOnBits_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -251,7 +312,6 @@ void test_xEventGroupSetBits_WithTaskBlockedOnBits_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( pxListItem_HasTaskBlockOnBit0 );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( BIT_0 );
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
@ -283,7 +343,6 @@ void test_vEventGroupSetBitsCallback_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -314,7 +373,6 @@ void test_xEventGroupGetBits_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -372,7 +430,6 @@ void test_xEventGroupClearBits_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -406,7 +463,6 @@ void test_vEventGroupClearBitsCallback_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -437,7 +493,6 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_WaitForBoth_ClearBit_Success( void
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
/* Expectation of Function: xEventGroupWaitBits */
vTaskSuspendAll_Ignore();
xTaskGetSchedulerState_IgnoreAndReturn( taskSCHEDULER_SUSPENDED );
vTaskPlaceOnUnorderedEventList_Ignore();
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -475,7 +530,6 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_NonBlock_WaitForEither_NoClear_Suc
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
/* Expectation of Function: xEventGroupWaitBits */
vTaskSuspendAll_Ignore();
xTaskGetSchedulerState_IgnoreAndReturn( taskSCHEDULER_SUSPENDED );
vTaskPlaceOnUnorderedEventList_Ignore();
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -513,7 +567,6 @@ void test_xEventGroupWaitBits_WhenBitWasSet_WaitForEither_NoClear_Success( void
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -557,7 +610,6 @@ void test_xEventGroupWaitBits_WhenBitWasSet_WaitForBoth_WithClear_Success( void
/* Expectation of Function: xEventGroupSetBits x2 */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
@ -607,7 +659,6 @@ void test_xEventGroupSync_SetBits_BlockWait_NotSynced_Success( void )
/* Expectation of Function: xEventGroupSetBits */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
xTaskResumeAll_IgnoreAndReturn( 1 );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
@ -644,7 +695,6 @@ void test_xEventGroupSync_NoSetBit_NonBlockWait_NotSynced_Success( void )
/* Expectation of Function: xEventGroupSetBits x2 */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
xTaskResumeAll_IgnoreAndReturn( 1 );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
@ -685,7 +735,6 @@ void test_xEventGroupSync_SetBits_BlockWait_Synced_Success( void )
/* Expectation of Function: xEventGroupSetBits x2 */
listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
vTaskSuspendAll_Ignore();
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
xTaskResumeAll_IgnoreAndReturn( 1 );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
@ -791,3 +840,104 @@ void test_xEventGroupSetBitsFromISR_Success( void )
/* API to Test */
( void ) xEventGroupSetBitsFromISR( NULL, BIT_0, &xHigherPriorityTaskWoken );
}
/*!
* @brief validate xEventGroupGetStaticBuffer with a null xEventGroup argument.
* @details Test that xEventGroupGetStaticBuffer asserts when xEventGroupGetStaticBuffer is called with a null EventGroupHandle_t
* @coverage xEventGroupGetStaticBuffer
*/
void test_xEventGroupGetStaticBuffer_null_xEventGroup( void )
{
StaticEventGroup_t * pxEventGroupBufferRet = NULL;
EXPECT_ASSERT_BREAK( xEventGroupGetStaticBuffer( NULL, &pxEventGroupBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pxEventGroupBufferRet );
}
/*!
* @brief validate xEventGroupGetStaticBuffer with a null ppxEventGroupBuffer argument.
* @details Test that xEventGroupGetStaticBuffer asserts when xEventGroupGetStaticBuffer is called with a null ppxEventGroupBuffer argument.
* @coverage xEventGroupGetStaticBuffer
*/
void test_xEventGroupGetStaticBuffer_null_ppxEventGroupBuffer( void )
{
EventGroupHandle_t xEventGroupHandle = NULL;
StaticEventGroup_t xCreatedEventGroup = { 0 };
/* Expectation of Function: xEventGroupCreate */
vListInitialise_Expect( 0 );
vListInitialise_IgnoreArg_pxList();
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
EXPECT_ASSERT_BREAK( xEventGroupGetStaticBuffer( xEventGroupHandle, NULL ) );
/* Expectation of Function: vEventGroupDelete */
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
vTaskRemoveFromUnorderedEventList_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
vEventGroupDelete( xEventGroupHandle );
}
/*!
* @brief validate xEventGroupGetStaticBuffer on a statically created event group
* @details Test xEventGroupGetStaticBuffer returns the buffer of a statically created event group
* @coverage xEventGroupGetStaticBuffer
*/
void test_xEventGroupGetStaticBuffer_static( void )
{
EventGroupHandle_t xEventGroupHandle = NULL;
StaticEventGroup_t xCreatedEventGroup = { 0 };
StaticEventGroup_t * pxEventGroupBufferRet = NULL;
/* Expectation of Function: xEventGroupCreate */
vListInitialise_Expect( 0 );
vListInitialise_IgnoreArg_pxList();
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
TEST_ASSERT_EQUAL( pdTRUE, xEventGroupGetStaticBuffer( xEventGroupHandle, &pxEventGroupBufferRet ) );
TEST_ASSERT_EQUAL( &xCreatedEventGroup, pxEventGroupBufferRet );
/* Expectation of Function: vEventGroupDelete */
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
vTaskRemoveFromUnorderedEventList_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
vEventGroupDelete( xEventGroupHandle );
}
/*!
* @brief validate xEventGroupGetStaticBuffer on a dynamically created event group
* @details Test xEventGroupGetStaticBuffer returns an error when called on a dynamically created event group
* @coverage xEventGroupGetStaticBuffer
*/
void test_xEventGroupGetStaticBuffer_dynamic( void )
{
EventGroupHandle_t xEventGroupHandle = NULL;
StaticEventGroup_t * pxEventGroupBufferRet = NULL;
/* Expectation of Function: xEventGroupCreate */
vListInitialise_Expect( 0 );
vListInitialise_IgnoreArg_pxList();
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
xEventGroupHandle = xEventGroupCreate();
TEST_ASSERT_EQUAL( pdFALSE, xEventGroupGetStaticBuffer( xEventGroupHandle, &pxEventGroupBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pxEventGroupBufferRet );
/* Expectation of Function: vEventGroupDelete */
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
vTaskRemoveFromUnorderedEventList_Ignore();
listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
xTaskResumeAll_IgnoreAndReturn( 1 );
vEventGroupDelete( xEventGroupHandle );
}

@ -798,3 +798,110 @@ void test_xMessageBufferReceiveFromISR_success( void )
vStreamBufferDelete( xMessageBuffer );
}
/**
* @brief validate xMessageBufferGetStaticBuffers with a null xMessageBuffer argument
* @details Test that xMessageBufferGetStaticBuffers asserts when a null MessageBufferHandle_t is given.
*/
void test_xMessageBufferGetStaticBuffers_null_xMessageBuffer( void )
{
uint8_t * pucMessageBufferStorageAreaRet = NULL;
StaticMessageBuffer_t * pxStaticMessageBuffer = NULL;
EXPECT_ASSERT_BREAK( xMessageBufferGetStaticBuffers( NULL, &pucMessageBufferStorageAreaRet, &pxStaticMessageBuffer ) );
validate_and_clear_assertions();
/* Check that pucMessageBufferStorageAreaRet and pxStaticMessageBuffer have not been modified */
TEST_ASSERT_EQUAL( NULL, pucMessageBufferStorageAreaRet );
TEST_ASSERT_EQUAL( NULL, pxStaticMessageBuffer );
}
/**
* @brief validate xMessageBufferGetStaticBuffers with a null ppxStaticMessageBuffer argument
* @details Test that xMessageBufferGetStaticBuffers asserts when a null ppxStaticMessageBuffer is given.
*/
void test_xMessageBufferGetStaticBuffers_null_ppxStaticMessageBuffer( void )
{
MessageBufferHandle_t xMessageBuffer = NULL;
StaticMessageBuffer_t messageBufferStruct;
uint8_t messageBufferArray[ TEST_MESSAGE_BUFFER_SIZE + 1 ] = { 0 };
uint8_t * pucMessageBufferStorageAreaRet = NULL;
xMessageBuffer = xMessageBufferCreateStatic( sizeof( messageBufferArray ), messageBufferArray, &messageBufferStruct );
EXPECT_ASSERT_BREAK( xMessageBufferGetStaticBuffers( xMessageBuffer, &pucMessageBufferStorageAreaRet, NULL ) );
validate_and_clear_assertions();
/* Check that pucMessageBufferStorageAreaRet has not been modified */
TEST_ASSERT_EQUAL( NULL, pucMessageBufferStorageAreaRet );
vMessageBufferDelete( xMessageBuffer );
}
/**
* @brief validate xMessageBufferGetStaticBuffers with a null ppucMessageBufferStorageArea argument
* @details Test that xMessageBufferGetStaticBuffers asserts when a null ppucMessageBufferStorageArea is given.
*/
void test_xMessageBufferGetStaticBuffers_null_ppucMessageBufferStorageArea( void )
{
MessageBufferHandle_t xMessageBuffer = NULL;
StaticMessageBuffer_t messageBufferStruct;
uint8_t messageBufferArray[ TEST_MESSAGE_BUFFER_SIZE + 1 ] = { 0 };
StaticMessageBuffer_t * pxStaticMessageBuffer = NULL;
xMessageBuffer = xMessageBufferCreateStatic( sizeof( messageBufferArray ), messageBufferArray, &messageBufferStruct );
EXPECT_ASSERT_BREAK( xMessageBufferGetStaticBuffers( xMessageBuffer, NULL, &pxStaticMessageBuffer ) );
validate_and_clear_assertions();
/* Check that pxStaticMessageBuffer has not been modified */
TEST_ASSERT_EQUAL( NULL, pxStaticMessageBuffer );
vMessageBufferDelete( xMessageBuffer );
}
/**
* @brief validate xMessageBufferGetStaticBuffers on a statically created message buffer
* @details Test xMessageBufferGetStaticBuffers returns the buffers of a statically created message buffer
*/
void test_xMessageBufferGetStaticBuffers_static( void )
{
MessageBufferHandle_t xMessageBuffer = NULL;
StaticMessageBuffer_t messageBufferStruct;
uint8_t messageBufferArray[ TEST_MESSAGE_BUFFER_SIZE + 1 ] = { 0 };
uint8_t * pucMessageBufferStorageAreaRet = NULL;
StaticMessageBuffer_t * pxStaticMessageBuffer = NULL;
xMessageBuffer = xMessageBufferCreateStatic( sizeof( messageBufferArray ), messageBufferArray, &messageBufferStruct );
TEST_ASSERT_EQUAL( pdTRUE, xMessageBufferGetStaticBuffers( xMessageBuffer, &pucMessageBufferStorageAreaRet, &pxStaticMessageBuffer ) );
TEST_ASSERT_EQUAL( messageBufferArray, pucMessageBufferStorageAreaRet );
TEST_ASSERT_EQUAL( &messageBufferStruct, pxStaticMessageBuffer );
vMessageBufferDelete( xMessageBuffer );
}
/**
* @brief validate xMessageBufferGetStaticBuffers on a dynamically created message buffer
* @details Test xMessageBufferGetStaticBuffers returns an error when called on a dynamically created message buffer
*/
void test_xMessageBufferGetStaticBuffers_dynamic( void )
{
MessageBufferHandle_t xMessageBuffer = NULL;
uint8_t * pucMessageBufferStorageAreaRet = NULL;
StaticMessageBuffer_t * pxStaticMessageBuffer = NULL;
xMessageBuffer = xMessageBufferCreate( TEST_MESSAGE_BUFFER_SIZE );
TEST_ASSERT_EQUAL( pdFALSE, xMessageBufferGetStaticBuffers( xMessageBuffer, &pucMessageBufferStorageAreaRet, &pxStaticMessageBuffer ) );
TEST_ASSERT_EQUAL( NULL, pucMessageBufferStorageAreaRet );
TEST_ASSERT_EQUAL( NULL, pxStaticMessageBuffer );
vMessageBufferDelete( xMessageBuffer );
}

@ -26,6 +26,7 @@ SUITE_UT_SRC += queue_receive_blocking_utest.c
SUITE_UT_SRC += queue_send_nonblocking_utest.c
SUITE_UT_SRC += queue_send_blocking_utest.c
SUITE_UT_SRC += queue_status_utest.c
SUITE_UT_SRC += queue_get_static_buffers_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR

@ -0,0 +1,159 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*! @file queue_status_utest.c */
/* C runtime includes. */
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "queue.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* ========================== Helper functions =========================== */
/* ============================= Test Cases ============================== */
/**
* @brief Test xQueueGetStaticBuffers with an invalid QueueHandle
* @coverage xQueueGetStaticBuffers xQueueGenericGetStaticBuffers
*/
void test_macro_xQueueGetStaticBuffers_invalid_handle( void )
{
uint8_t * pucQueueStorageRet = NULL;
StaticQueue_t * pxStaticQueueRet = NULL;
EXPECT_ASSERT_BREAK( xQueueGetStaticBuffers( NULL, &pucQueueStorageRet, &pxStaticQueueRet ) );
TEST_ASSERT_EQUAL( NULL, pucQueueStorageRet );
TEST_ASSERT_EQUAL( NULL, pxStaticQueueRet );
}
/**
* @brief Test xQueueGetStaticBuffers with a null ppxStaticQueue argument
* @coverage xQueueGetStaticBuffers xQueueGenericGetStaticBuffers
*/
void test_macro_xQueueGetStaticBuffers_null_ppxStaticQueue( void )
{
uint32_t queueStorage[ 5 ];
StaticQueue_t queueBuffer;
uint8_t * pucQueueStorageRet = NULL;
StaticQueue_t * pxStaticQueueRet = NULL;
QueueHandle_t xQueue = xQueueCreateStatic( 5, sizeof( uint32_t ), ( void * ) queueStorage, &queueBuffer );
EXPECT_ASSERT_BREAK( xQueueGetStaticBuffers( xQueue, &pucQueueStorageRet, NULL ) );
TEST_ASSERT_EQUAL( NULL, pucQueueStorageRet );
TEST_ASSERT_EQUAL( NULL, pxStaticQueueRet );
}
/**
* @brief Test xQueueGetStaticBuffers with a null ppucQueueStorage argument
* @coverage xQueueGetStaticBuffers xQueueGenericGetStaticBuffers
*/
void test_macro_xQueueGetStaticBuffers_null_ppucQueueStorage( void )
{
uint32_t queueStorage[ 5 ];
StaticQueue_t queueBuffer;
StaticQueue_t * pxStaticQueueRet = NULL;
QueueHandle_t xQueue = xQueueCreateStatic( 5, sizeof( uint32_t ), ( void * ) queueStorage, &queueBuffer );
TEST_ASSERT_EQUAL( pdTRUE, xQueueGetStaticBuffers( xQueue, NULL, &pxStaticQueueRet ) );
TEST_ASSERT_EQUAL( &queueBuffer, pxStaticQueueRet );
}
/**
* @brief xQueueGetStaticBuffers with a statically allocated queue.
* @details Test xQueueGetStaticBuffers returns the buffers of a statically allocated queue
* @coverage xQueueGetStaticBuffers xQueueGenericGetStaticBuffers
*/
void test_macro_xQueueGetStaticBuffers_static( void )
{
uint32_t queueStorage[ 5 ];
StaticQueue_t queueBuffer;
uint8_t * pucQueueStorageRet = NULL;
StaticQueue_t * pxStaticQueueRet = NULL;
QueueHandle_t xQueue = xQueueCreateStatic( 5, sizeof( uint32_t ), ( void * ) queueStorage, &queueBuffer );
TEST_ASSERT_EQUAL( pdTRUE, xQueueGetStaticBuffers( xQueue, &pucQueueStorageRet, &pxStaticQueueRet ) );
TEST_ASSERT_EQUAL( queueStorage, ( uint32_t * ) pucQueueStorageRet );
TEST_ASSERT_EQUAL( &queueBuffer, pxStaticQueueRet );
vQueueDelete( xQueue );
}
/**
* @brief xQueueGetStaticBuffers with a dynamically allocated queue.
* @details Test xQueueGetStaticBuffers returns an error when called on a dynamically allocated queue.
* @coverage xQueueGetStaticBuffers xQueueGenericGetStaticBuffers
*/
void test_macro_xQueueGetStaticBuffers_dynamic( void )
{
#if configSUPPORT_DYNAMIC_ALLOCATION == 1
uint8_t * pucQueueStorageRet = NULL;
StaticQueue_t * pxStaticQueueRet = NULL;
QueueHandle_t xQueue = xQueueCreate( 5, sizeof( uint32_t ) );
TEST_ASSERT_EQUAL( pdFALSE, xQueueGetStaticBuffers( xQueue, &pucQueueStorageRet, &pxStaticQueueRet ) );
TEST_ASSERT_EQUAL( NULL, pucQueueStorageRet );
TEST_ASSERT_EQUAL( NULL, pxStaticQueueRet );
vQueueDelete( xQueue );
#endif /* configSUPPORT_DYNAMIC_ALLOCATION == 1 */
}

@ -22,6 +22,7 @@ SUITE_UT_SRC += counting_semaphore_utest.c
SUITE_UT_SRC += semaphore_common_utest.c
SUITE_UT_SRC += mutex_utest.c
SUITE_UT_SRC += recursive_mutex_utest.c
SUITE_UT_SRC += semaphore_get_static_buffer_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR

@ -0,0 +1,130 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*! @file semaphore_common_utest.c */
#include "../queue_utest_common.h"
/* Queue includes */
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
/* ============================ GLOBAL VARIABLES =========================== */
/* ========================== CALLBACK FUNCTIONS =========================== */
/* ============================= Unity Fixtures ============================= */
void setUp( void )
{
commonSetUp();
}
void tearDown( void )
{
commonTearDown();
}
void suiteSetUp()
{
commonSuiteSetUp();
}
int suiteTearDown( int numFailures )
{
return commonSuiteTearDown( numFailures );
}
/* =========================== Helper functions ============================ */
/* ============================== Test Cases =============================== */
/**
* @brief Test xSemaphoreGetStaticBuffer with an invalid SemaphoreHandle
* @coverage xSemaphoreGetStaticBuffer xQueueGenericGetStaticBuffers
*/
void test_macro_xSemaphoreGetStaticBuffer_null_handle( void )
{
StaticSemaphore_t * pxSemaphoreBufferRet = NULL;
EXPECT_ASSERT_BREAK( xSemaphoreGetStaticBuffer( NULL, &pxSemaphoreBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pxSemaphoreBufferRet );
}
/**
* @brief Test xSemaphoreGetStaticBuffer with a null ppxSemaphoreBuffer argument
* @coverage xSemaphoreGetStaticBuffer xQueueGenericGetStaticBuffers
*/
void test_macro_xSemaphoreGetStaticBuffer_null_ppxSemaphoreBuffer( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
EXPECT_ASSERT_BREAK( xSemaphoreGetStaticBuffer( xSemaphore, NULL ) );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetStaticBuffer with a static Semaphore
* @details Test that xSemaphoreGetStaticBuffer returns the buffer of a statically allocated Semaphore
* @coverage xSemaphoreGetStaticBuffer xQueueGenericGetStaticBuffers
*/
void test_macro_xSemaphoreGetStaticBuffer_static( void )
{
SemaphoreHandle_t xSemaphore = NULL;
StaticSemaphore_t xSemaphoreBuffer;
StaticSemaphore_t * pxSemaphoreBufferRet = NULL;
xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
TEST_ASSERT_EQUAL( pdTRUE, xSemaphoreGetStaticBuffer( xSemaphore, &pxSemaphoreBufferRet ) );
TEST_ASSERT_EQUAL( &xSemaphoreBuffer, pxSemaphoreBufferRet );
vSemaphoreDelete( xSemaphore );
}
/**
* @brief Test xSemaphoreGetStaticBuffer with a dynamic Semaphore
* @details Test that xSemaphoreGetStaticBuffer returns an error when called on a dynamically allocated Semaphore
* @coverage xSemaphoreGetStaticBuffer xQueueGenericGetStaticBuffers
*/
void test_macro_xSemaphoreGetStaticBuffer_dynamic( void )
{
#if configSUPPORT_DYNAMIC_ALLOCATION == 1
StaticSemaphore_t * pxSemaphoreBufferRet = NULL;
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
TEST_ASSERT_EQUAL( pdFALSE, xSemaphoreGetStaticBuffer( xSemaphore, &pxSemaphoreBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pxSemaphoreBufferRet );
vSemaphoreDelete( xSemaphore );
#endif /* configSUPPORT_DYNAMIC_ALLOCATION == 1 */
}

@ -18,6 +18,7 @@ PROJECT_HEADER_DEPS += FreeRTOS.h
# SUITE_UT_SRC: .c files that contain test cases (must end in _utest.c)
SUITE_UT_SRC += queue_create_static_utest.c
SUITE_UT_SRC += queue_delete_static_utest.c
SUITE_UT_SRC += queue_get_static_buffers_utest.c
# SUITE_SUPPORT_SRC: .c files used for testing that do not contain test cases.
# Paths are relative to PROJECT_DIR

@ -0,0 +1 @@
../generic/queue_get_static_buffers_utest.c

@ -1455,3 +1455,115 @@ void test_xStreamBufferSend_WrapOver( void )
vStreamBufferDelete( xStreamBuffer );
}
/**
* @brief validate xStreamBufferGetStaticBuffers with a null xStreamBuffer argument
* @details Test that xStreamBufferGetStaticBuffers asserts when a null StreamBufferHandle_t is given.
*/
void test_xStreamBufferGetStaticBuffers_null_xStreamBuffer( void )
{
uint8_t * pucStreamBufferStorageAreaRet = NULL;
StaticStreamBuffer_t * pxStaticStreamBufferRet = NULL;
EXPECT_ASSERT_BREAK( xStreamBufferGetStaticBuffers( NULL, &pucStreamBufferStorageAreaRet, &pxStaticStreamBufferRet ) );
validate_and_clear_assertions();
/* Assert that pucStreamBufferStorageAreaRet and pxStaticStreamBufferRet were not modified */
TEST_ASSERT_EQUAL( NULL, pucStreamBufferStorageAreaRet );
TEST_ASSERT_EQUAL( NULL, pxStaticStreamBufferRet );
}
/**
* @brief Test xStreamBufferGetStaticBuffers with a null ppxStaticStreamBuffer argument
* @details Test that xStreamBufferGetStaticBuffers asserts when a null ppxStaticStreamBuffer is given.
*/
void test_xStreamBufferGetStaticBuffers_null_ppxStaticStreamBuffer( void )
{
StreamBufferHandle_t xStreamBuffer = NULL;
StaticStreamBuffer_t streamBufferStruct;
/* The size of stream buffer array should be one greater than the required size of stream buffer. */
uint8_t streamBufferArray[ TEST_STREAM_BUFFER_SIZE + 1 ] = { 0 };
uint8_t * pucStreamBufferStorageAreaRet = NULL;
xStreamBuffer = xStreamBufferCreateStatic( sizeof( streamBufferArray ), TEST_STREAM_BUFFER_TRIGGER_LEVEL, streamBufferArray, &streamBufferStruct );
EXPECT_ASSERT_BREAK( xStreamBufferGetStaticBuffers( xStreamBuffer, &pucStreamBufferStorageAreaRet, NULL ) );
validate_and_clear_assertions();
/* Assert that pucStreamBufferStorageAreaRet was not modified */
TEST_ASSERT_EQUAL( NULL, pucStreamBufferStorageAreaRet );
vStreamBufferDelete( xStreamBuffer );
}
/**
* @brief Test xStreamBufferGetStaticBuffers with a null ppucStreamBufferStorageArea argument
* @details Test that xStreamBufferGetStaticBuffers asserts when a null ppucStreamBufferStorageArea is given.
*/
void test_xStreamBufferGetStaticBuffers_null_ppucStreamBufferStorageArea( void )
{
StreamBufferHandle_t xStreamBuffer = NULL;
StaticStreamBuffer_t streamBufferStruct;
/* The size of stream buffer array should be one greater than the required size of stream buffer. */
uint8_t streamBufferArray[ TEST_STREAM_BUFFER_SIZE + 1 ] = { 0 };
StaticStreamBuffer_t * pxStaticStreamBufferRet = NULL;
xStreamBuffer = xStreamBufferCreateStatic( sizeof( streamBufferArray ), TEST_STREAM_BUFFER_TRIGGER_LEVEL, streamBufferArray, &streamBufferStruct );
EXPECT_ASSERT_BREAK( xStreamBufferGetStaticBuffers( xStreamBuffer, NULL, &pxStaticStreamBufferRet ) );
validate_and_clear_assertions();
/* Assert that pxStaticStreamBufferRet was not modified */
TEST_ASSERT_EQUAL( NULL, pxStaticStreamBufferRet );
vStreamBufferDelete( xStreamBuffer );
}
/**
* @brief validate xStreamBufferGetStaticBuffers on a statically created stream buffer
* @details Test xStreamBufferGetStaticBuffers returns the buffers of a statically created stream buffer
*/
void test_xStreamBufferGetStaticBuffers_static( void )
{
StreamBufferHandle_t xStreamBuffer = NULL;
StaticStreamBuffer_t streamBufferStruct;
/* The size of stream buffer array should be one greater than the required size of stream buffer. */
uint8_t streamBufferArray[ TEST_STREAM_BUFFER_SIZE + 1 ] = { 0 };
uint8_t * pucStreamBufferStorageAreaRet = NULL;
StaticStreamBuffer_t * pxStaticStreamBufferRet = NULL;
xStreamBuffer = xStreamBufferCreateStatic( sizeof( streamBufferArray ), TEST_STREAM_BUFFER_TRIGGER_LEVEL, streamBufferArray, &streamBufferStruct );
TEST_ASSERT_EQUAL( pdTRUE, xStreamBufferGetStaticBuffers( xStreamBuffer, &pucStreamBufferStorageAreaRet, &pxStaticStreamBufferRet ) );
TEST_ASSERT_EQUAL( streamBufferArray, pucStreamBufferStorageAreaRet );
TEST_ASSERT_EQUAL( &streamBufferStruct, pxStaticStreamBufferRet );
vStreamBufferDelete( xStreamBuffer );
}
/**
* @brief validate xStreamBufferGetStaticBuffers on a dynamically created stream buffer
* @details Test xStreamBufferGetStaticBuffers returns an error when called on a dynamically created stream buffer
*/
void test_xStreamBufferGetStaticBuffers_dynamic( void )
{
StreamBufferHandle_t xStreamBuffer = NULL;
uint8_t * pucStreamBufferStorageAreaRet = NULL;
StaticStreamBuffer_t * pxStaticStreamBufferRet = NULL;
xStreamBuffer = xStreamBufferCreate( TEST_STREAM_BUFFER_SIZE, TEST_STREAM_BUFFER_TRIGGER_LEVEL );
TEST_ASSERT_NOT_EQUAL( NULL, xStreamBuffer );
TEST_ASSERT_EQUAL( pdFALSE, xStreamBufferGetStaticBuffers( xStreamBuffer, &pucStreamBufferStorageAreaRet, &pxStaticStreamBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pucStreamBufferStorageAreaRet );
TEST_ASSERT_EQUAL( NULL, pxStaticStreamBufferRet );
vStreamBufferDelete( xStreamBuffer );
}

@ -71,22 +71,11 @@ typedef struct tskTaskControlBlock /* The old naming convention is used to
#endif
#if ( configGENERATE_RUN_TIME_STATS == 1 )
uint32_t ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
configRUN_TIME_COUNTER_TYPE ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */
#endif
#if ( configUSE_NEWLIB_REENTRANT == 1 )
/* Allocate a Newlib reent structure that is specific to this task.
* Note Newlib support has been included by popular demand, but is not
* used by the FreeRTOS maintainers themselves. FreeRTOS is not
* responsible for resulting newlib operation. User must be familiar with
* newlib and must provide system-wide implementations of the necessary
* stubs. Be warned that (at the time of writing) the current newlib design
* implements a system-wide malloc() that must be provided with locks.
*
* See the third party link http://www.nadler.com/embedded/newlibAndFreeRTOS.html
* for additional information. */
struct _reent xNewLib_reent;
#if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 )
configTLS_BLOCK_TYPE xTLSBlock; /**< Memory block used as Thread Local Storage (TLS) Block for the task. */
#endif
#if ( configUSE_TASK_NOTIFICATIONS == 1 )

@ -5440,3 +5440,212 @@ void test_ulTaskGenericNotifyValueClear_success_null_handle()
TEST_ASSERT_EQUAL( 2, task_to_notify->ulNotifiedValue[ uxIndexToClear ] );
}
/* ---------- end testing configUSE_TASK_NOTIFICATIONS --------------- */
/* ---------------------- testing xTaskGetStaticBuffers ----------------------*/
/**
* @brief Test xTaskGetStaticBuffers with a static task
* @details Test xTaskGetStaticBuffers returns the buffers of a statically allocated task
* @coverage xTaskGetStaticBuffers
*/
void test_xTaskGetStaticBuffers_static_task( void )
{
StackType_t puxStackBuffer[ 300 ];
StaticTask_t * pxTaskBuffer = malloc( sizeof( TCB_t ) );
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t ulStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t xTaskHandle = NULL;
StackType_t * puxStackBufferRet = NULL;
StaticTask_t * pxTaskBufferRet = NULL;
memset( puxStackBuffer, 0xa5U, ulStackDepth * sizeof( StackType_t ) );
vListInitialiseItem_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
/* set owner */
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
/* set owner */
pxPortInitialiseStack_ExpectAnyArgsAndReturn( puxStackBuffer );
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
listINSERT_END_ExpectAnyArgs();
xTaskHandle = xTaskCreateStatic( pxTaskCode,
pcName,
ulStackDepth,
pvParameters,
uxPriority,
puxStackBuffer,
pxTaskBuffer );
TEST_ASSERT_EQUAL( pdTRUE, xTaskGetStaticBuffers( xTaskHandle, &puxStackBufferRet, &pxTaskBufferRet ) );
TEST_ASSERT_EQUAL( &puxStackBuffer, puxStackBufferRet );
TEST_ASSERT_EQUAL( pxTaskBuffer, pxTaskBufferRet );
free( pxTaskBuffer );
}
/**
* @brief Test xTaskGetStaticBuffers with a dynamically allocated TCB but a statically allocated stack.
* @details Test xTaskGetStaticBuffers returns the buffers of a statically allocated task
* @coverage xTaskGetStaticBuffers
*/
void test_xTaskGetStaticBuffers_static_stack_dynamic_tcb( void )
{
StackType_t puxStackBuffer[ 300 ];
StaticTask_t * pxTaskBuffer = malloc( sizeof( TCB_t ) );
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t ulStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t xTaskHandle = NULL;
StackType_t * puxStackBufferRet = NULL;
StaticTask_t * pxTaskBufferRet = NULL;
memset( puxStackBuffer, 0xa5U, ulStackDepth * sizeof( StackType_t ) );
vListInitialiseItem_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
/* set owner */
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
/* set owner */
pxPortInitialiseStack_ExpectAnyArgsAndReturn( puxStackBuffer );
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
listINSERT_END_ExpectAnyArgs();
xTaskHandle = xTaskCreateStatic( pxTaskCode,
pcName,
ulStackDepth,
pvParameters,
uxPriority,
puxStackBuffer,
pxTaskBuffer );
/* Workaround since the portUSING_MPU_WRAPPERS == 1 config is not tested */
( ( TCB_t * ) xTaskHandle )->ucStaticallyAllocated = 1;
TEST_ASSERT_EQUAL( pdTRUE, xTaskGetStaticBuffers( xTaskHandle, &puxStackBufferRet, &pxTaskBufferRet ) );
TEST_ASSERT_EQUAL( &puxStackBuffer, puxStackBufferRet );
TEST_ASSERT_EQUAL( NULL, pxTaskBufferRet );
free( pxTaskBuffer );
}
/**
* @brief Test xTaskGetStaticBuffers with a static task as the current task and a null task handle argument.
* @details Test xTaskGetStaticBuffers returns the buffers of a statically allocated task
* @coverage xTaskGetStaticBuffers
*/
void test_xTaskGetStaticBuffers_static_task_null_handle( void )
{
StackType_t puxStackBuffer[ 300 ];
StaticTask_t * pxTaskBuffer = malloc( sizeof( TCB_t ) );
TaskFunction_t pxTaskCode = NULL;
const char * const pcName = { __FUNCTION__ };
const uint32_t ulStackDepth = 300;
void * const pvParameters = NULL;
UBaseType_t uxPriority = 3;
TaskHandle_t xTaskHandle = NULL;
StackType_t * puxStackBufferRet = NULL;
StaticTask_t * pxTaskBufferRet = NULL;
memset( puxStackBuffer, 0xa5U, ulStackDepth * sizeof( StackType_t ) );
vListInitialiseItem_ExpectAnyArgs();
vListInitialiseItem_ExpectAnyArgs();
/* set owner */
listSET_LIST_ITEM_VALUE_ExpectAnyArgs();
/* set owner */
pxPortInitialiseStack_ExpectAnyArgsAndReturn( puxStackBuffer );
for( int i = ( UBaseType_t ) 0U; i < ( UBaseType_t ) configMAX_PRIORITIES; i++ )
{
vListInitialise_ExpectAnyArgs();
}
/* Delayed Task List 1 */
vListInitialise_ExpectAnyArgs();
/* Delayed Task List 2 */
vListInitialise_ExpectAnyArgs();
/* Pending Ready List */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskDelete */
vListInitialise_ExpectAnyArgs();
/* INCLUDE_vTaskSuspend */
vListInitialise_ExpectAnyArgs();
listINSERT_END_ExpectAnyArgs();
xTaskHandle = xTaskCreateStatic( pxTaskCode,
pcName,
ulStackDepth,
pvParameters,
uxPriority,
puxStackBuffer,
pxTaskBuffer );
pxCurrentTCB = ( TCB_t * ) xTaskHandle;
TEST_ASSERT_EQUAL( pdTRUE, xTaskGetStaticBuffers( NULL, &puxStackBufferRet, &pxTaskBufferRet ) );
TEST_ASSERT_EQUAL( &puxStackBuffer, puxStackBufferRet );
TEST_ASSERT_EQUAL( pxTaskBuffer, pxTaskBufferRet );
free( pxTaskBuffer );
}
/**
* @brief Test xTaskGetStaticBuffers with a dynamic task
* @details Test xTaskGetStaticBuffers returns an error when called on a dynamically allocated task
* @coverage xTaskGetStaticBuffers
*/
void test_xTaskGetStaticBuffers_dynamic_task( void )
{
StackType_t * puxStackBufferRet = NULL;
StaticTask_t * pxTaskBufferRet = NULL;
TaskHandle_t taskHandle = create_task();
TEST_ASSERT_EQUAL( pdFALSE, xTaskGetStaticBuffers( taskHandle, &puxStackBufferRet, &pxTaskBufferRet ) );
TEST_ASSERT_EQUAL( NULL, puxStackBufferRet );
TEST_ASSERT_EQUAL( NULL, pxTaskBufferRet );
}
/* -------------------- end testing xTaskGetStaticBuffers --------------------*/

@ -72,7 +72,7 @@
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 5
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */

@ -1784,3 +1784,63 @@ void test_timer_function_success_wrap_timer( void )
/* Validations */
TEST_ASSERT_EQUAL( 1, *retVal );
}
void test_xTimerGetStaticBuffer_static( void )
{
TimerHandle_t ret_timer_create;
UBaseType_t pvTimerID;
StaticTimer_t pxTimerBuffer[ sizeof( StaticTimer_t ) ];
StaticTimer_t * pxTimerBufferRet = NULL;
/* Setup */
/* Expectations */
/* prvInitialiseNewTimer */
/* prvCheckForValidListAndQueue */
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreateStatic_ExpectAnyArgsAndReturn( NULL );
/* Back prvInitialiseNewTimer */
vListInitialiseItem_ExpectAnyArgs();
/* API Call */
ret_timer_create = xTimerCreateStatic( "ut_timer_task",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
( void * ) &pvTimerID,
xCallback_Test,
pxTimerBuffer );
TEST_ASSERT_EQUAL( pdTRUE, xTimerGetStaticBuffer( ret_timer_create, &pxTimerBufferRet ) );
TEST_ASSERT_EQUAL( pxTimerBuffer, pxTimerBufferRet );
}
void test_xTimerGetStaticBuffer_dynamic( void )
{
TimerHandle_t xTimer = NULL;
UBaseType_t pvTimerID = 0;
Timer_t pxNewTimer = { 0 };
StaticTimer_t * pxTimerBufferRet = NULL;
pvPortMalloc_ExpectAndReturn( sizeof( Timer_t ), &pxNewTimer );
/* Setup */
/* Expectations */
/* prvInitialiseNewTimer */
/* prvCheckForValidListAndQueue */
vListInitialise_ExpectAnyArgs();
vListInitialise_ExpectAnyArgs();
xQueueGenericCreateStatic_ExpectAnyArgsAndReturn( NULL );
/* Back prvInitialiseNewTimer */
vListInitialiseItem_ExpectAnyArgs();
/* API Call */
xTimer = xTimerCreate( "ut_timer_task",
pdMS_TO_TICKS( 1000 ),
pdTRUE,
( void * ) &pvTimerID,
xCallback_Test );
TEST_ASSERT_EQUAL( pdFALSE, xTimerGetStaticBuffer( xTimer, &pxTimerBufferRet ) );
TEST_ASSERT_EQUAL( NULL, pxTimerBufferRet );
}

Loading…
Cancel
Save