From patchwork Thu Oct 3 15:20:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2080 Return-Path: Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3766760BE9 for ; Thu, 3 Oct 2019 17:19:06 +0200 (CEST) X-Originating-IP: 2.224.242.101 Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C22CFC000B; Thu, 3 Oct 2019 15:19:05 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Oct 2019 17:20:36 +0200 Message-Id: <20191003152037.74617-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003152037.74617-1-jacopo@jmondi.org> References: <20191003152037.74617-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/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: Thu, 03 Oct 2019 15:19:06 -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 --- test/ipa/ipa_interface_test.cpp | 147 ++++++++++++++++++++++++++++++++ test/ipa/meson.build | 3 +- 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 test/ipa/ipa_interface_test.cpp diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp new file mode 100644 index 000000000000..83eef7440fa4 --- /dev/null +++ b/test/ipa/ipa_interface_test.cpp @@ -0,0 +1,147 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * ipa_interface_test.cpp - Test the IPA interface communication using the VIMC + * dummy IPA module + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ipa_module.h" + +#include "test.h" +#include "thread.h" + +using namespace std; +using namespace libcamera; + +/* Keep with in sync with the VIMC IPA module. */ +static const char *ipaFifoPath = "/tmp/vimc_ipa_fifo"; +#define IPA_INIT_CODE 0x01 + +static const char *vimcModulePath = "src/ipa/ipa_vimc.so"; + +class IPAInterfaceTest : public Test, public Object +{ +public: + IPAInterfaceTest() + : fd_(0), data_(0) + { + } + + ~IPAInterfaceTest() + { + /* + * Delete the IPA Interface instance -before- deleting the + * module used to create it, as the IPAModule destructor closes + * the IPA shared object, resulting in segfault at interface + * deletion time. + */ + IPAInterface *ipa = ipa_.release(); + delete ipa; + + if (ipaModule_) + delete ipaModule_; + + delete notifier_; + } + +protected: + int init() override + { + int ret = mkfifo(ipaFifoPath, S_IRUSR | S_IWUSR); + if (ret) { + cerr << "Failed to create IPA test fifo at: " + << ipaFifoPath << ": " << strerror(errno) << endl; + return TestFail; + } + + ret = open(ipaFifoPath, O_RDONLY | O_NONBLOCK); + if (ret < 0) { + cerr << "Failed to open IPA test fifo at: " + << ipaFifoPath << ": " << strerror(errno) << endl; + unlink(ipaFifoPath); + return TestFail; + } + fd_ = ret; + + notifier_ = new EventNotifier(fd_, EventNotifier::Read, this); + notifier_->activated.connect(this, &IPAInterfaceTest::readFifo); + + return TestPass; + } + + int run() override + { + EventDispatcher *dispatcher = thread()->eventDispatcher(); + Timer timer; + + ipaModule_ = new IPAModule(vimcModulePath); + if (!ipaModule_ || !ipaModule_->isValid()) { + cerr << "Failed to create VIMC IPA module at: " + << vimcModulePath << endl; + return TestFail; + } + + if (!ipaModule_->load()) { + cerr << "Failed to load VIMC IPA module" << endl; + return TestFail; + } + + ipa_ = ipaModule_->createInstance(); + 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() && data_ != IPA_INIT_CODE) + dispatcher->processEvents(); + + if (data_ != IPA_INIT_CODE) { + cerr << "Failed to test IPA initialization sequence" + << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() override + { + close(fd_); + unlink(ipaFifoPath); + } + +private: + void readFifo(EventNotifier *notifier) + { + size_t s = read(notifier->fd(), &data_, 1); + if (s < 0) { + cerr << "Failed to to read from IPA test fifo at: " + << ipaFifoPath << strerror(errno) << endl; + data_ = -1; + } + } + + std::unique_ptr ipa_; + EventNotifier *notifier_; + IPAModule *ipaModule_; + unsigned int fd_; + int8_t data_; +}; + +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