|
| 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 | +** File: es_behavior_test.c |
| 22 | +** |
| 23 | +** Purpose: |
| 24 | +** Functional test of basic ES Application Behavior APIs |
| 25 | +** |
| 26 | +** Demonstration of how to register and use the UT assert functions. |
| 27 | +** |
| 28 | +*************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * Includes |
| 32 | + */ |
| 33 | + |
| 34 | +#include "cfe_test.h" |
| 35 | + |
| 36 | +void TestRunCounter(void) |
| 37 | +{ |
| 38 | + CFE_ES_TaskId_t TaskId; |
| 39 | + CFE_ES_TaskInfo_t TaskInfo; |
| 40 | + uint32 ExecutionCounter; |
| 41 | + uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; |
| 42 | + |
| 43 | + UtPrintf("Testing: CFE_ES_RunLoop, CFE_ES_IncrementTaskCounter"); |
| 44 | + |
| 45 | + UtAssert_INT32_EQ(CFE_ES_GetTaskID(&TaskId), CFE_SUCCESS); |
| 46 | + UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS); |
| 47 | + ExecutionCounter = TaskInfo.ExecutionCounter; |
| 48 | + |
| 49 | + UtAssert_BOOL_TRUE(CFE_ES_RunLoop(&RunStatus)); |
| 50 | + UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS); |
| 51 | + UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 1)); |
| 52 | + |
| 53 | + UtAssert_BOOL_TRUE(CFE_ES_RunLoop(NULL)); |
| 54 | + UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS); |
| 55 | + UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 2)); |
| 56 | + |
| 57 | + UtAssert_VOIDCALL(CFE_ES_IncrementTaskCounter()); |
| 58 | + UtAssert_INT32_EQ(CFE_ES_GetTaskInfo(&TaskInfo, TaskId), CFE_SUCCESS); |
| 59 | + UtAssert_UINT32_EQ(TaskInfo.ExecutionCounter, (ExecutionCounter + 3)); |
| 60 | + |
| 61 | + RunStatus = CFE_ES_RunStatus_UNDEFINED; |
| 62 | + UtAssert_BOOL_FALSE(CFE_ES_RunLoop(&RunStatus)); |
| 63 | +} |
| 64 | + |
| 65 | +void TestWaitBehavior(void) |
| 66 | +{ |
| 67 | + CFE_TIME_SysTime_t start; |
| 68 | + CFE_TIME_SysTime_t end; |
| 69 | + CFE_TIME_SysTime_t TimePassed; |
| 70 | + CFE_TIME_SysTime_t TimeExpected = {8, 0}; |
| 71 | + |
| 72 | + start = CFE_TIME_GetTime(); |
| 73 | + |
| 74 | + /* MinSystemStates of CFE_ES_SystemState_SHUTDOWN and higher not tested because they cause a shutdown */ |
| 75 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_UNDEFINED, 10000), CFE_SUCCESS); |
| 76 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_EARLY_INIT, 10000), CFE_SUCCESS); |
| 77 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_STARTUP, 10000), CFE_SUCCESS); |
| 78 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_CORE_READY, 10000), CFE_SUCCESS); |
| 79 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_APPS_INIT, 10000), CFE_SUCCESS); |
| 80 | + UtAssert_INT32_EQ(CFE_ES_WaitForSystemState(CFE_ES_SystemState_OPERATIONAL, 10000), CFE_SUCCESS); |
| 81 | + UtAssert_VOIDCALL(CFE_ES_WaitForStartupSync(10000)); |
| 82 | + |
| 83 | + end = CFE_TIME_GetTime(); |
| 84 | + TimePassed = CFE_TIME_Subtract(end, start); |
| 85 | + |
| 86 | + UtAssert_UINT32_EQ(CFE_TIME_Compare(TimePassed, TimeExpected), CFE_TIME_A_LT_B); |
| 87 | +} |
| 88 | + |
| 89 | +void ESBehaviorestSetup(void) |
| 90 | +{ |
| 91 | + UtTest_Add(TestRunCounter, NULL, NULL, "Test Run Counter"); |
| 92 | + UtTest_Add(TestWaitBehavior, NULL, NULL, "Test Wait Behavior"); |
| 93 | +} |
0 commit comments