From 54398c1583f18ef9daf1a9227691b14c3b7f4212 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 22 Mar 2022 22:32:55 +0200 Subject: libcamera: base: timer: Drop start() overload with int argument The start(unsigned int msec) overload is error-prone, as the argument unit can easily be mistaken in callers. Drop it and update all callers to use the start(std::chrono::milliseconds) overload instead. The callers now need to use std::chrono_literals. The using statement could be added to timer.h for convenience, but "using" is discouraged in header files to avoid namespace pollution. Update the callers instead, and while at it, sort the "using" statements alphabetically in tests. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- test/camera/buffer_import.cpp | 3 ++- test/camera/camera_reconfigure.cpp | 3 ++- test/camera/capture.cpp | 3 ++- test/event-dispatcher.cpp | 9 +++++---- test/event.cpp | 11 ++++++----- test/fence.cpp | 6 +++--- test/hotplug-cameras.cpp | 5 +++-- test/ipa/ipa_interface_test.cpp | 9 +++++---- test/ipc/unixsocket.cpp | 5 +++-- test/log/log_process.cpp | 5 +++-- test/process/process_test.cpp | 5 +++-- test/timer-thread.cpp | 7 ++++--- test/timer.cpp | 31 ++++++++++++++++--------------- test/v4l2_videodevice/buffer_sharing.cpp | 3 ++- test/v4l2_videodevice/capture_async.cpp | 3 ++- test/v4l2_videodevice/v4l2_m2mdevice.cpp | 5 +++-- 16 files changed, 64 insertions(+), 49 deletions(-) (limited to 'test') diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp index c504ea09..92884004 100644 --- a/test/camera/buffer_import.cpp +++ b/test/camera/buffer_import.cpp @@ -25,6 +25,7 @@ #include "test.h" using namespace libcamera; +using namespace std::chrono_literals; namespace { @@ -135,7 +136,7 @@ protected: EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); Timer timer; - timer.start(1000); + timer.start(1000ms); while (timer.isRunning()) dispatcher->processEvents(); diff --git a/test/camera/camera_reconfigure.cpp b/test/camera/camera_reconfigure.cpp index 0fd8ab70..f6076baa 100644 --- a/test/camera/camera_reconfigure.cpp +++ b/test/camera/camera_reconfigure.cpp @@ -23,6 +23,7 @@ using namespace libcamera; using namespace std; +using namespace std::chrono_literals; namespace { @@ -117,7 +118,7 @@ private: EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); Timer timer; - timer.start(100); + timer.start(100ms); while (timer.isRunning()) dispatcher->processEvents(); diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index f3824f95..de824083 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -18,6 +18,7 @@ using namespace libcamera; using namespace std; +using namespace std::chrono_literals; namespace { @@ -137,7 +138,7 @@ protected: EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); Timer timer; - timer.start(1000); + timer.start(1000ms); while (timer.isRunning()) dispatcher->processEvents(); diff --git a/test/event-dispatcher.cpp b/test/event-dispatcher.cpp index 1cc17b04..9b07ab2b 100644 --- a/test/event-dispatcher.cpp +++ b/test/event-dispatcher.cpp @@ -16,8 +16,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; static EventDispatcher *dispatcher; static bool interrupt; @@ -50,7 +51,7 @@ protected: /* Event processing interruption by signal. */ std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); - timer.start(1000); + timer.start(1000ms); struct itimerval itimer = {}; itimer.it_value.tv_usec = 500000; @@ -69,7 +70,7 @@ protected: } /* Event processing interruption. */ - timer.start(1000); + timer.start(1000ms); dispatcher->interrupt(); dispatcher->processEvents(); @@ -79,7 +80,7 @@ protected: return TestFail; } - timer.start(1000); + timer.start(1000ms); itimer.it_value.tv_usec = 500000; interrupt = true; setitimer(ITIMER_REAL, &itimer, nullptr); diff --git a/test/event.cpp b/test/event.cpp index d4765eb1..19dceae1 100644 --- a/test/event.cpp +++ b/test/event.cpp @@ -16,8 +16,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class EventTest : public Test { @@ -55,7 +56,7 @@ protected: return TestFail; } - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -67,7 +68,7 @@ protected: /* Test read notification without data. */ notified_ = false; - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -86,7 +87,7 @@ protected: return TestFail; } - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); @@ -99,7 +100,7 @@ protected: notified_ = false; notifier_->setEnabled(true); - timeout.start(100); + timeout.start(100ms); dispatcher->processEvents(); timeout.stop(); diff --git a/test/fence.cpp b/test/fence.cpp index 524db2a1..1e38bc2f 100644 --- a/test/fence.cpp +++ b/test/fence.cpp @@ -22,9 +22,9 @@ #include "camera_test.h" #include "test.h" -using namespace std::chrono_literals; using namespace libcamera; using namespace std; +using namespace std::chrono_literals; class FenceTest : public CameraTest, public Test { @@ -316,7 +316,7 @@ int FenceTest::run() /* Loop for one second. */ Timer timer; - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && expectedCompletionResult_) { if (completedRequest_ == signalledRequestId_ && setFence_) /* @@ -324,7 +324,7 @@ int FenceTest::run() * been re-queued with a fence. Start the timer to * signal the fence in 10 msec. */ - fenceTimer.start(10); + fenceTimer.start(10ms); dispatcher_->processEvents(); } diff --git a/test/hotplug-cameras.cpp b/test/hotplug-cameras.cpp index df560403..5d9260a2 100644 --- a/test/hotplug-cameras.cpp +++ b/test/hotplug-cameras.cpp @@ -22,6 +22,7 @@ #include "test.h" using namespace libcamera; +using namespace std::chrono_literals; class HotplugTest : public Test { @@ -88,7 +89,7 @@ protected: std::ofstream(uvcDriverDir_ + "unbind", std::ios::binary) << uvcDeviceDir; Timer timer; - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && !cameraRemoved_) Thread::current()->eventDispatcher()->processEvents(); if (!cameraRemoved_) { @@ -99,7 +100,7 @@ protected: /* Bind the camera again and process events. */ std::ofstream(uvcDriverDir_ + "bind", std::ios::binary) << uvcDeviceDir; - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && !cameraAdded_) Thread::current()->eventDispatcher()->processEvents(); if (!cameraAdded_) { diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index 43562e60..3c0df843 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -27,8 +27,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class IPAInterfaceTest : public Test, public Object { @@ -111,7 +112,7 @@ protected: return TestFail; } - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationInit) dispatcher->processEvents(); @@ -123,7 +124,7 @@ protected: /* Test start of IPA module. */ ipa_->start(); - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStart) dispatcher->processEvents(); @@ -134,7 +135,7 @@ protected: /* Test stop of IPA module. */ ipa_->stop(); - timer.start(1000); + timer.start(1000ms); while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStop) dispatcher->processEvents(); diff --git a/test/ipc/unixsocket.cpp b/test/ipc/unixsocket.cpp index 7e90e629..304e613b 100644 --- a/test/ipc/unixsocket.cpp +++ b/test/ipc/unixsocket.cpp @@ -30,8 +30,9 @@ #define CMD_LEN_CMP 3 #define CMD_JOIN 4 -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; int calculateLength(int fd) { @@ -430,7 +431,7 @@ private: if (ret) return ret; - timeout.start(200); + timeout.start(200ms); while (!callDone_) { if (!timeout.isRunning()) { cerr << "Call timeout!" << endl; diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp index 2484c58f..966b80cf 100644 --- a/test/log/log_process.cpp +++ b/test/log/log_process.cpp @@ -26,8 +26,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; static const string message("hello from the child"); @@ -80,7 +81,7 @@ protected: return TestFail; } - timeout.start(200); + timeout.start(200ms); while (timeout.isRunning()) dispatcher->processEvents(); diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp index b410756b..cb6940c6 100644 --- a/test/process/process_test.cpp +++ b/test/process/process_test.cpp @@ -18,8 +18,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class ProcessTestChild { @@ -61,7 +62,7 @@ protected: return TestFail; } - timeout.start(2000); + timeout.start(2000ms); while (timeout.isRunning() && exitStatus_ == Process::NotExited) dispatcher->processEvents(); diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp index f7e8743d..61821753 100644 --- a/test/timer-thread.cpp +++ b/test/timer-thread.cpp @@ -14,8 +14,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class TimeoutHandler : public Object { @@ -24,13 +25,13 @@ public: : timer_(this), timeout_(false) { timer_.timeout.connect(this, &TimeoutHandler::timeoutHandler); - timer_.start(100); + timer_.start(100ms); } void restart() { timeout_ = false; - timer_.start(100); + timer_.start(100ms); } bool timeout() const diff --git a/test/timer.cpp b/test/timer.cpp index be79d010..0f01c3cb 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -14,8 +14,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class ManagedTimer : public Timer { @@ -26,7 +27,7 @@ public: timeout.connect(this, &ManagedTimer::timeoutHandler); } - void start(int msec) + void start(std::chrono::milliseconds msec) { count_ = 0; start_ = std::chrono::steady_clock::now(); @@ -82,7 +83,7 @@ protected: ManagedTimer timer2; /* Timer expiration. */ - timer.start(1000); + timer.start(1000ms); if (!timer.isRunning()) { cout << "Timer expiration test failed" << endl; @@ -101,7 +102,7 @@ protected: * Nanosecond resolution in a 32 bit value wraps at 4.294967 * seconds (0xFFFFFFFF / 1000000) */ - timer.start(4295); + timer.start(4295ms); dispatcher->processEvents(); if (timer.hasFailed()) { @@ -110,7 +111,7 @@ protected: } /* Timer restart. */ - timer.start(500); + timer.start(500ms); if (!timer.isRunning()) { cout << "Timer restart test failed" << endl; @@ -125,9 +126,9 @@ protected: } /* Timer restart before expiration. */ - timer.start(50); - timer.start(100); - timer.start(150); + timer.start(50ms); + timer.start(100ms); + timer.start(150ms); dispatcher->processEvents(); @@ -147,8 +148,8 @@ protected: } /* Two timers. */ - timer.start(1000); - timer2.start(300); + timer.start(1000ms); + timer2.start(300ms); dispatcher->processEvents(); @@ -170,8 +171,8 @@ protected: } /* Restart timer before expiration. */ - timer.start(1000); - timer2.start(300); + timer.start(1000ms); + timer2.start(300ms); dispatcher->processEvents(); @@ -180,7 +181,7 @@ protected: return TestFail; } - timer.start(1000); + timer.start(1000ms); dispatcher->processEvents(); @@ -194,10 +195,10 @@ protected: * deleted. This will result in a crash on failure. */ ManagedTimer *dyntimer = new ManagedTimer(); - dyntimer->start(100); + dyntimer->start(100ms); delete dyntimer; - timer.start(200); + timer.start(200ms); dispatcher->processEvents(); return TestPass; diff --git a/test/v4l2_videodevice/buffer_sharing.cpp b/test/v4l2_videodevice/buffer_sharing.cpp index 75ee93ce..fa856ab6 100644 --- a/test/v4l2_videodevice/buffer_sharing.cpp +++ b/test/v4l2_videodevice/buffer_sharing.cpp @@ -21,6 +21,7 @@ #include "v4l2_videodevice_test.h" using namespace libcamera; +using namespace std::chrono_literals; class BufferSharingTest : public V4L2VideoDeviceTest { @@ -145,7 +146,7 @@ protected: return TestFail; } - timeout.start(10000); + timeout.start(10000ms); while (timeout.isRunning()) { dispatcher->processEvents(); if (framesCaptured_ > 30 && framesOutput_ > 30) diff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp index 3aa4ca0b..42e1e671 100644 --- a/test/v4l2_videodevice/capture_async.cpp +++ b/test/v4l2_videodevice/capture_async.cpp @@ -16,6 +16,7 @@ #include "v4l2_videodevice_test.h" using namespace libcamera; +using namespace std::chrono_literals; class CaptureAsyncTest : public V4L2VideoDeviceTest { @@ -60,7 +61,7 @@ protected: if (ret) return TestFail; - timeout.start(10000); + timeout.start(10000ms); while (timeout.isRunning()) { dispatcher->processEvents(); if (frames > 30) diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp index ebf3e245..852b853f 100644 --- a/test/v4l2_videodevice/v4l2_m2mdevice.cpp +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp @@ -19,8 +19,9 @@ #include "test.h" -using namespace std; using namespace libcamera; +using namespace std; +using namespace std::chrono_literals; class V4L2M2MDeviceTest : public Test { @@ -155,7 +156,7 @@ protected: } Timer timeout; - timeout.start(5000); + timeout.start(5000ms); while (timeout.isRunning()) { dispatcher->processEvents(); if (captureFrames_ > 30) -- cgit v1.2.1