From patchwork Fri Oct 4 16:37:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2102 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C33F6165B for ; Fri, 4 Oct 2019 18:36:02 +0200 (CEST) Received: from uno.localdomain (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B8075200008; Fri, 4 Oct 2019 16:36:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 4 Oct 2019 18:37:34 +0200 Message-Id: <20191004163734.15594-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191004163734.15594-1-jacopo@jmondi.org> References: <20191004163734.15594-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/6] 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: Fri, 04 Oct 2019 16:36:02 -0000 Implementing a basic test for IPA Interface using the VIMC dummy IPA module. The test implements a communication 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. Signed-off-by: Jacopo Mondi --- src/ipa/meson.build | 2 + test/ipa/ipa_interface_test.cpp | 136 ++++++++++++++++++++++++++++++++ test/ipa/meson.build | 10 ++- 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 test/ipa/ipa_interface_test.cpp diff --git a/src/ipa/meson.build b/src/ipa/meson.build index 2827dc0303b2..3e11e166f283 100644 --- a/src/ipa/meson.build +++ b/src/ipa/meson.build @@ -5,6 +5,8 @@ ipa_vimc_sources = [ ipa_install_dir = join_paths(get_option('libdir'), 'libcamera') +ipa_internal_includes = include_directories('.') + ipa_includes = [ libcamera_includes, libcamera_internal_includes, diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp new file mode 100644 index 000000000000..b6d0a4e7de20 --- /dev/null +++ b/test/ipa/ipa_interface_test.cpp @@ -0,0 +1,136 @@ +/* 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 "device_enumerator.h" +#include "ipa_manager.h" +#include "ipa_module.h" +#include "pipeline_handler.h" +#include "test.h" +#include "thread.h" + +#include "ipa_vimc.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(vimcFifoPath, S_IRUSR | S_IWUSR); + if (ret) { + cerr << "Failed to create IPA test fifo at: " + << vimcFifoPath << ": " << strerror(errno) << endl; + return TestFail; + } + + ret = open(vimcFifoPath, O_RDONLY | O_NONBLOCK); + if (ret < 0) { + cerr << "Failed to open IPA test fifo at: " + << vimcFifoPath << ": " << strerror(errno) << endl; + unlink(vimcFifoPath); + 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(vimcFifoPath); + } + +private: + void readTrace(EventNotifier *notifier) + { + ssize_t s = read(notifier->fd(), &trace_, sizeof(trace_)); + if (s < 0) { + cerr << "Failed to read from IPA test fifo: " + << strerror(errno) << endl; + trace_ = IPAOperationNone; + } + } + + std::shared_ptr pipe_; + std::unique_ptr ipa_; + enum IPAOperationCodes trace_; + EventNotifier *notifier_; + int fd_; +}; + +TEST_REGISTER(IPAInterfaceTest) diff --git a/test/ipa/meson.build b/test/ipa/meson.build index e174671d05e1..d19de18ab97e 100644 --- a/test/ipa/meson.build +++ b/test/ipa/meson.build @@ -1,12 +1,18 @@ ipa_test = [ - ['ipa_module_test', 'ipa_module_test.cpp'], + ['ipa_module_test', 'ipa_module_test.cpp'], + ['ipa_interface_test', 'ipa_interface_test.cpp'], +] + +test_includes_ipa = [ + test_includes_internal, + ipa_internal_includes, ] foreach t : ipa_test exe = executable(t[0], t[1], dependencies : libcamera_dep, link_with : test_libraries, - include_directories : test_includes_internal) + include_directories : test_includes_ipa) test(t[0], exe, suite : 'ipa') endforeach