From patchwork Sun Feb 3 11:00:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 488 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D68660DB8 for ; Sun, 3 Feb 2019 12:01:07 +0100 (CET) Received: from localhost.localdomain (218.182-78-194.adsl-static.isp.belgacom.be [194.78.182.218]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A97835AA; Sun, 3 Feb 2019 12:01:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549191666; bh=6IEmseyYCDF7xAtlbgbit0IeGxn/U4GY5MhKc462adI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEUEy6Bumu2yw9oSf5sGD6SudSHxeN+f3nIkolNzvqmGc+Rgky+8ev5AwYRG7r7gz GPvNmDcGiW92HhjL2psGl9sF3S/8H1uN0js3Nneoj0IKziWKmVlJ5u1A+KO5ZCScBC 1jNwls9GMYQPcAAcf5ELOXNHOXL+je7NdqOVtRLs= From: Kieran Bingham To: LibCamera Devel Date: Sun, 3 Feb 2019 12:00:52 +0100 Message-Id: <20190203110102.5663-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> References: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/11] 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: Sun, 03 Feb 2019 11:01:07 -0000 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 --- test/v4l2_device/v4l2_device_test.cpp | 28 +++++++++++++++++++++------ test/v4l2_device/v4l2_device_test.h | 7 +++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 362553712caa..e71a93cf2453 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,32 @@ 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; + } - /* Validate the device node exists. */ - if (!exists(device)) { - std::cout << "No video device available" << std::endl; - return TestSkip; + if (enumerator_->enumerate()) { + cerr << "Failed to enumerate media devices" << endl; + return TestFail; } - dev_ = new V4L2Device(device); + DeviceMatch dm("uvcvideo"); + media_ = std::move(enumerator_->search(dm)); + if (!media_) + return TestSkip; + + media_->acquire(); + + dev_ = new V4L2Device(*media_->entities()[0]); 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..d8652a5c9e15 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_; };