Skip to content

Commit 33f66a9

Browse files
committed
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
1 parent c4ae5b2 commit 33f66a9

File tree

5 files changed

+172
-12
lines changed

5 files changed

+172
-12
lines changed

modules/cfe_testcase/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_cfe_app(cfe_testcase
55
src/es_info_test.c
66
src/es_task_test.c
77
src/es_cds_test.c
8+
src/es_counter_test.c
89
src/es_misc_test.c
910
src/es_mempool_test.c
1011
src/fs_header_test.c

modules/cfe_testcase/src/cfe_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void CFE_TestMain(void)
5252
* Register test cases in UtAssert
5353
*/
5454
ESCDSTestSetup();
55+
ESCounterTestSetup();
5556
ESInfoTestSetup();
5657
ESMemPoolTestSetup();
5758
ESMiscTestSetup();

modules/cfe_testcase/src/cfe_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ typedef struct
7979

8080
void CFE_TestMain(void);
8181
void ESCDSTestSetup(void);
82+
void ESCounterTestSetup(void);
8283
void ESInfoTestSetup(void);
8384
void ESMemPoolTestSetup(void);
8485
void ESMiscTestSetup(void);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
*************************************************************************/
22+
23+
/**
24+
* @file
25+
*
26+
* Functional test of ES Generic Counter APIs
27+
*/
28+
29+
#include "cfe_test.h"
30+
31+
void TestCounterCreateDelete(void)
32+
{
33+
CFE_ES_CounterId_t Ids[CFE_PLATFORM_ES_MAX_GEN_COUNTERS];
34+
CFE_ES_CounterId_t TestId;
35+
CFE_ES_CounterId_t CheckId;
36+
char CounterName[CFE_MISSION_MAX_API_LEN];
37+
char CheckName[CFE_MISSION_MAX_API_LEN];
38+
CFE_Status_t Status;
39+
uint32 NumCounters;
40+
uint32 Idx;
41+
42+
snprintf(CounterName, sizeof(CounterName), "ut");
43+
44+
/* Confirm proper bad argument rejection */
45+
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&Ids[0], NULL), CFE_ES_BAD_ARGUMENT);
46+
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(NULL, CounterName), CFE_ES_BAD_ARGUMENT);
47+
48+
/* Create up to CFE_PLATFORM_ES_MAX_GEN_COUNTERS and confirm success */
49+
for (NumCounters = 0; NumCounters < CFE_PLATFORM_ES_MAX_GEN_COUNTERS; ++NumCounters)
50+
{
51+
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)NumCounters);
52+
Status = CFE_ES_RegisterGenCounter(&Ids[NumCounters], CounterName);
53+
if (Status != CFE_SUCCESS)
54+
{
55+
break;
56+
}
57+
}
58+
59+
/* Confirm that the expected number of counters were created */
60+
UtAssert_UINT32_EQ(NumCounters, CFE_PLATFORM_ES_MAX_GEN_COUNTERS);
61+
62+
/* Attempt to create one too many */
63+
snprintf(CounterName, sizeof(CounterName), "extra");
64+
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, CounterName), CFE_ES_NO_RESOURCE_IDS_AVAILABLE);
65+
66+
/* pick a single counter ID from the middle of the set for more detail testing of support APIs */
67+
TestId = Ids[NumCounters / 2];
68+
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)NumCounters / 2);
69+
70+
/* Confirm CFE_ES_CounterID_ToIndex works (nominal) */
71+
Idx = UINT32_MAX;
72+
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(TestId, &Idx), CFE_SUCCESS);
73+
UtAssert_UINT32_LT(Idx, CFE_PLATFORM_ES_MAX_GEN_COUNTERS);
74+
75+
/* Confirm proper rejection of bad args in CFE_ES_CounterID_ToIndex */
76+
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CFE_ES_COUNTERID_UNDEFINED, &Idx), CFE_ES_ERR_RESOURCEID_NOT_VALID);
77+
UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(TestId, NULL), CFE_ES_BAD_ARGUMENT);
78+
79+
/* Confirm conversion To/From Name */
80+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, CounterName), CFE_SUCCESS);
81+
cFE_FTAssert_ResourceID_EQ(CheckId, TestId);
82+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, TestId, sizeof(CheckName)), CFE_SUCCESS);
83+
UtAssert_STRINGBUF_EQ(CheckName, sizeof(CheckName), CounterName, sizeof(CounterName));
84+
85+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, "na"), CFE_ES_ERR_NAME_NOT_FOUND);
86+
87+
/* Confirm proper rejection of bad args in conversion To/From Name */
88+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(NULL, CounterName), CFE_ES_BAD_ARGUMENT);
89+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterIDByName(&CheckId, NULL), CFE_ES_BAD_ARGUMENT);
90+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, CFE_ES_COUNTERID_UNDEFINED, sizeof(CounterName)),
91+
CFE_ES_ERR_RESOURCEID_NOT_VALID);
92+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(CheckName, TestId, 0), CFE_ES_BAD_ARGUMENT);
93+
UtAssert_INT32_EQ(CFE_ES_GetGenCounterName(NULL, TestId, sizeof(CounterName)), CFE_ES_BAD_ARGUMENT);
94+
95+
/* Confirm proper rejection of bad args in CFE_ES_DeleteGenCounter (this returns CFE_ES_BAD_ARGUMENT instead) */
96+
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(CFE_ES_COUNTERID_UNDEFINED), CFE_ES_BAD_ARGUMENT);
97+
98+
/* Delete last counter to test duplicate name rejection (needs a free slot) */
99+
--NumCounters;
100+
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(Ids[NumCounters]), CFE_SUCCESS);
101+
snprintf(CounterName, sizeof(CounterName), "C%u", (unsigned int)0);
102+
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, CounterName), CFE_ES_ERR_DUPLICATE_NAME);
103+
104+
/* Delete remainder of counters */
105+
while (NumCounters > 0)
106+
{
107+
Status = CFE_ES_DeleteGenCounter(Ids[NumCounters - 1]);
108+
if (Status != CFE_SUCCESS)
109+
{
110+
break;
111+
}
112+
113+
--NumCounters;
114+
}
115+
116+
UtAssert_ZERO(NumCounters);
117+
}
118+
119+
void TestCounterGetSet(void)
120+
{
121+
CFE_ES_CounterId_t TestId;
122+
uint32 CountVal;
123+
124+
/* Setup - create a single counter */
125+
UtAssert_INT32_EQ(CFE_ES_RegisterGenCounter(&TestId, "ut"), CFE_SUCCESS);
126+
127+
/* Get and set its count - should be initially 0 */
128+
CountVal = UINT32_MAX;
129+
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS);
130+
UtAssert_ZERO(CountVal);
131+
UtAssert_INT32_EQ(CFE_ES_SetGenCount(TestId, 5), CFE_SUCCESS);
132+
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS);
133+
UtAssert_UINT32_EQ(CountVal, 5);
134+
UtAssert_INT32_EQ(CFE_ES_IncrementGenCounter(TestId), CFE_SUCCESS);
135+
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, &CountVal), CFE_SUCCESS);
136+
UtAssert_UINT32_EQ(CountVal, 6);
137+
138+
/*
139+
* Confirm bad arg rejection in Get/Set/Increment
140+
* Note these APIs return CFE_ES_BAD_ARGUMENT rather than
141+
* CFE_ES_ERR_RESOURCEID_NOT_VALID on a bad ID (historical)
142+
*/
143+
UtAssert_INT32_EQ(CFE_ES_GetGenCount(TestId, NULL), CFE_ES_BAD_ARGUMENT);
144+
UtAssert_INT32_EQ(CFE_ES_GetGenCount(CFE_ES_COUNTERID_UNDEFINED, &CountVal), CFE_ES_BAD_ARGUMENT);
145+
UtAssert_INT32_EQ(CFE_ES_IncrementGenCounter(CFE_ES_COUNTERID_UNDEFINED), CFE_ES_BAD_ARGUMENT);
146+
UtAssert_INT32_EQ(CFE_ES_SetGenCount(CFE_ES_COUNTERID_UNDEFINED, 0), CFE_ES_BAD_ARGUMENT);
147+
148+
/* Teardown - delete the counter */
149+
UtAssert_INT32_EQ(CFE_ES_DeleteGenCounter(TestId), CFE_SUCCESS);
150+
}
151+
152+
void ESCounterTestSetup(void)
153+
{
154+
UtTest_Add(TestCounterCreateDelete, NULL, NULL, "Test Counter Create/Delete");
155+
UtTest_Add(TestCounterGetSet, NULL, NULL, "Test Counter Get/Set");
156+
}

modules/core_api/fsw/inc/cfe_es.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ CFE_Status_t CFE_ES_TaskID_ToIndex(CFE_ES_TaskId_t TaskID, uint32 *Idx);
163163
* for future use.
164164
*
165165
* @param[in] CounterId Counter ID to convert
166-
* @param[out] Idx Buffer where the calculated index will be stored
166+
* @param[out] Idx Buffer where the calculated index will be stored @nonnull
167167
*
168168
* @return Execution status, see @ref CFEReturnCodes
169169
* @retval #CFE_SUCCESS @copybrief CFE_SUCCESS
@@ -1494,15 +1494,16 @@ void CFE_ES_PerfLogAdd(uint32 Marker, uint32 EntryExit);
14941494
** can be used for inter-task management.
14951495
**
14961496
** \par Assumptions, External Events, and Notes:
1497-
** None.
1497+
** The initial value of all newly registered counters is 0.
14981498
**
1499-
** \param[in] *CounterName The Name of the generic counter.
1499+
** \param[out] CounterIdPtr Buffer to store the Counter Id of the newly created counter @nonnull.
1500+
** \param[in] CounterName The Name of the generic counter @nonnull.
15001501
**
1501-
** \param[out] *CounterIdPtr The Counter Id of the newly created counter.
15021502
**
15031503
** \return Execution status, see \ref CFEReturnCodes
1504-
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
1505-
** \retval #CFE_ES_BAD_ARGUMENT \copybrief CFE_ES_BAD_ARGUMENT
1504+
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
1505+
** \retval #CFE_ES_BAD_ARGUMENT \copybrief CFE_ES_BAD_ARGUMENT
1506+
** \retval #CFE_ES_ERR_DUPLICATE_NAME \copybrief CFE_ES_ERR_DUPLICATE_NAME
15061507
**
15071508
** \sa #CFE_ES_IncrementGenCounter, #CFE_ES_DeleteGenCounter, #CFE_ES_SetGenCount, #CFE_ES_GetGenCount,
15081509
*#CFE_ES_GetGenCounterIDByName
@@ -1588,9 +1589,9 @@ CFE_Status_t CFE_ES_SetGenCount(CFE_ES_CounterId_t CounterId, uint32 Count);
15881589
** \par Assumptions, External Events, and Notes:
15891590
** None.
15901591
**
1591-
** \param[in] CounterId The Counter to get the value from.
1592+
** \param[in] CounterId The Counter to get the value from.
15921593
**
1593-
** \param[in] *Count The value of the Counter.
1594+
** \param[out] Count Buffer to store value of the Counter @nonnull.
15941595
**
15951596
** \return Execution status, see \ref CFEReturnCodes
15961597
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
@@ -1612,8 +1613,8 @@ CFE_Status_t CFE_ES_GetGenCount(CFE_ES_CounterId_t CounterId, uint32 *Count);
16121613
** \par Assumptions, External Events, and Notes:
16131614
** None.
16141615
**
1615-
** \param[out] CounterIdPtr Pointer to variable that is to receive the Counter's ID.
1616-
** \param[in] CounterName Pointer to null terminated character string containing a Counter name.
1616+
** \param[out] CounterIdPtr Pointer to variable that is to receive the Counter's ID @nonnull.
1617+
** \param[in] CounterName Pointer to null terminated character string containing a Counter name @nonnull.
16171618
**
16181619
** \return Execution status, see \ref CFEReturnCodes
16191620
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
@@ -1636,12 +1637,12 @@ CFE_Status_t CFE_ES_GetGenCounterIDByName(CFE_ES_CounterId_t *CounterIdPtr, cons
16361637
** \par Assumptions, External Events, and Notes:
16371638
** In the case of a failure (#CFE_ES_ERR_RESOURCEID_NOT_VALID), an empty string is returned.
16381639
**
1639-
** \param[out] CounterName Pointer to a character array of at least \c BufferLength in size that will
1640+
** \param[out] CounterName Pointer to a character array @nonnull of at least \c BufferLength in size that will
16401641
** be filled with the Counter name.
16411642
**
16421643
** \param[in] CounterId ID of Counter whose name is being requested.
16431644
**
1644-
** \param[in] BufferLength The maximum number of characters, including the null terminator, that can be put
1645+
** \param[in] BufferLength The maximum number of characters, including the null terminator @nonzero, that can be put
16451646
** into the \c CounterName buffer. This routine will truncate the name to this length,
16461647
** if necessary.
16471648
**

0 commit comments

Comments
 (0)