diff options
author | Jacopo Mondi <jacopo@jmondi.org> | 2019-02-25 12:42:17 +0100 |
---|---|---|
committer | Jacopo Mondi <jacopo@jmondi.org> | 2019-03-02 18:31:30 +0100 |
commit | de16573bcc670776565fe2966b86233408d38bc9 (patch) | |
tree | e918a72a134fce708963d8bc2afa5012ad13973b /test/v4l2_subdevice | |
parent | 0559c740f201bebf89983464c2e9ae92d0a8936b (diff) |
test: v4l2_subdevice: Add ListFormat test
Add test to list formats on a v4l2 subdevice.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'test/v4l2_subdevice')
-rw-r--r-- | test/v4l2_subdevice/list_formats.cpp | 81 | ||||
-rw-r--r-- | test/v4l2_subdevice/meson.build | 1 |
2 files changed, 82 insertions, 0 deletions
diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp new file mode 100644 index 00000000..bf859779 --- /dev/null +++ b/test/v4l2_subdevice/list_formats.cpp @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * libcamera V4L2 Subdevice format handling test + */ + +#include <iomanip> +#include <iostream> +#include <vector> + +#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<SizeRange> &formats); +}; + +void ListFormatsTest::printFormats(unsigned int pad, + unsigned int code, + std::vector<SizeRange> &sizes) +{ + cout << "Enumerate formats on pad " << pad << endl; + for (SizeRange &size : sizes) { + cout << " mbus code: 0x" << setfill('0') << setw(4) + << 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<unsigned int, std::vector<SizeRange>> formats; + + formats = scaler_->formats(0); + if (formats.empty()) { + cerr << "Failed to list formats on pad 0 of subdevice " + << scaler_->deviceName() << endl; + return TestFail; + } + for (auto it = formats.begin(); it != formats.end(); ++it) + printFormats(0, it->first, it->second); + + formats = scaler_->formats(1); + if (formats.empty()) { + cerr << "Failed to list formats on pad 1 of subdevice " + << scaler_->deviceName() << endl; + return TestFail; + } + for (auto it = formats.begin(); it != formats.end(); ++it) + printFormats(1, it->first, it->second); + + /* List format on a non-existing pad, format vector shall be empty. */ + formats = scaler_->formats(2); + if (!formats.empty()) { + 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 f45dca0d..80cfbbbf 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'], ] |