Skip to content

Commit

Permalink
Fix nasa#1253, Resolve UT uninit vars static analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed May 17, 2022
1 parent 4c08633 commit ef193f2
Show file tree
Hide file tree
Showing 42 changed files with 230 additions and 128 deletions.
8 changes: 8 additions & 0 deletions src/tests/bin-sem-flush-test/bin-sem-flush-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void task_1(void)
OS_bin_sem_prop_t bin_sem_prop;
int counter = 0;

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

OS_printf("Starting task 1\n");

OS_printf("TASK 1: Waiting on the semaphore\n");
Expand Down Expand Up @@ -96,6 +98,8 @@ void task_2(void)
OS_bin_sem_prop_t bin_sem_prop;
int counter = 0;

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

task_2_failures = 0;
OS_printf("Starting task 2\n");

Expand Down Expand Up @@ -134,6 +138,8 @@ void task_3(void)
OS_bin_sem_prop_t bin_sem_prop;
int counter = 0;

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

OS_printf("Starting task 3\n");

OS_printf("TASK 3: Waiting on the semaphore\n");
Expand Down Expand Up @@ -189,6 +195,8 @@ void BinSemFlushSetup(void)
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;

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

/* Note that UT assert is not multi-thread safe,
* so each thread must use a separate error counter
* and then we will assert that these remain zero
Expand Down
14 changes: 11 additions & 3 deletions src/tests/bin-sem-test/bin-sem-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ int counter = 0;
*/
void TimerFunction(osal_id_t local_timer_id)
{
int32 status;
int32 status;
OS_bin_sem_prop_t bin_sem_prop;

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

timer_counter++;

Expand All @@ -79,7 +82,6 @@ void TimerFunction(osal_id_t local_timer_id)
}

{
OS_bin_sem_prop_t bin_sem_prop;
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
if (status != OS_SUCCESS)
{
Expand All @@ -102,6 +104,8 @@ void task_1(void)
OS_bin_sem_prop_t bin_sem_prop;
int printf_counter = 0;

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

OS_printf("Starting task 1\n");

OS_printf("Delay for 1 second before starting\n");
Expand Down Expand Up @@ -153,6 +157,8 @@ void BinSemCheck(void)
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;

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

/* Delete the task, which should be pending in OS_BinSemTake() */
status = OS_TaskDelete(task_1_id);
UtAssert_True(status == OS_SUCCESS, "OS_TaskDelete Rc=%d", (int)status);
Expand Down Expand Up @@ -196,9 +202,11 @@ void UtTest_Setup(void)
void BinSemSetup(void)
{
uint32 status;
uint32 accuracy;
uint32 accuracy = 0;
OS_bin_sem_prop_t bin_sem_prop;

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

/* separate task failure counter because ut-assert is not reentrant */
task_1_failures = 0;
timer_failures = 0;
Expand Down
12 changes: 9 additions & 3 deletions src/tests/bin-sem-timeout-test/bin-sem-timeout-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ int counter = 0;
*/
void TimerFunction(osal_id_t local_timer_id)
{
int32 status;
int32 status;
OS_bin_sem_prop_t bin_sem_prop;

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

timer_counter++;

Expand All @@ -75,7 +78,6 @@ void TimerFunction(osal_id_t local_timer_id)
}

{
OS_bin_sem_prop_t bin_sem_prop;
status = OS_BinSemGetInfo(bin_sem_id, &bin_sem_prop);
if (status != OS_SUCCESS)
{
Expand All @@ -97,6 +99,8 @@ void task_1(void)
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;

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

OS_printf("Starting task 1\n");

OS_printf("Delay for 1 second before starting\n");
Expand Down Expand Up @@ -192,7 +196,9 @@ void BinSemTimeoutSetup(void)
{
uint32 status;
OS_bin_sem_prop_t bin_sem_prop;
uint32 accuracy;
uint32 accuracy = 0;

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

task_1_timeouts = 0;
task_1_work = 0;
Expand Down
26 changes: 15 additions & 11 deletions src/tests/file-api-test/file-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void TestCreatRemove(void)
char maxfilename[OS_MAX_PATH_LEN];
char longfilename[OS_MAX_PATH_LEN + 10];
int32 status;
osal_id_t fd;
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;
int i;

/* Short file name */
Expand Down Expand Up @@ -199,7 +199,7 @@ void TestOpenClose(void)
{
char filename[OS_MAX_PATH_LEN];
int32 status;
osal_id_t fd;
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;

strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1);
filename[sizeof(filename) - 1] = 0;
Expand Down Expand Up @@ -251,7 +251,7 @@ void TestChmod(void)
{
char filename[OS_MAX_PATH_LEN];
int32 status;
osal_id_t fd;
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;

/*Make a file to test on. Start in Read only mode */
strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1);
Expand Down Expand Up @@ -324,7 +324,9 @@ void TestReadWriteLseek(void)
size_t offset;
size_t size;
int32 status;
osal_id_t fd;
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;

memset(newbuffer, 0, sizeof(newbuffer));

strncpy(filename, "/drive0/Filename1", sizeof(filename) - 1);
filename[sizeof(filename) - 1] = 0;
Expand Down Expand Up @@ -446,11 +448,13 @@ void TestMkRmDirFreeBytes(void)
char buffer2[OS_MAX_PATH_LEN];
char copybuffer1[OS_MAX_PATH_LEN];
char copybuffer2[OS_MAX_PATH_LEN];
osal_id_t fd1;
osal_id_t fd2;
osal_id_t fd1 = OS_OBJECT_ID_UNDEFINED;
osal_id_t fd2 = OS_OBJECT_ID_UNDEFINED;
size_t size;
OS_statvfs_t statbuf;

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

/* make the directory names for testing, as well as the filenames and the buffers
* to put in the files */
strcpy(dir1, "/drive0/DIRECTORY_ONE");
Expand Down Expand Up @@ -561,9 +565,9 @@ void TestOpenReadCloseDir(void)
char buffer1[OS_MAX_PATH_LEN];
char buffer2[OS_MAX_PATH_LEN];
size_t size;
osal_id_t fd1;
osal_id_t fd2;
osal_id_t dirh;
osal_id_t fd1 = OS_OBJECT_ID_UNDEFINED;
osal_id_t fd2 = OS_OBJECT_ID_UNDEFINED;
osal_id_t dirh = OS_OBJECT_ID_UNDEFINED;
os_dirent_t dirent;

/* make the directory names for testing, as well as the filenames and the buffers
Expand Down Expand Up @@ -768,7 +772,7 @@ void TestRename(void)
char midname1[OS_MAX_PATH_LEN];
char newfilename1[OS_MAX_PATH_LEN];

osal_id_t fd1;
osal_id_t fd1 = OS_OBJECT_ID_UNDEFINED;
size_t size;

/* make the directory names for testing, as well as the filenames and the buffers
Expand Down Expand Up @@ -854,7 +858,7 @@ void TestStat(void)
char dir1slash[OS_MAX_PATH_LEN];
char buffer1[OS_MAX_PATH_LEN];
os_fstat_t StatBuff;
osal_id_t fd1;
osal_id_t fd1 = OS_OBJECT_ID_UNDEFINED;
size_t size;

strcpy(dir1, "/drive0/DirectoryName");
Expand Down
38 changes: 20 additions & 18 deletions src/tests/idmap-api-test/idmap-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ void Test_OS_ConvertToArrayIndex(void)
* Test Case For:
* int32 OS_ConvertToArrayIndex(void)
*/
osal_index_t TestArrayIndex;
osal_index_t TestMutex1Index;
osal_index_t TestMutex2Index;
osal_index_t TestArrayIndex = OSAL_INDEX_C(0);
osal_index_t TestMutex1Index = OSAL_INDEX_C(0);
osal_index_t TestMutex2Index = OSAL_INDEX_C(0);

/*
* Check different id types and verify array indices
Expand Down Expand Up @@ -249,40 +249,40 @@ void Test_OS_ObjectIdToArrayIndex(void)
* Test case for:
* int32 OS_ObjectIdToArrayIndex(osal_objtype_t idtype, osal_id_t object_id, osal_index_t *ArrayIndex);
*/
osal_index_t TestArrayIndex;
osal_index_t TestMutex1Index;
osal_index_t TestMutex2Index;
osal_index_t TestArrayIndex = OSAL_INDEX_C(0);
osal_index_t TestMutex1Index = OSAL_INDEX_C(0);
osal_index_t TestMutex2Index = OSAL_INDEX_C(0);

/* Test with nominal (correct) object types */
UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TASK, task_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_TASKS, "0 < TestArrayIndex(%lu) <= OS_MAX_TASKS",
UtAssert_True(TestArrayIndex < OS_MAX_TASKS, "TestArrayIndex(%lu) < OS_MAX_TASKS",
(long)TestArrayIndex);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_QUEUE, queue_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_QUEUES, "0 < TestArrayIndex(%lu) <= OS_MAX_QUEUES",
UtAssert_True(TestArrayIndex < OS_MAX_QUEUES, "TestArrayIndex(%lu) < OS_MAX_QUEUES",
(long)TestArrayIndex);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_COUNTSEM, count_sem_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_COUNT_SEMAPHORES,
"0 < TestArrayIndex(%lu) <= OS_MAX_COUNT_SEMAPHORES", (long)TestArrayIndex);
UtAssert_True(TestArrayIndex < OS_MAX_COUNT_SEMAPHORES,
"TestArrayIndex(%lu) < OS_MAX_COUNT_SEMAPHORES", (long)TestArrayIndex);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_BINSEM, bin_sem_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_BIN_SEMAPHORES,
"0 < TestArrayIndex(%lu) <= OS_MAX_BIN_SEMAPHORES", (long)TestArrayIndex);
UtAssert_True(TestArrayIndex < OS_MAX_BIN_SEMAPHORES,
"TestArrayIndex(%lu) < OS_MAX_BIN_SEMAPHORES", (long)TestArrayIndex);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_MUTEX, mutex_id1, &TestMutex1Index), OS_SUCCESS);
UtAssert_True(TestMutex1Index >= 0 && TestMutex1Index < OS_MAX_MUTEXES,
"0 < TestMutex1Index(%lu) <= OS_MAX_MUTEXES", (long)TestMutex1Index);
UtAssert_True(TestMutex1Index < OS_MAX_MUTEXES,
"TestMutex1Index(%lu) < OS_MAX_MUTEXES", (long)TestMutex1Index);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_MUTEX, mutex_id2, &TestMutex2Index), OS_SUCCESS);
UtAssert_True(TestMutex2Index >= 0 && TestMutex2Index < OS_MAX_MUTEXES,
"0 < TestMutex2Index(%lu) <= OS_MAX_MUTEXES", (long)TestMutex2Index);
UtAssert_True(TestMutex2Index < OS_MAX_MUTEXES,
"TestMutex2Index(%lu) < OS_MAX_MUTEXES", (long)TestMutex2Index);
UtAssert_True(TestMutex1Index != TestMutex2Index, "TestMutex1Index(%lu) != TestMutex2Index(%lu)",
(long)TestMutex1Index, (long)TestMutex2Index);

UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_TIMEBASE, time_base_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_TIMEBASES,
"0 < TestArrayIndex(%lu) <= OS_MAX_TIMEBASES", (long)TestArrayIndex);
UtAssert_True(TestArrayIndex < OS_MAX_TIMEBASES,
"TestArrayIndex(%lu) < OS_MAX_TIMEBASES", (long)TestArrayIndex);

/* Check cases where the object type and the ID are _not_ matched */
UtAssert_INT32_EQ(OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_QUEUE, task_id, &TestArrayIndex), OS_ERR_INVALID_ID);
Expand Down Expand Up @@ -403,6 +403,8 @@ void Test_OS_GetResourceName(void)
*/
char name[OS_MAX_API_NAME];

memset(name, 0, sizeof(name));

/* Nominal cases */
UtAssert_INT32_EQ(OS_GetResourceName(queue_id, name, sizeof(name)), OS_SUCCESS);
UtAssert_StrCmp(name, "Queue", "%s == %s", name, "Queue");
Expand Down
7 changes: 6 additions & 1 deletion src/tests/network-api-test/network-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void TestNetworkApiBadArgs(void)

void TestNetworkApiInet6(void)
{
osal_id_t socket_id;
osal_id_t socket_id = OS_OBJECT_ID_UNDEFINED;
OS_SockAddr_t addr;
int32 actual;

Expand Down Expand Up @@ -238,6 +238,11 @@ void TestDatagramNetworkApi(void)
OS_socket_prop_t prop;
OS_SockAddr_t l_addr;

memset(AddrBuffer1, 0, sizeof(AddrBuffer1));
memset(AddrBuffer2, 0, sizeof(AddrBuffer2));
memset(AddrBuffer3, 0, sizeof(AddrBuffer3));
memset(AddrBuffer4, 0, sizeof(AddrBuffer4));

if (!networkImplemented)
{
UtAssert_NA("Network API not implemented");
Expand Down
2 changes: 2 additions & 0 deletions src/tests/osal-core-test/osal-core-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ void TestGenericQueries(void)
TestCallbackState_t State;
char ResourceName[OS_MAX_API_NAME];

memset(ResourceName, 0, sizeof(ResourceName));

status = OS_TaskCreate(&task_0_id, "Task 0", task_generic_no_exit, OSAL_STACKPTR_C(task_0_stack),
sizeof(task_0_stack), OSAL_PRIORITY_C(TASK_0_PRIORITY), 0);
UtAssert_True(status == OS_SUCCESS, "OS_TaskCreate (%ld) == OS_SUCCESS", (long)status);
Expand Down
8 changes: 4 additions & 4 deletions src/tests/queue-test/queue-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void task_1(void)
{
int32 status;
size_t data_size;
uint32 data_received;
uint32 expected = 0;
uint32 data_received = 0;
uint32 expected = 0;

OS_printf("Starting task 1\n");

Expand Down Expand Up @@ -134,7 +134,7 @@ void QueueTimeoutCheck(void)
void QueueTimeoutSetup(void)
{
int32 status;
uint32 accuracy;
uint32 accuracy = 0;

task_1_failures = 0;
task_1_messages = 0;
Expand Down Expand Up @@ -193,7 +193,7 @@ void QueueMessageCheck(void)
void QueueMessageSetup(void)
{
int32 status;
uint32 accuracy;
uint32 accuracy = 0;
int i;
uint32 Data = 0;
task_1_failures = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/tests/select-test/select-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void BinSemSetup(void)
{
OS_bin_sem_prop_t bin_sem_prop;

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

/*
* Create the binary semaphore
* BinSem1 is used to control when the server can accept connections
Expand Down Expand Up @@ -165,7 +167,7 @@ bool FillOutputBuffer(osal_id_t conn_id)

void Server_Fn(void)
{
osal_id_t connsock_id;
osal_id_t connsock_id = OS_OBJECT_ID_UNDEFINED;
OS_SockAddr_t addr;

/* Accept incoming connections */
Expand All @@ -177,7 +179,7 @@ void Server_Fn(void)

void Server_Fn2(void)
{
osal_id_t connsock_id;
osal_id_t connsock_id = OS_OBJECT_ID_UNDEFINED;
OS_SockAddr_t addr;

/* Accept incoming connections */
Expand Down
2 changes: 1 addition & 1 deletion src/tests/shell-test/shell-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void TestOutputToFile(void)
size_t size;
int32 filepos;
int32 status;
osal_id_t fd;
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;

OS_mkfs(NULL, "/ramdev0", "RAM", 512, 20);
OS_mount("/ramdev0", "/drive0");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/symbol-api-test/symbol-api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
void TestSymbolApi(void)
{
int32 status;
cpuaddr SymAddress;
cpuaddr SymAddress = 0;

/* Make the file system */
status = OS_mkfs(0, "/ramdev0", "RAM", 512, 2048);
Expand Down
Loading

0 comments on commit ef193f2

Please sign in to comment.