From patchwork Thu Oct 3 17:49:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2090 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4DB2A61925 for ; Thu, 3 Oct 2019 19:50:41 +0200 (CEST) X-Halon-ID: 33b48f9b-e606-11e9-837a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [84.172.88.101]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 33b48f9b-e606-11e9-837a-0050569116f7; Thu, 03 Oct 2019 19:49:52 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Oct 2019 19:49:38 +0200 Message-Id: <20191003174941.1296988-9-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003174941.1296988-1-niklas.soderlund@ragnatech.se> References: <20191003174941.1296988-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/11] test: Add timeline test 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: Thu, 03 Oct 2019 17:50:41 -0000 Add a test of the timeline to make sure events fire and the estimated frame interval are OK. Signed-off-by: Niklas Söderlund --- test/meson.build | 1 + test/timeline.cpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/timeline.cpp diff --git a/test/meson.build b/test/meson.build index 84722cceb35db86e..6a4c4cd373043469 100644 --- a/test/meson.build +++ b/test/meson.build @@ -28,6 +28,7 @@ internal_tests = [ ['object-invoke', 'object-invoke.cpp'], ['signal-threads', 'signal-threads.cpp'], ['threads', 'threads.cpp'], + ['timeline', 'timeline.cpp'], ['timer', 'timer.cpp'], ['timer-thread', 'timer-thread.cpp'], ] diff --git a/test/timeline.cpp b/test/timeline.cpp new file mode 100644 index 0000000000000000..55b651b455a07ffc --- /dev/null +++ b/test/timeline.cpp @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * timeline.cpp - Timeline test + */ + +#include +#include +#include + +#include + +#include "test.h" +#include "thread.h" +#include "timeline.h" + +using namespace std; +using namespace libcamera; + +enum TimelineTestActionType { + Inc, +}; + +class IncrementAction : public FrameAction +{ +public: + IncrementAction(unsigned int frame, unsigned int *counter) + : FrameAction(Inc, frame), counter_(counter) + { + } + + void run() override + { + (*counter_)++; + } + +private: + unsigned int *counter_; +}; + +class TimelineTest : public Test +{ +public: + void fakeSOE() + { + timeline_.notifyStartOfExposure(sequence_++, + std::chrono::steady_clock::now()); + } + + int init() + { + sequence_ = 0; + return 0; + } + + int run() + { + EventDispatcher *dispatcher = Thread::current()->eventDispatcher(); + unsigned int loops, counter; + Timer timer; + + /* + * Run frames and make sure an event is fired for each and that + * the messured frame interval is true. + */ + loops = 500; + counter = 0; + for (unsigned int i = 0; i < loops; i++) { + timeline_.scheduleAction(new IncrementAction(i + 1, &counter)); + fakeSOE(); + timer.start(10); + while (timer.isRunning()) + dispatcher->processEvents(); + } + + cout << "Got " << counter << " evens, expected " << loops - 1 << endl; + if (counter != loops - 1) + return TestFail; + + unsigned int interval = std::chrono::duration_cast(timeline_.frameInterval()).count(); + cout << "Messured frame interval " << interval << " expected 10" << endl; + if (interval != 10) + return TestFail; + + return TestPass; + } + + void cleanup() + { + } +private: + unsigned int sequence_; + Timeline timeline_; +}; + +TEST_REGISTER(TimelineTest)