[PATCH v11 12/19] lc-compliance: Move buffer allocation to separate function
Sven Püschel
s.pueschel at pengutronix.de
Mon Apr 28 11:02:37 CEST 2025
From: Nícolas F. R. A. Prado <nfraprado at collabora.com>
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 <nfraprado at collabora.com>
Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
Signed-off-by: Sven Püschel <s.pueschel at pengutronix.de>
---
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<const libcamera::StreamRole> 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<unsigned int> 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> 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<const libcamera::StreamRole> roles);
+ void allocateBuffers(unsigned int count = 0);
void run(unsigned int captureLimit, std::optional<unsigned int> queueLimit = {});
private:
@@ -42,4 +43,5 @@ private:
std::optional<unsigned int> 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);
}
--
2.49.0
More information about the libcamera-devel
mailing list