Skip to content

Commit

Permalink
Fix #807, Add ES Application Behavior Functional Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Aug 9, 2021
1 parent cfadad6 commit f86e57e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
1 change: 1 addition & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Create the app module
add_cfe_app(cfe_testcase
src/cfe_test.c
src/es_behavior_test.c
src/es_info_test.c
src/es_task_test.c
src/es_cds_test.c
Expand Down
3 changes: 2 additions & 1 deletion modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void CFE_TestMain(void)
/*
* Register test cases in UtAssert
*/
ESBehaviorestSetup();
ESCDSTestSetup();
ESInfoTestSetup();
ESMemPoolTestSetup();
Expand All @@ -62,8 +63,8 @@ void CFE_TestMain(void)
MessageIdTestSetup();
SBPipeMangSetup();
TimeArithmeticTestSetup();
TimeCurrentTestSetup();
TimeConversionTestSetup();
TimeCurrentTestSetup();

/*
* Execute the tests
Expand Down
3 changes: 2 additions & 1 deletion modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef struct

bool TimeInRange(CFE_TIME_SysTime_t Time, CFE_TIME_SysTime_t Target, OS_time_t difference);

void ESBehaviorestSetup(void);
void CFE_TestMain(void);
void ESCDSTestSetup(void);
void ESInfoTestSetup(void);
Expand All @@ -91,7 +92,7 @@ void FSUtilTestSetup(void);
void MessageIdTestSetup(void);
void SBPipeMangSetup(void);
void TimeArithmeticTestSetup(void);
void TimeCurrentTestSetup(void);
void TimeConversionTestSetup(void);
void TimeCurrentTestSetup(void);

#endif /* CFE_TEST_H */
93 changes: 93 additions & 0 deletions modules/cfe_testcase/src/es_behavior_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*************************************************************************
**
** 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:https://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_behavior_test.c
**
** Purpose:
** Functional test of basic ES Application Behavior APIs
**
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/

/*
* Includes
*/

#include "cfe_test.h"

void TestRunCounter(void)
{
CFE_ES_TaskId_t TaskId;
CFE_ES_TaskInfo_t TaskInfo;
uint32 ExecutionCounter;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;

UtPrintf("Testing: CFE_ES_RunLoop, CFE_ES_IncrementTaskCounter");

UtAssert_INT32_EQ(CFE_ES_GetTaskID(&TaskId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS);
ExecutionCounter = TaskInfo.ExecutionCounter;

UtAssert_BOOL_TRUE(CFE_ES_RunLoop(&RunStatus));
UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS);
UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 1));

UtAssert_BOOL_TRUE(CFE_ES_RunLoop(NULL));
UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS);
UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 2));

UtAssert_VOIDCALL(CFE_ES_IncrementTaskCounter());
UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS);
UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 3));

RunStatus = CFE_ES_RunStatus_UNDEFINED;
UtAssert_BOOL_FALSE(CFE_ES_RunLoop(&RunStatus));
}

void TestWaitBehavior(void)
{
CFE_TIME_SysTime_t start;
CFE_TIME_SysTime_t end;
CFE_TIME_SysTime_t TimePassed;
CFE_TIME_SysTime_t TimeExpected = {8, 0};

start = CFE_TIME_GetTime();

/* MinSystemStates of CFE_ES_SystemState_SHUTDOWN and higher not tested because they cause a shutdown */
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_UNDEFINED, 10000), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_EARLY_INIT, 10000), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_STARTUP, 10000), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 10000), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_APPS_INIT, 10000), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_OPERATIONAL, 10000), CFE_SUCCESS);
UtAssert_VOIDCALL(CFE_ES_WaitForStartupSync(10000));

end = CFE_TIME_GetTime();
TimePassed = CFE_TIME_Subtract(end, start);

UtAssert_UINT32_EQ(CFE_TIME_Compare(TimePassed, TimeExpected), CFE_TIME_A_LT_B);
}

void ESBehaviorestSetup(void)
{
UtTest_Add(TestRunCounter, NULL, NULL, "Test Run Counter");
UtTest_Add(TestWaitBehavior, NULL, NULL, "Test Wait Behavior");
}
7 changes: 3 additions & 4 deletions modules/core_api/fsw/inc/cfe_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,9 @@ bool CFE_ES_RunLoop(uint32 *RunStatus);
**
** \param[in] MinSystemState Determine the state of the App
** \param[in] TimeOutMilliseconds The timeout value in Milliseconds.
** This parameter must be at least 1000. Lower values
** will be rounded up. There is not an option to
** wait indefinitely to avoid hanging a critical
** application because a non-critical app did not start.
** There is not an option to wait indefinitely to
** avoid hanging a critical application because a
** non-critical app did not start.
**
** \return Execution status, see \ref CFEReturnCodes
** \retval #CFE_SUCCESS State successfully achieved
Expand Down

0 comments on commit f86e57e

Please sign in to comment.