Patch Detail
Show a patch.
GET /api/patches/3692/?format=api
{ "id": 3692, "url": "https://patchwork.libcamera.org/api/patches/3692/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3692/", "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": "<20200506103346.3433-5-email@uajain.com>", "date": "2020-05-06T10:33:55", "name": "[libcamera-devel,4/4] tests: Introduce hotplug hot-unplug unit test", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "83985fe913b439b24d1b2990b503aca94459494b", "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/3692/mbox/", "series": [ { "id": 881, "url": "https://patchwork.libcamera.org/api/series/881/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=881", "date": "2020-05-06T10:33:51", "name": "Introduce UVC hotplug support", "version": 1, "mbox": "https://patchwork.libcamera.org/series/881/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3692/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3692/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 03B9261698\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 6 May 2020 12:33:56 +0200 (CEST)", "by filter0073p3las1.sendgrid.net with SMTP id\n\tfilter0073p3las1-3640-5EB29293-16\n\t2020-05-06 10:33:55.304344903 +0000 UTC m=+1773093.727196486", "from mail.uajain.com (unknown)\n\tby ismtpd0004p1maa1.sendgrid.net (SG) with ESMTP id\n\tP8_x8N4PRbSs4TaL1yjd6A for <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 May 2020 10:33:54.981 +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=\"qJgcUaff\"; \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=cVkjUO5BjpbgYvPjS7Ub9dJ9A6WwFxXwH5SJcYlIxXA=;\n\tb=qJgcUaffKpeHNIZhg++dr/ce9Gqj+xr4TnLgu/KVEfcTVCnk3QtdV9GQKb2dZYoV1j0V\n\tUv/JM0cZrbBCAMH9maihgBs8LDQvNqYz2run/wrx9wp32uz4HRZgv7nJo1EEphRUUmoruw\n\tO3t3WTLmSJiw5LM2LKZozj5vIVWH9Oz/M=", "From": "Umang Jain <email@uajain.com>", "Date": "Wed, 06 May 2020 10:33:55 +0000 (UTC)", "Message-Id": "<20200506103346.3433-5-email@uajain.com>", "In-Reply-To": "<20200506103346.3433-1-email@uajain.com>", "References": "<20200506103346.3433-1-email@uajain.com>", "Mime-Version": "1.0", "X-SG-EID": "1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcYDswUgqLHty1lirORaEnteN0qcmeuvSogZGEEe3BYijD8Pro8oSDTZzlek2qF6WQhMQYR/09D8OsJUPsv5DM7FNqgTy70nLnpX1TmbNZHaeJTM1hdlL+bPmmqOUM8AxYb1XqTt4Wx0PyRnOTAEQt975chNisywfZmwWF640U9fysAUQywHFP9J8VoFnBsgz4", "To": "libcamera-devel <libcamera-devel@lists.libcamera.org>", "Content-Transfer-Encoding": "7bit", "Content-Type": "text/plain; charset=us-ascii", "Subject": "[libcamera-devel] [PATCH 4/4] tests: Introduce hotplug hot-unplug\n\tunit 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": "Wed, 06 May 2020 10:33:57 -0000" }, "content": "Signed-off-by: Umang Jain <email@uajain.com>\n---\n test/hotplug-cameras.cpp | 152 +++++++++++++++++++++++++++++++++++++++\n test/meson.build | 1 +\n 2 files changed, 153 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..7f1e5a5\n--- /dev/null\n+++ b/test/hotplug-cameras.cpp\n@@ -0,0 +1,152 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Umang Jain <email@uajain.com>\n+ *\n+ * hotplug-cameras.cpp - Emulate 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 <fcntl.h>\n+#include <sys/stat.h>\n+#include <sys/types.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 \"file.h\"\n+#include \"test.h\"\n+#include \"thread.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class HotplugTest : public Test\n+{\n+protected:\n+\tvoid cameraAddedHandler(Camera *cam)\n+\t{\n+\t\tcameraAddedPass_ = true;\n+\t}\n+\n+\tvoid cameraRemovedHandler(Camera *cam)\n+\t{\n+\t\tcameraRemovedPass_ = 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\tcameraAddedPass_ = false;\n+\t\tcameraRemovedPass_ = false;\n+\n+\t\tcm_->cameraAdded.connect(this, &HotplugTest::cameraAddedHandler);\n+\t\tcm_->cameraRemoved.connect(this, &HotplugTest::cameraRemovedHandler);\n+\n+\t\tuvc_toplevel_ = \"/sys/module/uvcvideo/drivers/usb:uvcvideo/\";\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint run()\n+\t{\n+\t\tDIR *dir;\n+\t\tstruct dirent *dirent, *dirent2;\n+\t\tstd::string uvc_driver_dir;\n+\t\tbool uvc_driver_found = false;\n+\n+\t\tdir = opendir(uvc_toplevel_.c_str());\n+\t\t/* Find a UVC device driver symlink, which we can bind/unbind */\n+\t\twhile ((dirent = readdir(dir)) != nullptr) {\n+\t\t\tif (dirent->d_type != DT_LNK)\n+\t\t\t\tcontinue;\n+\n+\t\t\tstd::string child_dir = uvc_toplevel_ + dirent->d_name;\n+\t\t\tDIR *device_driver = opendir(child_dir.c_str());\n+\t\t\twhile ((dirent2 = readdir(device_driver)) != nullptr) {\n+\t\t\t\tif (strncmp(dirent2->d_name, \"video4linux\", 11) == 0) {\n+\t\t\t\t\tuvc_driver_dir = dirent->d_name;\n+\t\t\t\t\tuvc_driver_found = true;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tclosedir(device_driver);\n+\n+\t\t\tif (uvc_driver_found)\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tclosedir(dir);\n+\n+\t\t/* If no UVC driver found, skip */\n+\t\tif (!uvc_driver_found)\n+\t\t\treturn TestSkip;\n+\n+\t\t/* Unbind a camera, process events */\n+\t\tint fd1 = open(\"/sys/module/uvcvideo/drivers/usb:uvcvideo/unbind\", O_WRONLY);\n+\t\twrite(fd1, uvc_driver_dir.c_str(), uvc_driver_dir.size());\n+\t\tclose(fd1);\n+\t\tTimer timer;\n+\t\ttimer.start(1000);\n+\t\twhile (timer.isRunning())\n+\t\t\tThread::current()->eventDispatcher()->processEvents();\n+\n+\t\t/* \\todo: Fix this workaround of stopping and starting the camera-manager.\n+\t\t * We need to do this, so that cm_ release all references to the uvc media symlinks.\n+\t\t */\n+\t\tcm_->stop();\n+\t\tif (cm_->start()) {\n+\t\t\tstd::cout << \"Failed to restart camera-manager\" << std::endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Bind the camera again, process events */\n+\t\tint fd2 = open(\"/sys/module/uvcvideo/drivers/usb:uvcvideo/bind\", O_WRONLY);\n+\t\twrite(fd2, uvc_driver_dir.c_str(), uvc_driver_dir.size());\n+\t\tclose(fd2);\n+\n+\t\ttimer.start(1000);\n+\t\twhile (timer.isRunning())\n+\t\t\tThread::current()->eventDispatcher()->processEvents();\n+\n+\t\tif (cameraAddedPass_ && cameraRemovedPass_)\n+\t\t\treturn TestPass;\n+\t\telse\n+\t\t\treturn TestFail;\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+\tstd::string uvc_toplevel_;\n+\tbool cameraRemovedPass_;\n+\tbool cameraAddedPass_;\n+};\n+\n+TEST_REGISTER(HotplugTest)\n+\ndiff --git a/test/meson.build b/test/meson.build\nindex 5a45a85..383a7ea 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -29,6 +29,7 @@ internal_tests = [\n ['file', 'file.cpp'],\n ['file-descriptor', 'file-descriptor.cpp'],\n ['message', 'message.cpp'],\n+ ['hotplug-cameras', 'hotplug-cameras.cpp'],\n ['object', 'object.cpp'],\n ['object-invoke', 'object-invoke.cpp'],\n ['signal-threads', 'signal-threads.cpp'],\n", "prefixes": [ "libcamera-devel", "4/4" ] }