[{"id":22436,"web_url":"https://patchwork.libcamera.org/comment/22436/","msgid":"<YjxvCYHjGE0imp2H@pendragon.ideasonboard.com>","date":"2022-03-24T13:15:53","subject":"Re: [libcamera-devel] [PATCH] test: v4l2_videodevice: Verify the\n\tDequeue Watchdog","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, Mar 24, 2022 at 12:54:44PM +0000, Kieran Bingham via libcamera-devel wrote:\n> Add a test that captures 5 frames, with a short (5ms) watchdog.\n> The default framerate of the VIMC pipeline should ensure that\n> we never meet this watchdog, and the timeout should activate.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  test/v4l2_videodevice/dequeue_watchdog.cpp | 100 +++++++++++++++++++++\n>  test/v4l2_videodevice/meson.build          |   1 +\n>  2 files changed, 101 insertions(+)\n>  create mode 100644 test/v4l2_videodevice/dequeue_watchdog.cpp\n> \n> diff --git a/test/v4l2_videodevice/dequeue_watchdog.cpp b/test/v4l2_videodevice/dequeue_watchdog.cpp\n> new file mode 100644\n> index 000000000000..db0c65ff482e\n> --- /dev/null\n> +++ b/test/v4l2_videodevice/dequeue_watchdog.cpp\n> @@ -0,0 +1,100 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Ideas on Board Oy.\n> + *\n> + * libcamera V4L2 dequeue watchdog test\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include <libcamera/base/event_dispatcher.h>\n> +#include <libcamera/base/thread.h>\n> +#include <libcamera/base/timer.h>\n> +\n> +#include <libcamera/framebuffer.h>\n> +\n> +#include \"v4l2_videodevice_test.h\"\n> +\n> +using namespace std::chrono_literals;\n> +using namespace libcamera;\n\nI've recently sent a patch that sorts (some of) the tests to use\nalphabetical order for the using expressions, could you swap those ?\n\n> +\n> +class DequeueWatchdogTest : public V4L2VideoDeviceTest\n> +{\n> +public:\n> +\tDequeueWatchdogTest()\n> +\t\t: V4L2VideoDeviceTest(\"vimc\", \"Raw Capture 0\"), frames(0), barks(0) {}\n> +\n> +\tvoid receiveBuffer(FrameBuffer *buffer)\n> +\t{\n> +\t\tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n> +\t\t\treturn;\n> +\n> +\t\tstd::cout << \"Buffer received\" << std::endl;\n> +\t\tframes++;\n> +\n> +\t\t/* Requeue the buffer for further use. */\n> +\t\tcapture_->queueBuffer(buffer);\n> +\t}\n> +\n> +\tvoid barkCounter()\n> +\t{\n> +\t\tstd::cout << \"Watchdog is barking\" << std::endl;\n> +\t\tbarks++;\n> +\t}\n\nThose two functions can be private.\n\n> +\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tconst unsigned int bufferCount = 8;\n\nconstexpr\n\n> +\n> +\t\tEventDispatcher *dispatcher = Thread::current()->eventDispatcher();\n> +\t\tTimer timeout;\n> +\n> +\t\tint ret = capture_->allocateBuffers(bufferCount, &buffers_);\n> +\t\tif (ret < 0)\n> +\t\t\treturn TestFail;\n> +\n> +\t\tcapture_->dequeueTimeout.connect(this, &DequeueWatchdogTest::barkCounter);\n> +\t\tcapture_->setDequeueTimeout(5ms);\n> +\n> +\t\tcapture_->bufferReady.connect(this, &DequeueWatchdogTest::receiveBuffer);\n> +\n> +\t\tfor (const std::unique_ptr<FrameBuffer> &buffer : buffers_) {\n> +\t\t\tif (capture_->queueBuffer(buffer.get())) {\n> +\t\t\t\tstd::cout << \"Failed to queue buffer\" << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\t\t}\n> +\n> +\t\tret = capture_->streamOn();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n> +\n> +\t\ttimeout.start(5s);\n> +\t\twhile (timeout.isRunning()) {\n> +\t\t\tdispatcher->processEvents();\n> +\t\t\tif (frames > 5)\n> +\t\t\t\tbreak;\n> +\t\t}\n> +\n> +\t\tstd::cout << \"Processed \" << frames << \" frames and heard \"\n> +\t\t\t  << barks << \" barks\" << std::endl;\n> +\n> +\t\tif (barks < 1) {\n\n\tif (!barks) {\n\n> +\t\t\tstd::cout << \"Failed to hear any barks.\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tret = capture_->streamOff();\n> +\t\tif (ret)\n> +\t\t\treturn TestFail;\n\nYou could skip the error check as it's not the point of this test.\n\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +private:\n> +\tunsigned int frames;\n> +\tunsigned int barks;\n\nframes_ and barks_.\n\n> +};\n> +\n> +TEST_REGISTER(DequeueWatchdogTest)\n> diff --git a/test/v4l2_videodevice/meson.build b/test/v4l2_videodevice/meson.build\n> index 643f82edce5e..7a26f53d106a 100644\n> --- a/test/v4l2_videodevice/meson.build\n> +++ b/test/v4l2_videodevice/meson.build\n> @@ -6,6 +6,7 @@ v4l2_videodevice_tests = [\n>      ['double_open',         'double_open.cpp'],\n>      ['controls',            'controls.cpp'],\n>      ['formats',             'formats.cpp'],\n> +    ['dequeue_watchdog',    'dequeue_watchdog.cpp'],\n\nI wouldn't mind if you sorted the array, while at it.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>      ['request_buffers',     'request_buffers.cpp'],\n>      ['buffer_cache',        'buffer_cache.cpp'],\n>      ['stream_on_off',       'stream_on_off.cpp'],","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C38F7C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Mar 2022 13:15:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4762960397;\n\tThu, 24 Mar 2022 14:15:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E8E8460397\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Mar 2022 14:15:54 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 569B31844;\n\tThu, 24 Mar 2022 14:15:54 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648127756;\n\tbh=Z9pZKwEPKTds8AZR5lsS1nzyWjym9k1HbGxzKsxArJg=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=KppI0+1ap7OVqZBEsnXlJO6mj7UmFXY4dkPbU+0blfMLS2zXQ+loKGYJqMs3x9Nv7\n\tM63j+0YzASqAtJNcl0MT/KuhWIxmbEq5Kwn5H47kQ8pFoTXSsP3MF9QAfGmagdItyp\n\tzLY5Ng2o7U0J6jFutZyc8K3L1AsuPHuRCLMWKxPZhZdW32GhUWGAGsjYb54dYKY5h3\n\tJhetQmqKNcX/lp0TpTG2b4F7Wce+sB7e/VQ08ieTme8fA99gZosVgFFlp8ThN2EMoE\n\tAI2k3fedkP1URM+6fzC8TGrx0/u8kO2UUtZUsqM7ByTfFQYNWvggltg6K5GpJj4Fn4\n\trP90s33z+50Ew==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648127754;\n\tbh=Z9pZKwEPKTds8AZR5lsS1nzyWjym9k1HbGxzKsxArJg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=drbZUbYxJ8MO8Gr4mdE2EfvgOaAGjTkHSP/z8d+Uj4PbGyHow7CL/x1GgzTiyEkNS\n\t94W8JxbPBjJmItQXUR0DLqyWbYOrmHDd/+B8AqFx2DsCwg+4+GMkSuLvJUyR0Mp+eE\n\tVe4NBGF360ye05IQRPS6UTB2FGXyysnQJ5J0Tv9I="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"drbZUbYx\"; dkim-atps=neutral","Date":"Thu, 24 Mar 2022 15:15:53 +0200","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<YjxvCYHjGE0imp2H@pendragon.ideasonboard.com>","References":"<20220324093409.29247-1-naush@raspberrypi.com>\n\t<20220324125444.1389060-1-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220324125444.1389060-1-kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] test: v4l2_videodevice: Verify the\n\tDequeue Watchdog","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]