{"id":215,"url":"https://patchwork.libcamera.org/api/1.1/patches/215/?format=json","web_url":"https://patchwork.libcamera.org/patch/215/","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":"<20190112141436.1562-4-jacopo@jmondi.org>","date":"2019-01-12T14:14:36","name":"[libcamera-devel,v3,3/3] test: media_device: Add link handling test","commit_ref":"d833c1d39e75141f98ab88f9952f9b86a4243006","pull_url":null,"state":"accepted","archived":false,"hash":"03b5ee081c642f082ab38f6e2eb9e9de5b3f3987","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/215/mbox/","series":[{"id":73,"url":"https://patchwork.libcamera.org/api/1.1/series/73/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=73","date":"2019-01-12T14:14:33","name":"test: media_device: Add link handling test","version":3,"mbox":"https://patchwork.libcamera.org/series/73/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/215/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/215/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net\n\t[217.70.183.194])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2D29560C6A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 12 Jan 2019 15:14:37 +0100 (CET)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 7367A40004;\n\tSat, 12 Jan 2019 14:14:36 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 12 Jan 2019 15:14:36 +0100","Message-Id":"<20190112141436.1562-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190112141436.1562-1-jacopo@jmondi.org>","References":"<20190112141436.1562-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 3/3] test: media_device: Add link\n\thandling 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":"Sat, 12 Jan 2019 14:14:37 -0000"},"content":"Add a test unit that exercise link handling on the VIMC media graph.\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n test/media_device/media_device_link_test.cpp | 246 +++++++++++++++++++\n test/media_device/meson.build                |   1 +\n 2 files changed, 247 insertions(+)\n create mode 100644 test/media_device/media_device_link_test.cpp","diff":"diff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp\nnew file mode 100644\nindex 0000000..2297e33\n--- /dev/null\n+++ b/test/media_device/media_device_link_test.cpp\n@@ -0,0 +1,246 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * media_device_link_test.cpp - Tests link handling on VIMC media device\n+ */\n+#include <iostream>\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+using namespace std;\n+\n+/*\n+ * This link test requires a vimc device in order to exercise the\n+ * MediaObject link handling API on a graph with a predetermined topology.\n+ *\n+ * vimc is a Media Controller kernel driver that creates virtual devices.\n+ * From a userspace point of view they appear as normal media controller\n+ * devices, but are not backed by any particular piece of hardware. They can\n+ * thus be used for testing purpose without depending on a particular hardware\n+ * platform.\n+ *\n+ * If no vimc device is found (most likely because the vimc driver is not\n+ * loaded) the test is skipped.\n+ */\n+\n+class MediaDeviceLinkTest : public Test\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\tdev_->acquire();\n+\n+\t\tif (dev_->open()) {\n+\t\t\tcerr << \"Failed to open media device at \"\n+\t\t\t     << dev_->devnode() << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\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\t\tcerr << \"Failed to disable all links in the media graph\";\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Test if link can be consistently retrieved through the\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\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\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\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\tif (!link2) {\n+\t\t\tcerr << \"Unable to find link: \" << linkName\n+\t\t\t     << \" using lookup by entity\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link != link2) {\n+\t\t\tcerr << \"Link lookup by name and by entity don't match\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tlink2 = dev_->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+\t\t\t     << \" using lookup by pad\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link != link2) {\n+\t\t\tcerr << \"Link lookup by name and by pad don't match\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* After reset the link shall not be enabled. */\n+\t\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\t\tcerr << \"Link \" << linkName\n+\t\t\t     << \" should not be enabled after a device reset\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Enable the link and test if enabling was successful. */\n+\t\tif (link->setEnabled(true)) {\n+\t\t\tcerr << \"Failed to enable link: \" << linkName\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!(link->flags() & MEDIA_LNK_FL_ENABLED)) {\n+\t\t\tcerr << \"Link \" << linkName\n+\t\t\t     << \" was enabled but it is reported as disabled\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Disable the link and test if disabling was successful. */\n+\t\tif (link->setEnabled(false)) {\n+\t\t\tcerr << \"Failed to disable link: \" << linkName\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\t\tcerr << \"Link \" << linkName\n+\t\t\t     << \" was disabled but it is reported as enabled\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\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\tif (link) {\n+\t\t\tcerr << \"Link lookup for \" << linkName\n+\t\t\t     << \" succeeded but link does not exist\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\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\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\tif (!(link->flags() & MEDIA_LNK_FL_IMMUTABLE)) {\n+\t\t\tcerr << \"Link \" << linkName\n+\t\t\t     << \" should be 'IMMUTABLE'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Disabling an immutable link shall fail. */\n+\t\tif (!link->setEnabled(false)) {\n+\t\t\tcerr << \"Disabling immutable link \" << linkName\n+\t\t\t     << \" succeeded but should have failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Enable an disabled link, and verify it is disabled again\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\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\tif (link->setEnabled(true)) {\n+\t\t\tcerr << \"Failed to enable link: \" << linkName\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!(link->flags() & MEDIA_LNK_FL_ENABLED)) {\n+\t\t\tcerr << \"Link \" << linkName\n+\t\t\t     << \" was enabled but it is reported as disabled\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (dev_->disableLinks()) {\n+\t\t\tcerr << \"Failed to disable all links in the media graph\";\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\t\tcerr << \"All links in the media graph have been disabled\"\n+\t\t\t     << \" but link \" << linkName\n+\t\t\t     << \" is still reported as enabled\"  << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn 0;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t\tdev_->close();\n+\t\tdev_->release();\n+\t}\n+\n+private:\n+\tunique_ptr<DeviceEnumerator> enumerator;\n+\tMediaDevice *dev_;\n+};\n+\n+TEST_REGISTER(MediaDeviceLinkTest);\ndiff --git a/test/media_device/meson.build b/test/media_device/meson.build\nindex e4bedb7..d91a022 100644\n--- a/test/media_device/meson.build\n+++ b/test/media_device/meson.build\n@@ -1,5 +1,6 @@\n media_device_tests = [\n     ['media_device_print_test',         'media_device_print_test.cpp'],\n+    ['media_device_link_test',          'media_device_link_test.cpp'],\n ]\n \n foreach t : media_device_tests\n","prefixes":["libcamera-devel","v3","3/3"]}