Skip to content

Commit

Permalink
Fix# 809, add ES Child Task Functional Test
Browse files Browse the repository at this point in the history
Fix# 1291, fix spelling typo
  • Loading branch information
zanzaben committed Apr 16, 2021
1 parent e80aae9 commit fbdf2cf
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 4 deletions.
1 change: 0 additions & 1 deletion cmake/sample_defs/cpu1_cfe_es_startup.scr
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ CFE_APP, sch_lab, SCH_Lab_AppMain, SCH_LAB_APP, 80, 16384, 0x0, 0;
! 3. The filename field (2) no longer requires a fully-qualified filename; the path and extension
! may be omitted. If omitted, the standard virtual path (/cf) and a platform-specific default
! extension will be used, which is derived from the build system.

1 change: 1 addition & 0 deletions modules/cfe_testcase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ include_directories("${UT_ASSERT_SOURCE_DIR}/inc")
add_cfe_app(cfe_testcase
src/cfe_test.c
src/es_info_test.c
src/es_task_test.c
)
1 change: 1 addition & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
int32 CFE_Test_Init(int32 LibId)
{
ESInfoTestSetup(LibId);
ESTaskTestSetup(LibId);
return CFE_SUCCESS;
}
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 @@ -49,10 +49,11 @@
CFE_RESOURCEID_TO_ULONG(actual), #expect, CFE_RESOURCEID_TO_ULONG(expect))

/* Check if a Resource ID is Undefined */
#define UtAssert_ResourceID_Undifeined(id) \
#define UtAssert_ResourceID_Undefined(id) \
UtAssert_True(!CFE_RESOURCEID_TEST_DEFINED(id), "%s (%lu) not defined", #id, CFE_RESOURCEID_TO_ULONG(id))

int32 CFE_Test_Init(int32 LibId);
int32 ESInfoTestSetup(int32 LibId);
int32 ESTaskTestSetup(int32 LibId);

#endif /* CFE_TEST_H */
4 changes: 2 additions & 2 deletions modules/cfe_testcase/src/es_info_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void TestAppInfo(void)
UtAssert_True(ESAppInfo.NumOfChildTasks > 0, "ES App Info -> Child Tasks = %d", (int)ESAppInfo.NumOfChildTasks);

UtAssert_INT32_EQ(CFE_ES_GetAppIDByName(&AppIdByName, InvalidName), CFE_ES_ERR_NAME_NOT_FOUND);
UtAssert_ResourceID_Undifeined(AppIdByName);
UtAssert_ResourceID_Undefined(AppIdByName);
UtAssert_INT32_EQ(CFE_ES_GetAppID(NULL), CFE_ES_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_ES_GetAppIDByName(NULL, TestAppName), CFE_ES_BAD_ARGUMENT);
UtAssert_INT32_EQ(CFE_ES_GetAppName(AppNameBuf, CFE_ES_APPID_UNDEFINED, sizeof(AppNameBuf)),
Expand Down Expand Up @@ -201,7 +201,7 @@ void TestLibInfo(void)

UtAssert_INT32_EQ(LibInfo.ExceptionAction, 0);
UtAssert_True(LibInfo.Priority == 0, "Lib Info -> Priority = %d", (int)LibInfo.Priority);
UtAssert_ResourceID_Undifeined(LibInfo.MainTaskId);
UtAssert_ResourceID_Undefined(LibInfo.MainTaskId);
UtAssert_True(LibInfo.ExecutionCounter == 0, "Lib Info -> ExecutionCounter = %d", (int)LibInfo.ExecutionCounter);
UtAssert_True(strlen(LibInfo.MainTaskName) == 0, "Lib Info -> Task Name = %s", LibInfo.MainTaskName);
UtAssert_True(LibInfo.NumOfChildTasks == 0, "Lib Info -> Child Tasks = %d", (int)LibInfo.NumOfChildTasks);
Expand Down
117 changes: 117 additions & 0 deletions modules/cfe_testcase/src/es_task_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*************************************************************************
**
** 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_task_test.c
**
** Purpose:
** Functional test of basic ES Child Tasks APIs
**
** Demonstration of how to register and use the UT assert functions.
**
*************************************************************************/

/*
* Includes
*/

#include "cfe_test.h"

uint32 count = 0;

void TaskFunction(void)
{
while (count < 200)
{
count += 1;
OS_TaskDelay(100);
}
return;
}

void TaskExitFunction(void)
{
while (count < 200)
{
count += 1;
CFE_ES_ExitChildTask();
}
return;
}

void TestCreateChild(void)
{
UtPrintf("Testing: CFE_ES_CreateChildTask, CFE_ES_GetTaskIDByName, CFE_ES_GetTaskName, CFE_ES_DeleteChildTask");

CFE_ES_TaskId_t TaskId;
const char * TaskName = "CHILD_TASK_1";
CFE_ES_TaskId_t TaskIdByName;
char TaskNameBuf[OS_MAX_API_NAME + 4];
CFE_ES_StackPointer_t StackPointer = CFE_ES_TASK_STACK_ALLOCATE;
size_t StackSize = CFE_PLATFORM_ES_PERF_CHILD_STACK_SIZE;
CFE_ES_TaskPriority_Atom_t Priority = CFE_PLATFORM_ES_PERF_CHILD_PRIORITY;
uint32 Flags = 0;
int countCopy;

UtAssert_INT32_EQ(CFE_ES_CreateChildTask(&TaskId, TaskName, TaskFunction, StackPointer, StackSize, Priority, Flags),
CFE_SUCCESS);

UtAssert_INT32_EQ(CFE_ES_GetTaskIDByName(&TaskIdByName, TaskName), CFE_SUCCESS);
UtAssert_ResourceID_EQ(TaskIdByName, TaskId);

UtAssert_INT32_EQ(CFE_ES_GetTaskName(TaskNameBuf, TaskId, sizeof(TaskNameBuf)), CFE_SUCCESS);
UtAssert_StrCmp(TaskNameBuf, TaskName, "CFE_ES_GetTaskName() = %s", TaskNameBuf);

OS_TaskDelay(500);

countCopy = count;

UtAssert_INT32_EQ(CFE_ES_DeleteChildTask(TaskId), CFE_SUCCESS);

OS_TaskDelay(500);

UtAssert_True(countCopy == count || countCopy == count + 1, "countCopy (%d) == count (%d)", countCopy, count);
}

void TestExitChild(void)
{
UtPrintf("Testing: CFE_ES_ExitChildTask");

CFE_ES_TaskId_t TaskId;
const char * TaskName = "CHILD_TASK_1";
CFE_ES_StackPointer_t StackPointer = CFE_ES_TASK_STACK_ALLOCATE;
size_t StackSize = CFE_PLATFORM_ES_PERF_CHILD_STACK_SIZE;
CFE_ES_TaskPriority_Atom_t Priority = CFE_PLATFORM_ES_PERF_CHILD_PRIORITY;
uint32 Flags = 0;
count = 0;

UtAssert_INT32_EQ(
CFE_ES_CreateChildTask(&TaskId, TaskName, TaskExitFunction, StackPointer, StackSize, Priority, Flags),
CFE_SUCCESS);
OS_TaskDelay(500);
UtAssert_INT32_EQ(count, 1);
}

int32 ESTaskTestSetup(int32 LibId)
{
UtTest_Add(TestCreateChild, NULL, NULL, "Test Create Child");
UtTest_Add(TestExitChild, NULL, NULL, "Test Exit Child");

return CFE_SUCCESS;
}

0 comments on commit fbdf2cf

Please sign in to comment.