open62541/tests/testing-plugins/testing_clock.h
Julius Pfrommer 054420cf33 refactor(test): Use the fake clock also for non-monotonic time-source
The subscription tests depend on a deterministic clock.
2023-12-26 00:30:17 +01:00

28 lines
1.0 KiB
C

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef TESTING_CLOCK_H_
#define TESTING_CLOCK_H_
#include <open62541/types.h>
#include <open62541/plugin/eventloop.h>
/* The testing clock is used for reproducible unit tests that require precise
* timings. It implements the following functions from ua_types.h. They return a
* deterministic time that can be advanced manually with UA_fakeSleep.
*
* UA_DateTime UA_EXPORT UA_DateTime_now(void);
* UA_DateTime UA_EXPORT UA_DateTime_nowMonotonic(void); */
/* Forwards the testing clock by the given duration in ms */
void UA_fakeSleep(UA_UInt32 duration);
/* Sleep for the duration in milliseconds. Used to wait for workers to complete. */
void UA_realSleep(UA_UInt32 duration);
/* To be hooked into the EventLoop for unit tests that need deterministic timings */
UA_DateTime UA_DateTime_now_fake(UA_EventLoop *el);
#endif /* TESTING_CLOCK_H_ */