|
| 1 | +/************************************************************************* |
| 2 | +** |
| 3 | +** GSC-18128-1, "Core Flight Executive Version 6.7" |
| 4 | +** |
| 5 | +** Copyright (c) 2006-2019 United States Government as represented by |
| 6 | +** the Administrator of the National Aeronautics and Space Administration. |
| 7 | +** All Rights Reserved. |
| 8 | +** |
| 9 | +** Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +** you may not use this file except in compliance with the License. |
| 11 | +** You may obtain a copy of the License at |
| 12 | +** |
| 13 | +** http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +** |
| 15 | +** Unless required by applicable law or agreed to in writing, software |
| 16 | +** distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +** See the License for the specific language governing permissions and |
| 19 | +** limitations under the License. |
| 20 | +** |
| 21 | +** File: es_info_test.c |
| 22 | +** |
| 23 | +** Purpose: |
| 24 | +** Functional test of Sb Pipe Managment APIs |
| 25 | +** |
| 26 | +** Demonstration of how to register and use the UT assert functions. |
| 27 | +** |
| 28 | +*************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * Includes |
| 32 | + */ |
| 33 | + |
| 34 | +#include "cfe_test.h" |
| 35 | + |
| 36 | +void TestPipeCreate(void) |
| 37 | +{ |
| 38 | + CFE_SB_PipeId_t PipeId1; |
| 39 | + uint16 PipeDepth = 10; |
| 40 | + const char PipeName[] = "Test Pipe"; |
| 41 | + |
| 42 | + UtPrintf("Testing: CFE_SB_CreatePipe, CFE_SB_DeletePipe"); |
| 43 | + |
| 44 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, PipeName), CFE_SUCCESS); |
| 45 | + |
| 46 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(NULL, PipeDepth, PipeName), CFE_SB_BAD_ARGUMENT); |
| 47 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, OS_QUEUE_MAX_DEPTH + 5, PipeName), CFE_SB_BAD_ARGUMENT); |
| 48 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, 0, PipeName), CFE_SB_BAD_ARGUMENT); |
| 49 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId1, PipeDepth, NULL), CFE_SB_PIPE_CR_ERR); |
| 50 | + |
| 51 | + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SUCCESS); |
| 52 | + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId1), CFE_SB_BAD_ARGUMENT); |
| 53 | +} |
| 54 | + |
| 55 | +void TestPipeIndex(void) |
| 56 | +{ |
| 57 | + CFE_SB_PipeId_t PipeId; |
| 58 | + uint16 PipeDepth = 10; |
| 59 | + const char PipeName[] = "Test Pipe"; |
| 60 | + uint32 Idx; |
| 61 | + |
| 62 | + UtPrintf("Testing: CFE_SB_PipeId_ToIndex"); |
| 63 | + |
| 64 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); |
| 65 | + |
| 66 | + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(PipeId, &Idx), CFE_SUCCESS); |
| 67 | + |
| 68 | + UtAssert_UINT32_EQ(Idx, 13); |
| 69 | + |
| 70 | + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(CFE_SB_INVALID_PIPE, &Idx), CFE_ES_ERR_RESOURCEID_NOT_VALID); |
| 71 | + UtAssert_INT32_EQ(CFE_SB_PipeId_ToIndex(PipeId, NULL), CFE_ES_BAD_ARGUMENT); |
| 72 | + |
| 73 | + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); |
| 74 | +} |
| 75 | + |
| 76 | +void TestPipeOptions(void) |
| 77 | +{ |
| 78 | + CFE_SB_PipeId_t PipeId; |
| 79 | + uint16 PipeDepth = 10; |
| 80 | + const char PipeName[] = "Test Pipe"; |
| 81 | + uint8 Opts = 2; |
| 82 | + uint8 OptsBuff; |
| 83 | + |
| 84 | + UtPrintf("Testing: CFE_SB_SetPipeOpts, CFE_SB_GetPipeOpts"); |
| 85 | + |
| 86 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); |
| 87 | + |
| 88 | + UtAssert_INT32_EQ(CFE_SB_SetPipeOpts(PipeId, Opts), CFE_SUCCESS); |
| 89 | + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(PipeId, &OptsBuff), CFE_SUCCESS); |
| 90 | + UtAssert_UINT32_EQ(Opts, OptsBuff); |
| 91 | + |
| 92 | + UtAssert_INT32_EQ(CFE_SB_SetPipeOpts(CFE_SB_INVALID_PIPE, Opts), CFE_SB_BAD_ARGUMENT); |
| 93 | + |
| 94 | + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(CFE_SB_INVALID_PIPE, &OptsBuff), CFE_SB_BAD_ARGUMENT); |
| 95 | + UtAssert_INT32_EQ(CFE_SB_GetPipeOpts(PipeId, NULL), CFE_SB_BAD_ARGUMENT); |
| 96 | + |
| 97 | + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); |
| 98 | +} |
| 99 | + |
| 100 | +void TestPipeName(void) |
| 101 | +{ |
| 102 | + CFE_SB_PipeId_t PipeId; |
| 103 | + uint16 PipeDepth = 10; |
| 104 | + const char PipeName[] = "Test Pipe"; |
| 105 | + char PipeNameBuf[OS_MAX_API_NAME]; |
| 106 | + CFE_SB_PipeId_t PipeIdBuff; |
| 107 | + const char InvalidPipeName[] = "Invalid Pipe"; |
| 108 | + |
| 109 | + UtPrintf("Testing: CFE_SB_GetPipeName, CFE_SB_GetPipeIdByName"); |
| 110 | + |
| 111 | + UtAssert_INT32_EQ(CFE_SB_CreatePipe(&PipeId, PipeDepth, PipeName), CFE_SUCCESS); |
| 112 | + |
| 113 | + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, sizeof(PipeNameBuf), PipeId), CFE_SUCCESS); |
| 114 | + UtAssert_StrCmp(PipeNameBuf, PipeName, "CFE_SB_GetPipeName() = %s", PipeNameBuf); |
| 115 | + |
| 116 | + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(&PipeIdBuff, PipeName), CFE_SUCCESS); |
| 117 | + cFE_FTAssert_ResourceID_EQ(PipeId, PipeIdBuff); |
| 118 | + |
| 119 | + UtAssert_INT32_EQ(CFE_SB_GetPipeName(NULL, sizeof(PipeNameBuf), PipeId), CFE_SB_BAD_ARGUMENT); |
| 120 | + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, 0, PipeId), CFE_SB_BAD_ARGUMENT); |
| 121 | + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, OS_MAX_API_NAME * 4, PipeId), CFE_SB_BAD_ARGUMENT); |
| 122 | + UtAssert_INT32_EQ(CFE_SB_GetPipeName(PipeNameBuf, sizeof(PipeNameBuf), CFE_SB_INVALID_PIPE), CFE_SB_BAD_ARGUMENT); |
| 123 | + |
| 124 | + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(NULL, PipeName), CFE_SB_BAD_ARGUMENT); |
| 125 | + UtAssert_INT32_EQ(CFE_SB_GetPipeIdByName(&PipeIdBuff, InvalidPipeName), CFE_SB_BAD_ARGUMENT); |
| 126 | + |
| 127 | + UtAssert_INT32_EQ(CFE_SB_DeletePipe(PipeId), CFE_SUCCESS); |
| 128 | +} |
| 129 | + |
| 130 | +void SBPipeMangSetup(void) |
| 131 | +{ |
| 132 | + UtTest_Add(TestPipeCreate, NULL, NULL, "Test Pipe Create"); |
| 133 | + UtTest_Add(TestPipeIndex, NULL, NULL, "Test Pipe Index"); |
| 134 | + UtTest_Add(TestPipeOptions, NULL, NULL, "Test Pipe Options"); |
| 135 | +} |
0 commit comments