{"id":13248,"url":"https://patchwork.libcamera.org/api/patches/13248/?format=json","web_url":"https://patchwork.libcamera.org/patch/13248/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210806115132.353831-1-umang.jain@ideasonboard.com>","date":"2021-08-06T11:51:32","name":"[libcamera-devel,RFC] test: camera: Camera reconfiguration and fd-leak test","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6456f2ddfe4d0f3fa7a90ecaf0507a84b09a7e4d","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/?format=json","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"delegate":{"id":12,"url":"https://patchwork.libcamera.org/api/users/12/?format=json","username":"uajain","first_name":"Umang","last_name":"Jain","email":"umang.jain@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/13248/mbox/","series":[{"id":2317,"url":"https://patchwork.libcamera.org/api/series/2317/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2317","date":"2021-08-06T11:51:32","name":"[libcamera-devel,RFC] test: camera: Camera reconfiguration and fd-leak test","version":1,"mbox":"https://patchwork.libcamera.org/series/2317/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13248/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13248/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 44B83BD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Aug 2021 11:51:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8CEE168822;\n\tFri,  6 Aug 2021 13:51:40 +0200 (CEST)","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 2F35360266\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Aug 2021 13:51:39 +0200 (CEST)","from perceval.ideasonboard.com (unknown [103.251.226.40])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 095FC4FB;\n\tFri,  6 Aug 2021 13:51:37 +0200 (CEST)"],"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=\"W/K/FBmF\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1628250698;\n\tbh=1GCFHLhPtMgQZ6RP0ra1LI0x/JvhR8csOYS6feUq1d8=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=W/K/FBmFQqDa9UQlrY87AVU7vYYCbKuwjJqlGzKveTA0TEvX5kdW9PPHpo7mVoCUt\n\tDD4umx/wakCE0CwAa1ChjayaMGhDnwFgK79LXCVzgyFHRt9eyiw9lHn7/2eCn2w+w3\n\tGiTmhAYOP13KVNyUzLMfX6PEcbUFZ3j9oEo7wJVw=","From":"Umang Jain <umang.jain@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  6 Aug 2021 17:21:32 +0530","Message-Id":"<20210806115132.353831-1-umang.jain@ideasonboard.com>","X-Mailer":"git-send-email 2.31.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH] test: camera: Camera reconfiguration\n\tand fd-leak 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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This tests basically checks for two things:\n- Camera reconfigurations without stopping CameraManager\n- Fd leaks across IPA IPC boundary.\n\nCurrently, it uses vimc, but can be easily changed to using another\nplatform (for e.g. IPU3) by changing CAM_ID and IPA_PROXY_NAME defines.\n\nThis test is geared towards reproducing [1], issue noticed on IPU3.\n\nEnsure that test is run in isolated mode.\nRunning standalone:\n$ LIBCAMERA_IPA_FORCE_ISOLATION=1 ./build/test/camera/camera_reconfigure\n\n[1] https://bugs.libcamera.org/show_bug.cgi?id=63\n\nSigned-off-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n- still RFC because it's based on \"Pass buffers to VIMC IPA\" series\n- We probably need to set LIBCAMERA_IPA_FORCE_ISOLATION=1 from inside\n  the test. Setting at run-time with setenv(), sets the env var but still\n  the test is unable to run in isolated mode. For now, I only have it\n  working, by running it standalone as mentioned in the commit message.\n  OR any other ideas enforcing isolated mode on the test?\n- Some sprinkled prints are intentionally present, will be reworked in\n  v1. Please ignore those for review.\n  (log snippet: https://paste.debian.net/1206765/)\n---\n test/camera/camera_reconfigure.cpp | 250 +++++++++++++++++++++++++++++\n test/camera/meson.build            |   1 +\n 2 files changed, 251 insertions(+)\n create mode 100644 test/camera/camera_reconfigure.cpp","diff":"diff --git a/test/camera/camera_reconfigure.cpp b/test/camera/camera_reconfigure.cpp\nnew file mode 100644\nindex 00000000..20a4a6a4\n--- /dev/null\n+++ b/test/camera/camera_reconfigure.cpp\n@@ -0,0 +1,250 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * Test:\n+ * - Camera's multiple reconfigurations without stopping CameraManager\n+ * - leaking fds across IPA IPC boundary\n+ */\n+\n+#include <dirent.h>\n+#include <iostream>\n+#include <fstream>\n+\n+#include <libcamera/framebuffer_allocator.h>\n+\n+#include <libcamera/base/event_dispatcher.h>\n+#include <libcamera/base/file.h>\n+#include <libcamera/base/thread.h>\n+#include <libcamera/base/timer.h>\n+\n+#include \"camera_test.h\"\n+#include \"test.h\"\n+\n+using namespace std;\n+\n+#define CAM_ID\t\t\t\"platform/vimc.0 Sensor B\"\n+#define IPA_PROXY_NAME\t\t\"vimc_ipa_proxy\"\n+#define NUM_OF_RECONFIGURES\t20\n+\n+namespace {\n+\n+class CameraReconfigure : public CameraTest, public Test\n+{\n+public:\n+\tCameraReconfigure()\n+\t\t: CameraTest(CAM_ID)\n+\t{\n+\t}\n+\n+protected:\n+\tunsigned int configureRuns_;\n+\tunsigned int openFdsAtStart_;\n+\tstring vimcProxyName_;\n+\tbool allocated_;\n+\n+\tvector<unique_ptr<Request>> requests_;\n+\n+\tunique_ptr<CameraConfiguration> config_;\n+\tFrameBufferAllocator *allocator_;\n+\n+\tvoid requestComplete(Request *request)\n+\t{\n+\t\tif (request->status() != Request::RequestComplete)\n+\t\t\treturn;\n+\n+\t\tconst Request::BufferMap &buffers = request->buffers();\n+\n+\t\t/* Create a new request. */\n+\t\tconst Stream *stream = buffers.begin()->first;\n+\t\tFrameBuffer *buffer = buffers.begin()->second;\n+\n+\t\trequest->reuse();\n+\t\trequest->addBuffer(stream, buffer);\n+\t\tcamera_->queueRequest(request);\n+\t}\n+\n+\tint startAndStop ()\n+\t{\n+\t\tStreamConfiguration &cfg = config_->at(0);\n+\n+\t\tif (camera_->acquire()) {\n+\t\t\tcout << \"Failed to acquire the camera\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (camera_->configure(config_.get())) {\n+\t\t\tcout << \"Failed to set default configuration\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tStream *stream = cfg.stream();\n+\n+\t\tif (!allocated_) {\n+\t\t\tint ret = allocator_->allocate(stream);\n+\t\t\tif (ret < 0)\n+\t\t\t\treturn TestFail;\n+\t\t\tallocated_ = true;\n+\t\t}\n+\n+\t\tfor (const unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {\n+\t\t\tunique_ptr<Request> request = camera_->createRequest();\n+\t\t\tif (!request) {\n+\t\t\t\tcout << \"Failed to create request\" << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\n+\t\t\tif (request->addBuffer(stream, buffer.get())) {\n+\t\t\t\tcout << \"Failed to associating buffer with request\" << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\n+\t\t\trequests_.push_back(move(request));\n+\t\t}\n+\n+\t\tcamera_->requestCompleted.connect(this, &CameraReconfigure::requestComplete);\n+\n+\t\tif (camera_->start()) {\n+\t\t\tcout << \"Failed to start camera\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tfor (unique_ptr<Request> &request : requests_) {\n+\t\t\tif (camera_->queueRequest(request.get())) {\n+\t\t\t\tcout << \"Failed to queue request\" << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\tEventDispatcher *dispatcher = Thread::current()->eventDispatcher();\n+\n+\t\tTimer timer;\n+\t\ttimer.start(1000);\n+\t\twhile (timer.isRunning())\n+\t\t\tdispatcher->processEvents();\n+\n+\t\tif (camera_->stop()) {\n+\t\t\tcout << \"Failed to stop camera\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tif (camera_->release()) {\n+\t\t\tcout << \"Failed to release camera\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tcamera_->requestCompleted.disconnect(this, &CameraReconfigure::requestComplete);\n+\n+\t\trequests_.clear();\n+\n+\t\treturn 0;\n+\t}\n+\n+\tint fdsOpen(string pid)\n+\t{\n+\t\tstring proxyFdPath = \"/proc/\" + pid + \"/fd\";\n+\t\tDIR *dir;\n+\t\tstruct dirent *ptr;\n+\t\tunsigned int openFds = 0;\n+\n+\t\tdir = opendir(proxyFdPath.c_str());\n+\t\twhile((ptr = readdir(dir)) != nullptr) {\n+\t\t\tif ((strcmp(ptr->d_name, \".\") == 0) || (strcmp(ptr->d_name, \"..\") == 0))\n+\t\t\t\tcontinue;\n+\n+\t\t\topenFds++;\n+\t\t}\n+\t\tclosedir(dir);\n+\n+\t\treturn openFds;\n+\t}\n+\n+\tstring findProxyPid()\n+\t{\n+\t\tstring proxyPid;\n+\t\tDIR *dir;\n+\t\tstruct dirent *ptr;\n+\n+\t\tdir = opendir(\"/proc\");\n+\t\twhile((ptr = readdir(dir)) != nullptr) {\n+\t\t\tif(ptr->d_type != DT_DIR)\n+\t\t\t\tcontinue;\n+\n+\t\t\tstring pname(\"/proc/\" + string(ptr->d_name) + \"/comm\");\n+\t\t\tif(File::exists(pname.c_str())) {\n+\t\t\t\tifstream pfile(pname.c_str());\n+\t\t\t\tstring comm;\n+\t\t\t\tgetline (pfile, comm);\n+\t\t\t\tpfile.close();\n+\n+\t\t\t\tproxyPid = comm == vimcProxyName_ ?\n+\t\t\t\t\t   string(ptr->d_name) :\n+\t\t\t\t\t   \"\";\n+\t\t\t}\n+\n+\t\t\tif (!proxyPid.empty())\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tclosedir(dir);\n+\n+\t\treturn proxyPid;\n+\t}\n+\n+\tint init() override\n+\t{\n+\t\tif (status_ != TestPass)\n+\t\t\treturn status_;\n+\n+\t\tconfig_ = camera_->generateConfiguration({ StreamRole::StillCapture });\n+\t\tif (!config_ || config_->size() != 1) {\n+\t\t\tcout << \"Failed to generate default configuration\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\tallocator_ = new FrameBufferAllocator(camera_);\n+\n+\t\topenFdsAtStart_ = 0;\n+\t\tconfigureRuns_ = NUM_OF_RECONFIGURES;\n+\t\tvimcProxyName_ = IPA_PROXY_NAME;\n+\t\tallocated_ = false;\n+\n+\t\treturn TestPass;\n+\t}\n+\n+\tvoid cleanup() override\n+\t{\n+\t\tdelete allocator_;\n+\t}\n+\n+\tint run() override\n+\t{\n+\t\tunsigned int openFds = 0;\n+\t\t/* Find pid of vimc_ipa_proxy */\n+\t\tstring proxyPid = findProxyPid();\n+\t\tif (proxyPid.empty()) {\n+\t\t\tcout << \"Not running in isolated mode, exiting\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\t/* Find number of open fds  by vimc_ipa_proxy */\n+\t\topenFdsAtStart_ = fdsOpen(proxyPid);\n+\t\tcout << IPA_PROXY_NAME << \" PID:\" << proxyPid\n+\t\t\t<< \" has open fds at start:\"  << openFdsAtStart_ << endl;\n+\n+\t\tfor (unsigned int i = 0; i < configureRuns_; i++)\n+\t\t{\n+\t\t\tstartAndStop();\n+\t\t\topenFds = fdsOpen(proxyPid);\n+\t\t\tcout << \"No. of open fds after #\" << i << \" runs: \" << openFds << endl;\n+\t\t}\n+\n+\t\tif (openFds == openFdsAtStart_)\n+\t\t\treturn TestPass;\n+\t\telse\n+\t\t\treturn TestFail;\n+\t}\n+};\n+\n+} /* namespace */\n+\n+TEST_REGISTER(CameraReconfigure)\ndiff --git a/test/camera/meson.build b/test/camera/meson.build\nindex 002a87b5..668d5c03 100644\n--- a/test/camera/meson.build\n+++ b/test/camera/meson.build\n@@ -8,6 +8,7 @@ camera_tests = [\n     ['buffer_import',           'buffer_import.cpp'],\n     ['statemachine',            'statemachine.cpp'],\n     ['capture',                 'capture.cpp'],\n+    ['camera_reconfigure',      'camera_reconfigure.cpp'],\n ]\n \n foreach t : camera_tests\n","prefixes":["libcamera-devel","RFC"]}