Show a patch.

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

{
    "id": 2311,
    "url": "https://patchwork.libcamera.org/api/patches/2311/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2311/",
    "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": "<20191108205409.18845-16-laurent.pinchart@ideasonboard.com>",
    "date": "2019-11-08T20:54:00",
    "name": "[libcamera-devel,v2,15/24] test: Add ByteStreamBuffer test",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "65c90e666099f60a05273238f2f1c595892caba1",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2311/mbox/",
    "series": [
        {
            "id": 568,
            "url": "https://patchwork.libcamera.org/api/series/568/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=568",
            "date": "2019-11-08T20:53:45",
            "name": "Control serialization and IPA C API",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/568/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2311/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2311/checks/",
    "tags": {},
    "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 CA96D6153D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Nov 2019 21:54:27 +0100 (CET)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 776C331D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Nov 2019 21:54:27 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1573246467;\n\tbh=/o4v3ajYRaJ6lHjiWSB9hct6HF2EVFD4F9/qXSXbj9E=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=i6/pLUgwJTlrVd+hnKXbhNRLFhSMRvEapF9SHjiXd+Y8W1UoB1S5xcNFsTJRsJeQi\n\tCa12lBScA1o+kI2x/Fy0QnOXqo4bUdOik5LUxfIJP2mLtAvrI5+emhF9ZoBcrMhv6s\n\tXO3cUw/f3JjYdX7Def6h0jJWP2YifluBhzfLtZvE=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  8 Nov 2019 22:54:00 +0200",
        "Message-Id": "<20191108205409.18845-16-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.23.0",
        "In-Reply-To": "<20191108205409.18845-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20191108205409.18845-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 15/24] test: Add ByteStreamBuffer test",
        "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>",
        "X-List-Received-Date": "Fri, 08 Nov 2019 20:54:29 -0000"
    },
    "content": "The test exercises the API of the ByteStreamBuffer class in both read\nand write modes, including carve out buffers.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n test/byte-stream-buffer.cpp | 172 ++++++++++++++++++++++++++++++++++++\n test/meson.build            |   1 +\n 2 files changed, 173 insertions(+)\n create mode 100644 test/byte-stream-buffer.cpp",
    "diff": "diff --git a/test/byte-stream-buffer.cpp b/test/byte-stream-buffer.cpp\nnew file mode 100644\nindex 000000000000..bc1d462ebf6f\n--- /dev/null\n+++ b/test/byte-stream-buffer.cpp\n@@ -0,0 +1,172 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * byte_stream_buffer.cpp - ByteStreamBuffer tests\n+ */\n+\n+#include <array>\n+#include <iostream>\n+\n+#include \"byte_stream_buffer.h\"\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class ByteStreamBufferTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tstd::array<uint8_t, 100> data;\n+\t\tunsigned int i;\n+\t\tuint32_t value;\n+\t\tint ret;\n+\n+\t\t/*\n+\t\t * Write mode.\n+\t\t */\n+\t\tByteStreamBuffer wbuf(data.data(), data.size());\n+\n+\t\tif (wbuf.base() != data.data() || wbuf.size() != data.size() ||\n+\t\t    wbuf.offset() != 0 || wbuf.overflow()) {\n+\t\t\tcerr << \"Write buffer incorrectly constructed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test write. */\n+\t\tvalue = 0x12345678;\n+\t\tret = wbuf.write(&value);\n+\t\tif (ret || wbuf.offset() != 4 || wbuf.overflow() ||\n+\t\t    *reinterpret_cast<uint32_t *>(data.data()) != 0x12345678) {\n+\t\t\tcerr << \"Write failed on write buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test write carve out. */\n+\t\tByteStreamBuffer wco = wbuf.carveOut(10);\n+\t\tif (wco.base() != wbuf.base() + 4 || wco.size() != 10 ||\n+\t\t    wco.offset() != 0 || wco.overflow() || wbuf.offset() != 14 ||\n+\t\t    wbuf.overflow()) {\n+\t\t\tcerr << \"Carving out write buffer failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test write on the carved out buffer. */\n+\t\tvalue = 0x87654321;\n+\t\tret = wco.write(&value);\n+\t\tif (ret || wco.offset() != 4 || wco.overflow() ||\n+\t\t    *reinterpret_cast<uint32_t *>(data.data() + 4) != 0x87654321) {\n+\t\t\tcerr << \"Write failed on carve out buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (wbuf.offset() != 14 || wbuf.overflow()) {\n+\t\t\tcerr << \"Write on carve out buffer modified write buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read, this should fail. */\n+\t\tret = wbuf.read(&value);\n+\t\tif (!ret || wbuf.overflow()) {\n+\t\t\tcerr << \"Read should fail on write buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test overflow on carved out buffer. */\n+\t\tfor (i = 0; i < 2; ++i) {\n+\t\t\tret = wco.write(&value);\n+\t\t\tif (ret < 0)\n+\t\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (i != 1 || !wco.overflow() || !wbuf.overflow()) {\n+\t\t\tcerr << \"Write on carve out buffer failed to overflow\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test reinitialization of the buffer. */\n+\t\twbuf = ByteStreamBuffer(data.data(), data.size());\n+\t\tif (wbuf.overflow() || wbuf.base() != data.data() ||\n+\t\t    wbuf.offset() != 0) {\n+\t\t\tcerr << \"Write buffer reinitialization failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/*\n+\t\t * Read mode.\n+\t\t */\n+\t\tByteStreamBuffer rbuf(const_cast<const uint8_t *>(data.data()),\n+\t\t\t\t      data.size());\n+\n+\t\tif (rbuf.base() != data.data() || rbuf.size() != data.size() ||\n+\t\t    rbuf.offset() != 0 || rbuf.overflow()) {\n+\t\t\tcerr << \"Read buffer incorrectly constructed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read. */\n+\t\tvalue = 0;\n+\t\tret = rbuf.read(&value);\n+\t\tif (ret || rbuf.offset() != 4 || rbuf.overflow() ||\n+\t\t    value != 0x12345678) {\n+\t\t\tcerr << \"Write failed on write buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read carve out. */\n+\t\tByteStreamBuffer rco = rbuf.carveOut(10);\n+\t\tif (rco.base() != rbuf.base() + 4 || rco.size() != 10 ||\n+\t\t    rco.offset() != 0 || rco.overflow() || rbuf.offset() != 14 ||\n+\t\t    rbuf.overflow()) {\n+\t\t\tcerr << \"Carving out read buffer failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test read on the carved out buffer. */\n+\t\tvalue = 0;\n+\t\tret = rco.read(&value);\n+\t\tif (ret || rco.offset() != 4 || rco.overflow() || value != 0x87654321) {\n+\t\t\tcerr << \"Read failed on carve out buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (rbuf.offset() != 14 || rbuf.overflow()) {\n+\t\t\tcerr << \"Read on carve out buffer modified read buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test write, this should fail. */\n+\t\tret = rbuf.write(&value);\n+\t\tif (!ret || rbuf.overflow()) {\n+\t\t\tcerr << \"Write should fail on read buffer\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test overflow on carved out buffer. */\n+\t\tfor (i = 0; i < 2; ++i) {\n+\t\t\tret = rco.read(&value);\n+\t\t\tif (ret < 0)\n+\t\t\t\tbreak;\n+\t\t}\n+\n+\t\tif (i != 1 || !rco.overflow() || !rbuf.overflow()) {\n+\t\t\tcerr << \"Read on carve out buffer failed to overflow\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Test reinitialization of the buffer. */\n+\t\trbuf = ByteStreamBuffer(const_cast<const uint8_t *>(data.data()),\n+\t\t\t\t\tdata.size());\n+\t\tif (rbuf.overflow() || rbuf.base() != data.data() ||\n+\t\t    rbuf.offset() != 0) {\n+\t\t\tcerr << \"Read buffer reinitialization failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(ByteStreamBufferTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex cf5eb84d20b2..adb5b29e69f3 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -19,6 +19,7 @@ public_tests = [\n ]\n \n internal_tests = [\n+    ['byte-stream-buffer',              'byte-stream-buffer.cpp'],\n     ['camera-sensor',                   'camera-sensor.cpp'],\n     ['event',                           'event.cpp'],\n     ['event-dispatcher',                'event-dispatcher.cpp'],\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "15/24"
    ]
}