From patchwork Mon Apr 28 09:02:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Sven_P=C3=BCschel?= X-Patchwork-Id: 23284 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 055DCC3325 for ; Mon, 28 Apr 2025 09:05:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2037968B2A; Mon, 28 Apr 2025 11:05:31 +0200 (CEST) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D52F68B25 for ; Mon, 28 Apr 2025 11:05:08 +0200 (CEST) Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.guest.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1u9KQF-0001au-Oz; Mon, 28 Apr 2025 11:05:07 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Paul Elder , =?utf-8?q?Sven_P=C3=BCschel?= Subject: [PATCH v11 12/19] lc-compliance: Move buffer allocation to separate function Date: Mon, 28 Apr 2025 11:02:37 +0200 Message-ID: <20250428090413.38234-13-s.pueschel@pengutronix.de> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250428090413.38234-1-s.pueschel@pengutronix.de> References: <20250428090413.38234-1-s.pueschel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: libcamera-devel@lists.libcamera.org X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Nícolas F. R. A. Prado Move buffer allocation to its own function and with an optional count argument so tests can specify how many buffers to allocate. When count is omitted, allocate MinimumRequests buffers. Signed-off-by: Nícolas F. R. A. Prado Reviewed-by: Paul Elder Signed-off-by: Paul Elder Signed-off-by: Sven Püschel --- Changes in v11: - adapted to support multiple streams - added requestCount_ member to pass allocated count to start() - added assert to allocateBuffers Changes in v9: - rebased Changes in v8: - Made SimpleCapture::allocateBuffers() a single function with an optional parameter Changes in v5: - New --- src/apps/lc-compliance/helpers/capture.cpp | 36 ++++++++++++------- src/apps/lc-compliance/helpers/capture.h | 2 ++ src/apps/lc-compliance/tests/capture_test.cpp | 8 ++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/apps/lc-compliance/helpers/capture.cpp b/src/apps/lc-compliance/helpers/capture.cpp index 5e8b5df6..1e232dd1 100644 --- a/src/apps/lc-compliance/helpers/capture.cpp +++ b/src/apps/lc-compliance/helpers/capture.cpp @@ -44,6 +44,24 @@ void Capture::configure(libcamera::Span roles) } } +void Capture::allocateBuffers(unsigned int count) +{ + assert(!allocator_.allocated()); + + if (!count) + count = camera_->properties().get(properties::MinimumRequests).value(); + + for (const auto &cfg : *config_) { + Stream *stream = cfg.stream(); + + int allocatedCount = allocator_.allocate(stream, count); + ASSERT_GE(allocatedCount, 0) << "Failed to allocate buffers"; + EXPECT_EQ(allocatedCount, count) << "Allocated less buffers than expected"; + } + + requestCount_ = count; +} + void Capture::run(unsigned int captureLimit, std::optional queueLimit) { assert(!queueLimit || captureLimit <= *queueLimit); @@ -103,19 +121,16 @@ void Capture::start() { assert(config_); assert(!config_->empty()); - assert(!allocator_.allocated()); + assert(allocator_.allocated()); assert(requests_.empty()); - unsigned int bufferCount = - camera_->properties().get(properties::MinimumRequests).value(); - /* No point in testing less requests then the camera depth. */ - if (queueLimit_ && *queueLimit_ < bufferCount) { - GTEST_SKIP() << "Camera needs " << bufferCount + if (queueLimit_ && *queueLimit_ < requestCount_) { + GTEST_SKIP() << "Camera needs " << requestCount_ << " requests, can't test only " << *queueLimit_; } - for (std::size_t i = 0; i < bufferCount; i++) { + for (std::size_t i = 0; i < requestCount_; i++) { std::unique_ptr request = camera_->createRequest(); ASSERT_TRUE(request) << "Can't create request"; requests_.push_back(std::move(request)); @@ -124,13 +139,10 @@ void Capture::start() for (const auto &cfg : *config_) { Stream *stream = cfg.stream(); - int count = allocator_.allocate(stream, bufferCount); - ASSERT_GE(count, 0) << "Failed to allocate buffers"; - const auto &buffers = allocator_.buffers(stream); - ASSERT_EQ(buffers.size(), bufferCount) << "Mismatching buffer count"; + ASSERT_EQ(buffers.size(), requestCount_) << "Mismatching buffer count"; - for (std::size_t i = 0; i < bufferCount; i++) { + for (std::size_t i = 0; i < requestCount_; i++) { ASSERT_EQ(requests_[i]->addBuffer(stream, buffers[i].get()), 0) << "Failed to add buffer to request"; } diff --git a/src/apps/lc-compliance/helpers/capture.h b/src/apps/lc-compliance/helpers/capture.h index ea01c11c..2a14a721 100644 --- a/src/apps/lc-compliance/helpers/capture.h +++ b/src/apps/lc-compliance/helpers/capture.h @@ -21,6 +21,7 @@ public: ~Capture(); void configure(libcamera::Span roles); + void allocateBuffers(unsigned int count = 0); void run(unsigned int captureLimit, std::optional queueLimit = {}); private: @@ -42,4 +43,5 @@ private: std::optional queueLimit_; unsigned int captureCount_ = 0; unsigned int queueCount_ = 0; + unsigned int requestCount_ = 0; }; diff --git a/src/apps/lc-compliance/tests/capture_test.cpp b/src/apps/lc-compliance/tests/capture_test.cpp index d02caa8a..9fb82a2b 100644 --- a/src/apps/lc-compliance/tests/capture_test.cpp +++ b/src/apps/lc-compliance/tests/capture_test.cpp @@ -83,6 +83,8 @@ TEST_P(SimpleCapture, Capture) capture.configure(roles); + capture.allocateBuffers(); + capture.run(numRequests, numRequests); } @@ -102,8 +104,10 @@ TEST_P(SimpleCapture, CaptureStartStop) capture.configure(roles); - for (unsigned int starts = 0; starts < numRepeats; starts++) + for (unsigned int starts = 0; starts < numRepeats; starts++) { + capture.allocateBuffers(); capture.run(numRequests, numRequests); + } } /* @@ -121,6 +125,8 @@ TEST_P(SimpleCapture, UnbalancedStop) capture.configure(roles); + capture.allocateBuffers(); + capture.run(numRequests); }