From 054420cf334a0b7db1d3e0f010733461af185da3 Mon Sep 17 00:00:00 2001 From: Julius Pfrommer Date: Tue, 26 Dec 2023 00:13:07 +0100 Subject: [PATCH] refactor(test): Use the fake clock also for non-monotonic time-source The subscription tests depend on a deterministic clock. --- tests/client/check_client.c | 3 ++- tests/server/check_discovery.c | 9 ++++++--- tests/testing-plugins/test_helpers.h | 6 ++++-- tests/testing-plugins/testing_clock.c | 2 +- tests/testing-plugins/testing_clock.h | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/client/check_client.c b/tests/client/check_client.c index 4789635ee2d..afce66d908a 100644 --- a/tests/client/check_client.c +++ b/tests/client/check_client.c @@ -89,7 +89,8 @@ START_TEST(ClientConfig_Copy){ UA_ClientConfig srcConfig; memset(&srcConfig, 0, sizeof(UA_ClientConfig)); UA_ClientConfig_setDefault(&srcConfig); - srcConfig.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + srcConfig.eventLoop->dateTime_now = UA_DateTime_now_fake; + srcConfig.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; UA_StatusCode retval = UA_ClientConfig_copy(&srcConfig, &dstConfig); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); diff --git a/tests/server/check_discovery.c b/tests/server/check_discovery.c index eaccb1c85b4..bd291a7564a 100644 --- a/tests/server/check_discovery.c +++ b/tests/server/check_discovery.c @@ -192,7 +192,8 @@ registerServer(void) { memset(&cc, 0, sizeof(UA_ClientConfig)); UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0); UA_CertificateVerification_AcceptAll(&cc.certificateVerification); - cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + cc.eventLoop->dateTime_now = UA_DateTime_now_fake; + cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; *running_register = false; THREAD_JOIN(server_thread_register); @@ -222,7 +223,8 @@ unregisterServer(void) { memset(&cc, 0, sizeof(UA_ClientConfig)); UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0); UA_CertificateVerification_AcceptAll(&cc.certificateVerification); - cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + cc.eventLoop->dateTime_now = UA_DateTime_now_fake; + cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; *running_register = false; THREAD_JOIN(server_thread_register); @@ -266,7 +268,8 @@ Server_register_semaphore(void) { memset(&cc, 0, sizeof(UA_ClientConfig)); UA_ClientConfig_setDefaultEncryption(&cc, certificate, privateKey, NULL, 0, NULL, 0); UA_CertificateVerification_AcceptAll(&cc.certificateVerification); - cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + cc.eventLoop->dateTime_now = UA_DateTime_now_fake; + cc.eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; *running_register = false; THREAD_JOIN(server_thread_register); diff --git a/tests/testing-plugins/test_helpers.h b/tests/testing-plugins/test_helpers.h index bee204aae4d..1ce960bf4bb 100644 --- a/tests/testing-plugins/test_helpers.h +++ b/tests/testing-plugins/test_helpers.h @@ -16,7 +16,8 @@ UA_Server * UA_Server_newForUnitTest(void) { return NULL; UA_ServerConfig *config = UA_Server_getConfig(server); /* Manually set the eventloop clock to the fake clock */ - config->eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + config->eventLoop->dateTime_now = UA_DateTime_now_fake; + config->eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; return server; } @@ -27,7 +28,8 @@ UA_Client * UA_Client_newForUnitTest(void) { return NULL; UA_ClientConfig *config = UA_Client_getConfig(client); /* Manually set the eventloop clock to the fake clock */ - config->eventLoop->dateTime_nowMonotonic = UA_DateTime_nowMonotonic_fake; + config->eventLoop->dateTime_now = UA_DateTime_now_fake; + config->eventLoop->dateTime_nowMonotonic = UA_DateTime_now_fake; return client; } diff --git a/tests/testing-plugins/testing_clock.c b/tests/testing-plugins/testing_clock.c index 1dc44fadd99..58a56c124a3 100644 --- a/tests/testing-plugins/testing_clock.c +++ b/tests/testing-plugins/testing_clock.c @@ -31,6 +31,6 @@ UA_realSleep(UA_UInt32 duration) { #endif } -UA_DateTime UA_DateTime_nowMonotonic_fake(UA_EventLoop *el) { +UA_DateTime UA_DateTime_now_fake(UA_EventLoop *el) { return testingClock; } diff --git a/tests/testing-plugins/testing_clock.h b/tests/testing-plugins/testing_clock.h index 8e7a26285e1..e705c2dc47f 100644 --- a/tests/testing-plugins/testing_clock.h +++ b/tests/testing-plugins/testing_clock.h @@ -22,6 +22,6 @@ void UA_fakeSleep(UA_UInt32 duration); void UA_realSleep(UA_UInt32 duration); /* To be hooked into the EventLoop for unit tests that need deterministic timings */ -UA_DateTime UA_DateTime_nowMonotonic_fake(UA_EventLoop *el); +UA_DateTime UA_DateTime_now_fake(UA_EventLoop *el); #endif /* TESTING_CLOCK_H_ */