Show a patch.

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

{
    "id": 4030,
    "url": "https://patchwork.libcamera.org/api/patches/4030/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/4030/",
    "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": "<20200611171528.9381-7-email@uajain.com>",
    "date": "2020-06-11T17:16:08",
    "name": "[libcamera-devel,v4,6/6] tests: Introduce hotplug hot-unplug unit test",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "4456ec492d8cf4875ec64ff3db22753d7e815e9d",
    "submitter": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/people/1/?format=api",
        "name": "Umang Jain",
        "email": "email@uajain.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/4030/mbox/",
    "series": [
        {
            "id": 993,
            "url": "https://patchwork.libcamera.org/api/series/993/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=993",
            "date": "2020-06-11T17:16:02",
            "name": "Introduce UVC hotplugging support",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/993/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/4030/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/4030/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<bounces+15657259-5c31-libcamera-devel=lists.libcamera.org@em7280.uajain.com>",
        "Received": [
            "from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 51BAC61167\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jun 2020 19:16:09 +0200 (CEST)",
            "by filterdrecv-p3iad2-784dbb6bd8-hcng7 with SMTP id\n\tfilterdrecv-p3iad2-784dbb6bd8-hcng7-18-5EE266D7-DD\n\t2020-06-11 17:16:08.22047431 +0000 UTC m=+680961.308968930",
            "from mail.uajain.com (unknown)\n\tby ismtpd0008p1maa1.sendgrid.net (SG) with ESMTP\n\tid Pfb7fKVHRxi6I5sRD3YkMQ Thu, 11 Jun 2020 17:16:07.475 +0000 (UTC)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=uajain.com\n\theader.i=@uajain.com header.b=\"MLvjpl9k\"; \n\tdkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com;\n\th=from:subject:in-reply-to:references:mime-version:to:cc:\n\tcontent-transfer-encoding:content-type;\n\ts=s1; bh=BemP8mCiSuDiWTKrP7yL6afMkUnpjFUGlYIFEVEdddU=;\n\tb=MLvjpl9kjlza2Iy4nM/mQQ483uKT6+qClWBfu+oVNc50PH3WB9zKTVTnAucw5Xr9NBDL\n\tD6tqouVnW5bQATFqowVniHR6nCEytdnX3lmj79v/px3JVVBmpMma9efJr6i3YN8rVA5thl\n\tZqb3tLiVTmUgVcSuuoZconf7Wkw8YVWwk=",
        "From": "Umang Jain <email@uajain.com>",
        "Date": "Thu, 11 Jun 2020 17:16:08 +0000 (UTC)",
        "Message-Id": "<20200611171528.9381-7-email@uajain.com>",
        "In-Reply-To": "<20200611171528.9381-1-email@uajain.com>",
        "References": "<20200611171528.9381-1-email@uajain.com>",
        "Mime-Version": "1.0",
        "X-SG-EID": "1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcYDswUgqLHty1lirORaEntR95UyLLITGvBSHaUC4UjCvx2dCMfy3hTqgrHZ5ipiSUrCjpIrCCy7Qh//02WzlWEIfZvUgptFn09BhgLNaxQw8M8wHM6Zp0mHT8kaWM5v4ceJLBZ4db5ezZkpdmTwO67bGgf7EsIAJ9theFlLxjT8ZwRScRPCXYC2IVBPZPL4CF0yO7OkTG0mj+2f+XG5on3A==",
        "To": "laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org",
        "Content-Transfer-Encoding": "7bit",
        "Content-Type": "text/plain; charset=us-ascii",
        "Subject": "[libcamera-devel] [PATCH v4 6/6] tests: Introduce hotplug\n\thot-unplug unit 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": "Thu, 11 Jun 2020 17:16:09 -0000"
    },
    "content": "This test checks the code-paths for camera's hotplugged and\nunplugged support. It is based on bind/unbind of a UVC device\nfrom sysfs. Hence, this test requires root permissions to run\nand should have at least one already bound UVC device present\nin the system.\n\nSigned-off-by: Umang Jain <email@uajain.com>\n---\n test/hotplug-cameras.cpp | 124 +++++++++++++++++++++++++++++++++++++++\n test/meson.build         |   1 +\n 2 files changed, 125 insertions(+)\n create mode 100644 test/hotplug-cameras.cpp",
    "diff": "diff --git a/test/hotplug-cameras.cpp b/test/hotplug-cameras.cpp\nnew file mode 100644\nindex 0000000..07500fc\n--- /dev/null\n+++ b/test/hotplug-cameras.cpp\n@@ -0,0 +1,124 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Umang Jain <email@uajain.com>\n+ *\n+ * hotplug-cameras.cpp - Test cameraAdded/cameraRemoved signals in CameraManager\n+ */\n+\n+#include <dirent.h>\n+#include <fstream>\n+#include <iostream>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/camera_manager.h>\n+#include <libcamera/event_dispatcher.h>\n+#include <libcamera/timer.h>\n+\n+#include \"libcamera/internal/file.h\"\n+#include \"libcamera/internal/thread.h\"\n+\n+#include \"test.h\"\n+\n+using namespace libcamera;\n+\n+class HotplugTest : public Test\n+{\n+protected:\n+\tvoid cameraAddedHandler(std::shared_ptr<Camera> cam)\n+\t{\n+\t\tcameraAdded_ = true;\n+\t}\n+\n+\tvoid cameraRemovedHandler(std::shared_ptr<Camera> cam)\n+\t{\n+\t\tcameraRemoved_ = true;\n+\t}\n+\n+\tint init()\n+\t{\n+\t\tif (!File::exists(\"/sys/module/uvcvideo\")) {\n+\t\t\tstd::cout << \"uvcvideo driver is not loaded, skipping\" << std::endl;\n+\t\t\treturn TestSkip;\n+\t\t}\n+\n+\t\tif (geteuid() != 0) {\n+\t\t\tstd::cout << \"This test requires root permissions, skipping\" << std::endl;\n+\t\t\treturn TestSkip;\n+\t\t}\n+\n+\t\tcm_ = new CameraManager();\n+\t\tif (cm_->start()) {\n+\t\t\tstd::cout << \"Failed to start camera manager\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tcameraAdded_ = false;\n+\t\tcameraRemoved_ = false;\n+\n+\t\tcm_->cameraAdded.connect(this, &HotplugTest::cameraAddedHandler);\n+\t\tcm_->cameraRemoved.connect(this, &HotplugTest::cameraRemovedHandler);\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tDIR *dir;\n+\t\tstruct dirent *dirent;\n+\t\tstd::string uvcDeviceDir;\n+\n+\t\tdir = opendir(uvcDriverDir_.c_str());\n+\t\t/* Find a UVC device directory, which we can bind/unbind. */\n+\t\twhile ((dirent = readdir(dir)) != nullptr) {\n+\t\t\tif (!File::exists(uvcDriverDir_ + dirent->d_name + \"/video4linux\"))\n+\t\t\t\tcontinue;\n+\n+\t\t\tuvcDeviceDir = dirent->d_name;\n+\t\t\tbreak;\n+\t\t}\n+\t\tclosedir(dir);\n+\n+\t\t/* If no UVC device found, skip the test. */\n+\t\tif (uvcDeviceDir.empty())\n+\t\t\treturn TestSkip;\n+\n+\t\t/* Unbind a camera and process events. */\n+\t\tstd::ofstream(uvcDriverDir_ + \"unbind\", std::ios::binary)\n+\t\t\t<< uvcDeviceDir;\n+\t\tTimer timer;\n+\t\ttimer.start(1000);\n+\t\twhile (timer.isRunning() && !cameraRemoved_)\n+\t\t\tThread::current()->eventDispatcher()->processEvents();\n+\t\tif (!cameraRemoved_)\n+\t\t\treturn TestFail;\n+\n+\t\t/* Bind the camera again and process events. */\n+\t\tstd::ofstream(uvcDriverDir_ + \"bind\", std::ios::binary)\n+\t\t\t<< uvcDeviceDir;\n+\t\ttimer.start(1000);\n+\t\twhile (timer.isRunning() && !cameraAdded_)\n+\t\t\tThread::current()->eventDispatcher()->processEvents();\n+\t\tif (!cameraAdded_)\n+\t\t\treturn TestFail;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup()\n+\t{\n+\t\tcm_->stop();\n+\t\tdelete cm_;\n+\t}\n+\n+private:\n+\tCameraManager *cm_;\n+\tstatic const std::string uvcDriverDir_;\n+\tbool cameraRemoved_;\n+\tbool cameraAdded_;\n+};\n+\n+const std::string HotplugTest::uvcDriverDir_ = \"/sys/bus/usb/drivers/uvcvideo/\";\n+\n+TEST_REGISTER(HotplugTest)\ndiff --git a/test/meson.build b/test/meson.build\nindex bd7da14..a868813 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -30,6 +30,7 @@ internal_tests = [\n     ['event-thread',                    'event-thread.cpp'],\n     ['file',                            'file.cpp'],\n     ['file-descriptor',                 'file-descriptor.cpp'],\n+    ['hotplug-cameras',                 'hotplug-cameras.cpp'],\n     ['message',                         'message.cpp'],\n     ['object',                          'object.cpp'],\n     ['object-invoke',                   'object-invoke.cpp'],\n",
    "prefixes": [
        "libcamera-devel",
        "v4",
        "6/6"
    ]
}