[{"id":1042,"web_url":"https://patchwork.libcamera.org/comment/1042/","msgid":"<20190311084056.GD4775@pendragon.ideasonboard.com>","date":"2019-03-11T08:40:56","subject":"Re: [libcamera-devel] [PATCH v2 1/4] test: camera: Add read default\n\tconfiguration test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Mon, Mar 11, 2019 at 03:22:29AM +0100, Niklas Söderlund wrote:\n> Add a test to verify reading the default configuration from a camera\n> works.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  test/camera/camera_test.cpp           | 74 +++++++++++++++++++++++++++\n>  test/camera/camera_test.h             | 35 +++++++++++++\n>  test/camera/configuration_default.cpp | 68 ++++++++++++++++++++++++\n>  test/camera/meson.build               | 12 +++++\n>  test/meson.build                      |  1 +\n>  5 files changed, 190 insertions(+)\n>  create mode 100644 test/camera/camera_test.cpp\n>  create mode 100644 test/camera/camera_test.h\n>  create mode 100644 test/camera/configuration_default.cpp\n>  create mode 100644 test/camera/meson.build\n> \n> diff --git a/test/camera/camera_test.cpp b/test/camera/camera_test.cpp\n> new file mode 100644\n> index 0000000000000000..4ba6813c40ece44b\n> --- /dev/null\n> +++ b/test/camera/camera_test.cpp\n> @@ -0,0 +1,74 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera Camera API tests\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include \"camera_test.h\"\n> +\n> +using namespace libcamera;\n> +using namespace std;\n> +\n> +int CameraTest::init()\n> +{\n> +\tcm_ = CameraManager::instance();\n> +\n> +\tif (cm_->start()) {\n> +\t\tcout << \"Failed to start camera manager\" << endl;\n> +\t\treturn TestFail;\n> +\t}\n> +\n> +\tcamera_ = cm_->get(\"VIMC Sensor B\");\n> +\tif (!camera_) {\n> +\t\tcout << \"Can not find VIMC camera\" << endl;\n> +\t\treturn TestSkip;\n> +\t}\n> +\n> +\t/* Sanity check that the camera has streams. */\n> +\tif (camera_->streams().empty()) {\n> +\t\tcout << \"Camera has no stream\" << endl;\n> +\t\treturn TestFail;\n> +\t}\n> +\n> +\treturn TestPass;\n> +}\n> +\n> +void CameraTest::cleanup()\n> +{\n> +\tif (camera_) {\n> +\t\tcamera_->release();\n> +\t\tcamera_.reset();\n> +\t}\n> +\n> +\tcm_->stop();\n> +};\n> +\n> +bool CameraTest::configurationValid(const std::set<Stream *> &streams,\n> +\t\t\t\t    const std::map<Stream *, StreamConfiguration> &conf) const\n> +{\n> +\t/* Test numbers of streams matches that of configurations. */\n\n\"Test that the numbers ...\"\n\ns/configurations/configuration/\n\n> +\tif (streams.size() != conf.size())\n> +\t\treturn false;\n> +\n> +\t/*\n> +\t * Test stream can be found in configuration and that the\n\ns/Test/Test that/\n\n> +\t * configuration is valid.\n> +\t */\n> +\tfor (Stream *stream : streams) {\n> +\t\tstd::map<Stream *, StreamConfiguration>::const_iterator itr =\n> +\t\t\tconf.find(stream);\n> +\n> +\t\tif (itr == conf.end())\n> +\t\t\treturn false;\n\nWe customarily name iterators it, not itr.\n\n> +\n> +\t\tconst StreamConfiguration *sconf = &itr->second;\n> +\t\tif (sconf->width == 0 || sconf->height == 0 ||\n> +\t\t    sconf->pixelFormat == 0 || sconf->bufferCount == 0)\n> +\t\t\treturn false;\n> +\t}\n> +\n> +\treturn true;\n> +}\n> diff --git a/test/camera/camera_test.h b/test/camera/camera_test.h\n> new file mode 100644\n> index 0000000000000000..48fb47a23fe8f49c\n> --- /dev/null\n> +++ b/test/camera/camera_test.h\n> @@ -0,0 +1,35 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * camera_test.h - libcamera camera test base class\n> + */\n> +#ifndef __LIBCAMERA_CAMERA_TEST_H__\n> +#define __LIBCAMERA_CAMERA_TEST_H__\n> +\n> +#include <libcamera/libcamera.h>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace libcamera;\n> +\n> +class CameraTest : public Test\n> +{\n> +public:\n> +\tCameraTest()\n> +\t\t: cm_(nullptr) {}\n> +\n> +protected:\n> +\tint init();\n> +\tvoid cleanup();\n> +\n> +\tbool configurationValid(const std::set<Stream *> &streams,\n> +\t\t\t\tconst std::map<Stream *, StreamConfiguration> &conf) const;\n> +\n> +\tstd::shared_ptr<Camera> camera_;\n> +\n> +private:\n> +\tCameraManager *cm_;\n> +};\n> +\n> +#endif /* __LIBCAMERA_CAMERA_TEST_H__ */\n> diff --git a/test/camera/configuration_default.cpp b/test/camera/configuration_default.cpp\n> new file mode 100644\n> index 0000000000000000..b488b977c890a6da\n> --- /dev/null\n> +++ b/test/camera/configuration_default.cpp\n> @@ -0,0 +1,68 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera Camera API tests\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include \"camera_test.h\"\n> +\n> +using namespace std;\n> +\n> +namespace {\n> +\n> +class ConfigurationDefault : public CameraTest\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tstd::map<Stream *, StreamConfiguration> conf;\n> +\n> +\t\t/*\n> +\t\t * Test that asking for default configuration for a valid\n> +\t\t * array of streams returns something valid.\n> +\t\t */\n> +\t\tstd::set<Stream *> streams = { *camera_->streams().begin() };\n> +\t\tconf = camera_->streamConfiguration(streams);\n> +\t\tif (conf.empty()) {\n> +\t\t\tcout << \"Retrieving configuration for valid streams\" << endl;\n\n\"Failed to retrieve\" ?\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!configurationValid(streams, conf)) {\n> +\t\t\tcout << \"Default configuration invalid\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Test that asking for configuration for an empty array of\n> +\t\t * streams returns an empty list of configurations.\n> +\t\t */\n> +\t\tstd::set<Stream *> streams_empty = {};\n> +\t\tconf = camera_->streamConfiguration(streams_empty);\n> +\t\tif (!conf.empty()) {\n> +\t\t\tcout << \"Retrieving configuration for empty streams\" << endl;\n\nSame here.\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Test that asking for configuration for an array of bad streams\n> +\t\t * returns an empty list of configurations.\n> +\t\t */\n> +\t\tStream *stream_bad = reinterpret_cast<Stream *>(0xdeadbeef);\n> +\t\tstd::set<Stream *> streams_bad = { stream_bad };\n> +\t\tconf = camera_->streamConfiguration(streams_bad);\n> +\t\tif (!conf.empty()) {\n> +\t\t\tcout << \"Retrieving configuration for bad streams\" << endl;\n\nAnd here.\n\nWith these small issues addressed,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +} /* namespace */\n> +\n> +TEST_REGISTER(ConfigurationDefault);\n> diff --git a/test/camera/meson.build b/test/camera/meson.build\n> new file mode 100644\n> index 0000000000000000..186ba211b9fde026\n> --- /dev/null\n> +++ b/test/camera/meson.build\n> @@ -0,0 +1,12 @@\n> +# Tests are listed in order of complexity.\n> +# They are not alphabetically sorted.\n> +camera_tests = [\n> +  [ 'configuration_default',  'configuration_default.cpp' ],\n> +]\n> +\n> +foreach t : camera_tests\n> +  exe = executable(t[0], [t[1], 'camera_test.cpp'],\n> +                   link_with : test_libraries,\n> +                   include_directories : test_includes_internal)\n> +  test(t[0], exe, suite: 'camera', is_parallel: false)\n> +endforeach\n> diff --git a/test/meson.build b/test/meson.build\n> index 5fb16fa6afb62f8d..71a96921697c0e9e 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -1,5 +1,6 @@\n>  subdir('libtest')\n>  \n> +subdir('camera')\n>  subdir('media_device')\n>  subdir('pipeline')\n>  subdir('v4l2_device')","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D601E600FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 Mar 2019 09:41:02 +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 64349255;\n\tMon, 11 Mar 2019 09:41:02 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1552293662;\n\tbh=J6fHEahd59vaMj0nNC1TPe0gvNheoI+6U8339fa6JTk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ox5oDeuBgp3wupXpAtM4P1QW+W+thijHcxAHCNCo4rt+BTOxQH0YG8U0z0Qq3n6TY\n\tjdxRwPlzYegXJDLL2ohIp99yDUA7sDFgu1d6q7SEUFT9im2lodsI+2bR+sAZJHkhEC\n\t87ISbiALk9qVyz5vtFMJ1JHkgNeo4Yd2jH3K9oL0=","Date":"Mon, 11 Mar 2019 10:40:56 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190311084056.GD4775@pendragon.ideasonboard.com>","References":"<20190311022232.4759-1-niklas.soderlund@ragnatech.se>\n\t<20190311022232.4759-2-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190311022232.4759-2-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 1/4] test: camera: Add read default\n\tconfiguration 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":"Mon, 11 Mar 2019 08:41:03 -0000"}}]