From patchwork Sun Jan 6 02:33:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 160 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7857560B49 for ; Sun, 6 Jan 2019 03:32:30 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 16094513 for ; Sun, 6 Jan 2019 03:32:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1546741950; bh=Tc4Wf0VAQO5mKzYZoUU69kcuFeSmmSDiRQUyEsy9xr4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fBN6XlzAPZfJVUC9038u93Ont0R04iyUCBfd5KFULkISPa5Ic4LhxygBiWMyKq/Nz kZXeLGiE9bcaJPN20hsm97jEJr1Ogvcmc7GiznG/oeu2MqNRbjCxrvM2I7gpR0IGSH NO8toyK1vuFAWI7F1948ztPNqFk34QrNN1xp5m+I= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 6 Jan 2019 04:33:28 +0200 Message-Id: <20190106023328.10989-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190106023328.10989-1-laurent.pinchart@ideasonboard.com> References: <20190106023328.10989-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/11] test: Add event notifier test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jan 2019 02:32:31 -0000 Signed-off-by: Laurent Pinchart --- test/event.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 118 insertions(+) create mode 100644 test/event.cpp diff --git a/test/event.cpp b/test/event.cpp new file mode 100644 index 000000000000..52bc0c7e77f5 --- /dev/null +++ b/test/event.cpp @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * event.cpp - Event test + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class EventTest : public Test +{ +protected: + void readReady(EventNotifier *notifier) + { + size_ = read(notifier->fd(), data_, sizeof(data_)); + notified_ = true; + } + + int init() + { + return pipe(pipefd_); + } + + int run() + { + EventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher(); + std::string data("H2G2"); + Timer timeout; + + EventNotifier readNotifier(pipefd_[0], EventNotifier::Read); + readNotifier.activated.connect(this, &EventTest::readReady); + + /* Test read notification with data. */ + memset(data_, 0, sizeof(data_)); + size_ = 0; + + write(pipefd_[1], data.data(), data.size()); + + timeout.start(100); + dispatcher->processEvents(); + timeout.stop(); + + if (static_cast(size_) != data.size()) { + cout << "Event notifier read ready test failed" << endl; + return TestFail; + } + + /* Test read notification without data. */ + notified_ = false; + + timeout.start(100); + dispatcher->processEvents(); + timeout.stop(); + + if (notified_) { + cout << "Event notifier read no ready test failed" << endl; + return TestFail; + } + + /* Test read notifier disabling. */ + notified_ = false; + readNotifier.setEnabled(false); + + write(pipefd_[1], data.data(), data.size()); + + timeout.start(100); + dispatcher->processEvents(); + timeout.stop(); + + if (notified_) { + cout << "Event notifier read disabling failed" << endl; + return TestFail; + } + + /* Test read notifier enabling. */ + notified_ = false; + readNotifier.setEnabled(true); + + timeout.start(100); + dispatcher->processEvents(); + timeout.stop(); + + if (!notified_) { + cout << "Event notifier read enabling test failed" << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() + { + close(pipefd_[0]); + close(pipefd_[1]); + } + +private: + int pipefd_[2]; + + bool notified_; + char data_[16]; + ssize_t size_; +}; + +TEST_REGISTER(EventTest) diff --git a/test/meson.build b/test/meson.build index 12e7b30d4f73..e923404502b7 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,6 +3,7 @@ subdir('libtest') subdir('media_device') public_tests = [ + ['event', 'event.cpp'], ['list-cameras', 'list.cpp'], ['signal', 'signal.cpp'], ['timer', 'timer.cpp'],