{"id":1170,"url":"https://patchwork.libcamera.org/api/1.1/patches/1170/?format=json","web_url":"https://patchwork.libcamera.org/patch/1170/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190508151831.12274-6-niklas.soderlund@ragnatech.se>","date":"2019-05-08T15:18:25","name":"[libcamera-devel,v2,05/11] test: media_device: Create a common MediaDeviceTest base class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ef1f9d52335b410c1ba0feb8f5fd5842df0783c4","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1170/mbox/","series":[{"id":300,"url":"https://patchwork.libcamera.org/api/1.1/series/300/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=300","date":"2019-05-08T15:18:20","name":"libcamerea: Add support for exclusive access to cameras between processes","version":2,"mbox":"https://patchwork.libcamera.org/series/300/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1170/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1170/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5020360E6E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 May 2019 17:18:53 +0200 (CEST)","from localhost.localdomain (unknown [79.138.136.66])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 95197880-71a4-11e9-8fa2-005056917a89;\n\tWed, 08 May 2019 17:18:50 +0200 (CEST)"],"X-Halon-ID":"95197880-71a4-11e9-8fa2-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  8 May 2019 17:18:25 +0200","Message-Id":"<20190508151831.12274-6-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190508151831.12274-1-niklas.soderlund@ragnatech.se>","References":"<20190508151831.12274-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 05/11] test: media_device: Create a\n\tcommon MediaDeviceTest base class","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, 08 May 2019 15:18:53 -0000"},"content":"Before adding more tests which will act on the vimc pipeline break out a\ncommon base from media_device_link_test.cpp which already acts on vimc.\nThe new common base class will help reduce code duplication.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n test/media_device/media_device_link_test.cpp | 73 +++++---------------\n test/media_device/media_device_test.cpp      | 41 +++++++++++\n test/media_device/media_device_test.h        | 35 ++++++++++\n test/media_device/meson.build                |  2 +-\n 4 files changed, 96 insertions(+), 55 deletions(-)\n create mode 100644 test/media_device/media_device_test.cpp\n create mode 100644 test/media_device/media_device_test.h","diff":"diff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp\nindex 334bb44a6fc14371..26aedf0ea23ec709 100644\n--- a/test/media_device/media_device_link_test.cpp\n+++ b/test/media_device/media_device_link_test.cpp\n@@ -4,13 +4,10 @@\n  *\n  * media_device_link_test.cpp - Tests link handling on VIMC media device\n  */\n+\n #include <iostream>\n-#include <memory>\n \n-#include \"device_enumerator.h\"\n-#include \"media_device.h\"\n-\n-#include \"test.h\"\n+#include \"media_device_test.h\"\n \n using namespace libcamera;\n using namespace std;\n@@ -29,44 +26,21 @@ using namespace std;\n  * loaded) the test is skipped.\n  */\n \n-class MediaDeviceLinkTest : public Test\n+class MediaDeviceLinkTest : public MediaDeviceTest\n {\n-\tint init()\n-\t{\n-\t\tenumerator = unique_ptr<DeviceEnumerator>(DeviceEnumerator::create());\n-\t\tif (!enumerator) {\n-\t\t\tcerr << \"Failed to create device enumerator\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n-\t\tif (enumerator->enumerate()) {\n-\t\t\tcerr << \"Failed to enumerate media devices\" << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n-\t\tDeviceMatch dm(\"vimc\");\n-\t\tdev_ = enumerator->search(dm);\n-\t\tif (!dev_) {\n-\t\t\tcerr << \"No VIMC media device found: skip test\" << endl;\n-\t\t\treturn TestSkip;\n-\t\t}\n-\n-\t\tif (!dev_->acquire()) {\n-\t\t\tcerr << \"Unable to acquire media device \"\n-\t\t\t     << dev_->deviceNode() << endl;\n-\t\t\treturn TestSkip;\n-\t\t}\n-\n-\t\treturn 0;\n-\t}\n-\n \tint run()\n \t{\n+\t\tif (!media_->acquire()) {\n+\t\t\tcerr << \"Unable to acquire media device \"\n+\t\t\t     << media_->deviceNode() << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\t/*\n \t\t * First of all disable all links in the media graph to\n \t\t * ensure we start from a known state.\n \t\t */\n-\t\tif (dev_->disableLinks()) {\n+\t\tif (media_->disableLinks()) {\n \t\t\tcerr << \"Failed to disable all links in the media graph\";\n \t\t\treturn TestFail;\n \t\t}\n@@ -76,26 +50,26 @@ class MediaDeviceLinkTest : public Test\n \t\t * different methods the media device offers.\n \t\t */\n \t\tstring linkName(\"'Debayer A':[1] -> 'Scaler':[0]'\");\n-\t\tMediaLink *link = dev_->link(\"Debayer A\", 1, \"Scaler\", 0);\n+\t\tMediaLink *link = media_->link(\"Debayer A\", 1, \"Scaler\", 0);\n \t\tif (!link) {\n \t\t\tcerr << \"Unable to find link: \" << linkName\n \t\t\t     << \" using lookup by name\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tMediaEntity *source = dev_->getEntityByName(\"Debayer A\");\n+\t\tMediaEntity *source = media_->getEntityByName(\"Debayer A\");\n \t\tif (!source) {\n \t\t\tcerr << \"Unable to find entity: 'Debayer A'\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tMediaEntity *sink = dev_->getEntityByName(\"Scaler\");\n+\t\tMediaEntity *sink = media_->getEntityByName(\"Scaler\");\n \t\tif (!sink) {\n \t\t\tcerr << \"Unable to find entity: 'Scaler'\" << endl;\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tMediaLink *link2 = dev_->link(source, 1, sink, 0);\n+\t\tMediaLink *link2 = media_->link(source, 1, sink, 0);\n \t\tif (!link2) {\n \t\t\tcerr << \"Unable to find link: \" << linkName\n \t\t\t     << \" using lookup by entity\" << endl;\n@@ -108,7 +82,7 @@ class MediaDeviceLinkTest : public Test\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tlink2 = dev_->link(source->getPadByIndex(1),\n+\t\tlink2 = media_->link(source->getPadByIndex(1),\n \t\t\t\t   sink->getPadByIndex(0));\n \t\tif (!link2) {\n \t\t\tcerr << \"Unable to find link: \" << linkName\n@@ -160,7 +134,7 @@ class MediaDeviceLinkTest : public Test\n \n \t\t/* Try to get a non existing link. */\n \t\tlinkName = \"'Sensor A':[1] -> 'Scaler':[0]\";\n-\t\tlink = dev_->link(\"Sensor A\", 1, \"Scaler\", 0);\n+\t\tlink = media_->link(\"Sensor A\", 1, \"Scaler\", 0);\n \t\tif (link) {\n \t\t\tcerr << \"Link lookup for \" << linkName\n \t\t\t     << \" succeeded but link does not exist\"\n@@ -170,7 +144,7 @@ class MediaDeviceLinkTest : public Test\n \n \t\t/* Now get an immutable link and try to disable it. */\n \t\tlinkName = \"'Sensor A':[0] -> 'Raw Capture 0':[0]\";\n-\t\tlink = dev_->link(\"Sensor A\", 0, \"Raw Capture 0\", 0);\n+\t\tlink = media_->link(\"Sensor A\", 0, \"Raw Capture 0\", 0);\n \t\tif (!link) {\n \t\t\tcerr << \"Unable to find link: \" << linkName\n \t\t\t     << \" using lookup by name\" << endl;\n@@ -195,7 +169,7 @@ class MediaDeviceLinkTest : public Test\n \t\t * after disabling all links in the media graph.\n \t\t */\n \t\tlinkName = \"'Debayer B':[1] -> 'Scaler':[0]'\";\n-\t\tlink = dev_->link(\"Debayer B\", 1, \"Scaler\", 0);\n+\t\tlink = media_->link(\"Debayer B\", 1, \"Scaler\", 0);\n \t\tif (!link) {\n \t\t\tcerr << \"Unable to find link: \" << linkName\n \t\t\t     << \" using lookup by name\" << endl;\n@@ -215,7 +189,7 @@ class MediaDeviceLinkTest : public Test\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (dev_->disableLinks()) {\n+\t\tif (media_->disableLinks()) {\n \t\t\tcerr << \"Failed to disable all links in the media graph\";\n \t\t\treturn TestFail;\n \t\t}\n@@ -229,15 +203,6 @@ class MediaDeviceLinkTest : public Test\n \n \t\treturn 0;\n \t}\n-\n-\tvoid cleanup()\n-\t{\n-\t\tdev_->release();\n-\t}\n-\n-private:\n-\tunique_ptr<DeviceEnumerator> enumerator;\n-\tshared_ptr<MediaDevice> dev_;\n };\n \n TEST_REGISTER(MediaDeviceLinkTest);\ndiff --git a/test/media_device/media_device_test.cpp b/test/media_device/media_device_test.cpp\nnew file mode 100644\nindex 0000000000000000..710613eeb80b6de1\n--- /dev/null\n+++ b/test/media_device/media_device_test.cpp\n@@ -0,0 +1,41 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * libcamera MediaDevice API tests\n+ */\n+\n+#include <iostream>\n+\n+#include \"media_device_test.h\"\n+\n+using namespace libcamera;\n+using namespace std;\n+\n+int MediaDeviceTest::init()\n+{\n+\tenumerator_ = unique_ptr<DeviceEnumerator>(DeviceEnumerator::create());\n+\tif (!enumerator_) {\n+\t\tcerr << \"Failed to create device enumerator\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (enumerator_->enumerate()) {\n+\t\tcerr << \"Failed to enumerate media devices\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tDeviceMatch dm(\"vimc\");\n+\tmedia_ = enumerator_->search(dm);\n+\tif (!media_) {\n+\t\tcerr << \"No VIMC media device found: skip test\" << endl;\n+\t\treturn TestSkip;\n+\t}\n+\n+\treturn TestPass;\n+}\n+\n+void MediaDeviceTest::cleanup()\n+{\n+\tmedia_->release();\n+}\ndiff --git a/test/media_device/media_device_test.h b/test/media_device/media_device_test.h\nnew file mode 100644\nindex 0000000000000000..af5c89f4fff2f63e\n--- /dev/null\n+++ b/test/media_device/media_device_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+ * media_device_test.h - libcamera media devie base class\n+ */\n+#ifndef __LIBCAMERA_MEDIADEVICE_TEST_H__\n+#define __LIBCAMERA_MEDIADEVICE_TEST_H__\n+\n+#include <memory>\n+\n+#include \"device_enumerator.h\"\n+#include \"media_device.h\"\n+\n+#include \"test.h\"\n+\n+using namespace libcamera;\n+\n+class MediaDeviceTest : public Test\n+{\n+public:\n+\tMediaDeviceTest()\n+\t\t: media_(nullptr), enumerator_(nullptr) {}\n+\n+protected:\n+\tint init();\n+\tvoid cleanup();\n+\n+\tstd::shared_ptr<MediaDevice> media_;\n+\n+private:\n+\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n+};\n+\n+#endif /* __LIBCAMERA_MEDIADEVICE_TEST_H__ */\ndiff --git a/test/media_device/meson.build b/test/media_device/meson.build\nindex d91a022fab190abf..1005685409d99aa7 100644\n--- a/test/media_device/meson.build\n+++ b/test/media_device/meson.build\n@@ -4,7 +4,7 @@ media_device_tests = [\n ]\n \n foreach t : media_device_tests\n-    exe = executable(t[0], t[1],\n+    exe = executable(t[0], [t[1], 'media_device_test.cpp'],\n                      link_with : test_libraries,\n                      include_directories : test_includes_internal)\n \n","prefixes":["libcamera-devel","v2","05/11"]}