[{"id":366,"web_url":"https://patchwork.libcamera.org/comment/366/","msgid":"<20190116150316.GD6484@bigcity.dyn.berto.se>","date":"2019-01-16T15:03:16","subject":"Re: [libcamera-devel] [PATCH v3 3/3] test: v4l2_device: Add test\n\tsuite and initial test","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nThanks for your work.\n\nOn 2019-01-15 23:19:09 +0000, Kieran Bingham wrote:\n> Provide a base class to construct a v4l2_device object for further tests\n> and an initial test which validates the FD handle can not be leaked.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  test/meson.build                      |  1 +\n>  test/v4l2_device/double_open.cpp      | 38 +++++++++++++++++++++++\n>  test/v4l2_device/meson.build          | 12 ++++++++\n>  test/v4l2_device/v4l2_device_test.cpp | 43 +++++++++++++++++++++++++++\n>  test/v4l2_device/v4l2_device_test.h   | 27 +++++++++++++++++\n>  5 files changed, 121 insertions(+)\n>  create mode 100644 test/v4l2_device/double_open.cpp\n>  create mode 100644 test/v4l2_device/meson.build\n>  create mode 100644 test/v4l2_device/v4l2_device_test.cpp\n>  create mode 100644 test/v4l2_device/v4l2_device_test.h\n> \n> diff --git a/test/meson.build b/test/meson.build\n> index 32152888a55e..fb6b115eb2ab 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -1,6 +1,7 @@\n>  subdir('libtest')\n>  \n>  subdir('media_device')\n> +subdir('v4l2_device')\n>  \n>  public_tests = [\n>      ['event',           'event.cpp'],\n> diff --git a/test/v4l2_device/double_open.cpp b/test/v4l2_device/double_open.cpp\n> new file mode 100644\n> index 000000000000..ca2b201454a4\n> --- /dev/null\n> +++ b/test/v4l2_device/double_open.cpp\n> @@ -0,0 +1,38 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 API tests\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include \"v4l2_device_test.h\"\n> +\n> +namespace {\n> +\n> +class DoubleOpen : public V4L2DeviceTest\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tint ret;\n> +\n> +\t\t/*\n> +\t\t * Expect failure: The device has already been opened by the\n> +\t\t * V4L2DeviceTest base class\n> +\t\t */\n> +\t\tret = dev_->open();\n> +\t\tif (!ret) {\n> +\t\t\tstd::cout << \"Double open erroneously succeeded\" << std::endl;\n> +\t\t\tdev_->close();\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +} /* namespace */\n> +\n> +TEST_REGISTER(DoubleOpen);\n> diff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build\n> new file mode 100644\n> index 000000000000..41675a303498\n> --- /dev/null\n> +++ b/test/v4l2_device/meson.build\n> @@ -0,0 +1,12 @@\n> +# Tests are listed in order of complexity.\n> +# They are not alphabetically sorted.\n> +v4l2_device_tests = [\n> +  [ 'double_open',        'double_open.cpp' ],\n> +]\n> +\n> +foreach t : v4l2_device_tests\n> +  exe = executable(t[0], [t[1], 'v4l2_device_test.cpp'],\n> +\t\t   link_with : test_libraries,\n> +\t\t   include_directories : test_includes_internal)\n> +  test(t[0], exe, suite: 'v4l2_device', is_parallel: false)\n> +endforeach\n> diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\n> new file mode 100644\n> index 000000000000..362553712caa\n> --- /dev/null\n> +++ b/test/v4l2_device/v4l2_device_test.cpp\n> @@ -0,0 +1,43 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 API tests\n> + */\n> +\n> +#include <iostream>\n> +#include <sys/stat.h>\n> +\n> +#include \"v4l2_device_test.h\"\n> +\n> +using namespace libcamera;\n> +\n> +bool exists(const std::string &path)\n> +{\n> +\tstruct stat sb;\n> +\n> +\tif (stat(path.c_str(), &sb) == 0)\n> +\t\treturn true;\n> +\n> +\treturn false;\n> +}\n> +\n> +int V4L2DeviceTest::init()\n> +{\n> +\tconst std::string device(\"/dev/video0\");\n> +\n> +\t/* Validate the device node exists. */\n> +\tif (!exists(device)) {\n> +\t\tstd::cout << \"No video device available\" << std::endl;\n> +\t\treturn TestSkip;\n> +\t}\n> +\n> +\tdev_ = new V4L2Device(device);\n> +\n> +\treturn dev_->open();\n> +}\n> +\n> +void V4L2DeviceTest::cleanup()\n> +{\n> +\tdelete dev_;\n> +};\n> diff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h\n> new file mode 100644\n> index 000000000000..405cb7d6f404\n> --- /dev/null\n> +++ b/test/v4l2_device/v4l2_device_test.h\n> @@ -0,0 +1,27 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2018, Google Inc.\n> + *\n> + * vl42device_test.h - libcamera v4l2device test base class\n> + */\n> +#ifndef __LIBCAMERA_V4L2_DEVICE_TEST_H_\n> +#define __LIBCAMERA_V4L2_DEVICE_TEST_H_\n> +\n> +#include \"test.h\"\n> +#include \"v4l2_device.h\"\n> +\n> +using namespace libcamera;\n> +\n> +class V4L2DeviceTest : public Test\n> +{\n> +public:\n> +\tV4L2DeviceTest() : dev_(nullptr) { };\n> +\n> +protected:\n> +\tint init();\n> +\tvoid cleanup();\n> +\n> +\tV4L2Device *dev_;\n> +};\n> +\n> +#endif /* __LIBCAMERA_V4L2_DEVICE_TEST_H_ */\n> -- \n> 2.17.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E3FB460B2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 16 Jan 2019 16:03:18 +0100 (CET)","by mail-lf1-x142.google.com with SMTP id y14so5100608lfg.13\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 16 Jan 2019 07:03:18 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tc5-v6sm1063590lja.62.2019.01.16.07.03.17\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 16 Jan 2019 07:03:17 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=y5Jy2cAeEZ639U6KXGp4ReQ1FWQCjVLgf5siRL/AmHc=;\n\tb=K5Mle8KM5HBFlWJ313jkGjzWLZN4ujemqBrBeNULVXBJHVClH/x91KyrYKbSoVsWnv\n\t/RzpWbJ9TCLjiIiCny6KyCeT7PePfolgYj/at7JF23zceJhOd3KSdfZCs5Ac+4T7gLZb\n\tHGNsQIyiMEEkfn5GuSd368xsVQ6sA1s19vhp9BAEquzpNzxT7ptqZmVb8BSYkaCSvOv8\n\t6mTV0PUZ9iWE4B/Mv5X4E/uXOf4U67P9oA5J6aMLsaEzinmHhqXTaKTfc4ORCLA3Vejq\n\t+LfFjlEmWPhXl5g648+WL9LLrhSJxAVE/yCtI4qgCsQmVe+TD5/lX2rw2vah0HvX3P7s\n\tflow==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=y5Jy2cAeEZ639U6KXGp4ReQ1FWQCjVLgf5siRL/AmHc=;\n\tb=lW6zzNFEE+qLXXVL+NvpKFzrn0K7p5T6nQZyBIDT+fHlMiIlav+ewl630oj/zz8Jy/\n\tBGal68qhpycH0Mebp42m5QhTmaLYnDNQSyg6EVaZ8sQBNE8RoyNfzrRrKiZpTOCtz34z\n\tQyjxZnwdSWu3/bUbDygy0QuSpJy9EgzAhgwT0ciFeluolydeTBKqUPs/84Kr7RuXklwx\n\tiDff1xMs60GvG+KPggyut7gwng9Kjt1Q1CNX8zITYQzxvVqx4JKBqD61Ne9d/hBTfATq\n\tV7lM0V1ZmJBTRDfkEn04KyWjr222KltsGCodkq3a1j+63HAvnRMGW5APjFjphMBQDlHc\n\t1WQA==","X-Gm-Message-State":"AJcUukf8KrHW4imtOce+/UyFWdC+EkcCDfrz8yeYMZrpwcPBOQhEQKba\n\tjGS5/lLzz9gbLHjPeQSq82L3TgJUfmg=","X-Google-Smtp-Source":"ALg8bN7hnR65xhEhcDyqjdnVsh9jYjs0NUeoSe8HiLaWqRYt/ydbxPtTploIuLRZov3izbjIXTN0Lw==","X-Received":"by 2002:a19:59c2:: with SMTP id\n\tn185mr6934826lfb.118.1547650998115; \n\tWed, 16 Jan 2019 07:03:18 -0800 (PST)","Date":"Wed, 16 Jan 2019 16:03:16 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190116150316.GD6484@bigcity.dyn.berto.se>","References":"<20190115231909.19893-1-kieran.bingham@ideasonboard.com>\n\t<20190115231909.19893-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190115231909.19893-4-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 3/3] test: v4l2_device: Add test\n\tsuite and initial 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":"Wed, 16 Jan 2019 15:03:19 -0000"}}]