Skip to content

Commit

Permalink
Update #437, add UT Test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Apr 30, 2020
1 parent afb70b0 commit 93c0832
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -332,6 +377,7 @@ void UtTest_Setup(void)
ADD_TEST(OS_TaskGetIdByName);
ADD_TEST(OS_TaskGetInfo);
ADD_TEST(OS_TaskInstallDeleteHandler);
ADD_TEST(OS_TaskFindIdBySystemData);
}


Expand Down
34 changes: 34 additions & 0 deletions src/unit-test-coverage/vxworks/src/coveragetest-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------*/

Expand Down Expand Up @@ -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);
}


0 comments on commit 93c0832

Please sign in to comment.