summaryrefslogtreecommitdiff
path: root/test/v4l2_device/v4l2_device_test.cpp
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2019-01-29 15:01:18 +0000
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-02-06 06:49:25 +0200
commit93ec63b8673b786065df815ab7035891cfc3a56c (patch)
treebda2f5bca681edb641bca4082443ce07fda93fad /test/v4l2_device/v4l2_device_test.cpp
parent83148ce8be55e49d30da9006582a1c1eb6371815 (diff)
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>
Diffstat (limited to 'test/v4l2_device/v4l2_device_test.cpp')
-rw-r--r--test/v4l2_device/v4l2_device_test.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp
index 36255371..18d014ca 100644
--- a/test/v4l2_device/v4l2_device_test.cpp
+++ b/test/v4l2_device/v4l2_device_test.cpp
@@ -10,6 +10,10 @@
#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)
@@ -24,20 +28,40 @@ bool exists(const std::string &path)
int V4L2DeviceTest::init()
{
- const std::string device("/dev/video0");
+ 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;
+ }
- /* Validate the device node exists. */
- if (!exists(device)) {
- std::cout << "No video device available" << std::endl;
+ 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;
+ }
}
- dev_ = new V4L2Device(device);
+ if (!dev_)
+ return TestSkip;
return dev_->open();
}
void V4L2DeviceTest::cleanup()
{
+ media_->release();
+
delete dev_;
};