[{"id":990,"web_url":"https://patchwork.libcamera.org/comment/990/","msgid":"<20190301124454.GF26239@pendragon.ideasonboard.com>","date":"2019-03-01T12:44:54","subject":"Re: [libcamera-devel] [PATCH v6 2/5] test: v4l2_subdevice: Add\n\tListFormat test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Fri, Mar 01, 2019 at 12:51:36PM +0100, Jacopo Mondi wrote:\n> Add test to list formats on a v4l2 subdevice.\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  test/v4l2_subdevice/list_formats.cpp | 81 ++++++++++++++++++++++++++++\n>  test/v4l2_subdevice/meson.build      |  1 +\n>  2 files changed, 82 insertions(+)\n>  create mode 100644 test/v4l2_subdevice/list_formats.cpp\n> \n> diff --git a/test/v4l2_subdevice/list_formats.cpp b/test/v4l2_subdevice/list_formats.cpp\n> new file mode 100644\n> index 000000000000..b4eab68f9f7e\n> --- /dev/null\n> +++ b/test/v4l2_subdevice/list_formats.cpp\n> @@ -0,0 +1,81 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 Subdevice format handling test\n> + */\n> +\n> +#include <iomanip>\n> +#include <iostream>\n> +#include <vector>\n> +\n> +#include \"geometry.h\"\n> +#include \"v4l2_subdevice.h\"\n> +#include \"v4l2_subdevice_test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +/* List image formats on the \"Scaler\" subdevice of vimc media device.  */\n> +\n> +class ListFormatsTest : public V4L2SubdeviceTest\n> +{\n> +protected:\n> +\tint run() override;\n> +\n> +private:\n> +\tvoid printFormats(unsigned int pad, unsigned code,\n> +\t\t\t  std::vector<SizeRange> &formats);\n> +};\n> +\n> +void ListFormatsTest::printFormats(unsigned int pad,\n> +\t\t\t\t   unsigned int code,\n> +\t\t\t\t   std::vector<SizeRange> &sizes)\n> +{\n> +\tcout << \"Enumerate formats on pad \" << pad << endl;\n> +\tfor (SizeRange &size : sizes) {\n> +\t\tcout << \"\tmbus code: 0x\" << setfill('0') << setw(4)\n> +\t\t     << hex << code << endl;\n> +\t\tcout << \"\tmin width: \" << dec << size.minWidth << endl;\n> +\t\tcout << \"\tmin height: \" << dec << size.minHeight << endl;\n> +\t\tcout << \"\tmax width: \" << dec << size.maxWidth << endl;\n> +\t\tcout << \"\tmax height: \" << dec << size.maxHeight << endl;\n> +\t}\n> +}\n> +\n> +int ListFormatsTest::run()\n> +{\n> +\t/* List all formats available on existing \"Scaler\" pads. */\n> +\tstd::map<unsigned int, std::vector<SizeRange>> formats;\n> +\n> +\tformats = scaler_->formats(0);\n> +\tif (formats.size() == 0) {\n\nWhen you check if a container is empty, I find .empty() to be more\nreadable than .size() == 0. Apart from that (here and in two locations\nbelow) the patch looks good to me.\n\n> +\t\tcerr << \"Failed to list formats on pad 0 of subdevice \"\n> +\t\t     << scaler_->deviceName() << endl;\n> +\t\treturn TestFail;\n> +\t}\n> +\tfor (auto it = formats.begin(); it != formats.end(); ++it)\n> +\t\tprintFormats(0, it->first, it->second);\n> +\n> +\tformats = scaler_->formats(1);\n> +\tif (formats.size() == 0) {\n> +\t\tcerr << \"Failed to list formats on pad 1 of subdevice \"\n> +\t\t     << scaler_->deviceName() << endl;\n> +\t\treturn TestFail;\n> +\t}\n> +\tfor (auto it = formats.begin(); it != formats.end(); ++it)\n> +\t\tprintFormats(1, it->first, it->second);\n> +\n> +\t/* List format on a non-existing pad, format vector shall be empty. */\n> +\tformats = scaler_->formats(2);\n> +\tif (formats.size() != 0) {\n> +\t\tcerr << \"Listing formats on non-existing pad 2 of subdevice \"\n> +\t\t     << scaler_->deviceName()\n> +\t\t     << \" should return an empty format list\" << endl;\n> +\t\treturn TestFail;\n> +\t}\n> +\n> +\treturn TestPass;\n> +}\n> +\n> +TEST_REGISTER(ListFormatsTest);\n> diff --git a/test/v4l2_subdevice/meson.build b/test/v4l2_subdevice/meson.build\n> index f45dca0d23d7..80cfbbbf9413 100644\n> --- a/test/v4l2_subdevice/meson.build\n> +++ b/test/v4l2_subdevice/meson.build\n> @@ -1,4 +1,5 @@\n>  v4l2_subdevice_tests = [\n> +  [ 'list_formats',             'list_formats.cpp'],\n>    [ 'test_formats',             'test_formats.cpp'],\n>  ]\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6D30F610BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Mar 2019 13:45:00 +0100 (CET)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DFF0F49;\n\tFri,  1 Mar 2019 13:44:59 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1551444300;\n\tbh=TQZ/TJpp9f/mHhVttWU5GQIAlO2MSbY8bp3Ufrw4+UI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fkfbmIvcVUyAO/8f/xy56NexdITwuvkDDnkj977c3EIHJI6B9xs13tQiP4UAuV5ip\n\t1GiMJgsrmtNj2nX4RqaTsZ1oEPmdfQjZ1myy+6cGSGJ0uLz17MzorC4akHtgt6cAd+\n\tCSVXVKfWdS/aB90Fbawif/dHIYEWLLJeB++sSwQ8=","Date":"Fri, 1 Mar 2019 14:44:54 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190301124454.GF26239@pendragon.ideasonboard.com>","References":"<20190301115139.11060-1-jacopo@jmondi.org>\n\t<20190301115139.11060-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190301115139.11060-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v6 2/5] test: v4l2_subdevice: Add\n\tListFormat test","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Fri, 01 Mar 2019 12:45:00 -0000"}}]