From 701e293888faa3d64fec9b69c5e41878fc1f7723 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 3 Jun 2021 16:12:42 -0400 Subject: [PATCH 01/16] Partial #1052, BinSem test cases --- src/unit-test-coverage/shared/src/coveragetest-binsem.c | 3 ++- src/unit-tests/oscore-test/ut_oscore_binsem_test.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 8619b59d1..143bd75bf 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -61,7 +61,8 @@ void Test_OS_BinSemCreate(void) UtAssert_True(actual == expected, "OS_BinSemCreate() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(NULL, "UT", 0, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, NULL, 0, 0), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } diff --git a/src/unit-tests/oscore-test/ut_oscore_binsem_test.c b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c index defbf2f0e..b95f2523c 100644 --- a/src/unit-tests/oscore-test/ut_oscore_binsem_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_binsem_test.c @@ -134,6 +134,7 @@ void UT_os_bin_sem_delete_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "DeleteTest", 1, 0))) @@ -157,6 +158,7 @@ void UT_os_bin_sem_flush_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemFlush(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemFlush(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "FlushTest", 1, 0))) @@ -181,6 +183,7 @@ void UT_os_bin_sem_give_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemGive(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "GiveTest", 1, 0))) @@ -206,6 +209,7 @@ void UT_os_bin_sem_take_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemTake(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "TakeTest", 1, 0))) @@ -230,6 +234,7 @@ void UT_os_bin_sem_timed_wait_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemTimedWait(UT_OBJID_INCORRECT, 1000), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemTimedWait(OS_OBJECT_ID_UNDEFINED, 1000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "TimedWait", 1, 0)) && UT_SETUP(OS_BinSemTake(bin_sem_id))) @@ -299,6 +304,7 @@ void UT_os_bin_sem_get_info_test() /*-----------------------------------------------------*/ UT_RETVAL(OS_BinSemGetInfo(UT_OBJID_INCORRECT, &bin_sem_prop), OS_ERR_INVALID_ID); + UT_RETVAL(OS_BinSemGetInfo(OS_OBJECT_ID_UNDEFINED, &bin_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ if (UT_SETUP(OS_BinSemCreate(&bin_sem_id, "GetInfo", 1, 0))) From 8b41f8655499119c1af419b901fc41e115fd3da4 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 3 Jun 2021 17:31:34 -0400 Subject: [PATCH 02/16] Partial #1052, CountSem test cases --- src/unit-test-coverage/shared/src/coveragetest-countsem.c | 3 ++- src/unit-tests/oscore-test/ut_oscore_countsem_test.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 46612a774..40f8cfc7e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -61,7 +61,8 @@ void Test_OS_CountSemCreate(void) UtAssert_True(actual == expected, "OS_CountSemCreate() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, NULL, 0, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(NULL, "UT", 0, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, NULL, 0, 0), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate(&objid, "UT", 0, 0), OS_ERR_NAME_TOO_LONG); } diff --git a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c index b5cbc7eae..4a52897ea 100644 --- a/src/unit-tests/oscore-test/ut_oscore_countsem_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_countsem_test.c @@ -163,6 +163,7 @@ void UT_os_count_sem_delete_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_CountSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_CountSemDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -191,6 +192,7 @@ void UT_os_count_sem_give_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_CountSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_CountSemGive(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -221,6 +223,7 @@ void UT_os_count_sem_take_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_CountSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_CountSemTake(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -250,6 +253,7 @@ void UT_os_count_sem_timed_wait_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_CountSemTimedWait(UT_OBJID_INCORRECT, 1000), OS_ERR_INVALID_ID); + UT_RETVAL(OS_CountSemTimedWait(OS_OBJECT_ID_UNDEFINED, 1000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Sem-take-timed-out */ @@ -341,6 +345,7 @@ void UT_os_count_sem_get_info_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_CountSemGetInfo(UT_OBJID_INCORRECT, &count_sem_prop), OS_ERR_INVALID_ID); + UT_RETVAL(OS_CountSemGetInfo(OS_OBJECT_ID_UNDEFINED, &count_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg */ From 1e00b53bc1b250ae5a4edf68c4f58b73fac7d304 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 3 Jun 2021 17:38:15 -0400 Subject: [PATCH 03/16] Partial #1052, Mutex test cases --- src/unit-test-coverage/shared/src/coveragetest-mutex.c | 3 ++- src/unit-tests/oscore-test/ut_oscore_mutex_test.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 00776a4f3..42f04489a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -60,7 +60,8 @@ void Test_OS_MutSemCreate(void) UtAssert_True(actual == expected, "OS_MutSemCreate() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(NULL, NULL, 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(NULL, "UT", 0), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, NULL, 0), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate(&objid, "UT", 0), OS_ERR_NAME_TOO_LONG); } diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c index b42bfe2cf..4fe79ebb6 100644 --- a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c @@ -149,6 +149,7 @@ void UT_os_mut_sem_delete_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_MutSemDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_MutSemDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -176,6 +177,7 @@ void UT_os_mut_sem_give_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_MutSemGive(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_MutSemGive(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -208,6 +210,7 @@ void UT_os_mut_sem_take_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_MutSemTake(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_MutSemTake(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -284,6 +287,7 @@ void UT_os_mut_sem_get_info_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_MutSemGetInfo(UT_OBJID_INCORRECT, &mut_sem_prop), OS_ERR_INVALID_ID); + UT_RETVAL(OS_MutSemGetInfo(OS_OBJECT_ID_UNDEFINED, &mut_sem_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg */ From 60836bb5a6360a6b1969bf09e9a92ae51981ec5a Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 3 Jun 2021 17:56:07 -0400 Subject: [PATCH 04/16] Partial #1052, Queue test cases --- src/os/shared/src/osapi-queue.c | 2 ++ src/unit-test-coverage/shared/src/coveragetest-queue.c | 4 ++++ src/unit-tests/oscore-test/ut_oscore_queue_test.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/src/os/shared/src/osapi-queue.c b/src/os/shared/src/osapi-queue.c index f50278f8e..24a303577 100644 --- a/src/os/shared/src/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -166,6 +166,7 @@ int32 OS_QueueGet(osal_id_t queue_id, void *data, size_t size, size_t *size_copi /* Check Parameters */ OS_CHECK_POINTER(data); OS_CHECK_POINTER(size_copied); + OS_CHECK_SIZE(size); return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) @@ -205,6 +206,7 @@ int32 OS_QueuePut(osal_id_t queue_id, const void *data, size_t size, uint32 flag /* Check Parameters */ OS_CHECK_POINTER(data); + OS_CHECK_SIZE(size); return_code = OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, queue_id, &token); if (return_code == OS_SUCCESS) diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index a9493e87f..e7bbabbe6 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -118,6 +118,8 @@ void Test_OS_QueueGet(void) expected = OS_QUEUE_INVALID_SIZE; actual = OS_QueueGet(UT_OBJID_1, Buf, sizeof(Buf), &actual_size, 0); UtAssert_True(actual == expected, "OS_QueueGet() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); + + OSAPI_TEST_FUNCTION_RC(OS_QueueGet(UT_OBJID_1, Buf, 0, &actual_size, 0), OS_ERR_INVALID_SIZE); } void Test_OS_QueuePut(void) @@ -144,6 +146,8 @@ void Test_OS_QueuePut(void) expected = OS_QUEUE_INVALID_SIZE; actual = OS_QueuePut(UT_OBJID_1, Data, 1 + sizeof(Data), 0); UtAssert_True(actual == expected, "OS_QueuePut() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual); + + OSAPI_TEST_FUNCTION_RC(OS_QueuePut(UT_OBJID_1, Data, 0, 0), OS_ERR_INVALID_SIZE); } void Test_OS_QueueGetIdByName(void) diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.c b/src/unit-tests/oscore-test/ut_oscore_queue_test.c index f69faa716..d59d82e20 100644 --- a/src/unit-tests/oscore-test/ut_oscore_queue_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.c @@ -161,6 +161,7 @@ void UT_os_queue_delete_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_QueueDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_QueueDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -195,6 +196,8 @@ void UT_os_queue_get_test() UT_RETVAL(OS_QueueGet(UT_OBJID_INCORRECT, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK), OS_ERR_INVALID_ID); + UT_RETVAL(OS_QueueGet(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_in, sizeof(uint32), &size_copied, OS_CHECK), + OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg-1 */ @@ -205,6 +208,7 @@ void UT_os_queue_get_test() { UT_RETVAL(OS_QueueGet(queue_id, NULL, sizeof(uint32), &size_copied, OS_CHECK), OS_INVALID_POINTER); UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, sizeof(uint32), NULL, OS_CHECK), OS_INVALID_POINTER); + UT_RETVAL(OS_QueueGet(queue_id, &queue_data_in, 0, &size_copied, OS_CHECK), OS_ERR_INVALID_SIZE); UT_TEARDOWN(OS_QueueDelete(queue_id)); } @@ -304,6 +308,7 @@ void UT_os_queue_put_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_QueuePut(UT_OBJID_INCORRECT, (void *)&queue_data_out, sizeof(uint32), 0), OS_ERR_INVALID_ID); + UT_RETVAL(OS_QueuePut(OS_OBJECT_ID_UNDEFINED, (void *)&queue_data_out, sizeof(uint32), 0), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg */ @@ -313,6 +318,8 @@ void UT_os_queue_put_test() { UT_RETVAL(OS_QueuePut(queue_id, NULL, sizeof(uint32), 0), OS_INVALID_POINTER); UT_RETVAL(OS_QueuePut(queue_id, &queue_data_out, sizeof(uint32) + 1, 0), OS_QUEUE_INVALID_SIZE); + UT_RETVAL(OS_QueuePut(queue_id, &queue_data_out, 0, 0), OS_ERR_INVALID_SIZE); + UT_TEARDOWN(OS_QueueDelete(queue_id)); } @@ -412,6 +419,7 @@ void UT_os_queue_get_info_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_QueueGetInfo(UT_OBJID_INCORRECT, &queue_prop), OS_ERR_INVALID_ID); + UT_RETVAL(OS_QueueGetInfo(OS_OBJECT_ID_UNDEFINED, &queue_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg */ From 9f4db84433ea26fb41c786507d8ee145eb1abb31 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 3 Jun 2021 18:06:33 -0400 Subject: [PATCH 05/16] Partial #1052, Task test cases --- src/os/inc/osapi-task.h | 2 +- src/unit-test-coverage/shared/src/coveragetest-task.c | 10 ++++++++-- src/unit-tests/oscore-test/ut_oscore_task_test.c | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/os/inc/osapi-task.h b/src/os/inc/osapi-task.h index d9ed32915..55dd5ee90 100644 --- a/src/os/inc/osapi-task.h +++ b/src/os/inc/osapi-task.h @@ -91,7 +91,7 @@ typedef osal_task((*osal_task_entry)(void)); /**< @brief For task entry point */ * In that case, a stack of the requested size will be dynamically allocated from * the system heap. * - * @param[out] task_id will be set to the non-zero ID of the newly-created resource + * @param[out] task_id will be set to the non-zero ID of the newly-created resource @nonnull * @param[in] task_name the name of the new resource to create @nonnull * @param[in] function_pointer the entry point of the new task @nonnull * @param[in] stack_pointer pointer to the stack for the task, or NULL diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 58f51904f..7c288ca8e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -116,7 +116,13 @@ void Test_OS_TaskCreate(void) OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); OSAPI_TEST_FUNCTION_RC( - OS_TaskCreate(NULL, NULL, NULL, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_TaskCreate(NULL, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, NULL, UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), + OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC( + OS_TaskCreate(&objid, "UT", NULL, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), OS_INVALID_POINTER); OSAPI_TEST_FUNCTION_RC( OS_TaskCreate(&objid, "UT", UT_TestHook, OSAL_TASK_STACK_ALLOCATE, OSAL_SIZE_C(0), OSAL_PRIORITY_C(0), 0), @@ -248,7 +254,7 @@ void Test_OS_TaskGetInfo(void) OS_task_table[1].stack_size = OSAL_SIZE_C(0); OS_task_table[1].priority = OSAL_PRIORITY_C(0); - OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(OS_OBJECT_ID_UNDEFINED, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo(UT_OBJID_1, NULL), OS_INVALID_POINTER); } void Test_OS_TaskInstallDeleteHandler(void) diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 8f77534f0..5bb7daac1 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -225,6 +225,7 @@ void UT_os_task_delete_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_TaskDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TaskDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -431,6 +432,7 @@ void UT_os_task_set_priority_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_TaskSetPriority(UT_OBJID_INCORRECT, OSAL_PRIORITY_C(100)), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TaskSetPriority(OS_OBJECT_ID_UNDEFINED, OSAL_PRIORITY_C(100)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #4 Nominal */ @@ -557,6 +559,7 @@ void UT_os_task_get_info_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_TaskGetInfo(UT_OBJID_INCORRECT, &task_prop), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TaskGetInfo(OS_OBJECT_ID_UNDEFINED, &task_prop), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-pointer-arg */ From a440d375901d0af15d8cb3b497753a481bf808d8 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 14:40:37 -0400 Subject: [PATCH 06/16] Partial #1052, Module test cases --- .../osloader-test/ut_osloader_module_test.c | 2 ++ .../osloader-test/ut_osloader_symtable_test.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/unit-tests/osloader-test/ut_osloader_module_test.c b/src/unit-tests/osloader-test/ut_osloader_module_test.c index aca22eefa..27697ac3e 100644 --- a/src/unit-tests/osloader-test/ut_osloader_module_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_module_test.c @@ -185,6 +185,7 @@ void UT_os_module_unload_test() /* #1 Invalid-ID-arg */ UT_RETVAL(OS_ModuleUnload(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_ModuleUnload(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 OS-call-failure */ @@ -224,6 +225,7 @@ void UT_os_module_info_test() /* #2 Invalid-ID-arg */ UT_RETVAL(OS_ModuleInfo(UT_OBJID_INCORRECT, &module_info), OS_ERR_INVALID_ID); + UT_RETVAL(OS_ModuleInfo(OS_OBJECT_ID_UNDEFINED, &module_info), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ diff --git a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c index b9dcad61d..204d0cd35 100644 --- a/src/unit-tests/osloader-test/ut_osloader_symtable_test.c +++ b/src/unit-tests/osloader-test/ut_osloader_symtable_test.c @@ -129,22 +129,23 @@ void UT_os_module_symbol_lookup_test() } /*-----------------------------------------------------*/ - /* #1 Invalid-pointer-arg-1 */ - - UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, 0, "Sym"), OS_INVALID_POINTER); - - /*-----------------------------------------------------*/ - /* #2 Invalid-pointer-arg-2 */ + /* Invalid object ID */ - UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, 0), OS_INVALID_POINTER); + UT_RETVAL(OS_ModuleSymbolLookup(OS_OBJECT_ID_UNDEFINED, &symbol_addr, "Sym"), OS_ERR_INVALID_ID); + UT_RETVAL(OS_ModuleSymbolLookup(UT_OBJID_INCORRECT, &symbol_addr, "Sym"), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* Setup for remainder of tests */ if (UT_SETUP(OS_ModuleLoad(&module_id, "Mod1", UT_OS_GENERIC_MODULE_NAME2, OS_MODULE_FLAG_LOCAL_SYMBOLS))) { /*-----------------------------------------------------*/ - /* #3 Symbol-not-found */ + /* #1 Invalid-pointer-arg */ + + UT_RETVAL(OS_ModuleSymbolLookup(module_id, NULL, "Sym"), OS_INVALID_POINTER); + UT_RETVAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, NULL), OS_INVALID_POINTER); + /*-----------------------------------------------------*/ + /* #3 Symbol-not-found */ UT_RETVAL(OS_ModuleSymbolLookup(module_id, &symbol_addr, "NotFound"), OS_ERROR); /*-----------------------------------------------------*/ From ae50ba7f345cca4bb09e40e44176759cae50b1ce Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 14:50:59 -0400 Subject: [PATCH 07/16] Partial #1052, Network test cases --- src/os/inc/osapi-network.h | 4 ++-- src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/os/inc/osapi-network.h b/src/os/inc/osapi-network.h index c4339e800..99badf779 100644 --- a/src/os/inc/osapi-network.h +++ b/src/os/inc/osapi-network.h @@ -61,8 +61,8 @@ int32 OS_NetworkGetID(void); * If configured in the underlying network stack, * this function retrieves the local hostname of the system. * - * @param[out] host_name Buffer to hold name information - * @param[in] name_len Maximum length of host name buffer + * @param[out] host_name Buffer to hold name information @nonnull + * @param[in] name_len Maximum length of host name buffer @nonzero * * @return Execution status, see @ref OSReturnCodes * @retval #OS_SUCCESS @copybrief OS_SUCCESS diff --git a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c index c4944db2d..dc1bf3a97 100644 --- a/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c +++ b/src/unit-tests/osnetwork-test/ut_osnetwork_misc_test.c @@ -150,7 +150,7 @@ void UT_os_networkgethostname_test() /*-----------------------------------------------------*/ /* #1 Null-pointer-arg */ - UT_RETVAL(OS_NetworkGetHostName(NULL, 0), OS_INVALID_POINTER); + UT_RETVAL(OS_NetworkGetHostName(NULL, sizeof(buffer)), OS_INVALID_POINTER); /*-----------------------------------------------------*/ /* #2 Zero-name-length-arg */ From 8ff96654720fbd3a278179a6e2c9314f37b926cf Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 14:58:11 -0400 Subject: [PATCH 08/16] Partial #1052, Select test cases --- src/unit-tests/oscore-test/ut_oscore_select_test.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.c b/src/unit-tests/oscore-test/ut_oscore_select_test.c index b4fc89f50..4eeb31c11 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.c @@ -105,8 +105,11 @@ void UT_os_select_fd_test(void) UT_RETVAL(OS_SelectFdIsSet(NULL, selecttest_fd), false); UT_RETVAL(OS_SelectFdAdd(&FdSet, invalid_fd), OS_ERR_INVALID_ID); + UT_RETVAL(OS_SelectFdAdd(&FdSet, OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); UT_RETVAL(OS_SelectFdClear(&FdSet, invalid_fd), OS_ERR_INVALID_ID); + UT_RETVAL(OS_SelectFdClear(&FdSet, OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); UT_RETVAL(OS_SelectFdIsSet(&FdSet, invalid_fd), false); + UT_RETVAL(OS_SelectFdIsSet(&FdSet, OS_OBJECT_ID_UNDEFINED), false); UT_NOMINAL(OS_SelectFdZero(&FdSet)); UT_NOMINAL(OS_SelectFdAdd(&FdSet, selecttest_fd)); @@ -147,6 +150,7 @@ void UT_os_select_single_test(void) (unsigned int)StateFlags); UT_RETVAL(OS_SelectSingle(invalid_fd, &StateFlags, 0), OS_ERR_INVALID_ID); + UT_RETVAL(OS_SelectSingle(OS_OBJECT_ID_UNDEFINED, &StateFlags, 0), OS_ERR_INVALID_ID); } /*--------------------------------------------------------------------------------* From 1ccd30d1f2e5e2c9cb226dfb6d5385cce977161e Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 15:00:50 -0400 Subject: [PATCH 09/16] Partial #1052, Shell test cases --- src/unit-tests/osfile-test/ut_osfile_fileio_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index 1fb75bfd6..b81c49285 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -1425,6 +1425,7 @@ void UT_os_outputtofile_test() /* #2 Invalid-file-desc-arg */ UT_RETVAL(OS_ShellOutputToFile("ls", UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_ShellOutputToFile("ls", OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #4 Nominal */ From 7445a1c81ef3357422bccddf759ff21c9674836e Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 15:29:40 -0400 Subject: [PATCH 10/16] Partial #1052, Socket test cases --- src/tests/network-api-test/network-api-test.c | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index 846679088..81ae67740 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -117,6 +117,7 @@ void TestNetworkApiBadArgs(void) /* OS_SocketAddrToString */ UtAssert_INT32_EQ(OS_SocketAddrToString(addr_string, 0, &addr), OS_ERR_INVALID_SIZE); UtAssert_INT32_EQ(OS_SocketAddrToString(NULL, sizeof(addr_string), &addr), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_SocketAddrToString(addr_string, sizeof(addr_string), NULL), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_SocketAddrToString(addr_string, 1, &addr), OS_ERROR); } @@ -234,6 +235,7 @@ void TestDatagramNetworkApi(void) uint32 Buf3 = 222; uint32 Buf4 = 000; osal_id_t objid; + osal_id_t invalid_fd; uint16 PortNum; OS_socket_prop_t prop; OS_SockAddr_t l_addr; @@ -250,11 +252,11 @@ void TestDatagramNetworkApi(void) */ /* make a bad object ID by flipping the bits of a good object ID */ - objid = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(p2_socket_id) ^ 0xFFFFFFFF); + invalid_fd = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(p2_socket_id) ^ 0xFFFFFFFF); /* OS_SocketBind */ UtAssert_INT32_EQ(OS_SocketBind(OS_OBJECT_ID_UNDEFINED, &p2_addr), OS_ERR_INVALID_ID); - UtAssert_INT32_EQ(OS_SocketBind(objid, &p2_addr), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketBind(invalid_fd, &p2_addr), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketBind(regular_file_id, &p2_addr), OS_ERR_INCORRECT_OBJ_TYPE); UtAssert_INT32_EQ(OS_SocketBind(p2_socket_id, &p2_addr), OS_ERR_INCORRECT_OBJ_STATE); UtAssert_INT32_EQ(OS_SocketBind(p2_socket_id, NULL), OS_INVALID_POINTER); @@ -262,7 +264,7 @@ void TestDatagramNetworkApi(void) /* OS_SocketRecvFrom */ UtAssert_INT32_EQ(OS_SocketRecvFrom(OS_OBJECT_ID_UNDEFINED, &Buf2, sizeof(Buf2), &l_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); - UtAssert_INT32_EQ(OS_SocketRecvFrom(objid, &Buf2, sizeof(Buf2), &l_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketRecvFrom(invalid_fd, &Buf2, sizeof(Buf2), &l_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketRecvFrom(regular_file_id, &Buf2, sizeof(Buf2), &l_addr, UT_TIMEOUT), OS_ERR_INCORRECT_OBJ_TYPE); UtAssert_INT32_EQ(OS_SocketRecvFrom(p2_socket_id, NULL, sizeof(Buf2), &l_addr, UT_TIMEOUT), OS_INVALID_POINTER); @@ -270,7 +272,7 @@ void TestDatagramNetworkApi(void) /* OS_SocketSendTo */ UtAssert_INT32_EQ(OS_SocketSendTo(OS_OBJECT_ID_UNDEFINED, &Buf2, sizeof(Buf2), &l_addr), OS_ERR_INVALID_ID); - UtAssert_INT32_EQ(OS_SocketSendTo(objid, &Buf2, sizeof(Buf2), &l_addr), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketSendTo(invalid_fd, &Buf2, sizeof(Buf2), &l_addr), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketSendTo(regular_file_id, &Buf2, sizeof(Buf2), &l_addr), OS_ERR_INCORRECT_OBJ_TYPE); UtAssert_INT32_EQ(OS_SocketSendTo(p2_socket_id, NULL, sizeof(Buf2), &l_addr), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_SocketSendTo(p2_socket_id, &Buf2, 0, &l_addr), OS_ERR_INVALID_SIZE); @@ -278,7 +280,7 @@ void TestDatagramNetworkApi(void) /* OS_SocketGetInfo */ UtAssert_INT32_EQ(OS_SocketGetInfo(OS_OBJECT_ID_UNDEFINED, &prop), OS_ERR_INVALID_ID); - UtAssert_INT32_EQ(OS_SocketGetInfo(objid, &prop), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketGetInfo(invalid_fd, &prop), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketGetInfo(p2_socket_id, NULL), OS_INVALID_POINTER); /* OS_SocketGetIdByName */ @@ -455,6 +457,7 @@ void TestStreamNetworkApi(void) uint32 iter; uint32 loopcnt; osal_id_t temp_id; + osal_id_t invalid_fd; OS_SockAddr_t temp_addr; OS_task_prop_t taskprop; char Buf_rcv_c[4] = {0}; @@ -497,8 +500,9 @@ void TestStreamNetworkApi(void) /* OS_SocketAccept error conditions - check before binding */ /* create a bad ID by flipping the bits of a good ID */ - temp_id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(s_socket_id) ^ 0xFFFFFFFF); - UtAssert_INT32_EQ(OS_SocketAccept(temp_id, &temp_id, &temp_addr, 0), OS_ERR_INVALID_ID); + invalid_fd = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(s_socket_id) ^ 0xFFFFFFFF); + UtAssert_INT32_EQ(OS_SocketAccept(invalid_fd, &temp_id, &temp_addr, 0), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketAccept(OS_OBJECT_ID_UNDEFINED, &temp_id, &temp_addr, 0), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketAccept(s_socket_id, NULL, &temp_addr, UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_SocketAccept(s_socket_id, &temp_id, NULL, UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_SocketAccept(s_socket_id, &temp_id, &temp_addr, UT_TIMEOUT), OS_ERR_INCORRECT_OBJ_STATE); @@ -561,10 +565,12 @@ void TestStreamNetworkApi(void) if (iter == UT_STREAM_CONNECTION_INITIAL) { /* create a bad ID by flipping the bits of a good ID */ - temp_id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(c_socket_id) ^ 0xFFFFFFFF); + invalid_fd = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(c_socket_id) ^ 0xFFFFFFFF); /* OS_SocketShutdown */ - UtAssert_INT32_EQ(OS_SocketShutdown(temp_id, OS_SocketShutdownMode_SHUT_READ), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketShutdown(invalid_fd, OS_SocketShutdownMode_SHUT_READ), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketShutdown(OS_OBJECT_ID_UNDEFINED, OS_SocketShutdownMode_SHUT_READ), + OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketShutdown(regular_file_id, OS_SocketShutdownMode_SHUT_READ), OS_ERR_INCORRECT_OBJ_TYPE); UtAssert_INT32_EQ(OS_SocketShutdown(c_socket_id, OS_SocketShutdownMode_SHUT_READ), @@ -582,26 +588,29 @@ void TestStreamNetworkApi(void) if (iter == UT_STREAM_CONNECTION_INITIAL) { /* create a bad ID by flipping the bits of a good ID */ - temp_id = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(c_socket_id) ^ 0xFFFFFFFF); + invalid_fd = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(c_socket_id) ^ 0xFFFFFFFF); /* OS_SocketShutdown */ UtAssert_INT32_EQ(OS_SocketShutdown(c_socket_id, OS_SocketShutdownMode_NONE), OS_ERR_INVALID_ARGUMENT); /* OS_TimedRead */ - UtAssert_INT32_EQ(OS_TimedRead(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimedRead(invalid_fd, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), + OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, Buf_rcv_c, 0, UT_TIMEOUT), OS_ERR_INVALID_SIZE); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0), OS_ERROR_TIMEOUT); /* OS_TimedWrite */ - UtAssert_INT32_EQ(OS_TimedWrite(temp_id, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimedWrite(invalid_fd, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), + OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_TimedWrite(c_socket_id, Buf_rcv_c, 0, UT_TIMEOUT), OS_ERR_INVALID_SIZE); /* OS_SocketConnect */ - UtAssert_INT32_EQ(OS_SocketConnect(c_socket_id, NULL, UT_TIMEOUT), OS_INVALID_POINTER); - UtAssert_INT32_EQ(OS_SocketConnect(temp_id, &s_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketConnect(invalid_fd, &s_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_SocketConnect(OS_OBJECT_ID_UNDEFINED, &s_addr, UT_TIMEOUT), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_SocketConnect(regular_file_id, &s_addr, UT_TIMEOUT), OS_ERR_INCORRECT_OBJ_TYPE); + UtAssert_INT32_EQ(OS_SocketConnect(c_socket_id, NULL, UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_SocketConnect(c_socket_id, &s_addr, 0), OS_ERR_INCORRECT_OBJ_STATE); } From 6eedd76e3f658196d3d03b8d09dac5266e84fa22 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 15:54:13 -0400 Subject: [PATCH 11/16] Partial #1052, Timebase test cases --- .../time-base-api-test/time-base-api-test.c | 150 +++++------------- 1 file changed, 38 insertions(+), 112 deletions(-) diff --git a/src/tests/time-base-api-test/time-base-api-test.c b/src/tests/time-base-api-test/time-base-api-test.c index e3057a778..928b3c0d0 100644 --- a/src/tests/time-base-api-test/time-base-api-test.c +++ b/src/tests/time-base-api-test/time-base-api-test.c @@ -35,12 +35,6 @@ #include "uttest.h" #include "utbsp.h" -static int32 SyncTimeBaseCreateRc = 0; -static int32 SyncTimeBaseDeleteRc = 0; -static int32 SyncTimeBaseSetRc = 0; -static int32 SyncTimeBaseGetByNameRc = 0; -static int32 SyncTimeBaseGetInfoRc = 0; - static OS_timebase_prop_t SyncTimeBaseProp; static uint32 NumSyncs = 0; @@ -56,12 +50,13 @@ static uint32 UT_TimerSync(osal_id_t timer_id) */ if (NumSyncs == 0) { - SyncTimeBaseCreateRc = OS_TimeBaseCreate(&timer_id, "sync", 0); - SyncTimeBaseDeleteRc = OS_TimeBaseDelete(timer_id); - SyncTimeBaseSetRc = OS_TimeBaseSet(timer_id, 100, 100); - SyncTimeBaseGetByNameRc = OS_TimeBaseGetIdByName(&timer_id, "TimeBaseC"); - SyncTimeBaseGetInfoRc = OS_TimeBaseGetInfo(timer_id, &SyncTimeBaseProp); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&timer_id, "sync", 0), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimeBaseDelete(timer_id), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimeBaseSet(timer_id, 100, 100), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimeBaseGetIdByName(&timer_id, "TimeBaseC"), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimeBaseGetInfo(timer_id, &SyncTimeBaseProp), OS_ERR_INCORRECT_OBJ_STATE); } + ++NumSyncs; OS_TaskDelay(1); return 1; @@ -71,10 +66,9 @@ static uint32 UT_TimerSync(osal_id_t timer_id) void TestTimeBaseApi(void) { - int32 expected; - int32 actual; uint32 freerun; osal_id_t objid; + osal_id_t badid; osal_id_t time_base_id; osal_id_t time_base_id2; osal_id_t tb_id[OS_MAX_TIMEBASES]; @@ -87,17 +81,8 @@ void TestTimeBaseApi(void) */ /* Test for invalid inputs */ - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseCreate(NULL, NULL, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseCreate(NULL, "TimeBase6", 0); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseCreate(&time_base_id, NULL, 0); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseCreate(NULL, "TimeBase6", 0), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&time_base_id, NULL, 0), OS_INVALID_POINTER); memset(timebase_name, 'x', sizeof(timebase_name)); timebase_name[sizeof(timebase_name) - 1] = 0; @@ -125,16 +110,9 @@ void TestTimeBaseApi(void) OS_DeleteAllObjects(); /* Test for nominal inputs - these resources are used for the remainder of test */ - expected = OS_SUCCESS; - - actual = OS_TimeBaseCreate(&time_base_id, "TimeBaseA", 0); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_TimeBaseCreate(&time_base_id2, "TimeBaseB", NULL); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)actual); - - actual = OS_TimeBaseCreate(&time_base_id, "TimeBaseC", UT_TimerSync); - UtAssert_True(actual == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&time_base_id, "TimeBaseA", 0), OS_SUCCESS); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&time_base_id2, "TimeBaseB", NULL), OS_SUCCESS); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&time_base_id, "TimeBaseC", UT_TimerSync), OS_SUCCESS); /* Let the TimeBaseC accumulate at least one sync, so it will * attempt to call timebase APIs from its own context. */ @@ -143,56 +121,26 @@ void TestTimeBaseApi(void) OS_TaskDelay(1); } - /* Check that those configuration attempts all returned OS_ERR_INCORRECT_OBJ_STATE */ - UtAssert_True(SyncTimeBaseCreateRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimeBaseCreate(&timer_id, \"sync\", 0) (%d) == OS_ERR_INCORRECT_OBJ_STATE", - (int)SyncTimeBaseCreateRc); - UtAssert_True(SyncTimeBaseDeleteRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimeBaseDelete(timer_id) (%d) == OS_ERR_INCORRECT_OBJ_STATE", (int)SyncTimeBaseDeleteRc); - UtAssert_True(SyncTimeBaseSetRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimeBaseSet(timer_id, 100, 100) (%d) == OS_ERR_INCORRECT_OBJ_STATE", (int)SyncTimeBaseSetRc); - UtAssert_True(SyncTimeBaseGetByNameRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimeBaseGetIdByName(&timer_id, \"TimeBaseC\") (%d) == OS_ERR_INCORRECT_OBJ_STATE", - (int)SyncTimeBaseGetByNameRc); - UtAssert_True(SyncTimeBaseGetInfoRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimeBaseGetInfo(timer_id, &SyncTimeBaseProp) (%d) == OS_ERR_INCORRECT_OBJ_STATE", - (int)SyncTimeBaseGetInfoRc); - /* * Test Case For: * int32 OS_TimeBaseSet(uint32 timer_id, uint32 start_time, uint32 interval_time) */ /* Test for nominal inputs */ - expected = OS_SUCCESS; - actual = OS_TimeBaseSet(time_base_id, 1000, 1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_SUCCESS; - actual = OS_TimeBaseSet(time_base_id, 0, 0); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, 1000, 1000), OS_SUCCESS); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, 0, 0), OS_SUCCESS); /* Test for invalid inputs */ - /* overflow on input */ - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimeBaseSet(time_base_id, UINT32_MAX, UINT32_MAX); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); + /* create a bad ID by flipping the bits of a good ID */ + badid = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(time_base_id2) ^ 0xFFFFFFFF); - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimeBaseSet(time_base_id, -1000, -1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimeBaseSet(time_base_id, 1000, -1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - - expected = OS_TIMER_ERR_INVALID_ARGS; - actual = OS_TimeBaseSet(time_base_id, -1000, 1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_TIMER_ERR_INVALID_ARGS", (long)actual); - - expected = OS_ERR_INVALID_ID; - actual = OS_TimeBaseSet(OS_OBJECT_ID_UNDEFINED, 1000, 1000); - UtAssert_True(actual == expected, "OS_TimeBaseSet() (%ld) == OS_ERR_INVALID_ID", (long)actual); + /* overflow on input */ + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, UINT32_MAX, UINT32_MAX), OS_TIMER_ERR_INVALID_ARGS); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, -1000, -1000), OS_TIMER_ERR_INVALID_ARGS); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, 1000, -1000), OS_TIMER_ERR_INVALID_ARGS); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, -1000, 1000), OS_TIMER_ERR_INVALID_ARGS); + UtAssert_INT32_EQ(OS_TimeBaseSet(OS_OBJECT_ID_UNDEFINED, 1000, 1000), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimeBaseSet(badid, 1000, 1000), OS_ERR_INVALID_ID); /* * Test Case For: @@ -200,14 +148,11 @@ void TestTimeBaseApi(void) */ /* Test for nominal inputs */ - expected = OS_SUCCESS; - actual = OS_TimeBaseDelete(time_base_id); - UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseDelete(time_base_id), OS_SUCCESS); /* Test for invalid inputs */ - expected = OS_ERR_INVALID_ID; - actual = OS_TimeBaseDelete(OS_OBJECT_ID_UNDEFINED); - UtAssert_True(actual == expected, "OS_TimeBaseDelete() (%ld) == OS_ERR_INVALID_ID", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimeBaseDelete(badid), OS_ERR_INVALID_ID); /* * Test Case For: @@ -216,18 +161,14 @@ void TestTimeBaseApi(void) /* Test for nominal inputs */ /* Note: TimeBase2 was created above using TimeBaseCreate and id was set to time_base_id2 */ - expected = OS_SUCCESS; - objid = OS_OBJECT_ID_UNDEFINED; - actual = OS_TimeBaseGetIdByName(&objid, "TimeBaseB"); - UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_SUCCESS", (long)actual); + objid = OS_OBJECT_ID_UNDEFINED; + UtAssert_INT32_EQ(OS_TimeBaseGetIdByName(&objid, "TimeBaseB"), OS_SUCCESS); UtAssert_True(OS_ObjectIdEqual(objid, time_base_id2), "OS_TimeBaseGetIdByName() objid (%lu) Matches!", OS_ObjectIdToInteger(objid)); /* Test for invalid inputs */ - expected = OS_ERR_NAME_NOT_FOUND; - objid = OS_OBJECT_ID_UNDEFINED; - actual = OS_TimeBaseGetIdByName(&objid, "NF"); - UtAssert_True(actual == expected, "OS_TimeBaseGetIdByName() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + objid = OS_OBJECT_ID_UNDEFINED; + UtAssert_INT32_EQ(OS_TimeBaseGetIdByName(&objid, "NF"), OS_ERR_NAME_NOT_FOUND); UtAssert_True(!OS_ObjectIdDefined(objid), "OS_TimeBaseGetIdByName() objid (%lu) still OS_OBJECT_ID_UNDEFINED", OS_ObjectIdToInteger(objid)); @@ -243,7 +184,6 @@ void TestTimeBaseApi(void) * Test Case For: * int32 OS_TimeBaseGetInfo (uint32 timebase_id, OS_timebase_prop_t *timebase_prop) */ - expected = OS_SUCCESS; /* Test for nominal inputs */ /* Note: TimeBase2 was created above using TimeBaseCreate */ @@ -251,9 +191,7 @@ void TestTimeBaseApi(void) /* Initializing timebase_prop values to something other than time_base_id2 to ensure they have changed */ memset(&timebase_prop, 0x55, sizeof(timebase_prop)); - actual = OS_TimeBaseGetInfo(time_base_id2, &timebase_prop); - - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseGetInfo(time_base_id2, &timebase_prop), OS_SUCCESS); UtAssert_True(!OS_ObjectIdDefined(timebase_prop.creator), "timebase_prop.creator (%lu) undefined", OS_ObjectIdToInteger(timebase_prop.creator)); @@ -267,13 +205,9 @@ void TestTimeBaseApi(void) (unsigned long)timebase_prop.accuracy); /* Test for invalid inputs */ - expected = OS_ERR_INVALID_ID; - actual = OS_TimeBaseGetInfo(OS_OBJECT_ID_UNDEFINED, &timebase_prop); - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_ERR_INVALID_ID", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_TimeBaseGetInfo(time_base_id2, NULL); - UtAssert_True(actual == expected, "OS_TimeBaseGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseGetInfo(OS_OBJECT_ID_UNDEFINED, &timebase_prop), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimeBaseGetInfo(badid, &timebase_prop), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimeBaseGetInfo(time_base_id2, NULL), OS_INVALID_POINTER); /* * Test Case For: @@ -282,25 +216,17 @@ void TestTimeBaseApi(void) /* Test for nominal inputs */ /* Note: TimeBase2 was created above using TimeBaseCreate */ - expected = OS_SUCCESS; - freerun = 0xFFFFFFFF; - actual = OS_TimeBaseGetFreeRun(time_base_id2, &freerun); - UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseGetFreeRun(time_base_id2, &freerun), OS_SUCCESS); freerun = 0x0000000; - actual = OS_TimeBaseGetFreeRun(time_base_id2, &freerun); - UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TimeBaseGetFreeRun(time_base_id2, &freerun), OS_SUCCESS); + /* Test for invalid inputs */ UtAssert_INT32_EQ(OS_TimeBaseGetFreeRun(OS_OBJECT_ID_UNDEFINED, &freerun), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimeBaseGetFreeRun(badid, &freerun), OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_TimeBaseGetFreeRun(time_base_id2, NULL), OS_INVALID_POINTER); - /* Test for invalid inputs */ - expected = OS_ERR_INVALID_ID; - freerun = 0xFFFFFFFF; - actual = OS_TimeBaseGetFreeRun(OS_OBJECT_ID_UNDEFINED, &freerun); - UtAssert_True(actual == expected, "OS_TimeBaseGetFreeRun() (%ld) == OS_SUCCESS", (long)actual); - } /* end TestTimeBaseApi */ void UtTest_Setup(void) From afc930e666a3b0dc94af00a75915d6309e1bd8b5 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 16:14:07 -0400 Subject: [PATCH 12/16] Partial #1052, Timer test cases --- .../timer-add-api-test/timer-add-api-test.c | 47 ++++--------- .../ostimer-test/ut_ostimer_timerio_test.c | 66 +++++++------------ 2 files changed, 36 insertions(+), 77 deletions(-) diff --git a/src/tests/timer-add-api-test/timer-add-api-test.c b/src/tests/timer-add-api-test/timer-add-api-test.c index d80cc5656..21f4447cf 100644 --- a/src/tests/timer-add-api-test/timer-add-api-test.c +++ b/src/tests/timer-add-api-test/timer-add-api-test.c @@ -65,10 +65,8 @@ void TestTimerAddApi(void) * callback_ptr, void *callback_arg) */ - int32 actual; - int32 expected; - int32 tbc_ret_val; - int32 tbs_ret_val; + uint32 expected; + osal_id_t badid; osal_id_t timer_id; osal_id_t time_base_id; int i = 0; @@ -80,13 +78,8 @@ void TestTimerAddApi(void) /* Create and set the TimeBase obj and verify success */ - tbc_ret_val = OS_TimeBaseCreate(&time_base_id, "TimeBase", 0); - expected = OS_SUCCESS; - UtAssert_True(tbc_ret_val == expected, "OS_TimeBaseCreate() (%ld) == OS_SUCCESS", (long)tbc_ret_val); - - tbs_ret_val = OS_TimeBaseSet(time_base_id, 10000, 10000); /* ms */ - expected = OS_SUCCESS; - UtAssert_True(tbs_ret_val == expected, "OS_TimeBaseSet() (%ld) == OS_SUCCESS", (long)tbs_ret_val); + UtAssert_INT32_EQ(OS_TimeBaseCreate(&time_base_id, "TimeBase", 0), OS_SUCCESS); + UtAssert_INT32_EQ(OS_TimeBaseSet(time_base_id, 10000, 10000), OS_SUCCESS); memset(temp_name, 'x', sizeof(temp_name) - 1); temp_name[sizeof(temp_name) - 1] = 0; @@ -183,30 +176,18 @@ void TestTimerAddApi(void) } /* Test nominal inputs */ - expected = OS_SUCCESS; - actual = OS_TimerAdd(&timer_id, "Timer", time_base_id, null_func, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_SUCCESS", (long)actual); - - /* Test invalid inputs */ - expected = OS_INVALID_POINTER; - actual = OS_TimerAdd(NULL, "Timer", time_base_id, null_func, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, "Timer", time_base_id, null_func, NULL), OS_SUCCESS); - expected = OS_ERR_INVALID_ID; - actual = OS_TimerAdd(&timer_id, "Timer", OS_OBJECT_ID_UNDEFINED, null_func, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_INVALID_ID", (long)actual); + /* create a bad ID by flipping the bits of a good ID */ + badid = OS_ObjectIdFromInteger(OS_ObjectIdToInteger(time_base_id) ^ 0xFFFFFFFF); - expected = OS_INVALID_POINTER; - actual = OS_TimerAdd(&timer_id, "Timer", time_base_id, NULL, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_ERR_NAME_TAKEN; - actual = OS_TimerAdd(&timer_id, "Timer", time_base_id, null_func, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_ERR_NAME_TAKEN", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_TimerAdd(&timer_id, 0, time_base_id, null_func, NULL); - UtAssert_True(actual == expected, "OS_TimerAdd() (%ld) == OS_INVALID_POINTER", (long)actual); + /* Test invalid inputs */ + UtAssert_INT32_EQ(OS_TimerAdd(NULL, "Timer", time_base_id, null_func, NULL), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, "Timer", OS_OBJECT_ID_UNDEFINED, null_func, NULL), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, "Timer", badid, null_func, NULL), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, "Timer", time_base_id, NULL, NULL), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, "Timer", time_base_id, null_func, NULL), OS_ERR_NAME_TAKEN); + UtAssert_INT32_EQ(OS_TimerAdd(&timer_id, 0, time_base_id, null_func, NULL), OS_INVALID_POINTER); } /* end TestTimerAddApi */ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c index 57f5da660..1982191d3 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -55,15 +55,7 @@ osal_id_t g_timerIds[UT_OS_TIMER_LIST_LEN]; typedef struct { - bool IsValid; - - int32 CreateRc; - int32 AddRc; - int32 DeleteRc; - int32 SetRc; - int32 GetByNameRc; - int32 GetInfoRc; - + bool IsTested; OS_timer_prop_t Prop; } UT_reconf_status_t; @@ -82,7 +74,7 @@ void UT_os_reconftimercallback(osal_id_t timerId, void *arg) { UT_reconf_status_t *reconf = arg; - if (!reconf->IsValid) + if (!reconf->IsTested) { /* * Calls to timer configuration from the context of a timer function @@ -91,14 +83,16 @@ void UT_os_reconftimercallback(osal_id_t timerId, void *arg) * calls the various functions on the first time through and stores the * result, which is checked/asserted in the main task. */ - reconf->CreateRc = OS_TimerCreate(&timerId, "reconf", &g_clkAccuracy, UT_os_othertimercallback1); - reconf->AddRc = OS_TimerAdd(&timerId, "reconf", g_timerIds[1], UT_os_othertimercallback2, NULL); - reconf->DeleteRc = OS_TimerDelete(timerId); - reconf->SetRc = OS_TimerSet(timerId, 100, 100); - reconf->GetByNameRc = OS_TimerGetIdByName(&timerId, g_timerNames[7]); - reconf->GetInfoRc = OS_TimerGetInfo(timerId, &reconf->Prop); - - reconf->IsValid = true; + UtAssert_INT32_EQ(OS_TimerCreate(&timerId, "reconf", &g_clkAccuracy, UT_os_othertimercallback1), + OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimerAdd(&timerId, "reconf", g_timerIds[1], UT_os_othertimercallback2, NULL), + OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimerDelete(timerId), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimerSet(timerId, 100, 100), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimerGetIdByName(&timerId, g_timerNames[7]), OS_ERR_INCORRECT_OBJ_STATE); + UtAssert_INT32_EQ(OS_TimerGetInfo(timerId, &reconf->Prop), OS_ERR_INCORRECT_OBJ_STATE); + + reconf->IsTested = true; } } @@ -274,7 +268,7 @@ void UT_os_timerreconf_test() { if (UT_SETUP(OS_TimerSet(g_timerIds[2], 50, 50))) { - while (!reconf.IsValid) + while (!reconf.IsTested) { OS_TaskDelay(1); } @@ -288,25 +282,6 @@ void UT_os_timerreconf_test() /* Reset test environment */ UT_TEARDOWN(OS_TimeBaseDelete(g_timerIds[1])); } - - /* Check that those configuration attempts all returned OS_ERR_INCORRECT_OBJ_STATE */ - UtAssert_True(reconf.CreateRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerCreate(&timerId, \"reconf\", &g_clkAccuracy, UT_os_othertimercallback1) (%d) == " - "OS_ERR_INCORRECT_OBJ_STATE", - (int)reconf.CreateRc); - UtAssert_True(reconf.AddRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerAdd(&timerId, \"reconf\", g_timerIds[1], UT_os_othertimercallback2, NULL) (%d) == " - "OS_ERR_INCORRECT_OBJ_STATE", - (int)reconf.AddRc); - UtAssert_True(reconf.DeleteRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerDelete(timerId) (%d) == OS_ERR_INCORRECT_OBJ_STATE", (int)reconf.DeleteRc); - UtAssert_True(reconf.SetRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerSet(timerId, 100, 100) (%d) == OS_ERR_INCORRECT_OBJ_STATE", (int)reconf.SetRc); - UtAssert_True(reconf.GetByNameRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerGetIdByName(&timerId, g_timerNames[7]) (%d) == OS_ERR_INCORRECT_OBJ_STATE", - (int)reconf.GetByNameRc); - UtAssert_True(reconf.GetInfoRc == OS_ERR_INCORRECT_OBJ_STATE, - "OS_TimerGetInfo(timerId, &TimerProp) (%d) == OS_ERR_INCORRECT_OBJ_STATE", (int)reconf.GetInfoRc); } /*--------------------------------------------------------------------------------* @@ -357,6 +332,7 @@ void UT_os_timerdelete_test() /* #1 Invalid-id-arg */ UT_RETVAL(OS_TimerDelete(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TimerDelete(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Internal-error */ @@ -434,6 +410,7 @@ void UT_os_timerset_test() /* #1 Invalid-id-arg */ UT_RETVAL(OS_TimerSet(UT_OBJID_INCORRECT, 10000, 10000), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TimerSet(OS_OBJECT_ID_UNDEFINED, 10000, 10000), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Internal-error */ @@ -614,20 +591,21 @@ void UT_os_timergetinfo_test() OS_timer_prop_t timerProps; /*-----------------------------------------------------*/ - /* #1 Null-pointer-arg */ - - UT_RETVAL(OS_TimerGetInfo(UT_OBJID_INCORRECT, NULL), OS_INVALID_POINTER); - - /*-----------------------------------------------------*/ - /* #2 Invalid-id-arg */ + /* Invalid-id-arg */ UT_RETVAL(OS_TimerGetInfo(UT_OBJID_INCORRECT, &timerProps), OS_ERR_INVALID_ID); + UT_RETVAL(OS_TimerGetInfo(OS_OBJECT_ID_UNDEFINED, &timerProps), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ if (UT_SETUP(OS_TimerCreate(&g_timerIds[3], g_timerNames[3], &g_clkAccuracy, &UT_os_timercallback))) { + /*-----------------------------------------------------*/ + /* Null-pointer-arg */ + + UT_RETVAL(OS_TimerGetInfo(g_timerIds[3], NULL), OS_INVALID_POINTER); + memset(&timerProps, 0x00, sizeof(timerProps)); UT_NOMINAL(OS_TimerGetInfo(g_timerIds[3], &timerProps)); From a8ba70c68a2062178745ea7ebfa05a2d0d4ab5be Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 16:26:57 -0400 Subject: [PATCH 13/16] Partial #1052, Directory test cases --- src/unit-test-coverage/shared/src/coveragetest-dir.c | 6 +++++- src/unit-tests/osfile-test/ut_osfile_dirio_test.c | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index d197136a0..a6ea62bc1 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -70,7 +70,11 @@ void Test_OS_DirectoryOpen(void) UtAssert_True(actual == expected, "OS_DirectoryOpen() (%ld) == OS_SUCCESS", (long)actual); OSAPI_TEST_OBJID(objid, !=, OS_OBJECT_ID_UNDEFINED); - OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(NULL, NULL), OS_INVALID_POINTER); + /* + * Note that the second arg (path) is validated by a separate unit (OS_TranslatePath), + * so it should not be passed NULL here + */ + OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(NULL, "Dir"), OS_INVALID_POINTER); } void Test_OS_DirectoryClose(void) diff --git a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c index a71fd90c8..b6ed6d5a4 100644 --- a/src/unit-tests/osfile-test/ut_osfile_dirio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_dirio_test.c @@ -284,6 +284,7 @@ void UT_os_closedir_test() os_dirent_t dirEntry; UT_RETVAL(OS_DirectoryClose(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_DirectoryClose(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Nominal */ @@ -358,6 +359,7 @@ void UT_os_readdir_test() /* Invalid ID */ UT_RETVAL(OS_DirectoryRead(UT_OBJID_INCORRECT, &dirent), OS_ERR_INVALID_ID); + UT_RETVAL(OS_DirectoryRead(OS_OBJECT_ID_UNDEFINED, &dirent), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -449,6 +451,7 @@ void UT_os_rewinddir_test() /* Invalid ID */ UT_RETVAL(OS_DirectoryRewind(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_DirectoryRewind(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Nominal */ From 6b59b3524563e6a4745e614269bfb5eaac8f4242 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 16:41:04 -0400 Subject: [PATCH 14/16] Partial #1052, Filesys test cases --- src/os/inc/osapi-filesys.h | 2 +- src/os/shared/src/osapi-filesys.c | 1 + .../file-sys-add-fixed-map-api-test.c | 42 +++---------------- .../shared/src/coveragetest-filesys.c | 8 ++-- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h index 6f7fb47cf..58ca0ffbf 100644 --- a/src/os/inc/osapi-filesys.h +++ b/src/os/inc/osapi-filesys.h @@ -79,7 +79,7 @@ typedef struct * * OS_FileSysAddFixedMap(&fs_id, "/", "/root"); * - * @param[out] filesys_id A non-zero OSAL ID reflecting the file system + * @param[out] filesys_id A buffer to store the ID of the file system mapping @nonnull * @param[in] phys_path The native system directory (an existing mount point) @nonnull * @param[in] virt_path The virtual mount point of this filesystem @nonnull * diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 8a209fe13..68eb5f438 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -262,6 +262,7 @@ int32 OS_FileSysAddFixedMap(osal_id_t *filesys_id, const char *phys_path, const /* * Validate inputs */ + OS_CHECK_POINTER(filesys_id); OS_CHECK_STRING(phys_path, sizeof(filesys->system_mountpt), OS_FS_ERR_PATH_TOO_LONG); OS_CHECK_PATHNAME(virt_path); diff --git a/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c index 01047aadf..e1f0f0599 100644 --- a/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c +++ b/src/tests/file-sys-add-fixed-map-api-test/file-sys-add-fixed-map-api-test.c @@ -38,8 +38,6 @@ void TestFileSysAddFixedMapApi(void) { - int32 expected; - int32 actual; osal_id_t fs_id; char translated_path[OS_MAX_LOCAL_PATH_LEN + 5]; char long_path[OS_MAX_PATH_LEN + 5]; @@ -51,42 +49,14 @@ void TestFileSysAddFixedMapApi(void) * Just map /test to a dir of the same name, relative to current dir. */ - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_TranslatePath("/test/myfile.txt", translated_path); - UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_SUCCESS; - actual = OS_FileSysAddFixedMap(&fs_id, "./test", "/test"); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_SUCCESS; - actual = OS_TranslatePath("/test/myfile.txt", translated_path); - UtAssert_True(actual == expected, "OS_TranslatePath() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_FS_ERR_PATH_INVALID); + UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, "./test", "/test"), OS_SUCCESS); + UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_SUCCESS); /* Test for invalid inputs */ - expected = OS_ERR_NAME_TAKEN; - actual = OS_FileSysAddFixedMap(NULL, "./test", "/test"); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FileSysAddFixedMap(&fs_id, NULL, "/test"); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FileSysAddFixedMap(&fs_id, "./test", NULL); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FileSysAddFixedMap(NULL, NULL, NULL); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FileSysAddFixedMap(&fs_id, NULL, NULL); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FileSysAddFixedMap(NULL, "./test", NULL); - UtAssert_True(actual == expected, "OS_FileSysAddFixedMap() (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_INT32_EQ(OS_FileSysAddFixedMap(NULL, "./test", "/test"), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, NULL, "/test"), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, "./test", NULL), OS_INVALID_POINTER); /* Test names too long (phys_path and virt_path have different limits) */ memset(long_path, 'x', sizeof(long_path) - 1); diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 751a65f52..9e0fb6376 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -56,7 +56,8 @@ void Test_OS_FileSysAddFixedMap(void) osal_id_t id; OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", NULL), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, NULL, "/virt"), OS_INVALID_POINTER); UT_SetDeferredRetcode(UT_KEY(OCS_memchr), 1, OS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_FileSysAddFixedMap(&id, "/phys", "/virt"), OS_FS_ERR_PATH_TOO_LONG); @@ -441,9 +442,8 @@ void Test_OS_TranslatePath(void) LocalBuffer); /* Check various error paths */ - expected = OS_INVALID_POINTER; - actual = OS_TranslatePath(NULL, NULL); - UtAssert_True(actual == expected, "OS_TranslatePath(NULL,NULL) (%ld) == OS_INVALID_POINTER", (long)actual); + UtAssert_INT32_EQ(OS_TranslatePath("/cf/test", NULL), OS_INVALID_POINTER); + UtAssert_INT32_EQ(OS_TranslatePath(NULL, LocalBuffer), OS_INVALID_POINTER); UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); expected = OS_FS_ERR_PATH_TOO_LONG; From 46eaa70effdd80560abd78ed006c4b8b37327125 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 4 Jun 2021 16:49:12 -0400 Subject: [PATCH 15/16] Partial #1052, File test cases --- src/tests/network-api-test/network-api-test.c | 4 ++++ src/unit-tests/osfile-test/ut_osfile_fileio_test.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/tests/network-api-test/network-api-test.c b/src/tests/network-api-test/network-api-test.c index 81ae67740..5047add09 100644 --- a/src/tests/network-api-test/network-api-test.c +++ b/src/tests/network-api-test/network-api-test.c @@ -596,6 +596,8 @@ void TestStreamNetworkApi(void) /* OS_TimedRead */ UtAssert_INT32_EQ(OS_TimedRead(invalid_fd, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimedRead(OS_OBJECT_ID_UNDEFINED, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), + OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, NULL, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, Buf_rcv_c, 0, UT_TIMEOUT), OS_ERR_INVALID_SIZE); UtAssert_INT32_EQ(OS_TimedRead(c_socket_id, Buf_rcv_c, sizeof(Buf_rcv_c), 0), OS_ERROR_TIMEOUT); @@ -603,6 +605,8 @@ void TestStreamNetworkApi(void) /* OS_TimedWrite */ UtAssert_INT32_EQ(OS_TimedWrite(invalid_fd, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_ERR_INVALID_ID); + UtAssert_INT32_EQ(OS_TimedWrite(OS_OBJECT_ID_UNDEFINED, Buf_rcv_c, sizeof(Buf_rcv_c), UT_TIMEOUT), + OS_ERR_INVALID_ID); UtAssert_INT32_EQ(OS_TimedWrite(c_socket_id, NULL, sizeof(Buf_rcv_c), UT_TIMEOUT), OS_INVALID_POINTER); UtAssert_INT32_EQ(OS_TimedWrite(c_socket_id, Buf_rcv_c, 0, UT_TIMEOUT), OS_ERR_INVALID_SIZE); diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index b81c49285..0e54b6729 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -455,6 +455,7 @@ void UT_os_closefile_test() /* #1 Invalid-file-desc-arg */ UT_RETVAL(OS_close(UT_OBJID_INCORRECT), OS_ERR_INVALID_ID); + UT_RETVAL(OS_close(OS_OBJECT_ID_UNDEFINED), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #3 Nominal */ @@ -549,6 +550,7 @@ void UT_os_readfile_test() /*-----------------------------------------------------*/ /* #2 Invalid-file-desc-arg */ UT_RETVAL(OS_read(UT_OBJID_INCORRECT, g_readBuff, sizeof(g_readBuff)), OS_ERR_INVALID_ID); + UT_RETVAL(OS_read(OS_OBJECT_ID_UNDEFINED, g_readBuff, sizeof(g_readBuff)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #4 Nominal */ @@ -657,6 +659,7 @@ void UT_os_writefile_test() /* #2 Invalid-file-desc-arg */ UT_RETVAL(OS_write(UT_OBJID_INCORRECT, g_writeBuff, sizeof(g_writeBuff)), OS_ERR_INVALID_ID); + UT_RETVAL(OS_write(OS_OBJECT_ID_UNDEFINED, g_writeBuff, sizeof(g_writeBuff)), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #4 Nominal */ @@ -744,6 +747,7 @@ void UT_os_lseekfile_test() int32 pos1 = 0, pos2 = 0, pos3 = 0; UT_RETVAL(OS_lseek(UT_OBJID_INCORRECT, 0, OS_SEEK_SET), OS_ERR_INVALID_ID); + UT_RETVAL(OS_lseek(OS_OBJECT_ID_UNDEFINED, 0, OS_SEEK_SET), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #2 Invalid-whence-arg */ @@ -1535,6 +1539,7 @@ void UT_os_getfdinfo_test() /* #2 Invalid-file-desc-arg */ UT_RETVAL(OS_FDGetInfo(UT_OBJID_INCORRECT, &fdProps), OS_ERR_INVALID_ID); + UT_RETVAL(OS_FDGetInfo(OS_OBJECT_ID_UNDEFINED, &fdProps), OS_ERR_INVALID_ID); /*-----------------------------------------------------*/ /* #4 Nominal */ From 8036c9e54b5e9f80d27348c5764bb05efecb7256 Mon Sep 17 00:00:00 2001 From: "Gerardo E. Cruz-Ortiz" <59618057+astrogeco@users.noreply.github.com> Date: Wed, 23 Jun 2021 13:29:28 -0400 Subject: [PATCH 16/16] IC:2021-06-22, Bump to v5.1.0-rc1+dev548 --- README.md | 5 +++++ src/os/inc/osapi-version.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff16e2c4e..6d6484da3 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,11 @@ The autogenerated OSAL user's guide can be viewed at and + ### Development Build: v5.1.0-rc1+dev530 - Implement Coding Standard Rules in CodeQL diff --git a/src/os/inc/osapi-version.h b/src/os/inc/osapi-version.h index e38b1cd6f..c382e5a9c 100644 --- a/src/os/inc/osapi-version.h +++ b/src/os/inc/osapi-version.h @@ -36,7 +36,7 @@ /* * Development Build Macro Definitions */ -#define OS_BUILD_NUMBER 530 +#define OS_BUILD_NUMBER 548 #define OS_BUILD_BASELINE "v5.1.0-rc1" /*