From 9a16fd3c553c2a643e344ef55fe31f57504709e2 Mon Sep 17 00:00:00 2001 From: Van Date: Fri, 23 Jun 2023 15:21:44 -0400 Subject: [PATCH] Fix #1930, add code coverage for null check Fix #1930, add code coverage for null check in es. Add CFE_ES_GenPoolCreatePoolBlock and CFE_ES_GenPoolRecyclePoolBlock to header file --- modules/es/fsw/src/cfe_es_generic_pool.h | 33 ++++++++++++++++++++++++ modules/es/ut-coverage/es_UT.c | 10 +++++++ 2 files changed, 43 insertions(+) diff --git a/modules/es/fsw/src/cfe_es_generic_pool.h b/modules/es/fsw/src/cfe_es_generic_pool.h index 81fae514b..f564bb593 100644 --- a/modules/es/fsw/src/cfe_es_generic_pool.h +++ b/modules/es/fsw/src/cfe_es_generic_pool.h @@ -158,6 +158,39 @@ int32 CFE_ES_GenPoolInitialize(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t StartO */ int32 CFE_ES_GenPoolGetBlock(CFE_ES_GenPoolRecord_t *PoolRecPtr, size_t *BlockOffsetPtr, size_t ReqSize); +/*---------------------------------------------------------------------------------------*/ +/** + * \brief Create a new block of the given size. + * + * \note Internal helper routine only, not part of API. + * + * \param[inout] PoolRecPtr Pointer to pool structure + * \param[in] BucketId Bucket ID + * \param[in] NewSize Size of block + * \param[out] BlockOffsetPtr Location to output new block offset + * + * \return #CFE_SUCCESS, or error code #CFE_ES_BUFFER_NOT_IN_POOL #CFE_ES_ERR_MEM_BLOCK_SIZE + * \ref CFEReturnCodes + */ +int32 CFE_ES_GenPoolCreatePoolBlock(CFE_ES_GenPoolRecord_t *PoolRecPtr, uint16 BucketId, size_t NewSize, + size_t *BlockOffsetPtr); + +/*---------------------------------------------------------------------------------------*/ +/** + * \brief Find and re-allocate a previously returned block + * + * \note Internal helper routine only, not part of API. + * + * \param[inout] PoolRecPtr Pointer to pool structure + * \param[in] BucketId Bucket ID + * \param[in] NewSize Size of block + * \param[out] BlockOffsetPtr Location to output new block offset + * + * \return #CFE_SUCCESS, or error code #CFE_ES_BUFFER_NOT_IN_POOL \ref CFEReturnCodes + */ +int32 CFE_ES_GenPoolRecyclePoolBlock(CFE_ES_GenPoolRecord_t *PoolRecPtr, uint16 BucketId, size_t NewSize, + size_t *BlockOffsetPtr); + /*---------------------------------------------------------------------------------------*/ /** * \brief Returns a block to the pool diff --git a/modules/es/ut-coverage/es_UT.c b/modules/es/ut-coverage/es_UT.c index 68ae5b4e4..29d13ff1f 100644 --- a/modules/es/ut-coverage/es_UT.c +++ b/modules/es/ut-coverage/es_UT.c @@ -2457,6 +2457,16 @@ void TestGenericPool(void) /* Reset the structure so it will rebuild */ Pool1.TailPosition = 0; CFE_UtAssert_SUCCESS(CFE_ES_GenPoolRebuild(&Pool1)); + + /* Branch coverage for no buffer in pool */ + ES_ResetUnitTest(); + UtAssert_INT32_EQ(CFE_ES_GenPoolCreatePoolBlock(&Pool1, 0, Pool1.Buckets[0].BlockSize, &Offset1), + CFE_ES_BUFFER_NOT_IN_POOL); + + ES_ResetUnitTest(); + UtAssert_INT32_EQ(CFE_ES_GenPoolRecyclePoolBlock(&Pool1, 0, Pool1.Buckets[0].BlockSize, &Offset1), + CFE_ES_BUFFER_NOT_IN_POOL); + } void TestTask(void)