[{"id":261,"web_url":"https://patchwork.libcamera.org/comment/261/","msgid":"<7895974.NkzPZPFg11@avalon>","date":"2019-01-08T18:22:15","subject":"Re: [libcamera-devel] [PATCH v2 4/4] test: MediaDevice: Add link\n\texercise test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tuesday, 8 January 2019 19:04:07 EET Jacopo Mondi wrote:\n> Add test function to exercise the link handling abilities of the media\n> device.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n> v1->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> diff --git a/test/media_device/media_device_test.cpp\n> b/test/media_device/media_device_test.cpp index 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\nEspecially given how we skip the test if we have a non-vimc device, I thnk \nthis should really be part of a separate test class.\n\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\n> is\n> + * skipped.\n> + */\n> +int MediaDeviceTest::exerciseLinks(MediaDevice &media)\n> +{\n> +\tif (media.driver() != \"vimc\")\n> +\t\treturn TestSkip;\n\nThis check should be moved to the init() function of the test class.\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\n> devnode)\n> \n>  \t/* Run tests in sequence. */\n>  \tprintMediaGraph(dev, cerr);\n> +\n> +\tret = exerciseLinks(dev);\n> +\n\nYou should iterate over all the media devices present in the system and pick \nthe first vimc device, as it may not be /dev/media0. The device enumerator \nshould provide you with the media devices (and this would also serve as a \ndevice enumerator test :-)).\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;","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6849760B2E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jan 2019 19:21:07 +0100 (CET)","from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B1DD8586;\n\tTue,  8 Jan 2019 19:21:06 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546971667;\n\tbh=K/ME06YU3mTzZtZ9FtQRTRz0MK8IW2igN2XdgSjjn2g=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=X89qbyteK7K3VLPWs+qT2YQu6Wnb9P0bqopB7F3jtiIQ4/n+IDUCagU3IC2yxNmIb\n\tTODbZkiSSSqGK2hSLdISxCEw2PnQV78gRyKkr40DnfhW9XAKqY9R9SO1vR7CpWfY/i\n\t5KWHac2/WNLsrBdh6P7xLtbRuQhN/WA6Bcu42lIU=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 08 Jan 2019 20:22:15 +0200","Message-ID":"<7895974.NkzPZPFg11@avalon>","Organization":"Ideas on Board Oy","In-Reply-To":"<20190108170407.4770-5-jacopo@jmondi.org>","References":"<20190108170407.4770-1-jacopo@jmondi.org>\n\t<20190108170407.4770-5-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"7Bit","Content-Type":"text/plain; charset=\"us-ascii\"","Subject":"Re: [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 18:21:07 -0000"}}]