summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/event-dispatcher.cpp13
-rw-r--r--test/timer.cpp17
2 files changed, 15 insertions, 15 deletions
diff --git a/test/event-dispatcher.cpp b/test/event-dispatcher.cpp
index f243ec39..9f9cf178 100644
--- a/test/event-dispatcher.cpp
+++ b/test/event-dispatcher.cpp
@@ -5,6 +5,7 @@
* event-dispatcher.cpp - Event dispatcher test
*/
+#include <chrono>
#include <iostream>
#include <signal.h>
#include <sys/time.h>
@@ -47,8 +48,7 @@ protected:
Timer timer;
/* Event processing interruption by signal. */
- struct timespec start;
- clock_gettime(CLOCK_MONOTONIC, &start);
+ std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
timer.start(1000);
@@ -59,12 +59,11 @@ protected:
dispatcher->processEvents();
- struct timespec stop;
- clock_gettime(CLOCK_MONOTONIC, &stop);
- int duration = (stop.tv_sec - start.tv_sec) * 1000;
- duration += (stop.tv_nsec - start.tv_nsec) / 1000000;
+ std::chrono::steady_clock::time_point stop = std::chrono::steady_clock::now();
+ std::chrono::steady_clock::duration duration = stop - start;
+ int msecs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
- if (abs(duration - 1000) > 50) {
+ if (abs(msecs - 1000) > 50) {
cout << "Event processing restart test failed" << endl;
return TestFail;
}
diff --git a/test/timer.cpp b/test/timer.cpp
index c30709d4..af922cb3 100644
--- a/test/timer.cpp
+++ b/test/timer.cpp
@@ -5,6 +5,7 @@
* timer.cpp - Timer test
*/
+#include <chrono>
#include <iostream>
#include <libcamera/event_dispatcher.h>
@@ -28,28 +29,28 @@ public:
void start(int msec)
{
interval_ = msec;
- clock_gettime(CLOCK_MONOTONIC, &start_);
- expiration_ = { 0, 0 };
+ start_ = std::chrono::steady_clock::now();
+ expiration_ = std::chrono::steady_clock::time_point();
Timer::start(msec);
}
int jitter()
{
- int duration = (expiration_.tv_sec - start_.tv_sec) * 1000;
- duration += (expiration_.tv_nsec - start_.tv_nsec) / 1000000;
- return abs(duration - interval_);
+ std::chrono::steady_clock::duration duration = expiration_ - start_;
+ int msecs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+ return abs(msecs - interval_);
}
private:
void timeoutHandler(Timer *timer)
{
- clock_gettime(CLOCK_MONOTONIC, &expiration_);
+ expiration_ = std::chrono::steady_clock::now();
}
int interval_;
- struct timespec start_;
- struct timespec expiration_;
+ std::chrono::steady_clock::time_point start_;
+ std::chrono::steady_clock::time_point expiration_;
};
class TimerTest : public Test