-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #813, Add Generic Counter API test #1753
Merged
astrogeco
merged 2 commits into
nasa:integration-candidate
from
jphickey:fix-813-counter-tests
Aug 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CFE_ES_CounterID_ToIndex is being tested by #1716 so you don't need to check it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we wrote these tests in parallel. I don't see a real problem with testing it in two places, as they are slightly different variations. It doesn't hurt anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright just wanted to make sure we were aware.