{"id":208,"url":"https://patchwork.libcamera.org/api/1.1/patches/208/?format=json","web_url":"https://patchwork.libcamera.org/patch/208/","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":"<20190111132705.19329-4-jacopo@jmondi.org>","date":"2019-01-11T13:27:05","name":"[libcamera-devel,v2,3/3] test: media_device: Add link handling test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3c80e607e1e55fca075f7b01ede59cd1027004d6","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/208/mbox/","series":[{"id":69,"url":"https://patchwork.libcamera.org/api/1.1/series/69/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=69","date":"2019-01-11T13:27:02","name":"test: media_device: Add link handling test","version":2,"mbox":"https://patchwork.libcamera.org/series/69/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/208/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/208/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 439F960B34\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Jan 2019 14:27:10 +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 relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 8E1B91BF204;\n\tFri, 11 Jan 2019 13:27:08 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 11 Jan 2019 14:27:05 +0100","Message-Id":"<20190111132705.19329-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190111132705.19329-1-jacopo@jmondi.org>","References":"<20190111132705.19329-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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":"Fri, 11 Jan 2019 13:27:10 -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 | 188 +++++++++++++++++++\n test/media_device/meson.build                |   1 +\n 2 files changed, 189 insertions(+)\n create mode 100644 test/media_device/media_device_link_test.cpp\n\n--\n2.20.1","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..a335a1b\n--- /dev/null\n+++ b/test/media_device/media_device_link_test.cpp\n@@ -0,0 +1,188 @@\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 media devices\n+ */\n+#include <iostream>\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 test only runs on VIMC: exercising a known media graph makes possible\n+ * to make assumptions on the expected results.\n+ *\n+ * If the VIMC module is not loaded, the test is skipped.\n+ */\n+class MediaDeviceLinkTest : public Test\n+{\n+\tint init()\n+\t{\n+\t\tenumerator_ = DeviceEnumerator::create();\n+\t\tif (enumerator_->enumerate())\n+\t\t\treturn TestFail;\n+\n+\t\tDeviceMatch dm(\"vimc\");\n+\t\tdev_ = enumerator_->search(dm);\n+\t\tif (!dev_)\n+\t\t\treturn TestSkip;\n+\n+\t\tdev_->acquire();\n+\n+\t\tif (dev_->open())\n+\t\t\treturn TestFail;\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\t/* First of all reset all links in the media graph. */\n+\t\tint ret = dev_->disableLinks();\n+\t\tif (ret)\n+\t\t\treturn TestFail;\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\tMediaLink *link = dev_->link(\"Debayer A\", 1, \"Scaler\", 0);\n+\t\tif (!link) {\n+\t\t\tcerr << \"Unable to find link \\\"Debayer A\\\"[1] ->\"\n+\t\t\t     << \"\\\"Scaler\\\"[0]\" << endl\n+\t\t\t     << \"This link exists in VIMC media graph\"\n+\t\t\t     << 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 \\\"Debayer A\\\"[1] ->\"\n+\t\t\t     << \"\\\"Scaler\\\"[0]\" << endl\n+\t\t\t     << \"This link exists in VIMC media graph\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link != link2) {\n+\t\t\tcerr << \"The returned link does not match what expected\"\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 \\\"Debayer A\\\"[1] ->\"\n+\t\t\t     << \"\\\"Scaler\\\"[0]\" << endl\n+\t\t\t     << \"This link exists in VIMC media graph\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (link != link2) {\n+\t\t\tcerr << \"The returned link does not match what expected\"\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 \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\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\tret = link->setEnabled(true);\n+\t\tif (ret)\n+\t\t\treturn TestFail;\n+\n+\t\tif (!(link->flags() & MEDIA_LNK_FL_ENABLED)) {\n+\t\t\tcerr << \"Link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t\t     << \" should now be enabled\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Disable the link and test if disabling was successful. */\n+\t\tret = link->setEnabled(false);\n+\t\tif (ret)\n+\t\t\treturn TestFail;\n+\n+\t\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\t\tcerr << \"Link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t\t     << \" should now be disabled\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Try to get a non existing link. */\n+\t\tlink = dev_->link(\"Sensor A\", 1, \"Scaler\", 0);\n+\t\tif (link) {\n+\t\t\tcerr << \"Link \\\"Sensor A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t\t     << \" does not exist but something was returned\"\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\tlink = dev_->link(\"Sensor A\", 0, \"Raw Capture 0\", 0);\n+\t\tif (!link) {\n+\t\t\tcerr << \"Unable to find link \\\"Sensor A\\\"[0] -> \"\n+\t\t\t     << \"\\\"Raw Capture 0\\\"[0]\" << endl\n+\t\t\t     << \"This link exists in VIMC media graph\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (!(link->flags() & MEDIA_LNK_FL_IMMUTABLE)) {\n+\t\t\tcerr << \"Link \\\"Sensor A\\\"[0] -> \\\"Raw Capture 0\\\"[0]\"\n+\t\t\t     << \" should have been 'IMMUTABLE'\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Disabling an immutable link shall fail. */\n+\t\tret = link->setEnabled(false);\n+\t\tif (!ret) {\n+\t\t\tcerr << \"Link \\\"Sensor A\\\"[0] -> \\\"Raw Capture 0\\\"[0]\"\n+\t\t\t     << \" is 'IMMUTABLE', it shouldn't be disabled\"\n+\t\t\t     << 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+\n+\t\tdelete dev_;\n+\t\tdelete enumerator_;\n+\t}\n+\n+private:\n+\tDeviceEnumerator *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","v2","3/3"]}