libcamera/test/v4l2_device/v4l2_device_test.cpp
Kieran Bingham 93ec63b867 test: v4l2_device: Use DeviceEnumerator to find a UVCVideo
Utilise the existing DeviceEnumerator system to identify a suitable
V4L2Device for testing.

Specifically target these tests at a uvcvideo driver based device as a known
supported target.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-02-06 06:49:25 +02:00

67 lines
1.1 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* libcamera V4L2 API tests
*/
#include <iostream>
#include <sys/stat.h>
#include "v4l2_device_test.h"
#include "device_enumerator.h"
#include "media_device.h"
using namespace std;
using namespace libcamera;
bool exists(const std::string &path)
{
struct stat sb;
if (stat(path.c_str(), &sb) == 0)
return true;
return false;
}
int V4L2DeviceTest::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("uvcvideo");
media_ = std::move(enumerator_->search(dm));
if (!media_)
return TestSkip;
media_->acquire();
for (MediaEntity *entity : media_->entities()) {
if (entity->flags() & MEDIA_ENT_FL_DEFAULT) {
dev_ = new V4L2Device(entity);
break;
}
}
if (!dev_)
return TestSkip;
return dev_->open();
}
void V4L2DeviceTest::cleanup()
{
media_->release();
delete dev_;
};