From patchwork Wed Feb 6 06:07:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 517 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD71761022 for ; Wed, 6 Feb 2019 07:08:23 +0100 (CET) Received: from pendragon.ideasonboard.com (d51A4137F.access.telenet.be [81.164.19.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6C11B2D8 for ; Wed, 6 Feb 2019 07:08:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549433303; bh=cccDYJYCqgClqeKTmMAB9NH3IcXKA0AXfF7TghxU+UU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=USzbhqmKbdy2P1Hlvto41fEKb6B19J/e9fKHAD4JHFip8Yx7Xg9ueBMpnOptJYUyx nxOrFnGlfI25cQstjc1Q53MCMX7DfvJ7AgW/vq2a4DUb5oCV+BCqZD4Yxy2ccfuOAU CzeSSp2/RgaQag1owdZaJqA5PjB2vN7FZu4yY7R4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 6 Feb 2019 08:07:53 +0200 Message-Id: <20190206060818.13907-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> References: <20190206060818.13907-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/27] test: v4l2_device: Use DeviceEnumerator to find a UVCVideo X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Feb 2019 06:08:24 -0000 From: Kieran Bingham 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 Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Signed-off-by: Niklas Söderlund --- test/v4l2_device/v4l2_device_test.cpp | 34 +++++++++++++++++++++++---- test/v4l2_device/v4l2_device_test.h | 7 ++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 362553712caa..18d014caf4c8 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_; }; diff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h index 405cb7d6f404..ca231ab47fde 100644 --- a/test/v4l2_device/v4l2_device_test.h +++ b/test/v4l2_device/v4l2_device_test.h @@ -7,7 +7,12 @@ #ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_ #define __LIBCAMERA_V4L2_DEVICE_TEST_H_ +#include + #include "test.h" + +#include "device_enumerator.h" +#include "media_device.h" #include "v4l2_device.h" using namespace libcamera; @@ -21,6 +26,8 @@ protected: int init(); void cleanup(); + std::unique_ptr enumerator_; + std::shared_ptr media_; V4L2Device *dev_; };