From patchwork Tue Aug 4 21:47:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9197 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 5131EBD87A for ; Tue, 4 Aug 2020 21:47:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EEC406059B; Tue, 4 Aug 2020 23:47:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SHbusFKn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CC3BC60555 for ; Tue, 4 Aug 2020 23:47:17 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 58A31A66; Tue, 4 Aug 2020 23:47:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596577637; bh=8X9yghRwQQ+CEuljUFWC6/ib0WPrO/zRGEc2udASvCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SHbusFKnHTSKyxoe5SJ93rK/0o7gg2ZtsOMc55bgV4EjxpLqnC1rM1CMukxfOk8xa CLXSJ3rn5BWDe+UHteu3iHSNyCckQkbmw3LN1Y6rWBE0U39auTkl0qlY1M7AhhkYd1 nLf/Stujc8PisoSJteCZd3pUr52ngF1T87oRlcVk= From: Kieran Bingham To: libcamera devel Date: Tue, 4 Aug 2020 22:47:02 +0100 Message-Id: <20200804214711.177645-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200804214711.177645-1-kieran.bingham@ideasonboard.com> References: <20200804214711.177645-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 04/13] test: mapped-buffers: Provide MappedBuffer test 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" Provide initial testing framework for the MappedBuffer component. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- test/mapped-buffers.cpp | 113 ++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 114 insertions(+) create mode 100644 test/mapped-buffers.cpp diff --git a/test/mapped-buffers.cpp b/test/mapped-buffers.cpp new file mode 100644 index 000000000000..4c0557070ca3 --- /dev/null +++ b/test/mapped-buffers.cpp @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * libcamera internal MappedBuffer tests + */ + +#include + +#include "camera_test.h" +#include "test.h" + +#include "libcamera/internal/buffer.h" + +using namespace std; + +namespace { + +class MappedBuffers : public CameraTest, public Test +{ +public: + MappedBuffers() + : CameraTest("VIMC Sensor B") + { + } + +protected: + int init() override + { + if (status_ != TestPass) + return status_; + + config_ = camera_->generateConfiguration({ StreamRole::VideoRecording }); + if (!config_ || config_->size() != 1) { + cout << "Failed to generate default configuration" << endl; + return TestFail; + } + + allocator_ = new FrameBufferAllocator(camera_); + + StreamConfiguration &cfg = config_->at(0); + + if (camera_->acquire()) { + cout << "Failed to acquire the camera" << endl; + return TestFail; + } + + if (camera_->configure(config_.get())) { + cout << "Failed to set default configuration" << endl; + return TestFail; + } + + stream_ = cfg.stream(); + + int ret = allocator_->allocate(stream_); + if (ret < 0) + return TestFail; + + return TestPass; + } + + void cleanup() override + { + delete allocator_; + } + + int run() override + { + const std::unique_ptr &buffer = allocator_->buffers(stream_).front(); + std::vector maps; + + MappedFrameBuffer map(buffer.get(), PROT_READ); + if (!map.isValid()) { + cout << "Failed to successfully map buffer" << endl; + return TestFail; + } + + /* Make sure we can move it. */ + maps.emplace_back(std::move(map)); + + /* But copying is prevented, it would cause double-unmap. */ + // MappedFrameBuffer map_copy = map; + + /* Local map should be invalid (after move). */ + if (map.isValid()) { + cout << "Post-move map should not be valid" << endl; + return TestFail; + } + + /* Test for multiple successful maps on the same buffer. */ + MappedFrameBuffer write_map(buffer.get(), PROT_WRITE); + if (!write_map.isValid()) { + cout << "Failed to map write buffer" << endl; + return TestFail; + } + + MappedFrameBuffer rw_map(buffer.get(), PROT_READ | PROT_WRITE); + if (!rw_map.isValid()) { + cout << "Failed to map RW buffer" << endl; + return TestFail; + } + + return TestPass; + } + + std::unique_ptr config_; + FrameBufferAllocator *allocator_; + Stream *stream_; +}; + +} /* namespace */ + +TEST_REGISTER(MappedBuffers); diff --git a/test/meson.build b/test/meson.build index 775187159dec..376ee6cee175 100644 --- a/test/meson.build +++ b/test/meson.build @@ -31,6 +31,7 @@ internal_tests = [ ['file', 'file.cpp'], ['file-descriptor', 'file-descriptor.cpp'], ['hotplug-cameras', 'hotplug-cameras.cpp'], + ['mapped-buffers', 'mapped-buffers.cpp'], ['message', 'message.cpp'], ['object', 'object.cpp'], ['object-delete', 'object-delete.cpp'],