Show a patch.

GET /api/patches/19692/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 19692,
    "url": "https://patchwork.libcamera.org/api/patches/19692/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/19692/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240313105645.120317-5-stefan.klug@ideasonboard.com>",
    "date": "2024-03-13T10:56:36",
    "name": "[04/12] libcamera: delayed_controls: Update unit tests to expected semantics",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "c67c051cac86b8c00493bda0cee3e159e7b4984b",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/19692/mbox/",
    "series": [
        {
            "id": 4219,
            "url": "https://patchwork.libcamera.org/api/series/4219/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4219",
            "date": "2024-03-13T10:56:32",
            "name": "Preparation for per-frame-controls and initial tests",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4219/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/19692/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/19692/checks/",
    "tags": {},
    "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 E44D8C32A3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 13 Mar 2024 10:57:06 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1181B62C8C;\n\tWed, 13 Mar 2024 11:57:01 +0100 (CET)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 69DAA62C87\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Mar 2024 11:56:53 +0100 (CET)",
            "from jasper.fritz.box (unknown\n\t[IPv6:2a00:6020:448c:6c00:9b07:31b5:38e1:e957])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F33FBA8F;\n\tWed, 13 Mar 2024 11:56:30 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"S5tSoRva\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710327391;\n\tbh=7oapYLMN7cyigWB9FuJ2msVMCOH06w430iE+QjjU9L0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=S5tSoRva1KXH5Dojug4RUYR8uz8UDR1iv/KD6Cm3YE5+coRLsS+wtr0ZjVSpXImqs\n\tRVTeCSnWC2UmKpWwuwK926zfSQHNBOZmGiCkzR5SabwaNqf3J0BaF42AKBAPNrvMjr\n\tBQzXH1HJILne+KBLojvMiYrlUy4pgWqDnHOzRY5g=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH 04/12] libcamera: delayed_controls: Update unit tests to\n\texpected semantics",
        "Date": "Wed, 13 Mar 2024 11:56:36 +0100",
        "Message-Id": "<20240313105645.120317-5-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.40.1",
        "In-Reply-To": "<20240313105645.120317-1-stefan.klug@ideasonboard.com>",
        "References": "<20240313105645.120317-1-stefan.klug@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "This patches changes the tests in a way DelayedControls is expected to\nwork. It does not require a interface change in DelayedControls.\n\nThe changes are:\n- It is expected that for every apply() there was a previous push().\n- When a control is pushed for frame 0, that request is not lost, but\n  applied as soon as possible\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n test/delayed_controls.cpp | 203 +++++++++++++++++++++++++++++---------\n 1 file changed, 156 insertions(+), 47 deletions(-)",
    "diff": "diff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp\nindex a8ce9828..e0634fa1 100644\n--- a/test/delayed_controls.cpp\n+++ b/test/delayed_controls.cpp\n@@ -84,11 +84,8 @@ protected:\n \t\tdev_->setControls(&ctrls);\n \t\tdelayed->reset();\n \n-\t\t/* Trigger the first frame start event */\n-\t\tdelayed->applyControls(0);\n-\n \t\t/* Test control without delay are set at once. */\n-\t\tfor (unsigned int i = 1; i < 100; i++) {\n+\t\tfor (unsigned int i = 0; i < 100; i++) {\n \t\t\tint32_t value = 100 + i;\n \n \t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value);\n@@ -121,25 +118,30 @@ protected:\n \t\tControlList ctrls;\n \n \t\t/* Reset control to value that will be first in test. */\n-\t\tint32_t expected = 4;\n-\t\tctrls.set(V4L2_CID_BRIGHTNESS, expected);\n+\t\tint32_t initial = 4;\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, initial);\n \t\tdev_->setControls(&ctrls);\n \t\tdelayed->reset();\n \n-\t\t/* Trigger the first frame start event */\n-\t\tdelayed->applyControls(0);\n+\t\t/* Push a request for frame 0 */\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, 10);\n+\t\tdelayed->push(ctrls);\n \n \t\t/* Test single control with delay. */\n-\t\tfor (unsigned int i = 1; i < 100; i++) {\n+\t\tfor (unsigned int i = 0; i < 100; i++) {\n \t\t\tint32_t value = 10 + i;\n+\t\t\tint32_t expected = i < 1 ? initial : value;\n \n-\t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value);\n+\t\t\t/* push the request for frame i+1 */\n+\t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value + 1);\n \t\t\tdelayed->push(ctrls);\n \n \t\t\tdelayed->applyControls(i);\n \n \t\t\tControlList result = delayed->get(i);\n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n+\t\t\tControlList ctrlsV4L = dev_->getControls({ V4L2_CID_BRIGHTNESS });\n+\t\t\tint32_t brightnessV4L = ctrlsV4L.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tif (brightness != expected) {\n \t\t\t\tcerr << \"Failed single control with delay\"\n \t\t\t\t     << \" frame \" << i\n@@ -149,7 +151,72 @@ protected:\n \t\t\t\treturn TestFail;\n \t\t\t}\n \n-\t\t\texpected = value;\n+\t\t\tif (i > 0 && brightnessV4L != value + 1) {\n+\t\t\t\tcerr << \"Failed single control with delay\"\n+\t\t\t\t     << \" frame \" << i\n+\t\t\t\t     << \" expected V4L \" << value + 1\n+\t\t\t\t     << \" got \" << brightnessV4L\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\t/* This fails on the old delayed controls implementation */\n+\tint singleControlWithDelayStartUp()\n+\t{\n+\t\tstd::unordered_map<uint32_t, DelayedControls::ControlParams> delays = {\n+\t\t\t{ V4L2_CID_BRIGHTNESS, { 1, false } },\n+\t\t};\n+\t\tstd::unique_ptr<DelayedControls> delayed =\n+\t\t\tstd::make_unique<DelayedControls>(dev_.get(), delays);\n+\t\tControlList ctrls;\n+\n+\t\t/* Reset control to value that will be first in test. */\n+\t\tint32_t initial = 4;\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, initial);\n+\t\tdev_->setControls(&ctrls);\n+\t\tdelayed->reset();\n+\n+\t\t/* push a request for frame 0 */\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, 10);\n+\t\tdelayed->push(ctrls);\n+\n+\t\t/* Test single control with delay. */\n+\t\tfor (unsigned int i = 0; i < 100; i++) {\n+\t\t\tint32_t value = 10 + i;\n+\t\t\tint32_t expected = i < 1 ? initial : value;\n+\n+\t\t\t/* push the request for frame i+1 */\n+\t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value + 1);\n+\t\t\tdelayed->push(ctrls);\n+\n+\t\t\tdelayed->applyControls(i);\n+\n+\t\t\tControlList result = delayed->get(i);\n+\t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n+\t\t\tControlList ctrlsV4L = dev_->getControls({ V4L2_CID_BRIGHTNESS });\n+\t\t\tint32_t brightnessV4L = ctrlsV4L.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n+\n+\t\t\tif (brightness != expected) {\n+\t\t\t\tcerr << \"Failed single control with delay start up\"\n+\t\t\t\t     << \" frame \" << i\n+\t\t\t\t     << \" expected \" << expected\n+\t\t\t\t     << \" got \" << brightness\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\n+\t\t\tif (i > 0 && brightnessV4L != value + 1) {\n+\t\t\t\tcerr << \"Failed single control with delay start up\"\n+\t\t\t\t     << \" frame \" << i\n+\t\t\t\t     << \" expected V4L \" << value + 1\n+\t\t\t\t     << \" got \" << brightnessV4L\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n \t\t}\n \n \t\treturn TestPass;\n@@ -157,7 +224,7 @@ protected:\n \n \tint dualControlsWithDelay()\n \t{\n-\t\tstatic const unsigned int maxDelay = 2;\n+\t\tstatic const int maxDelay = 2;\n \n \t\tstd::unordered_map<uint32_t, DelayedControls::ControlParams> delays = {\n \t\t\t{ V4L2_CID_BRIGHTNESS, { 1, false } },\n@@ -174,15 +241,21 @@ protected:\n \t\tdev_->setControls(&ctrls);\n \t\tdelayed->reset();\n \n-\t\t/* Trigger the first frame start event */\n-\t\tdelayed->applyControls(0);\n+\t\t/* push two requests into the queue */\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, 10);\n+\t\tctrls.set(V4L2_CID_CONTRAST, 10);\n+\t\tdelayed->push(ctrls);\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, 11);\n+\t\tctrls.set(V4L2_CID_CONTRAST, 11);\n+\t\tdelayed->push(ctrls);\n \n \t\t/* Test dual control with delay. */\n-\t\tfor (unsigned int i = 1; i < 100; i++) {\n+\t\tfor (unsigned int i = 0; i < 100; i++) {\n \t\t\tint32_t value = 10 + i;\n \n-\t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value);\n-\t\t\tctrls.set(V4L2_CID_CONTRAST, value + 1);\n+\t\t\t/* we are pushing 2 frames ahead */\n+\t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value + 2);\n+\t\t\tctrls.set(V4L2_CID_CONTRAST, value + 2);\n \t\t\tdelayed->push(ctrls);\n \n \t\t\tdelayed->applyControls(i);\n@@ -190,17 +263,32 @@ protected:\n \t\t\tControlList result = delayed->get(i);\n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tint32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>();\n-\t\t\tif (brightness != expected || contrast != expected + 1) {\n-\t\t\t\tcerr << \"Failed dual controls\"\n-\t\t\t\t     << \" frame \" << i\n-\t\t\t\t     << \" brightness \" << brightness\n-\t\t\t\t     << \" contrast \" << contrast\n-\t\t\t\t     << \" expected \" << expected\n-\t\t\t\t     << endl;\n-\t\t\t\treturn TestFail;\n-\t\t\t}\n \n-\t\t\texpected = i < maxDelay ? expected : value - 1;\n+\t\t\tControlList ctrlsV4L = dev_->getControls({ V4L2_CID_BRIGHTNESS, V4L2_CID_CONTRAST });\n+\t\t\tint32_t brightnessV4L = ctrlsV4L.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n+\t\t\tint32_t contrastV4L = ctrlsV4L.get(V4L2_CID_CONTRAST).get<int32_t>();\n+\n+\t\t\tif (i > maxDelay) {\n+\t\t\t\tif (brightness != value || contrast != value) {\n+\t\t\t\t\tcerr << \"Failed dual controls\"\n+\t\t\t\t\t     << \" frame \" << i\n+\t\t\t\t\t     << \" brightness \" << brightness\n+\t\t\t\t\t     << \" contrast \" << contrast\n+\t\t\t\t\t     << \" expected \" << value\n+\t\t\t\t\t     << endl;\n+\t\t\t\t\treturn TestFail;\n+\t\t\t\t}\n+\t\t\t\tif (brightnessV4L != value + 1 || contrastV4L != value + maxDelay) {\n+\t\t\t\t\tcerr << \"Failed dual controls\"\n+\t\t\t\t\t     << \" frame \" << i\n+\t\t\t\t\t     << \" brightnessV4L \" << brightnessV4L\n+\t\t\t\t\t     << \" expected \" << value + 1\n+\t\t\t\t\t     << \" contrastV4L \" << contrastV4L\n+\t\t\t\t\t     << \" expected \" << value + maxDelay\n+\t\t\t\t\t     << endl;\n+\t\t\t\t\treturn TestFail;\n+\t\t\t\t}\n+\t\t\t}\n \t\t}\n \n \t\treturn TestPass;\n@@ -208,7 +296,7 @@ protected:\n \n \tint dualControlsMultiQueue()\n \t{\n-\t\tstatic const unsigned int maxDelay = 2;\n+\t\tstatic const int maxDelay = 2;\n \n \t\tstd::unordered_map<uint32_t, DelayedControls::ControlParams> delays = {\n \t\t\t{ V4L2_CID_BRIGHTNESS, { 1, false } },\n@@ -218,22 +306,19 @@ protected:\n \t\t\tstd::make_unique<DelayedControls>(dev_.get(), delays);\n \t\tControlList ctrls;\n \n-\t\t/* Reset control to value that will be first two frames in test. */\n-\t\tint32_t expected = 100;\n-\t\tctrls.set(V4L2_CID_BRIGHTNESS, expected);\n-\t\tctrls.set(V4L2_CID_CONTRAST, expected);\n+\t\t/* Reset control to a value that will be first two frames in test. */\n+\t\tint32_t initial = 100;\n+\t\tctrls.set(V4L2_CID_BRIGHTNESS, initial);\n+\t\tctrls.set(V4L2_CID_CONTRAST, initial);\n \t\tdev_->setControls(&ctrls);\n \t\tdelayed->reset();\n \n-\t\t/* Trigger the first frame start event */\n-\t\tdelayed->applyControls(0);\n-\n \t\t/*\n-\t\t * Queue all controls before any fake frame start. Note we\n+\t\t * Queue all controls before applyControls(). Note we\n \t\t * can't queue up more then the delayed controls history size\n-\t\t * which is 16. Where one spot is used by the reset control.\n+\t\t * which is 16.\n \t\t */\n-\t\tfor (unsigned int i = 0; i < 15; i++) {\n+\t\tfor (unsigned int i = 0; i < 14; i++) {\n \t\t\tint32_t value = 10 + i;\n \n \t\t\tctrls.set(V4L2_CID_BRIGHTNESS, value);\n@@ -241,9 +326,9 @@ protected:\n \t\t\tdelayed->push(ctrls);\n \t\t}\n \n-\t\t/* Process all queued controls. */\n-\t\tfor (unsigned int i = 1; i < 16; i++) {\n-\t\t\tint32_t value = 10 + i - 1;\n+\t\t/* Process 2 frames less than queued, so that the V4L controls are correct */\n+\t\tfor (unsigned int i = 0; i < 12; i++) {\n+\t\t\tint32_t expected = i < maxDelay ? initial : 10 + i;\n \n \t\t\tdelayed->applyControls(i);\n \n@@ -251,6 +336,11 @@ protected:\n \n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tint32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>();\n+\n+\t\t\tControlList ctrlsV4L = dev_->getControls({ V4L2_CID_BRIGHTNESS, V4L2_CID_CONTRAST });\n+\t\t\tint32_t brightnessV4L = ctrlsV4L.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n+\t\t\tint32_t contrastV4L = ctrlsV4L.get(V4L2_CID_CONTRAST).get<int32_t>();\n+\n \t\t\tif (brightness != expected || contrast != expected) {\n \t\t\t\tcerr << \"Failed multi queue\"\n \t\t\t\t     << \" frame \" << i\n@@ -261,7 +351,17 @@ protected:\n \t\t\t\treturn TestFail;\n \t\t\t}\n \n-\t\t\texpected = i < maxDelay ? expected : value - 1;\n+\t\t\t/* Check v4l values after they've settled */\n+\t\t\tif (i >= maxDelay && (brightnessV4L != expected + 1 || contrastV4L != expected + maxDelay)) {\n+\t\t\t\tcerr << \"Failed multi queue\"\n+\t\t\t\t     << \" frame \" << i\n+\t\t\t\t     << \" brightnessV4L \" << brightnessV4L\n+\t\t\t\t     << \" expected \" << expected + 1\n+\t\t\t\t     << \" contrastV4L \" << contrastV4L\n+\t\t\t\t     << \" expected \" << expected + maxDelay\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n \t\t}\n \n \t\treturn TestPass;\n@@ -269,27 +369,36 @@ protected:\n \n \tint run() override\n \t{\n-\t\tint ret;\n+\t\tint ret = 0;\n+\t\tbool failed = false;\n \n \t\t/* Test single control without delay. */\n \t\tret = singleControlNoDelay();\n \t\tif (ret)\n-\t\t\treturn ret;\n+\t\t\tfailed = true;\n \n \t\t/* Test single control with delay. */\n \t\tret = singleControlWithDelay();\n \t\tif (ret)\n-\t\t\treturn ret;\n+\t\t\tfailed = true;\n+\n+\t\t/* Test single control with delay. */\n+\t\tret = singleControlWithDelayStartUp();\n+\t\tif (ret)\n+\t\t\tfailed = true;\n \n \t\t/* Test dual controls with different delays. */\n \t\tret = dualControlsWithDelay();\n \t\tif (ret)\n-\t\t\treturn ret;\n+\t\t\tfailed = true;\n \n \t\t/* Test control values produced faster than consumed. */\n \t\tret = dualControlsMultiQueue();\n \t\tif (ret)\n-\t\t\treturn ret;\n+\t\t\tfailed = true;\n+\n+\t\tif (failed)\n+\t\t\treturn TestFail;\n \n \t\treturn TestPass;\n \t}\n",
    "prefixes": [
        "04/12"
    ]
}