[libcamera-devel,v1,7/8] libcamera: apps: lcc: Add optional stream tests
diff mbox series

Message ID 20230203094424.25243-8-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, MultiCaptureOptional. This tests operating with
multiple streams, where one of the two streams is not provided buffers
in certain requests.

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

Patch
diff mbox series

diff --git a/src/apps/lc-compliance/capture_test.cpp b/src/apps/lc-compliance/capture_test.cpp
index 8d534161e985..c6a09a63248a 100644
--- a/src/apps/lc-compliance/capture_test.cpp
+++ b/src/apps/lc-compliance/capture_test.cpp
@@ -209,6 +209,26 @@  TEST_P(MultiStream, Capture)
 	capture.capture(numRequests, NumStreams);
 }
 
+/*
+ * Test optional stream capture cycles
+ *
+ * Do not provide buffers for all streams in all Requests, testing that stream
+ * output can be optional.
+ */
+TEST_P(MultiStream, CaptureOptional)
+{
+	constexpr unsigned int NumStreams = 2;
+
+	auto [roles, numRequests] = GetParam();
+
+	MultiCaptureOptional capture(camera_);
+
+	capture.configure({ roles.first, roles.second });
+
+	capture.capture(numRequests, NumStreams, 0);
+	capture.capture(numRequests, NumStreams, 1);
+}
+
 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 23becf964fd7..a011dfb285c8 100644
--- a/src/apps/lc-compliance/multi_capture.cpp
+++ b/src/apps/lc-compliance/multi_capture.cpp
@@ -185,3 +185,56 @@  void MultiCapture::requestComplete(Request *request)
 	if (queueRequest(request))
 		loop_->exit(-EINVAL);
 }
+
+/* MultiCaptureOptional */
+
+MultiCaptureOptional::MultiCaptureOptional(std::shared_ptr<Camera> camera)
+	: MultiCapture(camera)
+{
+}
+
+void MultiCaptureOptional::capture(unsigned int numRequests, unsigned int numStreams,
+				   unsigned int optionalStream)
+{
+	start();
+
+	queueCount_ = 0;
+	captureCount_ = 0;
+	captureLimit_ = numRequests;
+
+	std::vector<const FrameBufferList *>
+		buffers = prepareBuffers(numRequests, numStreams);
+
+	if (!buffers.size())
+		GTEST_SKIP();
+
+	/* Queue the recommended number of requests. */
+	const unsigned int inFlightRequests = config_->at(0).bufferCount;
+	for (unsigned int i = 0; i < inFlightRequests; i++) {
+		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();
+
+			if (j == optionalStream && !i)
+				continue;
+
+			ASSERT_EQ(request->addBuffer(stream, (*bufferList)[i].get()), 0)
+				<< "Can't set buffer for request";
+		}
+
+		ASSERT_EQ(queueRequest(request.get()), 0)
+			<< "Failed to queue request";
+		requests_.push_back(std::move(request));
+	}
+
+	/* Run capture session. */
+	loop_ = new EventLoop();
+	loop_->exec();
+	stop();
+	delete loop_;
+
+	ASSERT_EQ(captureCount_, captureLimit_);
+}
diff --git a/src/apps/lc-compliance/multi_capture.h b/src/apps/lc-compliance/multi_capture.h
index 9037099988e5..3d92ba3d4c10 100644
--- a/src/apps/lc-compliance/multi_capture.h
+++ b/src/apps/lc-compliance/multi_capture.h
@@ -59,3 +59,12 @@  protected:
 	unsigned int captureCount_;
 	unsigned int captureLimit_;
 };
+
+class MultiCaptureOptional : public MultiCapture
+{
+public:
+	MultiCaptureOptional(std::shared_ptr<libcamera::Camera> camera);
+
+	void capture(unsigned int numRequests, unsigned int numStreams,
+		     unsigned int optionalStream);
+};