From 4b82abee9d1d522bcb490cb5a7b325c3a977a1df Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Wed, 12 Aug 2020 10:51:39 -0400 Subject: [PATCH] Fix #104, Remove OS_Tick2Micros and internalize OS_Milli2Ticks - Removed OS_Tick2Micros implementation, tests, stubs, references - Moved prototype from API to internal for OS_Milli2Ticks - Updated OS_Milli2Ticks to return status - Added check for rollover in OS_Milli2Ticks - OS_Milli2Ticks now sets and limits ticks as int - Updated all internal use of OS_Milli2Ticks to check for error and returns immediately on error (won't wait maximum amount) - Coverage tests updated to check for new error cases - OS_Milli2Ticks stub updated (default implementation) --- src/os/inc/osapi-os-core.h | 30 +---- src/os/posix/src/os-impl-timebase.c | 1 - src/os/rtems/src/os-impl-binsem.c | 7 +- src/os/rtems/src/os-impl-timebase.c | 2 +- src/os/shared/inc/os-shared-timebase.h | 6 + src/os/shared/src/osapi-timebase.c | 55 +++------ src/os/vxworks/src/os-impl-binsem.c | 13 ++- src/os/vxworks/src/os-impl-countsem.c | 14 ++- src/os/vxworks/src/os-impl-queues.c | 8 +- src/os/vxworks/src/os-impl-tasks.c | 7 +- src/os/vxworks/src/os-impl-timebase.c | 2 +- .../shared/src/coveragetest-timebase.c | 40 ++++--- .../vxworks/src/coveragetest-binsem.c | 4 + .../vxworks/src/coveragetest-countsem.c | 4 + .../vxworks/src/coveragetest-queues.c | 4 + .../vxworks/src/coveragetest-tasks.c | 4 + .../oscore-test/ut_oscore_misc_test.c | 110 ------------------ .../oscore-test/ut_oscore_misc_test.h | 3 - src/unit-tests/oscore-test/ut_oscore_test.c | 3 - src/ut-stubs/osapi-utstub-timebase.c | 24 ++-- 20 files changed, 121 insertions(+), 220 deletions(-) diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index 2c5923b55..c06f53e89 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -1222,38 +1222,10 @@ int32 OS_MutSemGetIdByName (osal_id_t *sem_id, const char *sem_name); int32 OS_MutSemGetInfo (osal_id_t sem_id, OS_mut_sem_prop_t *mut_prop); /**@}*/ -/** @defgroup OSAPITime OSAL Time/Tick APIs +/** @defgroup OSAPITime OSAL Time APIs * @{ */ -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Convert time units from milliseconds to system ticks - * - * This function accepts a time interval in milliseconds and - * returns the tick equivalent. If the result is not an exact - * number of system ticks, the result will be rounded up to - * the nearest tick. - * - * @param[in] milli_seconds the number of milliseconds - * - * @return The number of ticks - */ -int32 OS_Milli2Ticks (uint32 milli_seconds); - -/*-------------------------------------------------------------------------------------*/ -/** - * @brief Get the system tick size, in microseconds - * - * This function returns the duration of a system tick in micro seconds - * - * @note care is taken to ensure this does not return "0" since it is often used - * as the divisor in mathematical operations - * - * @return Duration of a system tick in microseconds - */ -int32 OS_Tick2Micros (void); - /*-------------------------------------------------------------------------------------*/ /** * @brief Get the local time diff --git a/src/os/posix/src/os-impl-timebase.c b/src/os/posix/src/os-impl-timebase.c index 4b206df49..9c7c23642 100644 --- a/src/os/posix/src/os-impl-timebase.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -275,7 +275,6 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void) /* * Pre-calculate the clock tick to microsecond conversion factor. - * This is used by OS_Tick2Micros(), OS_Milli2Ticks(), etc. */ OS_SharedGlobalVars.TicksPerSecond = sysconf(_SC_CLK_TCK); if (OS_SharedGlobalVars.TicksPerSecond <= 0) diff --git a/src/os/rtems/src/os-impl-binsem.c b/src/os/rtems/src/os-impl-binsem.c index e7f5ec9a7..b3200d7f3 100644 --- a/src/os/rtems/src/os-impl-binsem.c +++ b/src/os/rtems/src/os-impl-binsem.c @@ -244,9 +244,12 @@ int32 OS_BinSemTake_Impl (uint32 sem_id) int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) { rtems_status_code status; - uint32 TimeInTicks; + int TimeInTicks; - TimeInTicks = OS_Milli2Ticks(msecs); + if (OS_Milli2Ticks(msecs, &TimInTicks) != OS_SUCCESS) + { + return OS_ERROR; + } status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks) ; diff --git a/src/os/rtems/src/os-impl-timebase.c b/src/os/rtems/src/os-impl-timebase.c index 1d66682c3..919a71ec4 100644 --- a/src/os/rtems/src/os-impl-timebase.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -231,7 +231,7 @@ int32 OS_Rtems_TimeBaseAPI_Impl_Init ( void ) /* - * Finally compute the Microseconds per tick that is used for OS_Tick2Micros() call + * Finally compute the Microseconds per tick * This must further round again to the nearest microsecond, so it is undesirable to use * this for time computations if the result is not exact. */ diff --git a/src/os/shared/inc/os-shared-timebase.h b/src/os/shared/inc/os-shared-timebase.h index 31617c540..dd43e36f2 100644 --- a/src/os/shared/inc/os-shared-timebase.h +++ b/src/os/shared/inc/os-shared-timebase.h @@ -134,6 +134,12 @@ int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_ ------------------------------------------------------------------*/ void OS_TimeBase_CallbackThread (osal_id_t timebase_id); +/*---------------------------------------------------------------- + Function: OS_Milli2Ticks + + Purpose: Convert milliseconds to ticks + ------------------------------------------------------------------*/ +int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks); #endif /* INCLUDE_OS_SHARED_TIMEBASE_H_ */ diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index e1bd46dae..475a7d994 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -545,49 +545,32 @@ void OS_TimeBase_CallbackThread(osal_id_t timebase_id) } } /* end OS_TimeBase_CallbackThread */ -/**************************************************************************************** - Other Time-Related API Implementation - ***************************************************************************************/ - -/* - * This is the OSAL-defined interface to the OS Timer tick - - * Not sure what it is really useful for since none of the user API timer calls deal with - * OS ticks directly. - */ - - -/*---------------------------------------------------------------- - * - * Function: OS_Tick2Micros - * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail - * - *-----------------------------------------------------------------*/ -int32 OS_Tick2Micros (void) -{ - return (OS_SharedGlobalVars.MicroSecPerTick); -} /* end OS_Tick2Micros */ - - /*---------------------------------------------------------------- * * Function: OS_Milli2Ticks * - * Purpose: Implemented per public OSAL API - * See description in API and header file for detail + * Purpose: Internal helper to convert milliseconds to ticks + * + * Returns: OS_SUCCESS on success, OS_ERROR on failure (rollover) * *-----------------------------------------------------------------*/ -int32 OS_Milli2Ticks(uint32 milli_seconds) +int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks) { - unsigned long num_of_ticks; - - num_of_ticks = (unsigned long)milli_seconds; - num_of_ticks *= OS_SharedGlobalVars.TicksPerSecond; - num_of_ticks = (num_of_ticks + 999) / 1000; - - return((uint32)num_of_ticks); -} /* end OS_Milli2Ticks */ + uint64 num_of_ticks; + int32 return_code = OS_SUCCESS; + num_of_ticks = (((uint64)milli_seconds * OS_SharedGlobalVars.TicksPerSecond) + 999) / 1000; + /* Check against maximum int32 (limit from some OS's) */ + if (num_of_ticks <= INT_MAX) + { + *ticks = (int)num_of_ticks; + } + else + { + return_code = OS_ERROR; + *ticks = 0; + } + return return_code; +} /* end OS_Milli2Ticks */ diff --git a/src/os/vxworks/src/os-impl-binsem.c b/src/os/vxworks/src/os-impl-binsem.c index 021c0da39..60f527ec7 100644 --- a/src/os/vxworks/src/os-impl-binsem.c +++ b/src/os/vxworks/src/os-impl-binsem.c @@ -32,6 +32,7 @@ #include "os-impl-binsem.h" #include "os-shared-binsem.h" +#include "os-shared-timebase.h" /**************************************************************************************** DEFINES @@ -175,7 +176,17 @@ int32 OS_BinSemTake_Impl (uint32 sem_id) *-----------------------------------------------------------------*/ int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) { - return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, OS_Milli2Ticks(msecs)); + int ticks; + int32 status; + + status = OS_Milli2Ticks(msecs, &ticks); + + if (status == OS_SUCCESS) + { + status = OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, ticks); + } + + return status; } /* end OS_BinSemTimedWait_Impl */ diff --git a/src/os/vxworks/src/os-impl-countsem.c b/src/os/vxworks/src/os-impl-countsem.c index f7cbde4fc..d4416a3d7 100644 --- a/src/os/vxworks/src/os-impl-countsem.c +++ b/src/os/vxworks/src/os-impl-countsem.c @@ -31,6 +31,7 @@ #include "os-vxworks.h" #include "os-impl-countsem.h" #include "os-shared-countsem.h" +#include "os-shared-timebase.h" /**************************************************************************************** DEFINES @@ -153,8 +154,17 @@ int32 OS_CountSemTake_Impl (uint32 sem_id) *-----------------------------------------------------------------*/ int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs) { - return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, - OS_Milli2Ticks(msecs)); + int ticks; + int32 status; + + status = OS_Milli2Ticks(msecs, &ticks); + + if (status == OS_SUCCESS) + { + status = OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, ticks); + } + + return status; } /* end OS_CountSemTimedWait_Impl */ diff --git a/src/os/vxworks/src/os-impl-queues.c b/src/os/vxworks/src/os-impl-queues.c index 7f8273a2a..41a1a5889 100644 --- a/src/os/vxworks/src/os-impl-queues.c +++ b/src/os/vxworks/src/os-impl-queues.c @@ -31,6 +31,7 @@ #include "os-vxworks.h" #include "os-impl-queues.h" #include "os-shared-queue.h" +#include "os-shared-timebase.h" /**************************************************************************************** @@ -137,8 +138,11 @@ int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_c } else { - /* msecs rounded to the closest system tick count */ - ticks = OS_Milli2Ticks(timeout); + /* msecs rounded to the closest system tick count if possible */ + if (OS_Milli2Ticks(timeout, &ticks) != OS_SUCCESS) + { + return OS_ERROR; + } } status = msgQReceive(OS_impl_queue_table[queue_id].vxid, data, size, ticks); diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c index 8998f92ae..9740dd981 100644 --- a/src/os/vxworks/src/os-impl-tasks.c +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -33,6 +33,7 @@ #include "os-shared-task.h" #include "os-shared-idmap.h" +#include "os-shared-timebase.h" #include #include @@ -323,7 +324,11 @@ int32 OS_TaskDelay_Impl (uint32 milli_second) /* msecs rounded to the closest system tick count */ int sys_ticks; - sys_ticks = OS_Milli2Ticks(milli_second); + /* Convert to ticks if possible */ + if (OS_Milli2Ticks(milli_second, &sys_ticks) != OS_SUCCESS) + { + return OS_ERROR; + } /* if successful, the execution of task will pend here until delay finishes */ if(taskDelay(sys_ticks) != OK) diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index 9c618aebf..26c769c27 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -317,7 +317,7 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init ( void ) /* - * Finally compute the Microseconds per tick that is used for OS_Tick2Micros() call + * Finally compute the Microseconds per tick * This must further round again to the nearest microsecond, so it is undesirable to use * this for time computations if the result is not exact. */ diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index 3d4213897..995087a75 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -32,6 +32,7 @@ #include "os-shared-common.h" #include +#include static uint32 TimerSyncCount = 0; static uint32 TimerSyncRetVal = 0; @@ -293,28 +294,36 @@ void Test_OS_TimeBase_CallbackThread(void) OS_TimeBase_CallbackThread(UT_OBJID_2); } -void Test_OS_Tick2Micros(void) -{ - /* - * Test Case For: - * int32 OS_Tick2Micros (void) - */ - OS_SharedGlobalVars.MicroSecPerTick = 5555; - int32 actual = OS_Tick2Micros(); - - UtAssert_True(actual == 5555, "OS_Tick2Micros() (%ld) == 5555", (long)actual); -} - void Test_OS_Milli2Ticks(void) { /* * Test Case For: * int32 OS_Milli2Ticks(uint32 milli_seconds) */ - OS_SharedGlobalVars.TicksPerSecond = 500; - int32 actual = OS_Milli2Ticks(5678); + uint32 msec; + int ticks; + int expected; - UtAssert_True(actual == 2839, "OS_Milli2Ticks() (%ld) == 2839", (long)actual); + msec = 5678; + OS_SharedGlobalVars.TicksPerSecond = 500; + UtAssert_INT32_EQ(OS_Milli2Ticks(msec, &ticks), OS_SUCCESS); + UtAssert_INT32_EQ(ticks, 2839); + + /* Bigger than uint32 but valid case */ + msec = UINT_MAX - 1; + expected = (((uint64)msec * OS_SharedGlobalVars.TicksPerSecond) + 999) / 1000; + UtAssert_INT32_EQ(OS_Milli2Ticks(msec, &ticks), OS_SUCCESS); + UtAssert_INT32_EQ(ticks, expected); + + /* int rollover case */ + msec = UINT_MAX; + UtAssert_INT32_EQ(OS_Milli2Ticks(msec, &ticks), OS_ERROR); + UtAssert_INT32_EQ(ticks, 0); + + /* Max value rollover case */ + OS_SharedGlobalVars.TicksPerSecond = INT_MAX; + UtAssert_INT32_EQ(OS_Milli2Ticks(msec, &ticks), OS_ERROR); + UtAssert_INT32_EQ(ticks, 0); } @@ -354,7 +363,6 @@ void UtTest_Setup(void) ADD_TEST(OS_TimeBaseGetInfo); ADD_TEST(OS_TimeBaseGetFreeRun); ADD_TEST(OS_TimeBase_CallbackThread); - ADD_TEST(OS_Tick2Micros); ADD_TEST(OS_Milli2Ticks); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c index d7cb06327..2b6c06c07 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c @@ -31,6 +31,7 @@ #include "os-shared-binsem.h" #include "os-shared-idmap.h" +#include "os-shared-timebase.h" #include #include @@ -108,6 +109,9 @@ void Test_OS_BinSemTimedWait_Impl(void) UT_SetForceFail(UT_StubKey_GenericSemTake, OS_SEM_FAILURE); OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SEM_FAILURE); + + UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_ERROR); } void Test_OS_BinSemGetInfo_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c index 95218af28..dbff06dba 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c @@ -29,6 +29,7 @@ #include "ut-adaptor-countsem.h" #include "os-shared-countsem.h" +#include "os-shared-timebase.h" void Test_OS_VxWorks_CountSemAPI_Impl_Init(void) { @@ -85,6 +86,9 @@ void Test_OS_CountSemTimedWait_Impl(void) * int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) */ OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(0, 100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(0,100), OS_ERROR); } void Test_OS_CountSemGetInfo_Impl(void) diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c index b71ee0498..b2e19de3f 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c @@ -27,6 +27,7 @@ #include "os-vxworks-coveragetest.h" #include "ut-adaptor-queues.h" #include "os-shared-queue.h" +#include "os-shared-timebase.h" #include #include @@ -77,6 +78,9 @@ void Test_OS_QueueGet_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_ERROR); + UT_SetForceFail(UT_KEY(OCS_msgQReceive), OCS_ERROR); OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c index cd5e67a5e..e990db4e5 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -29,6 +29,7 @@ #include "os-shared-task.h" #include "os-shared-idmap.h" +#include "os-shared-timebase.h" #include @@ -147,6 +148,9 @@ void Test_OS_TaskDelay_Impl(void) UT_SetForceFail(UT_KEY(OCS_taskDelay), OCS_ERROR); OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); + + UT_SetForceFail(UT_KEY(OS_Milli2Ticks), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); } void Test_OS_TaskSetPriority_Impl(void) diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.c b/src/unit-tests/oscore-test/ut_oscore_misc_test.c index 2b9f720ee..233d0085c 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -223,116 +223,6 @@ void UT_os_printfdisable_test() } -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_Tick2Micros(void) -** Purpose: Returns the number of microseconds per OS tick -** Parameters: None -** Returns: Microseconds per OS tick -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue -** ----------------------------------------------------- -** Test #1: Nominal condition -** 1) Call this routine -** 2) Expect the returned value to be -** (a) a value greater than or equal to 0 -**--------------------------------------------------------------------------------*/ -void UT_os_tick2micros_test() -{ - int32 res = 0; - const char* testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_Tick2Micros(); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_tick2micros_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Nominal"; - - res = OS_Tick2Micros(); - if (res >= 0) - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_tick2micros_test_exit_tag: - return; - -} - -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_Milli2Ticks(uint32 milli_seconds) -** Purpose: Returns the equivalent number of system clock ticks for the given period -** of time in milliseconds -** Parameters: milli_seconds - the number of milliseconds to convert to ticks -** Returns: Number of ticks in the given period of milliseconds -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue -** ----------------------------------------------------- -** Test #1: Zero-value-argument condition -** 1) Call this routine with a zero argument -** 2) Expect the returned value to be -** (a) exactly 0 -** ----------------------------------------------------- -** Test #2: Nominal condition -** 1) Call this routine with a non-zero argument, T, in milli_seconds -** 2) Expect the returned value to be -** (a) a value greater than or equal to 0 -**--------------------------------------------------------------------------------*/ -void UT_os_milli2ticks_test() -{ - int32 res = 0; - uint32 timeInMillisecs = 0; - const char* testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - res = OS_Milli2Ticks(timeInMillisecs); - if (res == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_milli2ticks_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 zero-value-arg"; - - timeInMillisecs = 0; - res = OS_Milli2Ticks(timeInMillisecs); - if (res == 0) - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Nominal"; - - timeInMillisecs = 100; - res = OS_Milli2Ticks(timeInMillisecs); - if (res >= 0) - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - -UT_os_milli2ticks_test_exit_tag: - return; - -} - /*--------------------------------------------------------------------------------* ** Syntax: int32 OS_GetLocalTime(OS_time_t *time_struct) ** Purpose: Returns the local time of the machine it is on diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.h b/src/unit-tests/oscore-test/ut_oscore_misc_test.h index 3acfbe805..cb174697e 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.h @@ -59,9 +59,6 @@ void UT_os_printf_test(void); void UT_os_printfenable_test(void); void UT_os_printfdisable_test(void); -void UT_os_tick2micros_test(void); -void UT_os_milli2ticks_test(void); - void UT_os_getlocaltime_test(void); void UT_os_setlocaltime_test(void); diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c index af05fe1bc..37f7612f7 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -287,9 +287,6 @@ void UtTest_Setup(void) UtTest_Add(UT_os_geterrorname_test, NULL, NULL, "OS_GetErrorName"); - UtTest_Add(UT_os_tick2micros_test, NULL, NULL, "OS_Tick2Micros"); - UtTest_Add(UT_os_milli2ticks_test, NULL, NULL, "OS_Milli2Ticks"); - UtTest_Add(UT_os_getlocaltime_test, NULL, NULL, "OS_GetLocalTime"); UtTest_Add(UT_os_setlocaltime_test, NULL, NULL, "OS_SetLocalTime"); diff --git a/src/ut-stubs/osapi-utstub-timebase.c b/src/ut-stubs/osapi-utstub-timebase.c index 8bee73fcc..95676e73d 100644 --- a/src/ut-stubs/osapi-utstub-timebase.c +++ b/src/ut-stubs/osapi-utstub-timebase.c @@ -204,24 +204,24 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id) UT_DEFAULT_IMPL(OS_TimeBase_CallbackThread); } -/***************************************************************************** - * - * Stub for OS_Tick2Micros() function - * - *****************************************************************************/ -int32 OS_Tick2Micros (void) -{ - return UT_DEFAULT_IMPL_RC(OS_Tick2Micros,100); -} - /***************************************************************************** * * Stub for OS_Milli2Ticks() function * *****************************************************************************/ -int32 OS_Milli2Ticks(uint32 milli_seconds) +int32 OS_Milli2Ticks(uint32 milli_seconds, int *ticks) { UT_Stub_RegisterContextGenericArg(UT_KEY(OS_Milli2Ticks), milli_seconds); + UT_Stub_RegisterContextGenericArg(UT_KEY(OS_Milli2Ticks), ticks); - return UT_DEFAULT_IMPL_RC(OS_Milli2Ticks,100); + int32 status; + + status = UT_DEFAULT_IMPL(OS_Milli2Ticks); + + if (status >= 0) + { + UT_Stub_CopyToLocal(UT_KEY(OS_Milli2Ticks), (uint8 *)ticks, sizeof(*ticks)); + } + + return status; }