summaryrefslogtreecommitdiff
path: root/test/pipeline/rkisp1/rkisp1_pipeline_test.cpp
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2020-10-21 10:39:53 +0900
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-10-21 11:18:12 +0100
commit90c193f2a70093917730b86359c6e459c28d2c24 (patch)
treef32f6dffbb7542df962adf1fa46f7b4f026d1e14 /test/pipeline/rkisp1/rkisp1_pipeline_test.cpp
parentb8dd5ce944eca4d17df585bb059595729905f7ec (diff)
android: Modify Encoder interface
In Encoder::encode(), the |source| argument doesn't have to be a pointer. This replaces its type, const pointer, with const reference as the latter is preferred to the former. libcamera::Span is cheap to construct/copy/move. We should deal with the type as pass-by-value parameter. Therefore this also drops the const reference in the |destination| argument. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Umang Jain <email@uajain.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'test/pipeline/rkisp1/rkisp1_pipeline_test.cpp')
0 files changed, 0 insertions, 0 deletions
#n136'>136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * Test the IPA interface
 */

#include <fcntl.h>
#include <iostream>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <libcamera/ipa/vimc_ipa_proxy.h>

#include <libcamera/base/event_dispatcher.h>
#include <libcamera/base/event_notifier.h>
#include <libcamera/base/object.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>

#include "libcamera/internal/camera_manager.h"
#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/ipa_manager.h"
#include "libcamera/internal/ipa_module.h"
#include "libcamera/internal/pipeline_handler.h"

#include "test.h"

using namespace libcamera;
using namespace std;
using namespace std::chrono_literals;

class IPAInterfaceTest : public Test, public Object
{
public:
	IPAInterfaceTest()
		: trace_(ipa::vimc::IPAOperationNone), notifier_(nullptr), fd_(-1)
	{
	}

	~IPAInterfaceTest()
	{
		delete notifier_;
		ipa_.reset();
		cameraManager_.reset();
	}

protected:
	int init() override
	{
		cameraManager_ = make_unique<CameraManager>();

		/* Create a pipeline handler for vimc. */
		const std::vector<PipelineHandlerFactoryBase *> &factories =
			PipelineHandlerFactoryBase::factories();
		for (const PipelineHandlerFactoryBase *factory : factories) {
			if (factory->name() == "vimc") {
				pipe_ = factory->create(cameraManager_.get());
				break;
			}
		}

		if (!pipe_) {
			cerr << "Vimc pipeline not found" << endl;
			return TestPass;
		}

		/* Create and open the communication FIFO. */
		int ret = mkfifo(ipa::vimc::VimcIPAFIFOPath.c_str(), S_IRUSR | S_IWUSR);
		if (ret) {
			ret = errno;
			cerr << "Failed to create IPA test FIFO at '"
			     << ipa::vimc::VimcIPAFIFOPath << "': " << strerror(ret)
			     << endl;
			return TestFail;
		}

		ret = open(ipa::vimc::VimcIPAFIFOPath.c_str(), O_RDONLY | O_NONBLOCK);
		if (ret < 0) {
			ret = errno;
			cerr << "Failed to open IPA test FIFO at '"
			     << ipa::vimc::VimcIPAFIFOPath << "': " << strerror(ret)
			     << endl;
			unlink(ipa::vimc::VimcIPAFIFOPath.c_str());
			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::createIPA<ipa::vimc::IPAProxyVimc>(pipe_.get(), 0, 0);
		if (!ipa_) {
			cerr << "Failed to create VIMC IPA interface" << endl;
			return TestFail;
		}

		/* Test initialization of IPA module. */
		std::string conf = ipa_->configurationFile("vimc.conf");
		Flags<ipa::vimc::TestFlag> inFlags;
		Flags<ipa::vimc::TestFlag> outFlags;
		int ret = ipa_->init(IPASettings{ conf, "vimc" },
				     ipa::vimc::IPAOperationInit,
				     inFlags, &outFlags);
		if (ret < 0) {
			cerr << "IPA interface init() failed" << endl;
			return TestFail;
		}

		timer.start(1000ms);
		while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationInit)
			dispatcher->processEvents();

		if (trace_ != ipa::vimc::IPAOperationInit) {
			cerr << "Failed to test IPA initialization sequence"
			     << endl;
			return TestFail;
		}

		/* Test start of IPA module. */
		ipa_->start();
		timer.start(1000ms);
		while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStart)
			dispatcher->processEvents();

		if (trace_ != ipa::vimc::IPAOperationStart) {
			cerr << "Failed to test IPA start sequence" << endl;
			return TestFail;
		}

		/* Test stop of IPA module. */
		ipa_->stop();
		timer.start(1000ms);
		while (timer.isRunning() && trace_ != ipa::vimc::IPAOperationStop)
			dispatcher->processEvents();

		if (trace_ != ipa::vimc::IPAOperationStop) {
			cerr << "Failed to test IPA stop sequence" << endl;
			return TestFail;
		}

		return TestPass;
	}

	void cleanup() override
	{
		close(fd_);
		unlink(ipa::vimc::VimcIPAFIFOPath.c_str());
	}

private:
	void readTrace()
	{
		ssize_t s = read(notifier_->fd(), &trace_, sizeof(trace_));
		if (s < 0) {
			int ret = errno;
			cerr << "Failed to read from IPA test FIFO at '"
			     << ipa::vimc::VimcIPAFIFOPath << "': " << strerror(ret)
			     << endl;
			trace_ = ipa::vimc::IPAOperationNone;
		}
	}

	std::shared_ptr<PipelineHandler> pipe_;
	std::unique_ptr<ipa::vimc::IPAProxyVimc> ipa_;
	std::unique_ptr<CameraManager> cameraManager_;
	enum ipa::vimc::IPAOperationCode trace_;
	EventNotifier *notifier_;
	int fd_;
};

TEST_REGISTER(IPAInterfaceTest)