From c8b9301c2e8d2474795c70615d6ae387b5a4a4f3 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 25 Jun 2021 15:24:03 -0400 Subject: [PATCH] Fix #1087, do not register RTOS timer for external sync Skip the registration of a timer in VxWorks when the assigned_signal is 0 (this indicates an external sync function is used). --- src/os/vxworks/src/os-impl-timebase.c | 43 +++++++++++-------- .../vxworks/src/coveragetest-timebase.c | 29 +++++++++---- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/src/os/vxworks/src/os-impl-timebase.c b/src/os/vxworks/src/os-impl-timebase.c index f5175e0a3..959376ff3 100644 --- a/src/os/vxworks/src/os-impl-timebase.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -225,22 +225,31 @@ void OS_VxWorks_RegisterTimer(osal_id_t obj_id) { local = OS_OBJECT_TABLE_GET(OS_impl_timebase_table, token); - memset(&evp, 0, sizeof(evp)); - evp.sigev_notify = SIGEV_SIGNAL; - evp.sigev_signo = local->assigned_signal; + if (local->assigned_signal == 0) + { + /* nothing to register in RTOS */ + status = 0; + } + else + { + memset(&evp, 0, sizeof(evp)); + evp.sigev_notify = SIGEV_SIGNAL; + evp.sigev_signo = local->assigned_signal; + + /* + ** Create the timer + ** + ** The result is not returned from this function, because + ** this is a different task context from the original creator. + ** + ** The registration status is returned through the OS_impl_timebase_table entry, + ** which is checked by the creator before returning. + ** + ** If set to ERROR, then this task will be subsequently deleted. + */ + status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); + } - /* - ** Create the timer - ** - ** The result is not returned from this function, because - ** this is a different task context from the original creator. - ** - ** The registration status is returned through the OS_impl_timebase_table entry, - ** which is checked by the creator before returning. - ** - ** If set to ERROR, then this task will be subsequently deleted. - */ - status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); if (status < 0) { OS_DEBUG("timer_create() failed: errno=%d\n", errno); @@ -529,8 +538,8 @@ int32 OS_TimeBaseSet_Impl(const OS_object_token_t *token, uint32 start_time, uin /* There is only something to do here if we are generating a simulated tick */ if (local->assigned_signal <= 0) { - /* An externally synced timebase does not need to be set */ - return_code = OS_ERR_NOT_IMPLEMENTED; + /* An externally synced timebase does not need to be set (noop) */ + return_code = OS_SUCCESS; } else { diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 13d98c126..74576b883 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -156,19 +156,29 @@ void Test_OS_TimeBaseCreate_Impl(void) /* * Check outputs of OS_VxWorks_RegisterTimer() function. */ - UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); - UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); - UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered"); - - UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); + UT_TimeBaseTest_CallRegisterTimer(token.obj_id); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), + "timer successfully registered, with signal"); + + UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); UT_SetDefaultReturnValue(UT_KEY(OCS_timer_create), -1); - UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UT_TimeBaseTest_CallRegisterTimer(token.obj_id); UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(UT_INDEX_0), "timer registration failure state"); - UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_1); + UT_TimeBaseTest_Setup(UT_INDEX_0, 10, false); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetById), OS_ERROR); - UT_TimeBaseTest_CallRegisterTimer(OS_OBJECT_ID_UNDEFINED); + UT_TimeBaseTest_CallRegisterTimer(token.obj_id); UtAssert_True(!UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer registration bad ID"); + UT_ResetState(UT_KEY(OS_ObjectIdGetById)); + + UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false); + UT_TimeBaseTest_ClearTimeBaseRegState(UT_INDEX_0); + UT_TimeBaseTest_CallRegisterTimer(token.obj_id); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(UT_INDEX_0), "timer successfully registered, no signal"); } void Test_OS_VxWorks_SigWait(void) @@ -217,7 +227,8 @@ void Test_OS_TimeBaseSet_Impl(void) */ OS_object_token_t token = UT_TOKEN_0; - OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_ERR_NOT_IMPLEMENTED); + UT_TimeBaseTest_Setup(UT_INDEX_0, 0, false); + OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS); UT_TimeBaseTest_Setup(UT_INDEX_0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(&token, 1, 1), OS_SUCCESS);