From cf2e720e22b5165353e5113993f88e30badddfc2 Mon Sep 17 00:00:00 2001 From: Alex Campbell Date: Mon, 9 Aug 2021 13:17:07 -0400 Subject: [PATCH] Fix #807, Add ES Application Behavior Functional Tests --- modules/cfe_testcase/CMakeLists.txt | 1 + modules/cfe_testcase/src/cfe_test.c | 3 +- modules/cfe_testcase/src/cfe_test.h | 3 +- modules/cfe_testcase/src/es_behavior_test.c | 93 +++++++++++++++++++++ modules/core_api/fsw/inc/cfe_es.h | 7 +- 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 modules/cfe_testcase/src/es_behavior_test.c diff --git a/modules/cfe_testcase/CMakeLists.txt b/modules/cfe_testcase/CMakeLists.txt index 8189dba9b..af749e717 100644 --- a/modules/cfe_testcase/CMakeLists.txt +++ b/modules/cfe_testcase/CMakeLists.txt @@ -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 diff --git a/modules/cfe_testcase/src/cfe_test.c b/modules/cfe_testcase/src/cfe_test.c index b1dbe4767..f7f4be8f5 100644 --- a/modules/cfe_testcase/src/cfe_test.c +++ b/modules/cfe_testcase/src/cfe_test.c @@ -51,6 +51,7 @@ void CFE_TestMain(void) /* * Register test cases in UtAssert */ + ESBehaviorestSetup(); ESCDSTestSetup(); ESInfoTestSetup(); ESMemPoolTestSetup(); @@ -62,8 +63,8 @@ void CFE_TestMain(void) MessageIdTestSetup(); SBPipeMangSetup(); TimeArithmeticTestSetup(); - TimeCurrentTestSetup(); TimeConversionTestSetup(); + TimeCurrentTestSetup(); /* * Execute the tests diff --git a/modules/cfe_testcase/src/cfe_test.h b/modules/cfe_testcase/src/cfe_test.h index 558b0a1f6..9ec977f33 100644 --- a/modules/cfe_testcase/src/cfe_test.h +++ b/modules/cfe_testcase/src/cfe_test.h @@ -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); @@ -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 */ diff --git a/modules/cfe_testcase/src/es_behavior_test.c b/modules/cfe_testcase/src/es_behavior_test.c new file mode 100644 index 000000000..9600003b9 --- /dev/null +++ b/modules/cfe_testcase/src/es_behavior_test.c @@ -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://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"); +} diff --git a/modules/core_api/fsw/inc/cfe_es.h b/modules/core_api/fsw/inc/cfe_es.h index 53061b4a3..0b52145e5 100644 --- a/modules/core_api/fsw/inc/cfe_es.h +++ b/modules/core_api/fsw/inc/cfe_es.h @@ -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