From c0cb3c695684eab469292431a030faa00eccb7e4 Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Wed, 7 Jul 2021 08:47:22 -0400 Subject: [PATCH] Fix #1651, Add SB Pipe Management Functional Tests. --- modules/cfe_testcase/CMakeLists.txt | 1 + modules/cfe_testcase/src/cfe_test.c | 1 + modules/cfe_testcase/src/cfe_test.h | 1 + modules/cfe_testcase/src/sb_pipe_mang_test.c | 135 +++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 modules/cfe_testcase/src/sb_pipe_mang_test.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index 02df7b00e..7606c6f64 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -8,6 +8,7 @@ add_cfe_app(cfe_testcase src/es_misc_test.c src/es_mempool_test.c src/fs_header_test.c + src/sb_pipe_mang_test.c src/time_current_test.c ) diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index 1a37863f3..e9fa16c60 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -57,6 +57,7 @@ void CFE_TestMain(void) ESMiscTestSetup(); ESMemPoolTestSetup(); FSHeaderTestSetup(); + SBPipeMangSetup(); TimeCurrentTestSetup(); /* diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index ee6990f20..0d8a77058 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -79,6 +79,7 @@ void ESCDSTestSetup(void); void ESMiscTestSetup(void); void ESMemPoolTestSetup(void); void FSHeaderTestSetup(void); +void SBPipeMangSetup(void); void TimeCurrentTestSetup(void); #endif /* CFE_TEST_H */ diff --git a/modules/cfe_testcase/src/sb_pipe_mang_test.c b/modules/cfe_testcase/src/sb_pipe_mang_test.c new file mode 100644 index 000000000..e741b27e7 --- /dev/null +++ b/modules/cfe_testcase/src/sb_pipe_mang_test.c @@ -0,0 +1,135 @@ +/************************************************************************* +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +** +** File: es_info_test.c +** +** Purpose: +** Functional test of Sb Pipe Managment APIs +** +** Demonstration of how to register and use the UT assert functions. +** +*************************************************************************/ + +/* + * Includes + */ + +#include "cfe_test.h" + +void TestPipeCreate(void) +{ + CFE_SB_PipeId_t PipeId1; + uint16 PipeDepth = 10; + const char PipeName[] = "Test Pipe"; + + UtPrintf("Testing: CFE_SB_CreatePipe, CFE_SB_DeletePipe"); + + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, PipeName), CFE_SUCCESS); + + UtAssert_INT32_EQ(CFE_SB_CreatePipe(NULL, PipeDepth, PipeName), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, OS_QUEUE_MAX_DEPTH + 5, PipeName), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 0, PipeName), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, NULL), CFE_SB_PIPE_CR_ERR); + + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SB_BAD_ARGUMENT); +} + +void TestPipeIndex(void) +{ + CFE_SB_PipeId_t PipeId; + uint16 PipeDepth = 10; + const char PipeName[] = "Test Pipe"; + uint32 Idx; + + UtPrintf("Testing: CFE_SB_PipeId_ToIndex"); + + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); + + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(PipeId, &Idx), CFE_SUCCESS); + + UtAssert_UINT32_EQ(Idx, 13); + + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(CFE_SB_INVALID_PIPE, &Idx), CFE_ES_ERR_RESOURCEID_NOT_VALID); + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(PipeId, NULL), CFE_ES_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); +} + +void TestPipeOptions(void) +{ + CFE_SB_PipeId_t PipeId; + uint16 PipeDepth = 10; + const char PipeName[] = "Test Pipe"; + uint8 Opts = 2; + uint8 OptsBuff; + + UtPrintf("Testing: CFE_SB_SetPipeOpts, CFE_SB_GetPipeOpts"); + + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); + + UtAssert_INT32_EQ(CFE_SB_SetPipeOpts(PipeId, Opts), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(PipeId, &OptsBuff), CFE_SUCCESS); + UtAssert_UINT32_EQ(Opts, OptsBuff); + + UtAssert_INT32_EQ(CFE_SB_SetPipeOpts(CFE_SB_INVALID_PIPE, Opts), CFE_SB_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(CFE_SB_INVALID_PIPE, &OptsBuff), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(PipeId, NULL), CFE_SB_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); +} + +void TestPipeName(void) +{ + CFE_SB_PipeId_t PipeId; + uint16 PipeDepth = 10; + const char PipeName[] = "Test Pipe"; + char PipeNameBuf[OS_MAX_API_NAME]; + CFE_SB_PipeId_t PipeIdBuff; + const char InvalidPipeName[] = "Invalid Pipe"; + + UtPrintf("Testing: CFE_SB_GetPipeName, CFE_SB_GetPipeIdByName"); + + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); + + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, sizeof(PipeNameBuf), PipeId), CFE_SUCCESS); + UtAssert_StrCmp(PipeNameBuf, PipeName, "CFE_SB_GetPipeName() = %s", PipeNameBuf); + + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(&PipeIdBuff, PipeName), CFE_SUCCESS); + cFE_FTAssert_ResourceID_EQ(PipeId, PipeIdBuff); + + UtAssert_INT32_EQ(CFE_SB_GetPipeName(NULL, sizeof(PipeNameBuf), PipeId), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, 0, PipeId), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, OS_MAX_API_NAME * 4, PipeId), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, sizeof(PipeNameBuf), CFE_SB_INVALID_PIPE), CFE_SB_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(NULL, PipeName), CFE_SB_BAD_ARGUMENT); + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(&PipeIdBuff, InvalidPipeName), CFE_SB_BAD_ARGUMENT); + + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); +} + +void SBPipeMangSetup(void) +{ + UtTest_Add(TestPipeCreate, NULL, NULL, "Test Pipe Create"); + UtTest_Add(TestPipeIndex, NULL, NULL, "Test Pipe Index"); + UtTest_Add(TestPipeOptions, NULL, NULL, "Test Pipe Options"); +}