[libcamera-devel,v10,17/19] lc-compliance: Add test to queue more requests than hardware depth
diff mbox series

Message ID 20221228223003.2265712-18-paul.elder@ideasonboard.com
State New
Headers show
Series
  • lc-compliance: Add test to queue more requests than hardware depth
Related show

Commit Message

Paul Elder Dec. 28, 2022, 10:30 p.m. UTC
From: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>

A pipeline handler should be able to handle an arbitrary number of
simultaneous requests by submitting what it can to the video device and
queuing the rest internally until resources are available. This isn't
currently done by some pipeline handlers however [1].

Add a new test to lc-compliance that submits a lot of requests at once
to check if the pipeline handler is behaving well in this situation.

[1] https://bugs.libcamera.org/show_bug.cgi?id=24

Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
Changes in v9:
- rebased

(no changes since v6)

Changes in v6:
- Made MAX_SIMULTANEOUS_REQUESTS a constexpr

Changes in v5:
- Updated to use googletest, and CameraHolder and roleToString from previous
  patches
---
 src/apps/lc-compliance/capture_test.cpp   | 45 +++++++++++++++++++++++
 src/apps/lc-compliance/simple_capture.cpp | 29 +++++++++++++++
 src/apps/lc-compliance/simple_capture.h   | 11 ++++++
 3 files changed, 85 insertions(+)

Patch
diff mbox series

diff --git a/src/apps/lc-compliance/capture_test.cpp b/src/apps/lc-compliance/capture_test.cpp
index d62f7692..8dd26120 100644
--- a/src/apps/lc-compliance/capture_test.cpp
+++ b/src/apps/lc-compliance/capture_test.cpp
@@ -23,6 +23,8 @@  const std::vector<StreamRole> ROLES = {
 	StreamRole::Viewfinder
 };
 
+static constexpr unsigned int MAX_SIMULTANEOUS_REQUESTS = 8;
+
 static const std::string &roleToString(const StreamRole &role)
 {
 	static const std::map<StreamRole, std::string> rolesMap = {
@@ -59,12 +61,37 @@  void SingleStream::TearDown()
 	releaseCamera();
 }
 
+class RoleParametrizedTest : public testing::TestWithParam<StreamRole>, public CameraHolder
+{
+public:
+	static std::string nameParameters(const testing::TestParamInfo<RoleParametrizedTest::ParamType> &info);
+
+protected:
+	void SetUp() override;
+	void TearDown() override;
+};
+
+void RoleParametrizedTest::SetUp()
+{
+	acquireCamera();
+}
+
+void RoleParametrizedTest::TearDown()
+{
+	releaseCamera();
+}
+
 std::string SingleStream::nameParameters(const testing::TestParamInfo<SingleStream::ParamType> &info)
 {
 	return roleToString(std::get<0>(info.param)) + "_" +
 	       std::to_string(std::get<1>(info.param));
 }
 
+std::string RoleParametrizedTest::nameParameters(const testing::TestParamInfo<RoleParametrizedTest::ParamType> &info)
+{
+	return roleToString(info.param);
+}
+
 /*
  * Test single capture cycles
  *
@@ -127,8 +154,26 @@  TEST_P(SingleStream, UnbalancedStop)
 	capture.capture(numRequests);
 }
 
+TEST_P(RoleParametrizedTest, Overflow)
+{
+	auto role = GetParam();
+
+	SimpleCaptureOverflow capture(camera_);
+
+	capture.configure(role);
+
+	capture.allocateBuffers(MAX_SIMULTANEOUS_REQUESTS);
+
+	capture.capture();
+}
+
 INSTANTIATE_TEST_SUITE_P(CaptureTests,
 			 SingleStream,
 			 testing::Combine(testing::ValuesIn(ROLES),
 					  testing::ValuesIn(NUMREQUESTS)),
 			 SingleStream::nameParameters);
+
+INSTANTIATE_TEST_SUITE_P(CaptureTests,
+			 RoleParametrizedTest,
+			 testing::ValuesIn(ROLES),
+			 RoleParametrizedTest::nameParameters);
diff --git a/src/apps/lc-compliance/simple_capture.cpp b/src/apps/lc-compliance/simple_capture.cpp
index 6dd5c7af..a37a98ac 100644
--- a/src/apps/lc-compliance/simple_capture.cpp
+++ b/src/apps/lc-compliance/simple_capture.cpp
@@ -205,3 +205,32 @@  void SimpleCaptureUnbalanced::requestComplete(Request *request)
 	if (camera_->queueRequest(request))
 		loop_->exit(-EINVAL);
 }
+
+/* SimpleCaptureOverflow */
+
+SimpleCaptureOverflow::SimpleCaptureOverflow(std::shared_ptr<Camera> camera)
+	: SimpleCapture(camera)
+{
+}
+
+void SimpleCaptureOverflow::capture()
+{
+	start();
+
+	Stream *stream = config_->at(0).stream();
+	const std::vector<std::unique_ptr<FrameBuffer>> &buffers = allocator_->buffers(stream);
+
+	captureCount_ = 0;
+	captureLimit_ = buffers.size();
+
+	queueRequests(stream, buffers);
+
+	runCaptureSession();
+
+	ASSERT_EQ(captureCount_, captureLimit_);
+}
+
+void SimpleCaptureOverflow::requestComplete([[maybe_unused]] Request *request)
+{
+	captureCompleted();
+}
diff --git a/src/apps/lc-compliance/simple_capture.h b/src/apps/lc-compliance/simple_capture.h
index 89ecc71c..18be8a01 100644
--- a/src/apps/lc-compliance/simple_capture.h
+++ b/src/apps/lc-compliance/simple_capture.h
@@ -68,3 +68,14 @@  public:
 private:
 	void requestComplete(libcamera::Request *request) override;
 };
+
+class SimpleCaptureOverflow : public SimpleCapture
+{
+public:
+	SimpleCaptureOverflow(std::shared_ptr<libcamera::Camera> camera);
+
+	void capture();
+
+private:
+	void requestComplete(libcamera::Request *request) override;
+};