/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * v4l2_subdevice_test.cpp - VIMC-based V4L2 subdevice test
 */

#include <iostream>
#include <string.h>
#include <sys/stat.h>

#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/media_device.h"
#include "libcamera/internal/v4l2_subdevice.h"

#include "v4l2_subdevice_test.h"

using namespace std;
using namespace libcamera;

/*
 * This test runs on vimc media device. For a description of vimc, in the
 * context of libcamera testing, please refer to
 * 'test/media_device/media_device_link_test.cpp' file.
 *
 * If the vimc module is not loaded, the test gets skipped.
 */

int V4L2SubdeviceTest::init()
{
	enumerator_ = DeviceEnumerator::create();
	if (!enumerator_) {
		cerr << "Failed to create device enumerator" << endl;
		return TestFail;
	}

	if (enumerator_->enumerate()) {
		cerr << "Failed to enumerate media devices" << endl;
		return TestFail;
	}

	DeviceMatch dm("vimc");
	media_ = enumerator_->search(dm);
	if (!media_) {
		cerr << "Unable to find \'vimc\' media device node" << endl;
		return TestSkip;
	}

	MediaEntity *videoEntity = media_->getEntityByName("Scaler");
	if (!videoEntity) {
		cerr << "Unable to find media entity 'Scaler'" << endl;
		return TestFail;
	}

	scaler_ = new V4L2Subdevice(videoEntity);
	if (scaler_->open()) {
		cerr << "Unable to open video subdevice "
		     << scaler_->entity()->deviceNode() << endl;
		return TestSkip;
	}

	return 0;
}

void V4L2SubdeviceTest::cleanup()
{
	delete scaler_;
}
ons/cloud-lightning.svg?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>tree</a><a href='/libcamera/vivid.git/commit/src/qcam/assets/feathericons/cloud-lightning.svg?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>commit</a><a href='/libcamera/vivid.git/diff/src/qcam/assets/feathericons/cloud-lightning.svg?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>diff</a></td><td class='form'><form class='right' method='get' action='/libcamera/vivid.git/log/src/qcam/assets/feathericons/cloud-lightning.svg'>
<input type='hidden' name='h' value='v0.0.1'/><input type='hidden' name='id' value='79266225d2af742195f99be7c91c7d5356f7eb78'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/libcamera/vivid.git/tree/?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>root</a>/<a href='/libcamera/vivid.git/tree/src?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>src</a>/<a href='/libcamera/vivid.git/tree/src/qcam?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>qcam</a>/<a href='/libcamera/vivid.git/tree/src/qcam/assets?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>assets</a>/<a href='/libcamera/vivid.git/tree/src/qcam/assets/feathericons?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>feathericons</a>/<a href='/libcamera/vivid.git/tree/src/qcam/assets/feathericons/cloud-lightning.svg?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>cloud-lightning.svg</a></div><div class='content'>blob: 32d154cc00e3f398f04dac3df90c102c667475c8 (<a href='/libcamera/vivid.git/plain/src/qcam/assets/feathericons/cloud-lightning.svg?h=v0.0.1&amp;id=79266225d2af742195f99be7c91c7d5356f7eb78'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
</pre></td>
<td class='lines'><pre><code>