From patchwork Mon Jan 7 23:11:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 174 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 C11F860B50 for ; Tue, 8 Jan 2019 00:10:51 +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 5B20117CF for ; Tue, 8 Jan 2019 00:10:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1546902651; bh=HNfymYSEmXhYJ09QR+EBjEfNVr259lR2sHWY52LI+38=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Pd0kGO41oTSbv7O4ItrVtF+JeJ/5/1MICrXtGxLW5jDV2s+MgO9a3hGaUqxL3Yjf+ hsGT1kHSsfd2D1T+ljJeWg7gRXo5K8Kt8SukUBsdjbXIPuBNj5ugEENSaqiFHIgl4V j3bCPi3/vX/IY+iNWTyUv/A+8WClDV3Rb5wYOk1o= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Jan 2019 01:11:51 +0200 Message-Id: <20190107231151.23291-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107231151.23291-1-laurent.pinchart@ideasonboard.com> References: <20190107231151.23291-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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: Mon, 07 Jan 2019 23:10:51 -0000 Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- 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 f26c8701d827..32152888a55e 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-cameras.cpp'], ['signal', 'signal.cpp'], ['timer', 'timer.cpp'],