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));