Skip to content

Commit

Permalink
Fix nasa#1733, instantiate global once.
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Aug 4, 2021
1 parent 5dcefac commit 31548d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions modules/cfe_testcase/src/cfe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "cfe_assert.h"
#include "cfe_test.h"

CFE_FT_Global_t CFE_FT_Global;

/*
* Test main function
* Register this test routine with CFE Assert
Expand Down
5 changes: 4 additions & 1 deletion modules/cfe_testcase/src/cfe_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
typedef struct
{
CFE_FS_FileWriteMetaData_t FuncTestState;
int count;
/* Generic utility counter */
int Count;
} CFE_FT_Global_t;

extern CFE_FT_Global_t CFE_FT_Global;

/**
* Name of log file to write
*
Expand Down
42 changes: 21 additions & 21 deletions modules/cfe_testcase/src/es_task_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,21 @@

#include "cfe_test.h"

CFE_FT_Global_t CFE_FT_Global;

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

void TaskExitFunction(void)
{
while (CFE_FT_Global.count < 200)
while (CFE_FT_Global.Count < 200)
{
CFE_FT_Global.count += 1;
CFE_FT_Global.Count += 1;
CFE_ES_ExitChildTask();
}
return;
Expand All @@ -67,14 +65,15 @@ void TestCreateChild(void)
CFE_ES_TaskPriority_Atom_t Priority = CFE_PLATFORM_ES_PERF_CHILD_PRIORITY;
uint32 Flags = 0;
int ExpectedCount = 5;
CFE_FT_Global.count = 0;

CFE_FT_Global.Count = 0;

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

UtAssert_True(ExpectedCount >= CFE_FT_Global.count - 1 && ExpectedCount <= CFE_FT_Global.count + 1,
"countCopy (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.count);
UtAssert_True(ExpectedCount >= CFE_FT_Global.Count - 1 && ExpectedCount <= CFE_FT_Global.Count + 1,
"countCopy (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.Count);

UtAssert_INT32_EQ(
CFE_ES_CreateChildTask(&TaskId2, TaskName, TaskFunction, StackPointer, StackSize, Priority, Flags),
Expand Down Expand Up @@ -131,29 +130,30 @@ void TestChildTaskDelete(void)
UtPrintf("Testing: CFE_ES_DeleteChildTask");

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;
CFE_FT_Global.count = 0;
int ExpectedCount = 5;
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;
int ExpectedCount = 5;

CFE_FT_Global.Count = 0;

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

UtAssert_True(ExpectedCount >= CFE_FT_Global.count - 1 && ExpectedCount <= CFE_FT_Global.count + 1,
"countCopy (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.count);
UtAssert_True(ExpectedCount >= CFE_FT_Global.Count - 1 && ExpectedCount <= CFE_FT_Global.Count + 1,
"countCopy (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.Count);

ExpectedCount = CFE_FT_Global.count;
ExpectedCount = CFE_FT_Global.Count;

UtAssert_INT32_EQ(CFE_ES_DeleteChildTask(TaskId), CFE_SUCCESS);

OS_TaskDelay(500);

UtAssert_True(ExpectedCount == CFE_FT_Global.count || ExpectedCount == CFE_FT_Global.count + 1,
"ExpectedCount (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.count);
UtAssert_True(ExpectedCount == CFE_FT_Global.Count || ExpectedCount == CFE_FT_Global.Count + 1,
"ExpectedCount (%d) == count (%d)", (int)ExpectedCount, (int)CFE_FT_Global.Count);

UtAssert_INT32_EQ(CFE_ES_DeleteChildTask(CFE_ES_TASKID_UNDEFINED), CFE_ES_ERR_RESOURCEID_NOT_VALID);
}
Expand Down
3 changes: 0 additions & 3 deletions modules/cfe_testcase/src/fs_util_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

#include "cfe_test.h"

CFE_FT_Global_t CFE_FT_Global;

void TestFileCategory(void)
{
UtPrintf("Testing: CFE_FS_GetDefaultMountPoint, CFE_FS_GetDefaultExtension");
Expand Down Expand Up @@ -138,7 +136,6 @@ void TestFileDump(void)

UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState), false);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpRequest(&CFE_FT_Global.FuncTestState), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState), true);

/* Wait for background task to complete */
while (CFE_FS_BackgroundFileDumpIsPending(&CFE_FT_Global.FuncTestState) && count < MaxWait)
Expand Down

0 comments on commit 31548d4

Please sign in to comment.