[libcamera-devel,v1,8/8] libcamera: apps: lcc: Add stream hints test
diff mbox series

Message ID 20230203094424.25243-9-naush@raspberrypi.com
State New
Headers show
Series
  • Stream hints
Related show

Commit Message

Naushir Patuck Feb. 3, 2023, 9:44 a.m. UTC
Add a new test class, MultiCaptureHints. This tests the MandatoryStream
hint flag and ensures that requests are cancelled correctly if the flag
is set and no buffer is provided.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/apps/lc-compliance/capture_test.cpp  | 21 +++++++++++
 src/apps/lc-compliance/multi_capture.cpp | 48 ++++++++++++++++++++++++
 src/apps/lc-compliance/multi_capture.h   | 17 +++++++++
 3 files changed, 86 insertions(+)

Patch
diff mbox series

diff --git a/src/apps/lc-compliance/capture_test.cpp b/src/apps/lc-compliance/capture_test.cpp
index c6a09a63248a..9239e8b5fc8a 100644
--- a/src/apps/lc-compliance/capture_test.cpp
+++ b/src/apps/lc-compliance/capture_test.cpp
@@ -229,6 +229,27 @@  TEST_P(MultiStream, CaptureOptional)
 	capture.capture(numRequests, NumStreams, 1);
 }
 
+/*
+ * Test mandatory stream hints
+ *
+ * Mark a single stream as mandatory, and don't provide a buffer for it in the
+ * request. This should case the queueRequest call to fail.
+ */
+TEST_P(MultiStream, CaptureHints)
+{
+	constexpr unsigned int NumStreams = 2;
+
+	auto [roles, numRequests] = GetParam();
+
+	MultiCaptureHints capture0(camera_, 0);
+	capture0.configure({ roles.first, roles.second });
+	capture0.capture(NumStreams);
+
+	MultiCaptureHints capture1(camera_, 1);
+	capture1.configure({ roles.first, roles.second });
+	capture1.capture(NumStreams);
+}
+
 INSTANTIATE_TEST_SUITE_P(MultiCaptureTests,
 			 MultiStream,
 			 testing::Combine(testing::ValuesIn(MULTIROLES),
diff --git a/src/apps/lc-compliance/multi_capture.cpp b/src/apps/lc-compliance/multi_capture.cpp
index a011dfb285c8..6aa39b7e281f 100644
--- a/src/apps/lc-compliance/multi_capture.cpp
+++ b/src/apps/lc-compliance/multi_capture.cpp
@@ -238,3 +238,51 @@  void MultiCaptureOptional::capture(unsigned int numRequests, unsigned int numStr
 
 	ASSERT_EQ(captureCount_, captureLimit_);
 }
+
+/* MultiCaptureHints */
+
+MultiCaptureHints::MultiCaptureHints(std::shared_ptr<Camera> camera,
+				     unsigned int mandatoryStream)
+	: MultiCaptureBase(camera), mandatoryStream_(mandatoryStream)
+{
+}
+
+void MultiCaptureHints::capture(unsigned int numStreams)
+{
+	start();
+
+	std::vector<const FrameBufferList *>
+		buffers = prepareBuffers(config_->at(0).bufferCount, numStreams);
+
+	if (!buffers.size())
+		GTEST_SKIP();
+
+	/* Queue a single request */
+	std::unique_ptr<Request> request = camera_->createRequest();
+	ASSERT_TRUE(request) << "Can't create request";
+
+	for (unsigned int j = 0; j < numStreams; j++) {
+		const FrameBufferList *bufferList = buffers[j];
+		Stream *stream = config_->at(j).stream();
+
+		/*
+		 * Do not add a buffer for the mandatory stream to cause a
+		 * deliberate failure.
+		 */
+		if (j == mandatoryStream_)
+			continue;
+
+		ASSERT_EQ(request->addBuffer(stream, (*bufferList)[0].get()), 0)
+			<< "Can't set buffer for request";
+	}
+
+	ASSERT_EQ(camera_->queueRequest(request.get()), -ENOMEM)
+		<< "queueRequest did not fail!";
+
+	stop();
+}
+
+void MultiCaptureHints::updateConfig()
+{
+	config_.get()->at(mandatoryStream_).hints = StreamConfiguration::Hint::MandatoryStream;
+}
diff --git a/src/apps/lc-compliance/multi_capture.h b/src/apps/lc-compliance/multi_capture.h
index 3d92ba3d4c10..c48c16e7565d 100644
--- a/src/apps/lc-compliance/multi_capture.h
+++ b/src/apps/lc-compliance/multi_capture.h
@@ -68,3 +68,20 @@  public:
 	void capture(unsigned int numRequests, unsigned int numStreams,
 		     unsigned int optionalStream);
 };
+
+class MultiCaptureHints : public MultiCaptureBase
+{
+public:
+	MultiCaptureHints(std::shared_ptr<libcamera::Camera> camera,
+			  unsigned int mandatoryStream);
+
+	void capture(unsigned int numStreams);
+
+private:
+	void updateConfig() override;
+	void requestComplete([[maybe_unused]] libcamera::Request *request) override
+	{
+	}
+
+	unsigned int mandatoryStream_;
+};