diff options
Diffstat (limited to 'test/timer-thread.cpp')
-rw-r--r-- | test/timer-thread.cpp | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp index 32853b4e..55e5cfdf 100644 --- a/test/timer-thread.cpp +++ b/test/timer-thread.cpp @@ -2,20 +2,22 @@ /* * Copyright (C) 2019, Google Inc. * - * timer-thread.cpp - Threaded timer test + * Threaded timer test */ #include <chrono> #include <iostream> -#include <libcamera/event_dispatcher.h> -#include <libcamera/timer.h> +#include <libcamera/base/event_dispatcher.h> +#include <libcamera/base/object.h> +#include <libcamera/base/thread.h> +#include <libcamera/base/timer.h> #include "test.h" -#include "thread.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class TimeoutHandler : public Object { @@ -24,13 +26,7 @@ public: : timer_(this), timeout_(false) { timer_.timeout.connect(this, &TimeoutHandler::timeoutHandler); - timer_.start(100); - } - - void restart() - { - timeout_ = false; - timer_.start(100); + timer_.start(100ms); } bool timeout() const @@ -39,7 +35,7 @@ public: } private: - void timeoutHandler(Timer *timer) + void timeoutHandler() { timeout_ = true; } @@ -54,7 +50,9 @@ protected: int init() { thread_.start(); - timeout_.moveToThread(&thread_); + + timeout_ = new TimeoutHandler(); + timeout_->moveToThread(&thread_); return TestPass; } @@ -67,39 +65,27 @@ protected: */ this_thread::sleep_for(chrono::milliseconds(200)); - if (!timeout_.timeout()) { + if (!timeout_->timeout()) { cout << "Timer expiration test failed" << endl; return TestFail; } - /* - * Test that starting the timer from another thread fails. We - * need to interrupt the event dispatcher to make sure we don't - * succeed simply because the event dispatcher hasn't noticed - * the timer restart. - */ - timeout_.restart(); - thread_.eventDispatcher()->interrupt(); - - this_thread::sleep_for(chrono::milliseconds(200)); - - if (timeout_.timeout()) { - cout << "Timer restart test failed" << endl; - return TestFail; - } - return TestPass; } void cleanup() { - /* Must stop thread before destroying timeout. */ + /* + * Object class instances must be destroyed from the thread + * they live in. + */ + timeout_->deleteLater(); thread_.exit(0); thread_.wait(); } private: - TimeoutHandler timeout_; + TimeoutHandler *timeout_; Thread thread_; }; |