Skip to content

Commit

Permalink
Fix nasa#2100, Resolve UT uninit var static analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed May 17, 2022
1 parent 81416f8 commit 503c15a
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 202 deletions.
4 changes: 4 additions & 0 deletions modules/cfe_testcase/src/es_cds_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void TestCDSName(void)
CFE_ES_CDSHandle_t IdByName;
char CDSNameBuf[CFE_MISSION_ES_CDS_MAX_FULL_NAME_LEN];

memset(CDSNameBuf, 0, sizeof(CDSNameBuf));

UtPrintf("Testing: CFE_ES_GetCDSBlockIDByName, CFE_ES_GetCDSBlockName");

UtAssert_INT32_EQ(CFE_ES_RegisterCDS(&CDSHandlePtr, BlockSize, Name), CFE_ES_CDS_ALREADY_EXISTS);
Expand Down Expand Up @@ -119,6 +121,8 @@ void TestCopyRestoreCDS(void)
char Data[BlockSize];
char DataBuff[BlockSize];

memset(DataBuff, 0, sizeof(DataBuff));

UtPrintf("Testing: CFE_ES_CopyToCDS, CFE_ES_RestoreFromCDS");

snprintf(Data, BlockSize, "Test Data");
Expand Down
4 changes: 4 additions & 0 deletions modules/cfe_testcase/src/es_info_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ void TestModuleInfo(void)
CFE_ES_AppInfo_t TestAppInfo;
const char * LibName = "ASSERT_LIB";

memset(&ModuleInfo, 0, sizeof(ModuleInfo));
memset(&LibInfo, 0, sizeof(LibInfo));
memset(&TestAppInfo, 0, sizeof(TestAppInfo));

UtPrintf("Testing: CFE_ES_GetModuleInfo");

UtAssert_INT32_EQ(CFE_ES_GetAppID(&TestAppId), CFE_SUCCESS);
Expand Down
12 changes: 7 additions & 5 deletions modules/cfe_testcase/src/es_mempool_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static CFE_FT_PoolMemBlock_t CFE_FT_PoolMemBlock[CFE_PLATFORM_ES_MAX_MEMORY_POOL

void TestMemPoolCreate(void)
{
CFE_ES_MemHandle_t PoolID;
CFE_ES_MemHandle_t PoolID = CFE_ES_MEMHANDLE_UNDEFINED;

UtPrintf("Testing: CFE_ES_PoolCreateNoSem, CFE_ES_PoolCreate, CFE_ES_PoolCreateEx");

Expand Down Expand Up @@ -102,7 +102,7 @@ void TestMemPoolCreateMax(void)

void TestMemPoolGetBuf(void)
{
CFE_ES_MemHandle_t PoolID;
CFE_ES_MemHandle_t PoolID = CFE_ES_MEMHANDLE_UNDEFINED;
int8 Pool[1024];
size_t BufferSize = 512;
size_t BufferBig = 2048;
Expand All @@ -127,7 +127,7 @@ void TestMemPoolGetBuf(void)

void TestMemPoolBufInfo(void)
{
CFE_ES_MemHandle_t PoolID;
CFE_ES_MemHandle_t PoolID = CFE_ES_MEMHANDLE_UNDEFINED;
int8 Pool[1024];
size_t Buffer = 512;
CFE_ES_MemPoolBuf_t addressp = CFE_ES_MEMPOOLBUF_C(0);
Expand All @@ -152,7 +152,7 @@ void TestMemPoolBufInfo(void)

void TestMemPoolPutBuf(void)
{
CFE_ES_MemHandle_t PoolID;
CFE_ES_MemHandle_t PoolID = CFE_ES_MEMHANDLE_UNDEFINED;
int8 Pool[1024];
size_t Buffer = 512;
CFE_ES_MemPoolBuf_t addressp = CFE_ES_MEMPOOLBUF_C(0);
Expand All @@ -174,10 +174,12 @@ void TestMemPoolPutBuf(void)

void TestMemPoolDelete(void)
{
CFE_ES_MemHandle_t PoolID; /* Poo1 1 handle, no mutex */
CFE_ES_MemHandle_t PoolID = CFE_ES_MEMHANDLE_UNDEFINED; /* Poo1 1 handle, no mutex */
uint8 Buffer[1024];
CFE_ES_MemPoolStats_t Stats;

memset(&Stats, 0, sizeof(Stats));

UtPrintf("Testing: CFE_ES_PoolDelete, CFE_ES_GetMemPoolStats, CFE_ES_PoolCreateEx");

UtAssert_INT32_EQ(CFE_ES_PoolCreateEx(&PoolID, Buffer, sizeof(Buffer), 0, NULL, CFE_ES_NO_MUTEX), CFE_SUCCESS);
Expand Down
10 changes: 6 additions & 4 deletions modules/cfe_testcase/src/es_resource_id_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ void TestLibIDToIndex(void)
UtPrintf("Testing: CFE_ES_LibID_ToIndex");
const char * LibName = "ASSERT_LIB";
CFE_ES_LibId_t LibId;
uint32 LibIdx;
uint32 idx;
uint32 LibIdx = 0;
uint32 idx = 0;

UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&LibId, LibName), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(LibId, &LibIdx), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(LibId, &idx), CFE_SUCCESS);
Expand All @@ -65,9 +66,10 @@ void TestLibIDToIndex(void)
void TestTaskIDToIndex(void)
{
UtPrintf("Testing: CFE_ES_TaskID_ToIndex");
CFE_ES_TaskId_t TaskId;
CFE_ES_TaskId_t TaskId = CFE_ES_TASKID_UNDEFINED;
uint32 TaskIdx;
uint32 idx;
uint32 idx = 0;

UtAssert_INT32_EQ(CFE_ES_GetTaskID(&TaskId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(TaskId, &TaskIdx), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(TaskId, &idx), CFE_SUCCESS);
Expand Down
12 changes: 7 additions & 5 deletions modules/cfe_testcase/src/es_task_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void TestCreateChild(void)
{
UtPrintf("Testing: CFE_ES_CreateChildTask");

CFE_ES_TaskId_t TaskId;
CFE_ES_TaskId_t TaskId2;
CFE_ES_TaskId_t TaskId = CFE_ES_TASKID_UNDEFINED;
CFE_ES_TaskId_t TaskId2 = CFE_ES_TASKID_UNDEFINED;
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;
Expand All @@ -106,7 +106,7 @@ void TestCreateChild(void)
int32 ExpectedCount = 5;
int32 RetryCount;
char TaskNameBuf[16];
osal_id_t OtherTaskId;
osal_id_t OtherTaskId = OS_OBJECT_ID_UNDEFINED;
OS_task_prop_t task_prop;

CFE_FT_Global.Count = 0;
Expand Down Expand Up @@ -187,7 +187,7 @@ void TestChildTaskName(void)
{
UtPrintf("Testing: CFE_ES_GetTaskIDByName, CFE_ES_GetTaskName");

CFE_ES_TaskId_t TaskId;
CFE_ES_TaskId_t TaskId = CFE_ES_TASKID_UNDEFINED;
const char TaskName[] = "CHILD_TASK_1";
CFE_ES_TaskId_t TaskIdByName;
char TaskNameBuf[OS_MAX_API_NAME + 4];
Expand All @@ -196,6 +196,8 @@ void TestChildTaskName(void)
CFE_ES_TaskPriority_Atom_t Priority = CFE_PLATFORM_ES_PERF_CHILD_PRIORITY;
uint32 Flags = 0;

memset(TaskNameBuf, 0, sizeof(TaskNameBuf));

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

Expand Down Expand Up @@ -223,7 +225,7 @@ void TestChildTaskDelete(void)
{
UtPrintf("Testing: CFE_ES_DeleteChildTask");

CFE_ES_TaskId_t TaskId;
CFE_ES_TaskId_t TaskId = CFE_ES_TASKID_UNDEFINED;
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;
Expand Down
8 changes: 7 additions & 1 deletion modules/cfe_testcase/src/fs_header_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ char *fsAddrPtr = NULL;

static osal_id_t setup_file(void)
{
osal_id_t id;
osal_id_t id = OS_OBJECT_ID_UNDEFINED;

UtAssert_INT32_EQ(OS_OpenCreate(&id, OS_TEST_HEADER_FILENAME, OS_FILE_FLAG_CREATE, OS_READ_WRITE), OS_SUCCESS);

return id;
}

Expand Down Expand Up @@ -70,6 +72,8 @@ void TestReadHeader(void)
const char * TestDescription = "TEST_HEADER";
osal_id_t fd = setup_file();

memset(&ReadHeader, 0, sizeof(ReadHeader));

UtPrintf("Testing: CFE_FS_ReadHeader");

UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
Expand All @@ -96,6 +100,8 @@ void TestTimeStamp(void)
CFE_TIME_SysTime_t NewTimestamp = {0xFFFFFFFF, 0xFFFFFFFF};
osal_id_t fd = setup_file();

memset(&ReadHeader, 0, sizeof(ReadHeader));

UtPrintf("Testing: CFE_FS_SetTimestamp");

UtAssert_VOIDCALL(CFE_FS_InitHeader(&Header, TestDescription, CFE_FS_SubType_ES_ERLOG));
Expand Down
2 changes: 2 additions & 0 deletions modules/cfe_testcase/src/fs_util_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void TestFileName(void)
char Name[OS_MAX_FILE_NAME];
const char ExpectedName[] = "FileName.test";

memset(Name, 0, sizeof(Name));

UtPrintf("Testing: CFE_FS_ExtractFilenameFromPath");

snprintf(Path, sizeof(Path), "/func/FileName.test");
Expand Down
7 changes: 7 additions & 0 deletions modules/cfe_testcase/src/resource_id_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ void TestGetBaseSerial(void)
CFE_ResourceId_t ResourceID;
} CDSHandleIdBuf;

memset(&AppIdBuf, 0, sizeof(AppIdBuf));
memset(&LibIdBuf, 0, sizeof(LibIdBuf));
memset(&TaskIdBuf, 0, sizeof(TaskIdBuf));
memset(&CounterIdBuf, 0, sizeof(CounterIdBuf));
memset(&PoolIdBuf, 0, sizeof(PoolIdBuf));
memset(&CDSHandleIdBuf, 0, sizeof(CDSHandleIdBuf));

/* Referenced from cfe_core_resourceid_basevalues.h */
int TASKID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_OS_TASK);
int APPID_BASE = CFE_RESOURCEID_MAKE_BASE(OS_OBJECT_TYPE_USER + 1);
Expand Down
12 changes: 6 additions & 6 deletions modules/cfe_testcase/src/sb_pipe_mang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

void TestPipeCreate(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
uint16 PipeDepth = 10;
const char PipeName[] = "Test Pipe";

Expand Down Expand Up @@ -100,7 +100,7 @@ void TestPipeCreateMax(void)

void TestPipeIndex(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_PipeId_t PipeId = CFE_SB_INVALID_PIPE;
uint16 PipeDepth = 10;
const char PipeName[] = "Test Pipe";
uint32 Idx;
Expand All @@ -119,11 +119,11 @@ void TestPipeIndex(void)

void TestPipeOptions(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_PipeId_t PipeId = CFE_SB_INVALID_PIPE;
uint16 PipeDepth = 10;
const char PipeName[] = "Test Pipe";
uint8 Opts = 2;
uint8 OptsBuff;
uint8 OptsBuff = 0;

UtPrintf("Testing: CFE_SB_SetPipeOpts, CFE_SB_GetPipeOpts");

Expand All @@ -143,11 +143,11 @@ void TestPipeOptions(void)

void TestPipeName(void)
{
CFE_SB_PipeId_t PipeId;
CFE_SB_PipeId_t PipeId = CFE_SB_INVALID_PIPE;
uint16 PipeDepth = 10;
const char PipeName[] = "Test Pipe";
char PipeNameBuf[OS_MAX_API_NAME];
CFE_SB_PipeId_t PipeIdBuff;
CFE_SB_PipeId_t PipeIdBuff = CFE_SB_INVALID_PIPE;
const char InvalidPipeName[] = "Invalid Pipe";

UtPrintf("Testing: CFE_SB_GetPipeName, CFE_SB_GetPipeIdByName");
Expand Down
22 changes: 13 additions & 9 deletions modules/cfe_testcase/src/sb_sendrecv_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static CFE_FT_TestBigMessage_t CFE_FT_BigMsg;

void TestBasicTransmitRecv(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_FT_TestCmdMessage_t CmdMsg;
CFE_FT_TestTlmMessage_t TlmMsg;
CFE_SB_MsgId_t MsgId;
Expand All @@ -77,6 +77,8 @@ void TestBasicTransmitRecv(void)
const CFE_FT_TestCmdMessage_t *CmdPtr;
const CFE_FT_TestTlmMessage_t *TlmPtr;

memset(&CmdMsg, 0, sizeof(CmdMsg));

UtPrintf("Testing: CFE_SB_TransmitMsg");

/* Setup, create a pipe and subscribe (one cmd, one tlm) */
Expand Down Expand Up @@ -218,10 +220,10 @@ void TestBasicTransmitRecv(void)
*/
void TestMsgBroadcast(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId3;
CFE_SB_PipeId_t PipeId4;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId3 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId4 = CFE_SB_INVALID_PIPE;
CFE_FT_TestCmdMessage_t CmdMsg;
CFE_SB_MsgId_t MsgId;
CFE_SB_Buffer_t * MsgBuf1;
Expand All @@ -230,6 +232,8 @@ void TestMsgBroadcast(void)
CFE_SB_Buffer_t * MsgBuf4;
const CFE_FT_TestCmdMessage_t *CmdPtr;

memset(&CmdMsg, 0, sizeof(CmdMsg));

UtPrintf("Testing: MsgLimit enforcement");

/* Setup - subscribe same MsgId to multiple different pipes with different limits */
Expand Down Expand Up @@ -373,12 +377,12 @@ void TestMsgBroadcast(void)
/* This is a variant of the message transmit API that does not copy */
void TestZeroCopyTransmitRecv(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;
CFE_SB_Buffer_t * CmdBuf;
CFE_SB_Buffer_t * TlmBuf;
CFE_SB_Buffer_t * MsgBuf;
CFE_SB_MsgId_t MsgId;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_SequenceCount_t SeqCmd1;
CFE_MSG_SequenceCount_t SeqTlm1;
CFE_MSG_SequenceCount_t SeqCmd2;
Expand Down
14 changes: 7 additions & 7 deletions modules/cfe_testcase/src/sb_subscription_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static const CFE_SB_MsgId_t CFE_FT_TLM_MSGID = CFE_SB_MSGID_WRAP_VALUE(CFE_TEST_

void TestSubscribeUnsubscribe(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;

UtPrintf("Testing: CFE_SB_Subscribe, CFE_SB_Unsubscribe");

Expand Down Expand Up @@ -91,8 +91,8 @@ void TestSubscribeUnsubscribe(void)

void TestSubscribeUnsubscribeLocal(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;

UtPrintf("Testing: CFE_SB_SubscribeLocal, CFE_SB_UnsubscribeLocal");

Expand Down Expand Up @@ -143,8 +143,8 @@ void TestSubscribeUnsubscribeLocal(void)

void TestSubscribeEx(void)
{
CFE_SB_PipeId_t PipeId1;
CFE_SB_PipeId_t PipeId2;
CFE_SB_PipeId_t PipeId1 = CFE_SB_INVALID_PIPE;
CFE_SB_PipeId_t PipeId2 = CFE_SB_INVALID_PIPE;

/*
* NOTE: CFE_SB_SubscribeEx adds a "Quality" parameter for Qos, which is
Expand Down Expand Up @@ -185,7 +185,7 @@ void TestSBMaxSubscriptions(void)
CFE_Status_t Status;
uint32 NumSubs;
CFE_SB_MsgId_t TestMsgId;
CFE_SB_PipeId_t PipeId;
CFE_SB_PipeId_t PipeId = CFE_SB_INVALID_PIPE;

UtPrintf("Testing: CFE_SB_Subscribe, max routing table limit");

Expand Down
9 changes: 6 additions & 3 deletions modules/cfe_testcase/src/tbl_content_access_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ void LoadTable(TBL_TEST_Table_t *TestTable, CFE_Status_t ExpectedStatus)

void TestGetAddress(void)
{
UtPrintf("Testing: CFE_TBL_GetAddress");
void * TblPtr;
TBL_TEST_Table_t *TestTblPtr;
TBL_TEST_Table_t TestTable = {1, 2};

CFE_TBL_Handle_t SharedTblHandle = CFE_TBL_BAD_TABLE_HANDLE;
const char * SharedTblName = "SAMPLE_APP.SampleAppTable";

UtPrintf("Testing: CFE_TBL_GetAddress");

/* Never loaded */
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_ERR_NEVER_LOADED);
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_TBL_BAD_TABLE_HANDLE), CFE_TBL_ERR_INVALID_HANDLE);
Expand All @@ -64,8 +69,6 @@ void TestGetAddress(void)
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, CFE_FT_Global.TblHandle), CFE_TBL_ERR_INVALID_HANDLE);

/* Access a shared table */
CFE_TBL_Handle_t SharedTblHandle;
const char * SharedTblName = "SAMPLE_APP.SampleAppTable";
UtAssert_INT32_EQ(CFE_TBL_Share(&SharedTblHandle, SharedTblName), CFE_SUCCESS);
/* Returns CFE_TBL_INFO_UPDATED since it hasn't been touched since it was loaded */
UtAssert_INT32_EQ(CFE_TBL_GetAddress(&TblPtr, SharedTblHandle), CFE_TBL_INFO_UPDATED);
Expand Down
4 changes: 2 additions & 2 deletions modules/cfe_testcase/src/tbl_content_mang_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ void TblTest_UpdateOffset(CFE_ES_MemOffset_t *TgtVal, CFE_ES_MemOffset_t SetVal)
*/
void TblTest_GenerateTblFiles(void)
{
osal_id_t fh1;
osal_id_t fh2;
osal_id_t fh1 = OS_OBJECT_ID_UNDEFINED;
osal_id_t fh2 = OS_OBJECT_ID_UNDEFINED;
uint32 PartialOffset;
uint32 PartialSize;
union
Expand Down
Loading

0 comments on commit 503c15a

Please sign in to comment.