{"id":22577,"url":"https://patchwork.libcamera.org/api/patches/22577/?format=json","web_url":"https://patchwork.libcamera.org/patch/22577/","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":"<20250114182143.1773762-17-pobrn@protonmail.com>","date":"2025-01-14T18:23:05","name":"[RFC,v2,16/16] apps: lc-compliance: Run request completion handler in \"main\" thread","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"ffc787b5f2f7bf516e6cbb0dca1a1d25912a9899","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/?format=json","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22577/mbox/","series":[{"id":4951,"url":"https://patchwork.libcamera.org/api/series/4951/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4951","date":"2025-01-14T18:21:46","name":"apps: lc-compliance: Multi-stream tests","version":2,"mbox":"https://patchwork.libcamera.org/series/4951/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22577/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22577/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 BFAEAC3304\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jan 2025 18:23:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7868368562;\n\tTue, 14 Jan 2025 19:23:12 +0100 (CET)","from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E18468560\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 19:23:11 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"owY7BZKR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1736878989; x=1737138189;\n\tbh=5pID2MA8VOFbZIuXw2qYio4RxdA4dJ8xJoviCGtAhlM=;\n\th=Date:To:From:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post;\n\tb=owY7BZKRPsbc8lKZzdINCT7687upzmtZAJiWyUdcBhWHew/KIPGJTVHsXHxEDyYXj\n\tgGl3oEvp404JYv/eSZWYvrqZtm0AH67oPyPFuYByoVtZf9LQOAY7EJJIzT6/45Woyo\n\tgh2XRnkksVkhYfhDEN3448XVyljCy01QpeoKm4kL46GLkKDFnc6YRG8F2Ot0bbxeee\n\tIfSuPghsIxM5nXcp1nQvu7ODchWnLb5xr+9qvk3k3ccFOvCIWarDuoPYKI5pWSv0dc\n\t9lnubmqU0GZ2ttzxnXFWXxJ+eQF18osHKNHQpYXLu2IRJw9RuEI9nk1kchie5VeMZX\n\tTxl4B0bxalltg==","Date":"Tue, 14 Jan 2025 18:23:05 +0000","To":"libcamera-devel@lists.libcamera.org","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Subject":"[RFC PATCH v2 16/16] apps: lc-compliance: Run request completion\n\thandler in \"main\" thread","Message-ID":"<20250114182143.1773762-17-pobrn@protonmail.com>","In-Reply-To":"<20250114182143.1773762-1-pobrn@protonmail.com>","References":"<20250114182143.1773762-1-pobrn@protonmail.com>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"6272a51921d450ec30a7bf583bae3c870de9ce89","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","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":"Currently, `Capture::requestCompleted()` runs in the `CameraManager`'s\nthread. This makes it a bit more complicated to use googletest and\nreport errors in those callbacks since lc-compliance sets up\ngoogletest to throw exceptions on fatal errors / test skip, but\nthose exceptions are only caught on the \"main\" thread, the one\nrunning the test suite.\n\nTo minimize the burden of dealing with synchronization in tests,\nexecute `Capture::requestCompleted()` in the event loop's thread\nby utilizing `EventLoop::callLater()`.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n src/apps/lc-compliance/helpers/capture.cpp | 21 ++++++++++++---------\n src/apps/lc-compliance/helpers/capture.h   |  2 +-\n 2 files changed, 13 insertions(+), 10 deletions(-)","diff":"diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp\nindex dbaff4138..528a3a13a 100644\n--- a/src/apps/lc-compliance/helpers/capture.cpp\n+++ b/src/apps/lc-compliance/helpers/capture.cpp\n@@ -129,16 +129,13 @@ void Capture::prepareRequests(std::optional<unsigned int> queueLimit)\n \t}\n }\n \n-int Capture::queueRequest(libcamera::Request *request)\n+void Capture::queueRequest(libcamera::Request *request)\n {\n \tif (queueLimit_ && queueCount_ >= *queueLimit_)\n-\t\treturn 0;\n-\n-\tif (int ret = camera_->queueRequest(request); ret < 0)\n-\t\treturn ret;\n+\t\treturn;\n \n+\tASSERT_EQ(camera_->queueRequest(request), 0);\n \tqueueCount_ += 1;\n-\treturn 0;\n }\n \n void Capture::requestComplete(Request *request)\n@@ -153,8 +150,7 @@ void Capture::requestComplete(Request *request)\n \t\t<< \"Request didn't complete successfully\";\n \n \trequest->reuse(Request::ReuseBuffers);\n-\tif (queueRequest(request))\n-\t\tloop_->exit(-EINVAL);\n+\tqueueRequest(request);\n }\n \n void Capture::start()\n@@ -173,7 +169,14 @@ void Capture::start()\n \n \tASSERT_TRUE(allocator_.allocated());\n \n-\tcamera_->requestCompleted.connect(this, &Capture::requestComplete);\n+\tcamera_->requestCompleted.connect(this, [this](libcamera::Request *request) {\n+\t\t/* Runs in the CameraManager thread. */\n+\n+\t\tloop_->callLater([this, request] {\n+\t\t\t/* Run handler in the context of the event loop. */\n+\t\t\trequestComplete(request);\n+\t\t});\n+\t});\n \n \tASSERT_EQ(camera_->start(), 0) << \"Failed to start camera\";\n }\ndiff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h\nindex 391184ad6..9003a0934 100644\n--- a/src/apps/lc-compliance/helpers/capture.h\n+++ b/src/apps/lc-compliance/helpers/capture.h\n@@ -30,7 +30,7 @@ private:\n \tvoid stop();\n \n \tvoid prepareRequests(std::optional<unsigned int> queueLimit = {});\n-\tint queueRequest(libcamera::Request *request);\n+\tvoid queueRequest(libcamera::Request *request);\n \tvoid requestComplete(libcamera::Request *request);\n \n \tstd::shared_ptr<libcamera::Camera> camera_;\n","prefixes":["RFC","v2","16/16"]}