Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1253 #1254, Resolve static analysis warnings #1255

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
60 changes: 26 additions & 34 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 All @@ -203,34 +203,29 @@ void Test_OS_ConvertToArrayIndex(void)
* Test with nominal values
*/
UtAssert_INT32_EQ(OS_ConvertToArrayIndex(task_id, &TestArrayIndex), OS_SUCCESS);
UtAssert_True(TestArrayIndex >= 0 && TestArrayIndex < OS_MAX_TASKS, "0 < TestArrayIndex(%lu) <= OS_MAX_TASKS",
(long)TestArrayIndex);
UtAssert_True(TestArrayIndex < OS_MAX_TASKS, "TestArrayIndex(%lu) < OS_MAX_TASKS", (long)TestArrayIndex);

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

UtAssert_INT32_EQ(OS_ConvertToArrayIndex(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_ConvertToArrayIndex(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_ConvertToArrayIndex(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_ConvertToArrayIndex(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_ConvertToArrayIndex(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);

/*
* Test with extreme cases using invalid inputs and checking
Expand All @@ -249,40 +244,35 @@ 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",
(long)TestArrayIndex);
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",
(long)TestArrayIndex);
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 +393,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
20 changes: 13 additions & 7 deletions 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 @@ -228,16 +228,22 @@ void TestDatagramNetworkApi(void)
char AddrBuffer2[32];
char AddrBuffer3[32];
char AddrBuffer4[32];
uint32 Buf1 = 111;
uint32 Buf2 = 000;
uint32 Buf3 = 222;
uint32 Buf4 = 000;
osal_id_t objid;
uint32 Buf1 = 111;
uint32 Buf2 = 0;
uint32 Buf3 = 222;
uint32 Buf4 = 0;
osal_id_t objid = OS_OBJECT_ID_UNDEFINED;
osal_id_t invalid_fd;
uint16 PortNum;
uint16 PortNum = 0;
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));
memset(&prop, 0, sizeof(prop));

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
Loading