{"id":185,"url":"https://patchwork.libcamera.org/api/1.1/patches/185/?format=json","web_url":"https://patchwork.libcamera.org/patch/185/","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":"<20190108170407.4770-5-jacopo@jmondi.org>","date":"2019-01-08T17:04:07","name":"[libcamera-devel,v2,4/4] test: MediaDevice: Add link exercise test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"20da624b8534e41cccdca0fe70d5d48512a527bb","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/185/mbox/","series":[{"id":61,"url":"https://patchwork.libcamera.org/api/1.1/series/61/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=61","date":"2019-01-08T17:04:03","name":"libcamera: media device: Add link handling","version":2,"mbox":"https://patchwork.libcamera.org/series/61/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/185/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/185/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E7CA660B3B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 18:04: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 relay12.mail.gandi.net (Postfix) with ESMTPSA id 8DB8520000F;\n\tTue,  8 Jan 2019 17:04:10 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Jan 2019 18:04:07 +0100","Message-Id":"<20190108170407.4770-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190108170407.4770-1-jacopo@jmondi.org>","References":"<20190108170407.4770-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 4/4] test: MediaDevice: Add link\n\texercise 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, 08 Jan 2019 17:04:11 -0000"},"content":"Add test function to exercise the link handling abilities of the media\ndevice.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\nv1->v2:\n- Make the link handling test work only on vimc as operating on a known\n  graph makes it possible to identify unexpected results.\n\n test/media_device/media_device_test.cpp | 147 +++++++++++++++++++++++-\n 1 file changed, 143 insertions(+), 4 deletions(-)\n\n--\n2.20.1","diff":"diff --git a/test/media_device/media_device_test.cpp b/test/media_device/media_device_test.cpp\nindex c482b2e..2b2f5cd 100644\n--- a/test/media_device/media_device_test.cpp\n+++ b/test/media_device/media_device_test.cpp\n@@ -42,8 +42,145 @@ private:\n \tvoid printMediaGraph(const MediaDevice &media, ostream &os);\n \tvoid printLinkFlags(const MediaLink *link, ostream &os);\n \tvoid printNode(const MediaPad *pad, ostream &os);\n+\n+\tint exerciseLinks(MediaDevice &media);\n };\n\n+/*\n+ * Exercise the link handling interface.\n+ *\n+ * Try to get existing and non-existing links, and try to enable\n+ * disable links.\n+ *\n+ * WARNING: this test only runs on VIMC, as a known media graph allows\n+ * the test to exercise known links and verify the result of operations\n+ * known to fail or succeed. If the 'vimc' driver is not loaded, the test is\n+ * skipped.\n+ */\n+int MediaDeviceTest::exerciseLinks(MediaDevice &media)\n+{\n+\tif (media.driver() != \"vimc\")\n+\t\treturn TestSkip;\n+\n+\t/* First of all reset all links in the media graph. */\n+\tint ret = media.resetLinks();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * Test if link can be consistently retrieved through the different\n+\t * methods the media device offers.\n+\t */\n+\tMediaLink *link = media.link(\"Debayer A\", 1, \"Scaler\", 0);\n+\tif (!link) {\n+\t\tcerr << \"Unable to find link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << endl << \"This link exists in VIMC media graph\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tMediaEntity *source = media.getEntityByName(\"Debayer A\");\n+\tif (!source) {\n+\t\tcerr << \"Unable to find entity \\\"Debayer A\\\"\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tMediaEntity *sink = media.getEntityByName(\"Scaler\");\n+\tif (!sink) {\n+\t\tcerr << \"Unable to find entity \\\"Scaler\\\"\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tMediaLink *link2 = media.link(source, 1, sink, 0);\n+\tif (!link2) {\n+\t\tcerr << \"Unable to find link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << endl << \"This link exists in VIMC media graph\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (link != link2) {\n+\t\tcerr << \"The returned link does not match what was expected\"\n+\t\t     << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tlink2 = media.link(source->getPadByIndex(1), sink->getPadByIndex(0));\n+\tif (!link2) {\n+\t\tcerr << \"Unable to find link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << endl << \"This link exists in VIMC media graph\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (link != link2) {\n+\t\tcerr << \"The returned link does not match what was expected\"\n+\t\t     << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* After reset the link shall not be enabled. */\n+\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\tcerr << \"Link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << \" should not be enabled after a media device reset\"\n+\t\t     << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Enable the link and test if enabling was successful. */\n+\tret = link->setEnable(true);\n+\tif (ret)\n+\t\treturn TestFail;\n+\n+\tif (!(link->flags() & MEDIA_LNK_FL_ENABLED)) {\n+\t\tcerr << \"Link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << \" should now be enabled\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Disable the link and test if disabling was successful. */\n+\tret = link->setEnable(false);\n+\tif (ret)\n+\t\treturn TestFail;\n+\n+\tif (link->flags() & MEDIA_LNK_FL_ENABLED) {\n+\t\tcerr << \"Link \\\"Debayer A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << \" should now be disabled\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Try to get a non existing link. */\n+\tlink = media.link(\"Sensor A\", 1, \"Scaler\", 0);\n+\tif (link) {\n+\t\tcerr << \"Link \\\"Sensor A\\\"[1] -> \\\"Scaler\\\"[0]\"\n+\t\t     << \" does not exist but something was returned\"\n+\t\t     << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Now get an immutable link and try to disable it. */\n+\tlink = media.link(\"Sensor A\", 0, \"Raw Capture 0\", 0);\n+\tif (!link) {\n+\t\tcerr << \"Unable to find link \\\"Sensor A\\\"[0] -> \"\n+\t\t     << \"\\\"Raw Capture 0\\\"[0]\"\n+\t\t     << endl << \"This link exists in VIMC media graph\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (!(link->flags() & MEDIA_LNK_FL_IMMUTABLE)) {\n+\t\tcerr << \"Link \\\"Sensor A\\\"[0] -> \\\"Raw Capture 0\\\"[0]\"\n+\t\t     << \" should have been 'IMMUTABLE'\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Disabling an immutable link shall fail. */\n+\tret = link->setEnable(false);\n+\tif (!ret) {\n+\t\tcerr << \"Link \\\"Sensor A\\\"[0] -> \\\"Raw Capture 0\\\"[0]\"\n+\t\t     << \" is 'IMMUTABLE', it shouldn't be disabled\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\treturn 0;\n+}\n+\n void MediaDeviceTest::printNode(const MediaPad *pad, ostream &os)\n {\n \tconst MediaEntity *entity = pad->entity();\n@@ -136,11 +273,14 @@ int MediaDeviceTest::testMediaDevice(const string devnode)\n\n \t/* Run tests in sequence. */\n \tprintMediaGraph(dev, cerr);\n+\n+\tret = exerciseLinks(dev);\n+\n \t/* TODO: add more tests here. */\n\n \tdev.close();\n\n-\treturn 0;\n+\treturn ret;\n }\n\n /* Run tests on all media devices. */\n@@ -149,7 +289,7 @@ int MediaDeviceTest::run()\n {\n \tconst string devnode(\"/dev/media\");\n \tunsigned int i;\n-\tint ret = 77; /* skip test exit code */\n+\tint ret = TestSkip;\n\n \t/*\n \t * Run the test sequence on all media device found in the\n@@ -163,9 +303,8 @@ int MediaDeviceTest::run()\n \t\t\tcontinue;\n\n \t\tret = testMediaDevice(mediadev);\n-\t\tif (ret)\n+\t\tif (ret && ret != TestSkip)\n \t\t\treturn ret;\n-\n \t}\n\n \treturn ret;\n","prefixes":["libcamera-devel","v2","4/4"]}