From patchwork Mon Oct 7 08:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2127 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EA4FE6196D for ; Mon, 7 Oct 2019 10:57:03 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id B4C9E24000F for ; Mon, 7 Oct 2019 08:57:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Oct 2019 10:58:42 +0200 Message-Id: <20191007085842.7608-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007085842.7608-1-jacopo@jmondi.org> References: <20191007085842.7608-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/5] test: ipa: Add test for the IPA Interface 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: Mon, 07 Oct 2019 08:57:04 -0000 Implement a basic test for IPA Interface using the VIMC dummy IPA module. The test implements an out-of-band feedback channel between the test and the dummy IPA module to verify the success of the IPA interactions. Test the only available operation defined by the IPA interface by receiving a confirmation code on the fifo communication channel. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- test/ipa/ipa_interface_test.cpp | 142 ++++++++++++++++++++++++++++++++ test/ipa/meson.build | 3 +- 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 test/ipa/ipa_interface_test.cpp -- 2.23.0 diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp new file mode 100644 index 000000000000..171e572461a5 --- /dev/null +++ b/test/ipa/ipa_interface_test.cpp @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * ipa_interface_test.cpp - Test the IPA interface + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include "device_enumerator.h" +#include "ipa_manager.h" +#include "ipa_module.h" +#include "pipeline_handler.h" +#include "test.h" +#include "thread.h" + +using namespace std; +using namespace libcamera; + +class IPAInterfaceTest : public Test, public Object +{ +public: + IPAInterfaceTest() + : trace_(IPAOperationNone), notifier_(nullptr), fd_(-1) + { + } + + ~IPAInterfaceTest() + { + delete notifier_; + } + +protected: + int init() override + { + /* Create a pipeline handler for vimc. */ + std::vector &factories = + PipelineHandlerFactory::factories(); + for (PipelineHandlerFactory *factory : factories) { + if (factory->name() == "PipelineHandlerVimc") { + pipe_ = factory->create(nullptr); + break; + } + } + + if (!pipe_) { + cerr << "Vimc pipeline not found" << endl; + return TestPass; + } + + /* Create and open the communication FIFO. */ + int ret = mkfifo(VIMC_IPA_FIFO_PATH, S_IRUSR | S_IWUSR); + if (ret) { + ret = errno; + cerr << "Failed to create IPA test FIFO at '" + << VIMC_IPA_FIFO_PATH << "': " << strerror(ret) + << endl; + return TestFail; + } + + ret = open(VIMC_IPA_FIFO_PATH, O_RDONLY | O_NONBLOCK); + if (ret < 0) { + ret = errno; + cerr << "Failed to open IPA test FIFO at '" + << VIMC_IPA_FIFO_PATH << "': " << strerror(ret) + << endl; + unlink(VIMC_IPA_FIFO_PATH); + return TestFail; + } + fd_ = ret; + + notifier_ = new EventNotifier(fd_, EventNotifier::Read, this); + notifier_->activated.connect(this, &IPAInterfaceTest::readTrace); + + return TestPass; + } + + int run() override + { + EventDispatcher *dispatcher = thread()->eventDispatcher(); + Timer timer; + + ipa_ = IPAManager::instance()->createIPA(pipe_.get(), 0, 0); + if (!ipa_) { + cerr << "Failed to create VIMC IPA interface" << endl; + return TestFail; + } + + /* Test initialization of IPA module. */ + ipa_->init(); + timer.start(1000); + while (timer.isRunning() && trace_ != IPAOperationInit) + dispatcher->processEvents(); + + if (trace_ != IPAOperationInit) { + cerr << "Failed to test IPA initialization sequence" + << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() override + { + close(fd_); + unlink(VIMC_IPA_FIFO_PATH); + } + +private: + void readTrace(EventNotifier *notifier) + { + ssize_t s = read(notifier->fd(), &trace_, sizeof(trace_)); + if (s < 0) { + int ret = errno; + cerr << "Failed to read from IPA test FIFO at '" + << VIMC_IPA_FIFO_PATH << "': " << strerror(ret) + << endl; + trace_ = IPAOperationNone; + } + } + + std::shared_ptr pipe_; + std::unique_ptr ipa_; + enum IPAOperationCode trace_; + EventNotifier *notifier_; + int fd_; +}; + +TEST_REGISTER(IPAInterfaceTest) diff --git a/test/ipa/meson.build b/test/ipa/meson.build index e174671d05e1..c501fcf99aed 100644 --- a/test/ipa/meson.build +++ b/test/ipa/meson.build @@ -1,5 +1,6 @@ ipa_test = [ - ['ipa_module_test', 'ipa_module_test.cpp'], + ['ipa_module_test', 'ipa_module_test.cpp'], + ['ipa_interface_test', 'ipa_interface_test.cpp'], ] foreach t : ipa_test