summaryrefslogtreecommitdiff
path: root/test/v4l2_subdevice/v4l2_subdevice_test.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-02-12 23:21:16 +0100
committerJacopo Mondi <jacopo@jmondi.org>2019-03-01 12:33:17 +0100
commit7f4ce94ad9e14fa4fd53644abb2ce2bb2bf03dc3 (patch)
treefc7f6fd2cf7256f10fc23986a6ec2ca67a7ea2e9 /test/v4l2_subdevice/v4l2_subdevice_test.cpp
parenta56f8a57b554e97116086a1d4078f7462e068486 (diff)
test: v4l2_subdevice: Add format handling test
Add test for video format get and set operations on V4L2Subdevice class. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'test/v4l2_subdevice/v4l2_subdevice_test.cpp')
-rw-r--r--test/v4l2_subdevice/v4l2_subdevice_test.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp
new file mode 100644
index 00000000..06582969
--- /dev/null
+++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp
@@ -0,0 +1,82 @@
+/* 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 "device_enumerator.h"
+#include "media_device.h"
+#include "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_ = std::move(enumerator_->search(dm));
+ if (!media_) {
+ cerr << "Unable to find \'vimc\' media device node" << endl;
+ return TestSkip;
+ }
+
+ media_->acquire();
+
+ int ret = media_->open();
+ if (ret) {
+ cerr << "Unable to open media device: " << media_->deviceNode()
+ << ": " << strerror(ret) << endl;
+ media_->release();
+ return TestSkip;
+ }
+
+ MediaEntity *videoEntity = media_->getEntityByName("Scaler");
+ if (!videoEntity) {
+ cerr << "Unable to find media entity 'Scaler'" << endl;
+ media_->release();
+ return TestFail;
+ }
+
+ scaler_ = new V4L2Subdevice(videoEntity);
+ ret = scaler_->open();
+ if (ret) {
+ cerr << "Unable to open video subdevice "
+ << scaler_->deviceNode() << endl;
+ media_->release();
+ return TestSkip;
+ }
+
+ return 0;
+}
+
+void V4L2SubdeviceTest::cleanup()
+{
+ media_->release();
+
+ delete scaler_;
+}