diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index 230571665..df31123db 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -292,6 +292,51 @@ void Test_OS_TaskInstallDeleteHandler(void) OS_task_table[1].delete_hook_pointer = NULL; } +void Test_OS_TaskFindIdBySystemData(void) +{ + /* + * Test Case For: + * int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sysdata_size) + */ + + int32 expected; + int32 actual; + uint32 task_id; + + /* + * Use a compound data struct for the system data. + * The intent is to intentionally make something bigger that will not fit into e.g. "uint32" + */ + struct + { + unsigned long v; + void *p; + } test_sysdata; + + memset(&test_sysdata, 'x', sizeof(test_sysdata)); + + expected = OS_SUCCESS; + actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); + UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_SUCCESS", (long)actual); + + /* Test parameter validation branches */ + expected = OS_INVALID_POINTER; + actual = OS_TaskFindIdBySystemData(NULL, &test_sysdata, sizeof(test_sysdata)); + UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); + + UT_SetForceFail(UT_KEY(OS_TaskValidateSystemData_Impl), expected); + actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); + UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_INVALID_POINTER", (long)actual); + UT_ClearForceFail(UT_KEY(OS_TaskValidateSystemData_Impl)); + + /* Test search failure */ + expected = OS_ERR_NAME_NOT_FOUND; + UT_SetForceFail(UT_KEY(OS_ObjectIdGetBySearch), expected); + actual = OS_TaskFindIdBySystemData(&task_id, &test_sysdata, sizeof(test_sysdata)); + UtAssert_True(actual == expected, "OS_TaskFindIdBySystemData() (%ld) == OS_ERR_NAME_NOT_FOUND", (long)actual); + UT_ClearForceFail(UT_KEY(OS_ObjectIdGetBySearch)); +} + /* Osapi_Test_Setup * @@ -332,6 +377,7 @@ void UtTest_Setup(void) ADD_TEST(OS_TaskGetIdByName); ADD_TEST(OS_TaskGetInfo); ADD_TEST(OS_TaskInstallDeleteHandler); + ADD_TEST(OS_TaskFindIdBySystemData); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index cc9f5752f..5fe2162a6 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -188,6 +188,38 @@ void Test_OS_TaskGetInfo_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(0,&task_prop), OS_SUCCESS); } +void Test_OS_TaskValidateSystemData_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) + */ + OCS_TASK_ID test_sys_id; + + memset(&test_sys_id, 'x', sizeof(test_sys_id)); + + OSAPI_TEST_FUNCTION_RC(OS_TaskValidateSystemData_Impl(&test_sys_id, sizeof(test_sys_id)), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_TaskValidateSystemData_Impl(NULL, sizeof(test_sys_id)), OS_INVALID_POINTER); + OSAPI_TEST_FUNCTION_RC(OS_TaskValidateSystemData_Impl(&test_sys_id, sizeof(test_sys_id)-1), OS_INVALID_POINTER); +} + +void Test_OS_TaskIdMatchSystemData_Impl(void) +{ + /* + * Test Case For: + * bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) + */ + OCS_TASK_ID test_sys_id; + + memset(&test_sys_id, 'x', sizeof(test_sys_id)); + + UT_TaskTest_SetImplTaskId(0, test_sys_id); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, 0, NULL), true); + + memset(&test_sys_id, 'y', sizeof(test_sys_id)); + OSAPI_TEST_FUNCTION_RC(OS_TaskIdMatchSystemData_Impl(&test_sys_id, 0, NULL), false); +} + /* ------------------- End of test cases --------------------------------------*/ @@ -234,6 +266,8 @@ void UtTest_Setup(void) ADD_TEST(OS_TaskRegister_Impl); ADD_TEST(OS_TaskGetId_Impl); ADD_TEST(OS_TaskGetInfo_Impl); + ADD_TEST(OS_TaskValidateSystemData_Impl); + ADD_TEST(OS_TaskIdMatchSystemData_Impl); }