{"id":243,"url":"https://patchwork.libcamera.org/api/patches/243/?format=json","web_url":"https://patchwork.libcamera.org/patch/243/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190115160212.30100-3-kieran.bingham@ideasonboard.com>","date":"2019-01-15T16:02:12","name":"[libcamera-devel,v2,2/2] test: v4l2_device: Add test suite and initial test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6233aa9444b7705f6875860316b7ad0fc9903d24","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/?format=json","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/243/mbox/","series":[{"id":82,"url":"https://patchwork.libcamera.org/api/series/82/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=82","date":"2019-01-15T16:02:10","name":"V4L2Device: Add basic V4L2 support class","version":2,"mbox":"https://patchwork.libcamera.org/series/82/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/243/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/243/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@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 D471360C86\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Jan 2019 17:02:16 +0100 (CET)","from localhost.localdomain\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E63459B;\n\tTue, 15 Jan 2019 17:02:16 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1547568136;\n\tbh=CJ93eiZh/iCm5BWAn1wDJ1LR1lzR7Ubm/007oRBS9lQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=PszmGXhURRVd3ttmeJ9l9iMifOoWlEL9ynFnlz/P0gN20yUeA+UbEo/KLiE/gKyRw\n\tkzdjnrbPSM6w+HcZATXcpBMjbOuD1fMvmSASyV2L/pRBAxQ8Apsty3mSbUYbyForDd\n\tSl2qkvAdQU/KyihgzyR2UElCu6slp3ScTnIC7CTM=","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Date":"Tue, 15 Jan 2019 16:02:12 +0000","Message-Id":"<20190115160212.30100-3-kieran.bingham@ideasonboard.com>","X-Mailer":"git-send-email 2.17.1","In-Reply-To":"<20190115160212.30100-1-kieran.bingham@ideasonboard.com>","References":"<20190115160212.30100-1-kieran.bingham@ideasonboard.com>","Subject":"[libcamera-devel] [PATCH v2 2/2] test: v4l2_device: Add test suite\n\tand 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":"Tue, 15 Jan 2019 16:02:17 -0000"},"content":"Provide a base class to construct a v4l2_device object for further tests\nand an initial test which validates the FD handle can not be leaked.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\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","diff":"diff --git a/test/meson.build b/test/meson.build\nindex 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'],\ndiff --git a/test/v4l2_device/double_open.cpp b/test/v4l2_device/double_open.cpp\nnew file mode 100644\nindex 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);\ndiff --git a/test/v4l2_device/meson.build b/test/v4l2_device/meson.build\nnew file mode 100644\nindex 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\ndiff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\nnew file mode 100644\nindex 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+};\ndiff --git a/test/v4l2_device/v4l2_device_test.h b/test/v4l2_device/v4l2_device_test.h\nnew file mode 100644\nindex 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","prefixes":["libcamera-devel","v2","2/2"]}