Show a patch.

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

{
    "id": 14399,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14399/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14399/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20211028111520.256612-5-jacopo@jmondi.org>",
    "date": "2021-10-28T11:15:14",
    "name": "[libcamera-devel,04/10] test: Add test for the Fence class",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "2fad11577999cfeb1a33e015872de611748e0216",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/14399/mbox/",
    "series": [
        {
            "id": 2674,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2674/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2674",
            "date": "2021-10-28T11:15:10",
            "name": "libcamera: Introduce Fence support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2674/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14399/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14399/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 8A7C4C324E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 28 Oct 2021 11:14:47 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DDD2360334;\n\tThu, 28 Oct 2021 13:14:46 +0200 (CEST)",
            "from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 63722600BA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Oct 2021 13:14:39 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby relay9-d.mail.gandi.net (Postfix) with ESMTPSA id E8CD5FF80B;\n\tThu, 28 Oct 2021 11:14:38 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 28 Oct 2021 13:15:14 +0200",
        "Message-Id": "<20211028111520.256612-5-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.33.1",
        "In-Reply-To": "<20211028111520.256612-1-jacopo@jmondi.org>",
        "References": "<20211028111520.256612-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 04/10] test: Add test for the Fence class",
        "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": "Add a test for the Fence class by testing completion and expiration of\na Fence and testing that move semantic is implemented correctly.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n test/fence.cpp   | 148 +++++++++++++++++++++++++++++++++++++++++++++++\n test/meson.build |   1 +\n 2 files changed, 149 insertions(+)\n create mode 100644 test/fence.cpp",
    "diff": "diff --git a/test/fence.cpp b/test/fence.cpp\nnew file mode 100644\nindex 000000000000..9fb92b1c250b\n--- /dev/null\n+++ b/test/fence.cpp\n@@ -0,0 +1,148 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * fence.cpp - Fence test\n+ */\n+\n+#include <iostream>\n+#include <sys/eventfd.h>\n+#include <unistd.h>\n+\n+#include <libcamera/base/event_dispatcher_poll.h>\n+#include <libcamera/base/thread.h>\n+#include <libcamera/base/timer.h>\n+#include <libcamera/internal/fence.h>\n+\n+#include \"test.h\"\n+\n+using namespace libcamera;\n+using namespace std;\n+\n+class FenceTest : public Test\n+{\n+protected:\n+\tint init();\n+\tint run();\n+\tvoid cleanup();\n+\n+private:\n+\tvoid timeout();\n+\tvoid completed();\n+\n+\tint eventfd_;\n+\tTimer timer_;\n+\tEventDispatcher *dispatcher;\n+\tFence *fence_;\n+};\n+\n+int FenceTest::init()\n+{\n+\ttimer_.timeout.connect(this, &FenceTest::timeout);\n+\tdispatcher = Thread::current()->eventDispatcher();\n+\n+\teventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);\n+\tif (eventfd_ < 0) {\n+\t\tcerr << \"Unable to create eventfd\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tfence_ = new Fence(eventfd_);\n+\tif (!eventfd_) {\n+\t\tcerr << \"Fence creation should not reset the file descriptor\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (fence_->fd() != eventfd_) {\n+\t\tcerr << \"Fence file descriptor should not be duplicated\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tfence_->complete.connect(this, &FenceTest::completed);\n+\n+\treturn 0;\n+}\n+\n+void FenceTest::timeout()\n+{\n+\tuint64_t value = 1;\n+\tssize_t ret = write(eventfd_, &value, sizeof(value));\n+\tif (ret != sizeof(value))\n+\t\tcerr << \"Failed to write to event fd\" << endl;\n+\n+\t/* Let the fence complete on the eventfd read event. */\n+\tdispatcher->processEvents();\n+}\n+\n+void FenceTest::completed()\n+{\n+\tif (fence_->expired())\n+\t\treturn;\n+\n+\tuint64_t value;\n+\tssize_t ret = read(eventfd_, &value, sizeof(value));\n+\tif (ret != sizeof(value))\n+\t\tcerr << \"Failed to read from event fd\" << endl;\n+}\n+\n+int FenceTest::run()\n+{\n+\t/* Activate the fence and schedule a wake-up before it expires. */\n+\tfence_->enable();\n+\ttimer_.start(50);\n+\n+\tdispatcher->processEvents();\n+\n+\tif (fence_->expired()) {\n+\t\tcerr << \"Fence should not have expired\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (!fence_->completed()) {\n+\t\tcerr << \"Fence should have completed\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/* Now let the fence expire. */\n+\tfence_->enable();\n+\tdispatcher->processEvents();\n+\n+\tif (fence_->completed()) {\n+\t\tcerr << \"Fence should not have completed\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (!fence_->expired()) {\n+\t\tcerr << \"Fence should have expired\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\t/*\n+\t * Test fence move semantic.\n+\t *\n+\t * Create two temporary fences and verify we can move them.\n+\t */\n+\tFence fence1(eventfd_, 500);\n+\tFence fence2(0, 500);\n+\tfence2 = std::move(fence1);\n+\n+\tif (fence1.fd() != -1) {\n+\t\tcerr << \"A moved fence should have an invalid fd\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\tif (fence2.fd() != eventfd_ || fence2.timeout() != 500) {\n+\t\tcerr << \"Faile to move fence\" << endl;\n+\t\treturn TestFail;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void FenceTest::cleanup()\n+{\n+\tclose(eventfd_);\n+\tdelete fence_;\n+}\n+\n+TEST_REGISTER(FenceTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex d0466f17d7b6..377e392628bf 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -40,6 +40,7 @@ internal_tests = [\n     ['event-dispatcher',                'event-dispatcher.cpp'],\n     ['event-thread',                    'event-thread.cpp'],\n     ['file',                            'file.cpp'],\n+    ['fence',                           'fence.cpp'],\n     ['file-descriptor',                 'file-descriptor.cpp'],\n     ['flags',                           'flags.cpp'],\n     ['hotplug-cameras',                 'hotplug-cameras.cpp'],\n",
    "prefixes": [
        "libcamera-devel",
        "04/10"
    ]
}