-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nasa#813, Add Generic Counter API test
Add tests for the following APIs: CFE_ES_RegisterGenCounter CFE_ES_CounterID_ToIndex CFE_ES_GetGenCounterIDByName CFE_ES_GetGenCounterName CFE_ES_GetGenCount CFE_ES_SetGenCount CFE_ES_IncrementGenCounter CFE_ES_DeleteGenCounter
- Loading branch information
Showing
5 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/************************************************************************* | ||
** | ||
** 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 | ||
* | ||
* Functional test of ES Generic Counter APIs | ||
*/ | ||
|
||
#include "cfe_test.h" | ||
|
||
void TestCounterCreateDelete(void) | ||
{ | ||
CFE_ES_CounterId_t Ids[CFE_PLATFORM_ES_MAX_GEN_COUNTERS]; | ||
CFE_ES_CounterId_t TestId; | ||
CFE_ES_CounterId_t CheckId; | ||
char CounterName[CFE_MISSION_MAX_API_LEN]; | ||
char CheckName[CFE_MISSION_MAX_API_LEN]; | ||
CFE_Status_t Status; | ||
uint32 NumCounters; | ||
uint32 Idx; | ||
|
||
snprintf(CounterName, sizeof(CounterName), "ut"); | ||
|
||
/* Confirm proper bad argument rejection */ | ||
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&Ids[0], NULL), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(NULL, CounterName), CFE_ES_BAD_ARGUMENT); | ||
|
||
/* Create up to CFE_PLATFORM_ES_MAX_GEN_COUNTERS and confirm success */ | ||
for (NumCounters = 0; NumCounters < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; ++NumCounters) | ||
{ | ||
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)NumCounters); | ||
Status = CFE_ES_RegisterGenCounter(&Ids[NumCounters], CounterName); | ||
if (Status != CFE_SUCCESS) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
/* Confirm that the expected number of counters were created */ | ||
UtAssert_UINT32_EQ(NumCounters, CFE_PLATFORM_ES_MAX_GEN_COUNTERS); | ||
|
||
/* Attempt to create one too many */ | ||
snprintf(CounterName, sizeof(CounterName), "extra"); | ||
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, CounterName), CFE_ES_NO_RESOURCE_IDS_AVAILABLE); | ||
|
||
/* pick a single counter ID from the middle of the set for more detail testing of support APIs */ | ||
TestId = Ids[NumCounters / 2]; | ||
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)NumCounters / 2); | ||
|
||
/* Confirm CFE_ES_CounterID_ToIndex works (nominal) */ | ||
Idx = UINT32_MAX; | ||
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(TestId, &Idx), CFE_SUCCESS); | ||
UtAssert_UINT32_LT(Idx, CFE_PLATFORM_ES_MAX_GEN_COUNTERS); | ||
|
||
/* Confirm proper rejection of bad args in CFE_ES_CounterID_ToIndex */ | ||
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CFE_ES_COUNTERID_UNDEFINED, &Idx), CFE_ES_ERR_RESOURCEID_NOT_VALID); | ||
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(TestId, NULL), CFE_ES_BAD_ARGUMENT); | ||
|
||
/* Confirm conversion To/From Name */ | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, CounterName), CFE_SUCCESS); | ||
cFE_FTAssert_ResourceID_EQ(CheckId, TestId); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, TestId, sizeof(CheckName)), CFE_SUCCESS); | ||
UtAssert_STRINGBUF_EQ(CheckName, sizeof(CheckName), CounterName, sizeof(CounterName)); | ||
|
||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, "na"), CFE_ES_ERR_NAME_NOT_FOUND); | ||
|
||
/* Confirm proper rejection of bad args in conversion To/From Name */ | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(NULL, CounterName), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, NULL), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, CFE_ES_COUNTERID_UNDEFINED, sizeof(CounterName)), | ||
CFE_ES_ERR_RESOURCEID_NOT_VALID); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, TestId, 0), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(NULL, TestId, sizeof(CounterName)), CFE_ES_BAD_ARGUMENT); | ||
|
||
/* Confirm proper rejection of bad args in CFE_ES_DeleteGenCounter (this returns CFE_ES_BAD_ARGUMENT instead) */ | ||
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(CFE_ES_COUNTERID_UNDEFINED), CFE_ES_BAD_ARGUMENT); | ||
|
||
/* Delete last counter to test duplicate name rejection (needs a free slot) */ | ||
--NumCounters; | ||
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(Ids[NumCounters]), CFE_SUCCESS); | ||
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)0); | ||
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, CounterName), CFE_ES_ERR_DUPLICATE_NAME); | ||
|
||
/* Delete remainder of counters */ | ||
while (NumCounters > 0) | ||
{ | ||
Status = CFE_ES_DeleteGenCounter(Ids[NumCounters - 1]); | ||
if (Status != CFE_SUCCESS) | ||
{ | ||
break; | ||
} | ||
|
||
--NumCounters; | ||
} | ||
|
||
UtAssert_ZERO(NumCounters); | ||
} | ||
|
||
void TestCounterGetSet(void) | ||
{ | ||
CFE_ES_CounterId_t TestId; | ||
uint32 CountVal; | ||
|
||
/* Setup - create a single counter */ | ||
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, "ut"), CFE_SUCCESS); | ||
|
||
/* Get and set its count - should be initially 0 */ | ||
CountVal = UINT32_MAX; | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS); | ||
UtAssert_ZERO(CountVal); | ||
UtAssert_INT32_EQ(CFE_ES_SetGenCount(TestId, 5), CFE_SUCCESS); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS); | ||
UtAssert_UINT32_EQ(CountVal, 5); | ||
UtAssert_INT32_EQ(CFE_ES_IncrementGenCounter(TestId), CFE_SUCCESS); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS); | ||
UtAssert_UINT32_EQ(CountVal, 6); | ||
|
||
/* | ||
* Confirm bad arg rejection in Get/Set/Increment | ||
* Note these APIs return CFE_ES_BAD_ARGUMENT rather than | ||
* CFE_ES_ERR_RESOURCEID_NOT_VALID on a bad ID (historical) | ||
*/ | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, NULL), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_GetGenCount(CFE_ES_COUNTERID_UNDEFINED, &CountVal), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_IncrementGenCounter(CFE_ES_COUNTERID_UNDEFINED), CFE_ES_BAD_ARGUMENT); | ||
UtAssert_INT32_EQ(CFE_ES_SetGenCount(CFE_ES_COUNTERID_UNDEFINED, 0), CFE_ES_BAD_ARGUMENT); | ||
|
||
/* Teardown - delete the counter */ | ||
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(TestId), CFE_SUCCESS); | ||
} | ||
|
||
void ESCounterTestSetup(void) | ||
{ | ||
UtTest_Add(TestCounterCreateDelete, NULL, NULL, "Test Counter Create/Delete"); | ||
UtTest_Add(TestCounterGetSet, NULL, NULL, "Test Counter Get/Set"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters