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 16, 2022
1 parent 4c08633 commit 3b50c59
Show file tree
Hide file tree
Showing 37 changed files with 194 additions and 102 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
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
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
8 changes: 5 additions & 3 deletions src/tests/timer-test/timer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint32 timer_idlookup[OS_MAX_TIMERS];
*/
void test_func(osal_id_t timer_id)
{
osal_index_t idx;
osal_index_t idx = OSAL_INDEX_C(0);
OS_ConvertToArrayIndex(timer_id, &idx);
timer_counter[timer_idlookup[idx]]++;
}
Expand Down Expand Up @@ -114,10 +114,12 @@ void TimerTestTask(void)

int i = 0;
int32 TimerStatus[NUMBER_OF_TIMERS];
osal_index_t TableId;
osal_index_t TableId = OSAL_INDEX_C(0);
osal_id_t TimerID[NUMBER_OF_TIMERS];
char TimerName[NUMBER_OF_TIMERS][20] = {"TIMER1", "TIMER2", "TIMER3", "TIMER4", "TIMER5"};
uint32 ClockAccuracy;
uint32 ClockAccuracy = 0;

memset(TimerID, 0, sizeof(TimerID));

for (i = 0; i < NUMBER_OF_TIMERS && i < OS_MAX_TIMERS; i++)
{
Expand Down
6 changes: 4 additions & 2 deletions src/unit-test-coverage/shared/src/coveragetest-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Test_OS_BinSemCreate(void)
* int32 OS_BinSemCreate (uint32 *sem_id, const char *sem_name,
* uint32 sem_initial_value, uint32 options)
*/
osal_id_t objid;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;

OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_SUCCESS);
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
Expand Down Expand Up @@ -131,7 +131,7 @@ void Test_OS_BinSemGetIdByName(void)
*/
int32 expected = OS_SUCCESS;
int32 actual = ~OS_SUCCESS;
osal_id_t objid;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
actual = OS_BinSemGetIdByName(&objid, "UT");
Expand All @@ -157,6 +157,8 @@ void Test_OS_BinSemGetInfo(void)
int32 actual = ~OS_SUCCESS;
OS_bin_sem_prop_t prop;

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

OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_BINSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER);

actual = OS_BinSemGetInfo(UT_OBJID_1, &prop);
Expand Down
6 changes: 4 additions & 2 deletions src/unit-test-coverage/shared/src/coveragetest-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Test_OS_CountSemCreate(void)
* int32 OS_CountSemCreate (uint32 *sem_id, const char *sem_name,
* uint32 sem_initial_value, uint32 options)
*/
osal_id_t objid;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;

OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_SUCCESS);
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
Expand Down Expand Up @@ -119,7 +119,7 @@ void Test_OS_CountSemGetIdByName(void)
*/
int32 expected = OS_SUCCESS;
int32 actual = ~OS_SUCCESS;
osal_id_t objid;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS);
actual = OS_CountSemGetIdByName(&objid, "UT");
Expand All @@ -145,6 +145,8 @@ void Test_OS_CountSemGetInfo(void)
int32 actual = ~OS_SUCCESS;
OS_count_sem_prop_t prop;

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

OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_COUNTSEM, UT_INDEX_1, "ABC", UT_OBJID_OTHER);

actual = OS_CountSemGetInfo(UT_OBJID_1, &prop);
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/shared/src/coveragetest-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Test_OS_DirectoryOpen(void)
* Test Case For:
* int32 OS_DirectoryOpen(uint32 *dir_id, const char *path)
*/
osal_id_t objid;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;

OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), OS_SUCCESS);
OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED);
Expand Down
2 changes: 2 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void Test_OS_GetErrorName(void)
*/
os_err_name_t err_name;

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

OSAPI_TEST_FUNCTION_RC(OS_GetErrorName(OS_ERROR, &err_name), OS_SUCCESS);
UtAssert_True(strcmp(err_name, "OS_ERROR") == 0, "string(%s) == OS_ERROR", err_name);

Expand Down
2 changes: 2 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ void Test_OS_FDGetInfo(void)
*/
OS_file_prop_t file_prop;

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

OS_UT_SetupBasicInfoTest(OS_OBJECT_TYPE_OS_STREAM, UT_INDEX_1, "ABC", UT_OBJID_OTHER);
OSAPI_TEST_FUNCTION_RC(OS_FDGetInfo(UT_OBJID_1, &file_prop), OS_SUCCESS);
UtAssert_True(strcmp(file_prop.Path, "ABC") == 0, "file_prop.Path (%s) == ABC", file_prop.Path);
Expand Down
6 changes: 6 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ void Test_OS_FileSysStatVolume(void)
int32 expected;
int32 actual;

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

statref.block_size = OSAL_SIZE_C(1024);
statref.blocks_free = OSAL_BLOCKCOUNT_C(1111);
statref.total_blocks = OSAL_BLOCKCOUNT_C(2222);
Expand Down Expand Up @@ -374,6 +376,8 @@ void Test_OS_GetFsInfo(void)
os_fsinfo_t filesys_info;
OS_common_record_t rec;

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

UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdIteratorGetNext), 1);
UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorGetNext), 3, 0);
UT_SetDeferredRetcode(UT_KEY(OS_ObjectIdIteratorGetNext), 4, 0);
Expand Down Expand Up @@ -415,6 +419,8 @@ void Test_OS_TranslatePath(void)
int32 expected = OS_SUCCESS;
int32 actual = ~OS_SUCCESS;

memset(LocalBuffer, 0, sizeof(LocalBuffer));

/* Set up the local record for success */
OS_filesys_table[1].flags =
OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL;
Expand Down
Loading

0 comments on commit 3b50c59

Please sign in to comment.