From patchwork Mon Feb 8 10:21:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 11188 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se 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 ACAEFBD160 for ; Mon, 8 Feb 2021 10:22:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE85360D22; Mon, 8 Feb 2021 11:22:04 +0100 (CET) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14A0160D10 for ; Mon, 8 Feb 2021 11:22:04 +0100 (CET) X-Halon-ID: 7c757d75-69f7-11eb-b73f-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de [79.202.36.88]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 7c757d75-69f7-11eb-b73f-0050569116f7; Mon, 08 Feb 2021 11:22:03 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 8 Feb 2021 11:21:37 +0100 Message-Id: <20210208102137.2164282-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208102137.2164282-1-niklas.soderlund@ragnatech.se> References: <20210208102137.2164282-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] lc-compliance: Add test stopping single stream with requests queued 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" Add a test which stops a camera while requests are still queued. This intents to test cleanup paths where requests are dequeued from video devices in an uncompleted state. Signed-off-by: Niklas Söderlund --- src/lc-compliance/simple_capture.cpp | 63 ++++++++++++++++++++++++++++ src/lc-compliance/simple_capture.h | 14 +++++++ src/lc-compliance/single_stream.cpp | 23 ++++++++++ 3 files changed, 100 insertions(+) diff --git a/src/lc-compliance/simple_capture.cpp b/src/lc-compliance/simple_capture.cpp index e6699b689ace180d..cfcad79ad655fbfb 100644 --- a/src/lc-compliance/simple_capture.cpp +++ b/src/lc-compliance/simple_capture.cpp @@ -143,3 +143,66 @@ void SimpleCaptureBalanced::requestComplete(Request *request) if (queueRequest(request)) loop_->exit(-EINVAL); } + +/* SimpleCaptureUnbalanced */ + +SimpleCaptureUnbalanced::SimpleCaptureUnbalanced(std::shared_ptr camera) + : SimpleCapture(camera) +{ +} + +Results::Result SimpleCaptureUnbalanced::capture(unsigned int numRequests) +{ + Results::Result ret = start(); + if (ret.first != Results::Pass) + return ret; + + Stream *stream = config_->at(0).stream(); + const std::vector> &buffers = allocator_->buffers(stream); + + captureCount_ = 0; + captureLimit_ = numRequests; + + /* Queue the recommended number of reqeuests. */ + std::vector> requests; + for (const std::unique_ptr &buffer : buffers) { + std::unique_ptr request = camera_->createRequest(); + if (!request) { + stop(); + return { Results::Fail, "Can't create request" }; + } + + if (request->addBuffer(stream, buffer.get())) { + stop(); + return { Results::Fail, "Can't set buffer for request" }; + } + + if (camera_->queueRequest(request.get()) < 0) { + stop(); + return { Results::Fail, "Failed to queue request" }; + } + + requests.push_back(std::move(request)); + } + + /* Run capture session. */ + loop_ = new EventLoop(); + int status = loop_->exec(); + stop(); + delete loop_; + + return { status ? Results::Fail : Results::Pass, "Unbalanced capture of " + std::to_string(numRequests) + " requests" }; +} + +void SimpleCaptureUnbalanced::requestComplete(Request *request) +{ + captureCount_++; + if (captureCount_ >= captureLimit_) { + loop_->exit(0); + return; + } + + request->reuse(Request::ReuseBuffers); + if (camera_->queueRequest(request)) + loop_->exit(-EINVAL); +} diff --git a/src/lc-compliance/simple_capture.h b/src/lc-compliance/simple_capture.h index 3a6afc538c623050..4693c13404cee7d2 100644 --- a/src/lc-compliance/simple_capture.h +++ b/src/lc-compliance/simple_capture.h @@ -51,4 +51,18 @@ private: unsigned int captureLimit_; }; +class SimpleCaptureUnbalanced : public SimpleCapture +{ +public: + SimpleCaptureUnbalanced(std::shared_ptr camera); + + Results::Result capture(unsigned int numRequests); + +private: + void requestComplete(libcamera::Request *request) override; + + unsigned int captureCount_; + unsigned int captureLimit_; +}; + #endif /* __LC_COMPLIANCE_SIMPLE_CAPTURE_H__ */ diff --git a/src/lc-compliance/single_stream.cpp b/src/lc-compliance/single_stream.cpp index 0ed6f5dcfb5a516d..3d5ffdeadd7a0e1f 100644 --- a/src/lc-compliance/single_stream.cpp +++ b/src/lc-compliance/single_stream.cpp @@ -31,6 +31,18 @@ Results::Result testRequestBalance(std::shared_ptr camera, return { Results::Pass, "Balanced capture of " + std::to_string(numRequests) + " requests with " + std::to_string(startCycles) + " start cycles" }; } +Results::Result testRequestUnbalance(std::shared_ptr camera, + StreamRole role, unsigned int numRequests) +{ + SimpleCaptureUnbalanced capture(camera); + + Results::Result ret = capture.configure(role); + if (ret.first != Results::Pass) + return ret; + + return capture.capture(numRequests); +} + Results testSingleStream(std::shared_ptr camera) { const std::vector> roles = { @@ -69,6 +81,17 @@ Results testSingleStream(std::shared_ptr camera) std::cout << "* Test multiple start/stop cycles" << std::endl; for (unsigned int num : numRequests) results.add(testRequestBalance(camera, role.second, 3, num)); + + /* + * Test unbalanced stop + * + * Makes sure the camera supports a stop with requests queued. + * Example failure is a camera that does not handle cancelation + * of buffers coming back from the video device while stopping. + */ + std::cout << "* Test unbalanced stop" << std::endl; + for (unsigned int num : numRequests) + results.add(testRequestUnbalance(camera, role.second, num)); } return results;