[{"id":2350,"web_url":"https://patchwork.libcamera.org/comment/2350/","msgid":"<20190808212637.GG6055@pendragon.ideasonboard.com>","date":"2019-08-08T21:26:37","subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Thu, Aug 08, 2019 at 04:12:19PM +0100, Kieran Bingham wrote:\n> The V4L2M2MDevice requires two pipelines to be configured. This makes it unsuitable\n> to reuse the existing V4L2DeviceTest test library in it's current form.\n\ns/it's/its/\n\nCommit messages should wrap at 72 columns.\n\n> Implement a full test to run the two M2M pipelines through VIM2M.\n\nLovely, another driver for our test suite :-)\n\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  test/v4l2_videodevice/meson.build        |   1 +\n>  test/v4l2_videodevice/v4l2_m2mdevice.cpp | 210 +++++++++++++++++++++++\n>  2 files changed, 211 insertions(+)\n>  create mode 100644 test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> \n> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n> index 76be5e142bb6..ad41898b5f8b 100644\n> --- a/test/v4l2_videodevice/meson.build\n> +++ b/test/v4l2_videodevice/meson.build\n> @@ -7,6 +7,7 @@ v4l2_videodevice_tests = [\n>      [ 'stream_on_off',      'stream_on_off.cpp' ],\n>      [ 'capture_async',      'capture_async.cpp' ],\n>      [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n> +    [ 'v4l2_m2mdevice',     'v4l2_m2mdevice.cpp' ],\n>  ]\n>  \n>  foreach t : v4l2_videodevice_tests\n> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> new file mode 100644\n> index 000000000000..7a730f695ab7\n> --- /dev/null\n> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> @@ -0,0 +1,210 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 API tests\n\nCopy & paste ?\n\n> + */\n> +\n> +#include <libcamera/buffer.h>\n> +#include <libcamera/camera_manager.h>\n> +#include <libcamera/event_dispatcher.h>\n> +#include <libcamera/timer.h>\n> +\n> +#include <iostream>\n> +#include <memory>\n> +\n> +#include \"device_enumerator.h\"\n> +#include \"media_device.h\"\n> +#include \"v4l2_videodevice.h\"\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class V4L2M2MDeviceTest : public Test\n> +{\n> +public:\n> +\tV4L2M2MDeviceTest()\n> +\t\t: vim2m_(nullptr), outputFrames_(0), captureFrames_(0)\n> +\t{\n> +\t}\n> +\n> +\tvoid outputBufferComplete(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received output buffer \" << buffer->index()\n> +\t\t\t  << std::endl;\n\nMy preference goes with using the std:: prefix explicitly like here, in\nwhich case you should use it everywhere and drop the using namespace std\nstatement. The alternative is to remove it everywhere.\n\n> +\n> +\t\toutputFrames_++;\n> +\n> +\t\t/* Requeue the buffer for further use. */\n> +\t\tvim2m_->output()->queueBuffer(buffer);\n> +\t}\n> +\n> +\tvoid receiveCaptureBuffer(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received capture buffer \" << buffer->index()\n> +\t\t\t  << std::endl;\n> +\n> +\t\tcaptureFrames_++;\n> +\n> +\t\t/* Requeue the buffer for further use. */\n> +\t\tvim2m_->capture()->queueBuffer(buffer);\n> +\t}\n> +\n> +protected:\n> +\tint init()\n> +\t{\n> +\t\tenumerator_ = 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(\"vim2m\");\n> +\t\tdm.add(\"vim2m-source\");\n> +\t\tdm.add(\"vim2m-sink\");\n> +\n> +\t\tmedia_ = enumerator_->search(dm);\n> +\t\tif (!media_) {\n> +\t\t\tcerr << \"Failed to match device\" << endl;\n\nMaybe \"No vim2m device found\" ?\n\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n> +\t\tMediaEntity *entity = media_->getEntityByName(\"vim2m-source\");\n> +\t\tif (!entity) {\n> +\t\t\tcerr << \"Failed to get device entity\" << endl;\n\nThis can't happen due to the dm.add().\n\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n\nI would move the rest of the code to the run() function as it tests the\nV4L2M2MDevice API.\n\n> +\t\tvim2m_ = new V4L2M2MDevice(entity->deviceNode());\n> +\t\tif (vim2m_->status())\n\nYou should add a message here (and below). It's difficult to debug test\nfailures when no message is printed.\n\n> +\t\t\treturn TestFail;\n> +\n> +\t\tV4L2DeviceFormat format = {};\n> +\t\tif (vim2m_->capture()->getFormat(&format))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tformat.size.width = 640;\n> +\t\tformat.size.height = 480;\n> +\n> +\t\tif (vim2m_->capture()->setFormat(&format))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (vim2m_->output()->setFormat(&format))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tcerr << \"Initialised M2M ...\" << endl;\n\nI'd drop this line.\n\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run()\n> +\t{\n> +\t\tconst unsigned int bufferCount = 8;\n\ns/const/constexpr/\n\nWould 4 buffers be enough ?\n\n> +\n> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n> +\t\tTimer timeout;\n> +\t\tint ret;\n> +\n> +\t\tcapturePool_.createBuffers(bufferCount);\n> +\t\toutputPool_.createBuffers(bufferCount);\n> +\n> +\t\tret = vim2m_->capture()->exportBuffers(&capturePool_);\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to export Capture Buffers\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = vim2m_->output()->exportBuffers(&outputPool_);\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to export Output Buffers\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nI would store the capture and output devices to local variables to\nshorten the lines.\n\n> +\n> +\t\tvim2m_->capture()->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);\n> +\t\tvim2m_->output()->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);\n> +\n> +\t\t/* We can't \"queueAllBuffers()\" on an output device, so we do it manually */\n> +\t\tstd::vector<std::unique_ptr<Buffer>> outputBuffers;\n> +\t\tfor (unsigned int i = 0; i < outputPool_.count(); ++i) {\n> +\t\t\tBuffer *buffer = new Buffer(i);\n> +\t\t\toutputBuffers.emplace_back(buffer);\n> +\t\t\tret = vim2m_->output()->queueBuffer(buffer);\n> +\t\t\tif (ret)\n> +\t\t\t\treturn {};\n> +\t\t}\n> +\n> +\t\tstd::vector<std::unique_ptr<Buffer>> captureBuffers;\n> +\t\tcaptureBuffers = vim2m_->capture()->queueAllBuffers();\n> +\t\tif (captureBuffers.empty()) {\n> +\t\t\tcerr << \"Failed to queue all Capture Buffers\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nEven if it makes little difference in practice, I would queue the\nbuffers on the capture side first, \n\n> +\n> +\t\tret = vim2m_->output()->streamOn();\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to streamOn output\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = vim2m_->capture()->streamOn();\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to streamOn capture\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\ttimeout.start(10000);\n> +\t\twhile (timeout.isRunning()) {\n> +\t\t\tdispatcher->processEvents();\n> +\t\t\tif (captureFrames_ > 30)\n> +\t\t\t\tbreak;\n\nHow long does it take in practice to capture 30 frames ? Can we reduce\nthe timeout ?\n\n> +\t\t}\n> +\n> +\t\tif (captureFrames_ < 1) {\n> +\t\t\tstd::cout << \"Failed to capture any frames within timeout.\" << std::endl;\n\ns/timeout\\./timeout/\nLine wrap.\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (captureFrames_ < 30) {\n> +\t\t\tstd::cout << \"Failed to capture 30 frames within timeout.\" << std::endl;\n\nHere too.\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nYou could merge the two checks and print the number of captured frames.\n\n> +\n> +\t\tstd::cout << \"Output \" << outputFrames_ << \" frames\" << std::endl;\n> +\t\tstd::cout << \"Captured \" << captureFrames_ << \" frames\" << std::endl;\n> +\n> +\t\tret = vim2m_->capture()->streamOff();\n> +\t\tif (ret)\n\nError messages please.\n\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = vim2m_->output()->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tdelete vim2m_;\n> +\t};\n> +\n> +private:\n> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n> +\tstd::shared_ptr<MediaDevice> media_;\n> +\tV4L2M2MDevice *vim2m_;\n> +\n> +\tBufferPool capturePool_;\n> +\tBufferPool outputPool_;\n> +\n> +\tunsigned int outputFrames_;\n> +\tunsigned int captureFrames_;\n> +};\n> +\n> +TEST_REGISTER(V4L2M2MDeviceTest);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 350676161B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Aug 2019 23:26:42 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 99D86CC;\n\tThu,  8 Aug 2019 23:26:41 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565299601;\n\tbh=ZbqgnysB6wwbroqFT4oHiHfbyzzz1mbxxhAwLPq5aAA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L1h20ZgRk4tLaB9KkUKQSsowKuA8TfxHePLbvUJvb5IRgLbdWF4Cz8dcy/Bb/GV6C\n\tSFnfpYR5/u8a95JGTP/bIY3rQ4Jx/1SndC8I27D/Z0vdsqBz5bRn1Pf2JBQ5Oh/FQH\n\tKzBYEaZ94faxlyjVEb16WLflD0QhXZWjHKdrNeGc=","Date":"Fri, 9 Aug 2019 00:26:37 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190808212637.GG6055@pendragon.ideasonboard.com>","References":"<20190808151221.24254-1-kieran.bingham@ideasonboard.com>\n\t<20190808151221.24254-5-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190808151221.24254-5-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice 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":"Thu, 08 Aug 2019 21:26:42 -0000"}},{"id":2358,"web_url":"https://patchwork.libcamera.org/comment/2358/","msgid":"<29c411cd-1d22-2a08-d387-5c01bf0c5e40@ideasonboard.com>","date":"2019-08-09T10:32:15","subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice test","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"On 08/08/2019 22:26, Laurent Pinchart wrote:\n> Hi Kieran,\n> \n> Thank you for the patch.\n> \n> On Thu, Aug 08, 2019 at 04:12:19PM +0100, Kieran Bingham wrote:\n>> The V4L2M2MDevice requires two pipelines to be configured. This makes it unsuitable\n>> to reuse the existing V4L2DeviceTest test library in it's current form.\n> \n> s/it's/its/\n> \n> Commit messages should wrap at 72 columns.\n> \n>> Implement a full test to run the two M2M pipelines through VIM2M.\n> \n> Lovely, another driver for our test suite :-)\n\nIndeed! So many software devices to test :D\n\n\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  test/v4l2_videodevice/meson.build        |   1 +\n>>  test/v4l2_videodevice/v4l2_m2mdevice.cpp | 210 +++++++++++++++++++++++\n>>  2 files changed, 211 insertions(+)\n>>  create mode 100644 test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>>\n>> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n>> index 76be5e142bb6..ad41898b5f8b 100644\n>> --- a/test/v4l2_videodevice/meson.build\n>> +++ b/test/v4l2_videodevice/meson.build\n>> @@ -7,6 +7,7 @@ v4l2_videodevice_tests = [\n>>      [ 'stream_on_off',      'stream_on_off.cpp' ],\n>>      [ 'capture_async',      'capture_async.cpp' ],\n>>      [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n>> +    [ 'v4l2_m2mdevice',     'v4l2_m2mdevice.cpp' ],\n>>  ]\n>>  \n>>  foreach t : v4l2_videodevice_tests\n>> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>> new file mode 100644\n>> index 000000000000..7a730f695ab7\n>> --- /dev/null\n>> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>> @@ -0,0 +1,210 @@\n>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n>> +/*\n>> + * Copyright (C) 2019, Google Inc.\n>> + *\n>> + * libcamera V4L2 API tests\n> \n> Copy & paste ?\n\nOf course ;D - I'm not writing all this from scratch hehe.\n\n\n\n>> + */\n>> +\n>> +#include <libcamera/buffer.h>\n>> +#include <libcamera/camera_manager.h>\n>> +#include <libcamera/event_dispatcher.h>\n>> +#include <libcamera/timer.h>\n>> +\n>> +#include <iostream>\n>> +#include <memory>\n>> +\n>> +#include \"device_enumerator.h\"\n>> +#include \"media_device.h\"\n>> +#include \"v4l2_videodevice.h\"\n>> +\n>> +#include \"test.h\"\n>> +\n>> +using namespace std;\n>> +using namespace libcamera;\n>> +\n>> +class V4L2M2MDeviceTest : public Test\n>> +{\n>> +public:\n>> +\tV4L2M2MDeviceTest()\n>> +\t\t: vim2m_(nullptr), outputFrames_(0), captureFrames_(0)\n>> +\t{\n>> +\t}\n>> +\n>> +\tvoid outputBufferComplete(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received output buffer \" << buffer->index()\n>> +\t\t\t  << std::endl;\n> \n> My preference goes with using the std:: prefix explicitly like here, in\n> which case you should use it everywhere and drop the using namespace std\n> statement. The alternative is to remove it everywhere.\n\nI'd prefer shorter lines and removing it.\n\nBut really we just need some better test logging.\n\n\n>> +\n>> +\t\toutputFrames_++;\n>> +\n>> +\t\t/* Requeue the buffer for further use. */\n>> +\t\tvim2m_->output()->queueBuffer(buffer);\n>> +\t}\n>> +\n>> +\tvoid receiveCaptureBuffer(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received capture buffer \" << buffer->index()\n>> +\t\t\t  << std::endl;\n>> +\n>> +\t\tcaptureFrames_++;\n>> +\n>> +\t\t/* Requeue the buffer for further use. */\n>> +\t\tvim2m_->capture()->queueBuffer(buffer);\n>> +\t}\n>> +\n>> +protected:\n>> +\tint init()\n>> +\t{\n>> +\t\tenumerator_ = 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(\"vim2m\");\n>> +\t\tdm.add(\"vim2m-source\");\n>> +\t\tdm.add(\"vim2m-sink\");\n>> +\n>> +\t\tmedia_ = enumerator_->search(dm);\n>> +\t\tif (!media_) {\n>> +\t\t\tcerr << \"Failed to match device\" << endl;\n> \n> Maybe \"No vim2m device found\" ?\n> \n\nUpdated.\n\n>> +\t\t\treturn TestSkip;\n>> +\t\t}\n>> +\n>> +\t\tMediaEntity *entity = media_->getEntityByName(\"vim2m-source\");\n>> +\t\tif (!entity) {\n>> +\t\t\tcerr << \"Failed to get device entity\" << endl;\n> \n> This can't happen due to the dm.add().\n> \n\nRemoved.\n\n>> +\t\t\treturn TestSkip;\n>> +\t\t}\n>> +\n> \n> I would move the rest of the code to the run() function as it tests the\n> V4L2M2MDevice API.\n\nDone.\n\n> \n>> +\t\tvim2m_ = new V4L2M2MDevice(entity->deviceNode());\n>> +\t\tif (vim2m_->status())\n> \n> You should add a message here (and below). It's difficult to debug test\n> failures when no message is printed.\n\n\nMaybe we should revisit the TestStatus patches I proposed.\nThen it would be\n\n\t\t\treturn TestFail(\"Failed to open VIM2M device\")\n\nI recall dropping the series because you didn't seem to like the concept.\n\n\n\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tV4L2DeviceFormat format = {};\n>> +\t\tif (vim2m_->capture()->getFormat(&format))\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tformat.size.width = 640;\n>> +\t\tformat.size.height = 480;\n>> +\n>> +\t\tif (vim2m_->capture()->setFormat(&format))\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tif (vim2m_->output()->setFormat(&format))\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tcerr << \"Initialised M2M ...\" << endl;\n> \n> I'd drop this line.\n\nDropped.\n\n> \n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +\tint run()\n>> +\t{\n>> +\t\tconst unsigned int bufferCount = 8;\n> \n> s/const/constexpr/\n> \n> Would 4 buffers be enough ?\n\nSure.\n\n> \n>> +\n>> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n>> +\t\tTimer timeout;\n>> +\t\tint ret;\n>> +\n>> +\t\tcapturePool_.createBuffers(bufferCount);\n>> +\t\toutputPool_.createBuffers(bufferCount);\n>> +\n>> +\t\tret = vim2m_->capture()->exportBuffers(&capturePool_);\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to export Capture Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = vim2m_->output()->exportBuffers(&outputPool_);\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to export Output Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n> \n> I would store the capture and output devices to local variables to\n> shorten the lines.\n\nSure.\n\n> \n>> +\n>> +\t\tvim2m_->capture()->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);\n>> +\t\tvim2m_->output()->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);\n>> +\n>> +\t\t/* We can't \"queueAllBuffers()\" on an output device, so we do it manually */\n>> +\t\tstd::vector<std::unique_ptr<Buffer>> outputBuffers;\n>> +\t\tfor (unsigned int i = 0; i < outputPool_.count(); ++i) {\n>> +\t\t\tBuffer *buffer = new Buffer(i);\n>> +\t\t\toutputBuffers.emplace_back(buffer);\n>> +\t\t\tret = vim2m_->output()->queueBuffer(buffer);\n>> +\t\t\tif (ret)\n>> +\t\t\t\treturn {};\n>> +\t\t}\n>> +\n>> +\t\tstd::vector<std::unique_ptr<Buffer>> captureBuffers;\n>> +\t\tcaptureBuffers = vim2m_->capture()->queueAllBuffers();\n>> +\t\tif (captureBuffers.empty()) {\n>> +\t\t\tcerr << \"Failed to queue all Capture Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n> \n> Even if it makes little difference in practice, I would queue the\n> buffers on the capture side first, \n> \n>> +\n>> +\t\tret = vim2m_->output()->streamOn();\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to streamOn output\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = vim2m_->capture()->streamOn();\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to streamOn capture\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\ttimeout.start(10000);\n>> +\t\twhile (timeout.isRunning()) {\n>> +\t\t\tdispatcher->processEvents();\n>> +\t\t\tif (captureFrames_ > 30)\n>> +\t\t\t\tbreak;\n> \n> How long does it take in practice to capture 30 frames ? Can we reduce\n> the timeout ?\n\nOn my laptop:\n\n27/37 libcamera:v4l2_videodevice / v4l2_m2mdevice  OK       1.47 s\n\n\nOn a RaspberryPi 3:\n\n27/37 libcamera:v4l2_videodevice / v4l2_m2mdevice  OK       1.64 s\n\n\nI'll drop to 5 seconds timeout. It's only going to happen in the event\nof a pipeline stall which is unlikely.\n\n\n\n>> +\t\t}\n>> +\n>> +\t\tif (captureFrames_ < 1) {\n>> +\t\t\tstd::cout << \"Failed to capture any frames within timeout.\" << std::endl;\n> \n> s/timeout\\./timeout/\n> Line wrap.\n> \n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tif (captureFrames_ < 30) {\n>> +\t\t\tstd::cout << \"Failed to capture 30 frames within timeout.\" << std::endl;\n> \n> Here too.\n> \n>> +\t\t\treturn TestFail;\n>> +\t\t}\n> \n> You could merge the two checks and print the number of captured frames.\n\nDone.\n\n\n> \n>> +\n>> +\t\tstd::cout << \"Output \" << outputFrames_ << \" frames\" << std::endl;\n>> +\t\tstd::cout << \"Captured \" << captureFrames_ << \" frames\" << std::endl;\n>> +\n>> +\t\tret = vim2m_->capture()->streamOff();\n>> +\t\tif (ret)\n> \n> Error messages please.\n\nDone\n\n\n> \n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = vim2m_->output()->streamOff();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +\tvoid cleanup()\n>> +\t{\n>> +\t\tdelete vim2m_;\n>> +\t};\n>> +\n>> +private:\n>> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n>> +\tstd::shared_ptr<MediaDevice> media_;\n>> +\tV4L2M2MDevice *vim2m_;\n>> +\n>> +\tBufferPool capturePool_;\n>> +\tBufferPool outputPool_;\n>> +\n>> +\tunsigned int outputFrames_;\n>> +\tunsigned int captureFrames_;\n>> +};\n>> +\n>> +TEST_REGISTER(V4L2M2MDeviceTest);\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 84DC761620\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2019 12:32:18 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C8BE3CC;\n\tFri,  9 Aug 2019 12:32:17 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565346738;\n\tbh=atcJxYxgwQPNpe9HILx69PkuavCVscRdG/LLWFwfCM8=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=lyF/ARAoptaa5RkYQ5HSOOBWFP3T3+e0besIT9WRKlYEPa2kFlQ3VC+wT3LPfsga3\n\tPrreOMCD9DqDH9HyRU2wMFDXilbGpLPMiaPRN/UXq4p/x8q32aD+qB6nnJHxEMKzQb\n\t7J/efYJ2c0Op6KVFNS+UgpaJNwDEytvpNlJJPGJA=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","References":"<20190808151221.24254-1-kieran.bingham@ideasonboard.com>\n\t<20190808151221.24254-5-kieran.bingham@ideasonboard.com>\n\t<20190808212637.GG6055@pendragon.ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1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iUEGAEKAA8CGwwFAlnDlGsFCQeA/gIACgkQoR5GchCkYf1yYRAAq+Yo\n\tnbf9DGdK1kTAm2RTFg+w9oOp2Xjqfhds2PAhFFvrHQg1XfQR/UF/SjeUmaOmLSczM0s6XMeO\n\tVcE77UFtJ/+hLo4PRFKm5X1Pcar6g5m4xGqa+Xfzi9tRkwC29KMCoQOag1BhHChgqYaUH3yo\n\tUzaPwT/fY75iVI+yD0ih/e6j8qYvP8pvGwMQfrmN9YB0zB39YzCSdaUaNrWGD3iCBxg6lwSO\n\tLKeRhxxfiXCIYEf3vwOsP3YMx2JkD5doseXmWBGW1U0T/oJF+DVfKB6mv5UfsTzpVhJRgee7\n\t4jkjqFq4qsUGxcvF2xtRkfHFpZDbRgRlVmiWkqDkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<29c411cd-1d22-2a08-d387-5c01bf0c5e40@ideasonboard.com>","Date":"Fri, 9 Aug 2019 11:32:15 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.8.0","MIME-Version":"1.0","In-Reply-To":"<20190808212637.GG6055@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice 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, 09 Aug 2019 10:32:18 -0000"}},{"id":2363,"web_url":"https://patchwork.libcamera.org/comment/2363/","msgid":"<20190809143022.myl2rtdr4vhugphq@uno.localdomain>","date":"2019-08-09T14:30:22","subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice test","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Kieran,\n\nOn Thu, Aug 08, 2019 at 04:12:19PM +0100, Kieran Bingham wrote:\n> The V4L2M2MDevice requires two pipelines to be configured. This makes it unsuitable\n> to reuse the existing V4L2DeviceTest test library in it's current form.\n>\n> Implement a full test to run the two M2M pipelines through VIM2M.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  test/v4l2_videodevice/meson.build        |   1 +\n>  test/v4l2_videodevice/v4l2_m2mdevice.cpp | 210 +++++++++++++++++++++++\n>  2 files changed, 211 insertions(+)\n>  create mode 100644 test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>\n> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n> index 76be5e142bb6..ad41898b5f8b 100644\n> --- a/test/v4l2_videodevice/meson.build\n> +++ b/test/v4l2_videodevice/meson.build\n> @@ -7,6 +7,7 @@ v4l2_videodevice_tests = [\n>      [ 'stream_on_off',      'stream_on_off.cpp' ],\n>      [ 'capture_async',      'capture_async.cpp' ],\n>      [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n> +    [ 'v4l2_m2mdevice',     'v4l2_m2mdevice.cpp' ],\n>  ]\n>\n>  foreach t : v4l2_videodevice_tests\n> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> new file mode 100644\n> index 000000000000..7a730f695ab7\n> --- /dev/null\n> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> @@ -0,0 +1,210 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * libcamera V4L2 API tests\n> + */\n> +\n> +#include <libcamera/buffer.h>\n> +#include <libcamera/camera_manager.h>\n> +#include <libcamera/event_dispatcher.h>\n> +#include <libcamera/timer.h>\n> +\n> +#include <iostream>\n> +#include <memory>\n\nC++ includes before library includes\n\n> +\n> +#include \"device_enumerator.h\"\n> +#include \"media_device.h\"\n> +#include \"v4l2_videodevice.h\"\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class V4L2M2MDeviceTest : public Test\n> +{\n> +public:\n> +\tV4L2M2MDeviceTest()\n> +\t\t: vim2m_(nullptr), outputFrames_(0), captureFrames_(0)\n> +\t{\n> +\t}\n> +\n> +\tvoid outputBufferComplete(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received output buffer \" << buffer->index()\n> +\t\t\t  << std::endl;\n> +\n> +\t\toutputFrames_++;\n> +\n> +\t\t/* Requeue the buffer for further use. */\n> +\t\tvim2m_->output()->queueBuffer(buffer);\n> +\t}\n> +\n> +\tvoid receiveCaptureBuffer(Buffer *buffer)\n> +\t{\n> +\t\tstd::cout << \"Received capture buffer \" << buffer->index()\n> +\t\t\t  << std::endl;\n> +\n> +\t\tcaptureFrames_++;\n> +\n> +\t\t/* Requeue the buffer for further use. */\n> +\t\tvim2m_->capture()->queueBuffer(buffer);\n> +\t}\n> +\n> +protected:\n> +\tint init()\n> +\t{\n> +\t\tenumerator_ = 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(\"vim2m\");\n> +\t\tdm.add(\"vim2m-source\");\n> +\t\tdm.add(\"vim2m-sink\");\n> +\n> +\t\tmedia_ = enumerator_->search(dm);\n> +\t\tif (!media_) {\n> +\t\t\tcerr << \"Failed to match device\" << endl;\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n> +\t\tMediaEntity *entity = media_->getEntityByName(\"vim2m-source\");\n> +\t\tif (!entity) {\n> +\t\t\tcerr << \"Failed to get device entity\" << endl;\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n> +\t\tvim2m_ = new V4L2M2MDevice(entity->deviceNode());\n> +\t\tif (vim2m_->status())\n> +\t\t\treturn TestFail;\n\nDo we want a static function M2MFromEntityName like we have for\ndevices and subdevices?\n\n> +\n> +\t\tV4L2DeviceFormat format = {};\n> +\t\tif (vim2m_->capture()->getFormat(&format))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tformat.size.width = 640;\n> +\t\tformat.size.height = 480;\n> +\n> +\t\tif (vim2m_->capture()->setFormat(&format))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (vim2m_->output()->setFormat(&format))\n> +\t\t\treturn TestFail;\n\nDoes setFormat deserves a single helper as open()/close() are?\n\n> +\n> +\t\tcerr << \"Initialised M2M ...\" << endl;\n\ns/...//\nNot sure it makes a difference, but that should be cout.\n\nAlso, as Laurent said, what about keeping the std namespace explicit ?\n\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run()\n> +\t{\n> +\t\tconst unsigned int bufferCount = 8;\n> +\n> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n> +\t\tTimer timeout;\n> +\t\tint ret;\n\nSince you don't initialize it, could you declare them at the time\nthey're used?\n\n> +\n> +\t\tcapturePool_.createBuffers(bufferCount);\n> +\t\toutputPool_.createBuffers(bufferCount);\n> +\n> +\t\tret = vim2m_->capture()->exportBuffers(&capturePool_);\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to export Capture Buffers\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = vim2m_->output()->exportBuffers(&outputPool_);\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to export Output Buffers\" << endl;\n> +\t\t\treturn TestFail;\n\nShould we delete the pools ?\n\n> +\t\t}\n> +\n> +\t\tvim2m_->capture()->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);\n> +\t\tvim2m_->output()->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);\n> +\n> +\t\t/* We can't \"queueAllBuffers()\" on an output device, so we do it manually */\n> +\t\tstd::vector<std::unique_ptr<Buffer>> outputBuffers;\n> +\t\tfor (unsigned int i = 0; i < outputPool_.count(); ++i) {\n> +\t\t\tBuffer *buffer = new Buffer(i);\n> +\t\t\toutputBuffers.emplace_back(buffer);\n> +\t\t\tret = vim2m_->output()->queueBuffer(buffer);\n> +\t\t\tif (ret)\n> +\t\t\t\treturn {};\n\nreturn TestFail ? And maybe an error message for simmetry with the\nbelow one?\n\n> +\t\t}\n> +\n> +\t\tstd::vector<std::unique_ptr<Buffer>> captureBuffers;\n> +\t\tcaptureBuffers = vim2m_->capture()->queueAllBuffers();\n> +\t\tif (captureBuffers.empty()) {\n> +\t\t\tcerr << \"Failed to queue all Capture Buffers\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = vim2m_->output()->streamOn();\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to streamOn output\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = vim2m_->capture()->streamOn();\n> +\t\tif (ret) {\n> +\t\t\tcerr << \"Failed to streamOn capture\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\ttimeout.start(10000);\n> +\t\twhile (timeout.isRunning()) {\n> +\t\t\tdispatcher->processEvents();\n> +\t\t\tif (captureFrames_ > 30)\n> +\t\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\tif (captureFrames_ < 1) {\n> +\t\t\tstd::cout << \"Failed to capture any frames within timeout.\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (captureFrames_ < 30) {\n> +\t\t\tstd::cout << \"Failed to capture 30 frames within timeout.\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n\nOver 80 columns, I know you're not too concerned about that ;)\n\n> +\n> +\t\tstd::cout << \"Output \" << outputFrames_ << \" frames\" << std::endl;\n> +\t\tstd::cout << \"Captured \" << captureFrames_ << \" frames\" << std::endl;\n> +\n> +\t\tret = vim2m_->capture()->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tret = vim2m_->output()->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tdelete vim2m_;\n> +\t};\n> +\n> +private:\n> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n> +\tstd::shared_ptr<MediaDevice> media_;\n> +\tV4L2M2MDevice *vim2m_;\n> +\n> +\tBufferPool capturePool_;\n> +\tBufferPool outputPool_;\n> +\n> +\tunsigned int outputFrames_;\n> +\tunsigned int captureFrames_;\n> +};\n> +\n> +TEST_REGISTER(V4L2M2MDeviceTest);\n> --\n> 2.20.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 2D7F561623\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2019 16:28:59 +0200 (CEST)","from uno.localdomain\n\t(host150-24-dynamic.51-79-r.retail.telecomitalia.it [79.51.24.150])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 4A47C1BF20B;\n\tFri,  9 Aug 2019 14:28:58 +0000 (UTC)"],"X-Originating-IP":"79.51.24.150","Date":"Fri, 9 Aug 2019 16:30:22 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190809143022.myl2rtdr4vhugphq@uno.localdomain>","References":"<20190808151221.24254-1-kieran.bingham@ideasonboard.com>\n\t<20190808151221.24254-5-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"q73smiiatajaka36\"","Content-Disposition":"inline","In-Reply-To":"<20190808151221.24254-5-kieran.bingham@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice 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, 09 Aug 2019 14:28:59 -0000"}},{"id":2365,"web_url":"https://patchwork.libcamera.org/comment/2365/","msgid":"<fffd7720-c2a8-3f0b-edda-57d44cfab490@ideasonboard.com>","date":"2019-08-09T14:43:00","subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice test","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Jacopo,\n\nThanks for the review.\n\nI've picked up a couple of fixups and applied them ready for v2.\n\n\nOn 09/08/2019 15:30, Jacopo Mondi wrote:\n> Hi Kieran,\n> \n> On Thu, Aug 08, 2019 at 04:12:19PM +0100, Kieran Bingham wrote:\n>> The V4L2M2MDevice requires two pipelines to be configured. This makes it unsuitable\n>> to reuse the existing V4L2DeviceTest test library in it's current form.\n>>\n>> Implement a full test to run the two M2M pipelines through VIM2M.\n>>\n>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>> ---\n>>  test/v4l2_videodevice/meson.build        |   1 +\n>>  test/v4l2_videodevice/v4l2_m2mdevice.cpp | 210 +++++++++++++++++++++++\n>>  2 files changed, 211 insertions(+)\n>>  create mode 100644 test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>>\n>> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n>> index 76be5e142bb6..ad41898b5f8b 100644\n>> --- a/test/v4l2_videodevice/meson.build\n>> +++ b/test/v4l2_videodevice/meson.build\n>> @@ -7,6 +7,7 @@ v4l2_videodevice_tests = [\n>>      [ 'stream_on_off',      'stream_on_off.cpp' ],\n>>      [ 'capture_async',      'capture_async.cpp' ],\n>>      [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n>> +    [ 'v4l2_m2mdevice',     'v4l2_m2mdevice.cpp' ],\n>>  ]\n>>\n>>  foreach t : v4l2_videodevice_tests\n>> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>> new file mode 100644\n>> index 000000000000..7a730f695ab7\n>> --- /dev/null\n>> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n>> @@ -0,0 +1,210 @@\n>> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n>> +/*\n>> + * Copyright (C) 2019, Google Inc.\n>> + *\n>> + * libcamera V4L2 API tests\n>> + */\n>> +\n>> +#include <libcamera/buffer.h>\n>> +#include <libcamera/camera_manager.h>\n>> +#include <libcamera/event_dispatcher.h>\n>> +#include <libcamera/timer.h>\n>> +\n>> +#include <iostream>\n>> +#include <memory>\n> \n> C++ includes before library includes\n\nMoved, and dropped <memory> I don't think it's used.\n\n\n> \n>> +\n>> +#include \"device_enumerator.h\"\n>> +#include \"media_device.h\"\n>> +#include \"v4l2_videodevice.h\"\n>> +\n>> +#include \"test.h\"\n>> +\n>> +using namespace std;\n>> +using namespace libcamera;\n>> +\n>> +class V4L2M2MDeviceTest : public Test\n>> +{\n>> +public:\n>> +\tV4L2M2MDeviceTest()\n>> +\t\t: vim2m_(nullptr), outputFrames_(0), captureFrames_(0)\n>> +\t{\n>> +\t}\n>> +\n>> +\tvoid outputBufferComplete(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received output buffer \" << buffer->index()\n>> +\t\t\t  << std::endl;\n>> +\n>> +\t\toutputFrames_++;\n>> +\n>> +\t\t/* Requeue the buffer for further use. */\n>> +\t\tvim2m_->output()->queueBuffer(buffer);\n>> +\t}\n>> +\n>> +\tvoid receiveCaptureBuffer(Buffer *buffer)\n>> +\t{\n>> +\t\tstd::cout << \"Received capture buffer \" << buffer->index()\n>> +\t\t\t  << std::endl;\n>> +\n>> +\t\tcaptureFrames_++;\n>> +\n>> +\t\t/* Requeue the buffer for further use. */\n>> +\t\tvim2m_->capture()->queueBuffer(buffer);\n>> +\t}\n>> +\n>> +protected:\n>> +\tint init()\n>> +\t{\n>> +\t\tenumerator_ = 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(\"vim2m\");\n>> +\t\tdm.add(\"vim2m-source\");\n>> +\t\tdm.add(\"vim2m-sink\");\n>> +\n>> +\t\tmedia_ = enumerator_->search(dm);\n>> +\t\tif (!media_) {\n>> +\t\t\tcerr << \"Failed to match device\" << endl;\n>> +\t\t\treturn TestSkip;\n>> +\t\t}\n>> +\n>> +\t\tMediaEntity *entity = media_->getEntityByName(\"vim2m-source\");\n>> +\t\tif (!entity) {\n>> +\t\t\tcerr << \"Failed to get device entity\" << endl;\n>> +\t\t\treturn TestSkip;\n>> +\t\t}\n>> +\n>> +\t\tvim2m_ = new V4L2M2MDevice(entity->deviceNode());\n>> +\t\tif (vim2m_->status())\n>> +\t\t\treturn TestFail;\n> \n> Do we want a static function M2MFromEntityName like we have for\n> devices and subdevices?\n\nI think this looks clean, but we can add the helper later if you think\nit's useful.\n\n\n>> +\n>> +\t\tV4L2DeviceFormat format = {};\n>> +\t\tif (vim2m_->capture()->getFormat(&format))\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tformat.size.width = 640;\n>> +\t\tformat.size.height = 480;\n>> +\n>> +\t\tif (vim2m_->capture()->setFormat(&format))\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tif (vim2m_->output()->setFormat(&format))\n>> +\t\t\treturn TestFail;\n> \n> Does setFormat deserves a single helper as open()/close() are?\n\nNo - We can set different formats on the two pipes.\n\nIt's just this test where I set the same format on both for simplicity.\nI don't want to test the conversion capabilities of vim2m - just the\nbuffer flow.\n\n\n> \n>> +\n>> +\t\tcerr << \"Initialised M2M ...\" << endl;\n> \n> s/...//\n> Not sure it makes a difference, but that should be cout.\n> \n> Also, as Laurent said, what about keeping the std namespace explicit ?\n\nIt was there to help me when it wasn't running. I've removed it now.\n\n\n> \n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +\tint run()\n>> +\t{\n>> +\t\tconst unsigned int bufferCount = 8;\n>> +\n>> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n>> +\t\tTimer timeout;\n>> +\t\tint ret;\n> \n> Since you don't initialize it, could you declare them at the time\n> they're used?\n> \n\nThe ret is used by multiple statements, so I'd rather keep that separate.\n\nI've moved the Timer declaration to the usage.\n\n\n\n>> +\n>> +\t\tcapturePool_.createBuffers(bufferCount);\n>> +\t\toutputPool_.createBuffers(bufferCount);\n>> +\n>> +\t\tret = vim2m_->capture()->exportBuffers(&capturePool_);\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to export Capture Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = vim2m_->output()->exportBuffers(&outputPool_);\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to export Output Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n> \n> Should we delete the pools ?\n\nThe pools are class members. Their destructors will run when the class\nis destroyed.\n\n\n> \n>> +\t\t}\n>> +\n>> +\t\tvim2m_->capture()->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);\n>> +\t\tvim2m_->output()->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);\n>> +\n>> +\t\t/* We can't \"queueAllBuffers()\" on an output device, so we do it manually */\n>> +\t\tstd::vector<std::unique_ptr<Buffer>> outputBuffers;\n>> +\t\tfor (unsigned int i = 0; i < outputPool_.count(); ++i) {\n>> +\t\t\tBuffer *buffer = new Buffer(i);\n>> +\t\t\toutputBuffers.emplace_back(buffer);\n>> +\t\t\tret = vim2m_->output()->queueBuffer(buffer);\n>> +\t\t\tif (ret)\n>> +\t\t\t\treturn {};\n> \n> return TestFail ? And maybe an error message for simmetry with the\n> below one?\n\nYes, I've fixed this one already.\n\n\n\n> \n>> +\t\t}\n>> +\n>> +\t\tstd::vector<std::unique_ptr<Buffer>> captureBuffers;\n>> +\t\tcaptureBuffers = vim2m_->capture()->queueAllBuffers();\n>> +\t\tif (captureBuffers.empty()) {\n>> +\t\t\tcerr << \"Failed to queue all Capture Buffers\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = vim2m_->output()->streamOn();\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to streamOn output\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tret = vim2m_->capture()->streamOn();\n>> +\t\tif (ret) {\n>> +\t\t\tcerr << \"Failed to streamOn capture\" << endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\ttimeout.start(10000);\n>> +\t\twhile (timeout.isRunning()) {\n>> +\t\t\tdispatcher->processEvents();\n>> +\t\t\tif (captureFrames_ > 30)\n>> +\t\t\t\tbreak;\n>> +\t\t}\n>> +\n>> +\t\tif (captureFrames_ < 1) {\n>> +\t\t\tstd::cout << \"Failed to capture any frames within timeout.\" << std::endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n>> +\n>> +\t\tif (captureFrames_ < 30) {\n>> +\t\t\tstd::cout << \"Failed to capture 30 frames within timeout.\" << std::endl;\n>> +\t\t\treturn TestFail;\n>> +\t\t}\n> \n> Over 80 columns, I know you're not too concerned about that ;)\n\nFor debug lines in test cases : no - but those lines have already been\ndeleted for the next version.\n\n> \n>> +\n>> +\t\tstd::cout << \"Output \" << outputFrames_ << \" frames\" << std::endl;\n>> +\t\tstd::cout << \"Captured \" << captureFrames_ << \" frames\" << std::endl;\n>> +\n>> +\t\tret = vim2m_->capture()->streamOff();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\tret = vim2m_->output()->streamOff();\n>> +\t\tif (ret)\n>> +\t\t\treturn TestFail;\n>> +\n>> +\t\treturn TestPass;\n>> +\t}\n>> +\n>> +\tvoid cleanup()\n>> +\t{\n>> +\t\tdelete vim2m_;\n>> +\t};\n>> +\n>> +private:\n>> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n>> +\tstd::shared_ptr<MediaDevice> media_;\n>> +\tV4L2M2MDevice *vim2m_;\n>> +\n>> +\tBufferPool capturePool_;\n>> +\tBufferPool outputPool_;\n>> +\n>> +\tunsigned int outputFrames_;\n>> +\tunsigned int captureFrames_;\n>> +};\n>> +\n>> +TEST_REGISTER(V4L2M2MDeviceTest);\n>> --\n>> 2.20.1\n>>\n>> _______________________________________________\n>> libcamera-devel mailing list\n>> libcamera-devel@lists.libcamera.org\n>> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<kieran.bingham@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 93C2D61623\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2019 16:43:04 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F18FDCC;\n\tFri,  9 Aug 2019 16:43:03 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565361784;\n\tbh=maTV0M76eY8RYhRh4fK7gh3vJ6eqYn0x0hn+QSQu4G4=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=bFYODocYX6kbM1JNEAjahtTCKswRI585RXj5oIkEON4+agxLdVQYg1PFGR0AjDstV\n\t/yMMSr1iDOlObf6IBHrcxwWJ83fqPit/wxpjngmxe8jotVxu+SeI39WYWZe1GcqJmr\n\t6bFdjmfXrYNkAy2bBL8+6qaGUnDlnnPFdxQ8DuMU=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","References":"<20190808151221.24254-1-kieran.bingham@ideasonboard.com>\n\t<20190808151221.24254-5-kieran.bingham@ideasonboard.com>\n\t<20190809143022.myl2rtdr4vhugphq@uno.localdomain>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8Fie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4jkjqFq4qsUGxcvF2xtRkfHFpZDbRgRlVmiWkqDkT4qMA+4q1y/dWwshSKi/uwVZNycuLsz+\n\t+OD8xPNCsMTqeUkAKfbD8xW4LCay3r/dD2ckoxRxtMD9eOAyu5wYzo/ydIPTh1QEj9SYyvp8\n\tO0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU\n\tRCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA\n\tJxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q\n\tsbsRB8KNNvVXBOVNwko86rQqF9drZuw=","Organization":"Ideas on Board","Message-ID":"<fffd7720-c2a8-3f0b-edda-57d44cfab490@ideasonboard.com>","Date":"Fri, 9 Aug 2019 15:43:00 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.8.0","MIME-Version":"1.0","In-Reply-To":"<20190809143022.myl2rtdr4vhugphq@uno.localdomain>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice 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, 09 Aug 2019 14:43:04 -0000"}},{"id":2368,"web_url":"https://patchwork.libcamera.org/comment/2368/","msgid":"<20190809181804.GE5007@pendragon.ideasonboard.com>","date":"2019-08-09T18:18:04","subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice test","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nOn Fri, Aug 09, 2019 at 11:32:15AM +0100, Kieran Bingham wrote:\n> On 08/08/2019 22:26, Laurent Pinchart wrote:\n> > On Thu, Aug 08, 2019 at 04:12:19PM +0100, Kieran Bingham wrote:\n> >> The V4L2M2MDevice requires two pipelines to be configured. This makes it unsuitable\n> >> to reuse the existing V4L2DeviceTest test library in it's current form.\n> > \n> > s/it's/its/\n> > \n> > Commit messages should wrap at 72 columns.\n> > \n> >> Implement a full test to run the two M2M pipelines through VIM2M.\n> > \n> > Lovely, another driver for our test suite :-)\n> \n> Indeed! So many software devices to test :D\n> \n> >> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >> ---\n> >>  test/v4l2_videodevice/meson.build        |   1 +\n> >>  test/v4l2_videodevice/v4l2_m2mdevice.cpp | 210 +++++++++++++++++++++++\n> >>  2 files changed, 211 insertions(+)\n> >>  create mode 100644 test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> >>\n> >> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n> >> index 76be5e142bb6..ad41898b5f8b 100644\n> >> --- a/test/v4l2_videodevice/meson.build\n> >> +++ b/test/v4l2_videodevice/meson.build\n> >> @@ -7,6 +7,7 @@ v4l2_videodevice_tests = [\n> >>      [ 'stream_on_off',      'stream_on_off.cpp' ],\n> >>      [ 'capture_async',      'capture_async.cpp' ],\n> >>      [ 'buffer_sharing',     'buffer_sharing.cpp' ],\n> >> +    [ 'v4l2_m2mdevice',     'v4l2_m2mdevice.cpp' ],\n> >>  ]\n> >>  \n> >>  foreach t : v4l2_videodevice_tests\n> >> diff --git a/test/v4l2_videodevice/v4l2_m2mdevice.cpp b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> >> new file mode 100644\n> >> index 000000000000..7a730f695ab7\n> >> --- /dev/null\n> >> +++ b/test/v4l2_videodevice/v4l2_m2mdevice.cpp\n> >> @@ -0,0 +1,210 @@\n> >> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> >> +/*\n> >> + * Copyright (C) 2019, Google Inc.\n> >> + *\n> >> + * libcamera V4L2 API tests\n> > \n> > Copy & paste ?\n> \n> Of course ;D - I'm not writing all this from scratch hehe.\n> \n> >> + */\n> >> +\n> >> +#include <libcamera/buffer.h>\n> >> +#include <libcamera/camera_manager.h>\n> >> +#include <libcamera/event_dispatcher.h>\n> >> +#include <libcamera/timer.h>\n> >> +\n> >> +#include <iostream>\n> >> +#include <memory>\n> >> +\n> >> +#include \"device_enumerator.h\"\n> >> +#include \"media_device.h\"\n> >> +#include \"v4l2_videodevice.h\"\n> >> +\n> >> +#include \"test.h\"\n> >> +\n> >> +using namespace std;\n> >> +using namespace libcamera;\n> >> +\n> >> +class V4L2M2MDeviceTest : public Test\n> >> +{\n> >> +public:\n> >> +\tV4L2M2MDeviceTest()\n> >> +\t\t: vim2m_(nullptr), outputFrames_(0), captureFrames_(0)\n> >> +\t{\n> >> +\t}\n> >> +\n> >> +\tvoid outputBufferComplete(Buffer *buffer)\n> >> +\t{\n> >> +\t\tstd::cout << \"Received output buffer \" << buffer->index()\n> >> +\t\t\t  << std::endl;\n> > \n> > My preference goes with using the std:: prefix explicitly like here, in\n> > which case you should use it everywhere and drop the using namespace std\n> > statement. The alternative is to remove it everywhere.\n> \n> I'd prefer shorter lines and removing it.\n> \n> But really we just need some better test logging.\n> \n> >> +\n> >> +\t\toutputFrames_++;\n> >> +\n> >> +\t\t/* Requeue the buffer for further use. */\n> >> +\t\tvim2m_->output()->queueBuffer(buffer);\n> >> +\t}\n> >> +\n> >> +\tvoid receiveCaptureBuffer(Buffer *buffer)\n> >> +\t{\n> >> +\t\tstd::cout << \"Received capture buffer \" << buffer->index()\n> >> +\t\t\t  << std::endl;\n> >> +\n> >> +\t\tcaptureFrames_++;\n> >> +\n> >> +\t\t/* Requeue the buffer for further use. */\n> >> +\t\tvim2m_->capture()->queueBuffer(buffer);\n> >> +\t}\n> >> +\n> >> +protected:\n> >> +\tint init()\n> >> +\t{\n> >> +\t\tenumerator_ = 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(\"vim2m\");\n> >> +\t\tdm.add(\"vim2m-source\");\n> >> +\t\tdm.add(\"vim2m-sink\");\n> >> +\n> >> +\t\tmedia_ = enumerator_->search(dm);\n> >> +\t\tif (!media_) {\n> >> +\t\t\tcerr << \"Failed to match device\" << endl;\n> > \n> > Maybe \"No vim2m device found\" ?\n> \n> Updated.\n> \n> >> +\t\t\treturn TestSkip;\n> >> +\t\t}\n> >> +\n> >> +\t\tMediaEntity *entity = media_->getEntityByName(\"vim2m-source\");\n> >> +\t\tif (!entity) {\n> >> +\t\t\tcerr << \"Failed to get device entity\" << endl;\n> > \n> > This can't happen due to the dm.add().\n> \n> Removed.\n> \n> >> +\t\t\treturn TestSkip;\n> >> +\t\t}\n> >> +\n> > \n> > I would move the rest of the code to the run() function as it tests the\n> > V4L2M2MDevice API.\n> \n> Done.\n> \n> >> +\t\tvim2m_ = new V4L2M2MDevice(entity->deviceNode());\n> >> +\t\tif (vim2m_->status())\n> > \n> > You should add a message here (and below). It's difficult to debug test\n> > failures when no message is printed.\n> \n> Maybe we should revisit the TestStatus patches I proposed.\n> Then it would be\n> \n> \t\t\treturn TestFail(\"Failed to open VIM2M device\")\n> \n> I recall dropping the series because you didn't seem to like the concept.\n\nI think it's a good idea, but I also think it should be part of a\nlogging infrastructure for tests. We shouldn't design the two parts\nseparately.\n\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tV4L2DeviceFormat format = {};\n> >> +\t\tif (vim2m_->capture()->getFormat(&format))\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tformat.size.width = 640;\n> >> +\t\tformat.size.height = 480;\n> >> +\n> >> +\t\tif (vim2m_->capture()->setFormat(&format))\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tif (vim2m_->output()->setFormat(&format))\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tcerr << \"Initialised M2M ...\" << endl;\n> > \n> > I'd drop this line.\n> \n> Dropped.\n> \n> >> +\n> >> +\t\treturn TestPass;\n> >> +\t}\n> >> +\n> >> +\tint run()\n> >> +\t{\n> >> +\t\tconst unsigned int bufferCount = 8;\n> > \n> > s/const/constexpr/\n> > \n> > Would 4 buffers be enough ?\n> \n> Sure.\n> \n> >> +\n> >> +\t\tEventDispatcher *dispatcher = CameraManager::instance()->eventDispatcher();\n> >> +\t\tTimer timeout;\n> >> +\t\tint ret;\n> >> +\n> >> +\t\tcapturePool_.createBuffers(bufferCount);\n> >> +\t\toutputPool_.createBuffers(bufferCount);\n> >> +\n> >> +\t\tret = vim2m_->capture()->exportBuffers(&capturePool_);\n> >> +\t\tif (ret) {\n> >> +\t\t\tcerr << \"Failed to export Capture Buffers\" << endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\tret = vim2m_->output()->exportBuffers(&outputPool_);\n> >> +\t\tif (ret) {\n> >> +\t\t\tcerr << \"Failed to export Output Buffers\" << endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> > \n> > I would store the capture and output devices to local variables to\n> > shorten the lines.\n> \n> Sure.\n> \n> >> +\n> >> +\t\tvim2m_->capture()->bufferReady.connect(this, &V4L2M2MDeviceTest::receiveCaptureBuffer);\n> >> +\t\tvim2m_->output()->bufferReady.connect(this, &V4L2M2MDeviceTest::outputBufferComplete);\n> >> +\n> >> +\t\t/* We can't \"queueAllBuffers()\" on an output device, so we do it manually */\n> >> +\t\tstd::vector<std::unique_ptr<Buffer>> outputBuffers;\n> >> +\t\tfor (unsigned int i = 0; i < outputPool_.count(); ++i) {\n> >> +\t\t\tBuffer *buffer = new Buffer(i);\n> >> +\t\t\toutputBuffers.emplace_back(buffer);\n> >> +\t\t\tret = vim2m_->output()->queueBuffer(buffer);\n> >> +\t\t\tif (ret)\n> >> +\t\t\t\treturn {};\n> >> +\t\t}\n> >> +\n> >> +\t\tstd::vector<std::unique_ptr<Buffer>> captureBuffers;\n> >> +\t\tcaptureBuffers = vim2m_->capture()->queueAllBuffers();\n> >> +\t\tif (captureBuffers.empty()) {\n> >> +\t\t\tcerr << \"Failed to queue all Capture Buffers\" << endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> > \n> > Even if it makes little difference in practice, I would queue the\n> > buffers on the capture side first, \n> > \n> >> +\n> >> +\t\tret = vim2m_->output()->streamOn();\n> >> +\t\tif (ret) {\n> >> +\t\t\tcerr << \"Failed to streamOn output\" << endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\tret = vim2m_->capture()->streamOn();\n> >> +\t\tif (ret) {\n> >> +\t\t\tcerr << \"Failed to streamOn capture\" << endl;\n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\ttimeout.start(10000);\n> >> +\t\twhile (timeout.isRunning()) {\n> >> +\t\t\tdispatcher->processEvents();\n> >> +\t\t\tif (captureFrames_ > 30)\n> >> +\t\t\t\tbreak;\n> > \n> > How long does it take in practice to capture 30 frames ? Can we reduce\n> > the timeout ?\n> \n> On my laptop:\n> \n> 27/37 libcamera:v4l2_videodevice / v4l2_m2mdevice  OK       1.47 s\n> \n> On a RaspberryPi 3:\n> \n> 27/37 libcamera:v4l2_videodevice / v4l2_m2mdevice  OK       1.64 s\n> \n> I'll drop to 5 seconds timeout. It's only going to happen in the event\n> of a pipeline stall which is unlikely.\n\nSeems good to me.\n\n> >> +\t\t}\n> >> +\n> >> +\t\tif (captureFrames_ < 1) {\n> >> +\t\t\tstd::cout << \"Failed to capture any frames within timeout.\" << std::endl;\n> > \n> > s/timeout\\./timeout/\n> > Line wrap.\n> > \n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> >> +\n> >> +\t\tif (captureFrames_ < 30) {\n> >> +\t\t\tstd::cout << \"Failed to capture 30 frames within timeout.\" << std::endl;\n> > \n> > Here too.\n> > \n> >> +\t\t\treturn TestFail;\n> >> +\t\t}\n> > \n> > You could merge the two checks and print the number of captured frames.\n> \n> Done.\n> \n> >> +\n> >> +\t\tstd::cout << \"Output \" << outputFrames_ << \" frames\" << std::endl;\n> >> +\t\tstd::cout << \"Captured \" << captureFrames_ << \" frames\" << std::endl;\n> >> +\n> >> +\t\tret = vim2m_->capture()->streamOff();\n> >> +\t\tif (ret)\n> > \n> > Error messages please.\n> \n> Done\n> \n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\tret = vim2m_->output()->streamOff();\n> >> +\t\tif (ret)\n> >> +\t\t\treturn TestFail;\n> >> +\n> >> +\t\treturn TestPass;\n> >> +\t}\n> >> +\n> >> +\tvoid cleanup()\n> >> +\t{\n> >> +\t\tdelete vim2m_;\n> >> +\t};\n> >> +\n> >> +private:\n> >> +\tstd::unique_ptr<DeviceEnumerator> enumerator_;\n> >> +\tstd::shared_ptr<MediaDevice> media_;\n> >> +\tV4L2M2MDevice *vim2m_;\n> >> +\n> >> +\tBufferPool capturePool_;\n> >> +\tBufferPool outputPool_;\n> >> +\n> >> +\tunsigned int outputFrames_;\n> >> +\tunsigned int captureFrames_;\n> >> +};\n> >> +\n> >> +TEST_REGISTER(V4L2M2MDeviceTest);","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 74B5560E2F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  9 Aug 2019 20:18:07 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BD118CC;\n\tFri,  9 Aug 2019 20:18:06 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1565374687;\n\tbh=jhuDQY/pfTWjvtXLo5cu9E26jOzlZOHQd6Imf6k/6GY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=sw1w9R9VHP3fgXiIA6p55Teq0MrynI8DxOuUVunxfYo6RewPwSmuwjJWvZRdNJ+I4\n\thttipfW+7V0Kq7YjeVeN4fGKV83+tnNMSQjT5Gq0HqmFX7uOvc0nRUtibyw5sGT8+j\n\tO2iL0Sp0dlL1jrXO1clWdUbYQ/hiNWaAy2TklBi4=","Date":"Fri, 9 Aug 2019 21:18:04 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190809181804.GE5007@pendragon.ideasonboard.com>","References":"<20190808151221.24254-1-kieran.bingham@ideasonboard.com>\n\t<20190808151221.24254-5-kieran.bingham@ideasonboard.com>\n\t<20190808212637.GG6055@pendragon.ideasonboard.com>\n\t<29c411cd-1d22-2a08-d387-5c01bf0c5e40@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<29c411cd-1d22-2a08-d387-5c01bf0c5e40@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/6] test: v4l2_videodevice: Add M2M\n\tdevice 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, 09 Aug 2019 18:18:07 -0000"}}]