From patchwork Sun Oct 6 05:32:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2109 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D51CA6196C for ; Sun, 6 Oct 2019 07:32:37 +0200 (CEST) Received: from pendragon.ideasonboard.com (modemcable151.96-160-184.mc.videotron.ca [184.160.96.151]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 40460DD for ; Sun, 6 Oct 2019 07:32:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1570339957; bh=TL/JInXT1/VKkEKGlh6gIo9p7VKswEP0BpSBTjHdIjo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qUxj0lFiB432AUy3vzF6BYL374AruyhR2g1c9SJTiDfjxRbiCH0hIneNdiuVejXA9 Efm0lsTqqOZjak2BGajwBb4btz6iadb0eknyh5BTGeGgCybK0kXyGr+uBoLOd3FH5q XYPVLJdLwDP/1Y83LC+xl3Hju+Gbh9qyUHzG0Gqo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 6 Oct 2019 08:32:21 +0300 Message-Id: <20191006053226.8976-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191006053226.8976-1-laurent.pinchart@ideasonboard.com> References: <20191006053226.8976-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/9] test: timer: Test that a timer can be restarted before it expires X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Oct 2019 05:32:38 -0000 The Timer API allows restarting a timer before it expires. Add a corresponding test. The test fails as the Timer class doesn't comply with its API documentation. Signed-off-by: Laurent Pinchart --- test/timer.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/timer.cpp b/test/timer.cpp index d4f16a9bdd97..5ff94dbbdeb0 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -21,13 +21,14 @@ class ManagedTimer : public Timer { public: ManagedTimer() - : Timer() + : Timer(), count_(0) { timeout.connect(this, &ManagedTimer::timeoutHandler); } void start(int msec) { + count_ = 0; start_ = std::chrono::steady_clock::now(); expiration_ = std::chrono::steady_clock::time_point(); @@ -40,12 +41,19 @@ public: return abs(std::chrono::duration_cast(duration).count()); } + bool hasFailed() + { + return isRunning() || count_ != 1 || jitter() > 50; + } + private: void timeoutHandler(Timer *timer) { expiration_ = std::chrono::steady_clock::now(); + count_++; } + unsigned int count_; std::chrono::steady_clock::time_point start_; std::chrono::steady_clock::time_point expiration_; }; @@ -74,7 +82,7 @@ protected: dispatcher->processEvents(); - if (timer.isRunning() || timer.jitter() > 50) { + if (timer.hasFailed()) { cout << "Timer expiration test failed" << endl; return TestFail; } @@ -87,7 +95,7 @@ protected: timer.start(4295); dispatcher->processEvents(); - if (timer.isRunning() || timer.jitter() > 50) { + if (timer.hasFailed()) { cout << "Timer expiration test failed" << endl; return TestFail; } @@ -102,11 +110,23 @@ protected: dispatcher->processEvents(); - if (timer.isRunning() || timer.jitter() > 50) { + if (timer.hasFailed()) { cout << "Timer restart test failed" << endl; return TestFail; } + /* Timer restart before expiration. */ + timer.start(50); + timer.start(100); + timer.start(150); + + dispatcher->processEvents(); + + if (timer.hasFailed()) { + cout << "Timer restart before expiration test failed" << endl; + return TestFail; + } + /* Two timers. */ timer.start(1000); timer2.start(300);