From patchwork Thu Feb 28 20:01:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 676 Return-Path: Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C4B3610B7 for ; Thu, 28 Feb 2019 21:01:36 +0100 (CET) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id C09DA100002; Thu, 28 Feb 2019 20:01:35 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 21:01:50 +0100 Message-Id: <20190228200151.2948-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228200151.2948-1-jacopo@jmondi.org> References: <20190228200151.2948-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 8/9] test: v4l2_subdevice: Add ListFormat test 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: Thu, 28 Feb 2019 20:01:36 -0000 Add test to list formats on a v4l2 subdevice. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- test/v4l2_subdevice/list_formats.cpp | 85 ++++++++++++++++++++++++++++ test/v4l2_subdevice/meson.build | 1 + 2 files changed, 86 insertions(+) create mode 100644 test/v4l2_subdevice/list_formats.cpp diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp new file mode 100644 index 000000000000..b902a198b17e --- /dev/null +++ b/test/v4l2_subdevice/list_formats.cpp @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * libcamera V4L2 Subdevice format handling test + */ + +#include +#include + +#include "geometry.h" +#include "v4l2_subdevice.h" +#include "v4l2_subdevice_test.h" + +using namespace std; +using namespace libcamera; + +/* List image formats on the "Scaler" subdevice of vimc media device. */ + +class ListFormatsTest : public V4L2SubdeviceTest +{ +protected: + int run() override; + +private: + void printFormats(unsigned int pad, unsigned code, + std::vector &formats); +}; + +void ListFormatsTest::printFormats(unsigned int pad, + unsigned int code, + std::vector &sizes) +{ + cout << "Enumerate formats on pad " << pad << endl; + for (SizeRange &size : sizes) { + cout << " Mbus code: 0x" << hex << code << endl; + cout << " min Width: " << dec << size.minWidth << endl; + cout << " min Height: " << dec << size.minHeight << endl; + cout << " max Width: " << dec << size.maxWidth << endl; + cout << " max Height: " << dec << size.maxHeight << endl; + } +} + +int ListFormatsTest::run() +{ + /* List all formats available on existing "Scaler" pads. */ + std::map> formats; + + formats = scaler_->formats(0); + if (formats.size() == 0) { + cerr << "Failed to list formats on pad 0 of subdevice " + << scaler_->deviceName() << endl; + return TestFail; + } + auto it = formats.begin(); + while (it != formats.end()) { + printFormats(0, it->first, it->second); + ++it; + } + + formats = scaler_->formats(1); + if (formats.size() == 0) { + cerr << "Failed to list formats on pad 1 of subdevice " + << scaler_->deviceName() << endl; + return TestFail; + } + it = formats.begin(); + while (it != formats.end()) { + printFormats(1, it->first, it->second); + ++it; + } + + /* List format on a non-existing pad, format vector shall be empty. */ + formats = scaler_->formats(2); + if (formats.size() != 0) { + cerr << "Listing formats on non-existing pad 2 of subdevice " + << scaler_->deviceName() + << " should return an empty format list" << endl; + return TestFail; + } + + return TestPass; +} + +TEST_REGISTER(ListFormatsTest); diff --git a/test/v4l2_subdevice/meson.build b/test/v4l2_subdevice/meson.build index f45dca0d23d7..80cfbbbf9413 100644 --- a/test/v4l2_subdevice/meson.build +++ b/test/v4l2_subdevice/meson.build @@ -1,4 +1,5 @@ v4l2_subdevice_tests = [ + [ 'list_formats', 'list_formats.cpp'], [ 'test_formats', 'test_formats.cpp'], ]