From patchwork Wed Aug 5 15:14:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 9231 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 93A25BD87B for ; Wed, 5 Aug 2020 15:15:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 609C0607E7; Wed, 5 Aug 2020 17:15:15 +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="q1cFixOz"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8192C60599 for ; Wed, 5 Aug 2020 17:15:12 +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 03952D2F; Wed, 5 Aug 2020 17:15:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596640512; bh=gOM+OtUXdmlLUx5AKttWr5qtbwqqt0qdbGiYKpylbXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q1cFixOzfdgvrfVe0WDHHni7Gj/MhFoElpf+XlVVWxvfJZ36WgrsrYTn/Xau77A7R OtgySu0uiyYkdgUNyeMIHA86kjyVqCoJakiaBguMehBkzibtSgjNBwDvZvtcfPIPLE /mRh+jF5H1Dyr1vfPpj2CJbaj2iFsF6qIBIYQdFU= From: Kieran Bingham To: libcamera devel Date: Wed, 5 Aug 2020 16:14:58 +0100 Message-Id: <20200805151507.227503-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200805151507.227503-1-kieran.bingham@ideasonboard.com> References: <20200805151507.227503-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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. Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- test/mapped-buffer.cpp | 114 +++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 115 insertions(+) create mode 100644 test/mapped-buffer.cpp diff --git a/test/mapped-buffer.cpp b/test/mapped-buffer.cpp new file mode 100644 index 000000000000..b1c13ad03e62 --- /dev/null +++ b/test/mapped-buffer.cpp @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * libcamera internal MappedBuffer tests + */ + +#include + +#include "libcamera/internal/buffer.h" + +#include "camera_test.h" +#include "test.h" + +using namespace std; + +namespace { + +class MappedBufferTest : public CameraTest, public Test +{ +public: + MappedBufferTest() + : 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; + } + +private: + std::unique_ptr config_; + FrameBufferAllocator *allocator_; + Stream *stream_; +}; + +} /* namespace */ + +TEST_REGISTER(MappedBufferTest); diff --git a/test/meson.build b/test/meson.build index 775187159dec..0a1d434e3996 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-buffer', 'mapped-buffer.cpp'], ['message', 'message.cpp'], ['object', 'object.cpp'], ['object-delete', 'object-delete.cpp'],