From patchwork Sun Jul 12 14:44:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8746 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 8137FBD792 for ; Sun, 12 Jul 2020 14:44:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 811CD60589; Sun, 12 Jul 2020 16:44:48 +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="uytcLn6G"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E1F4960559 for ; Sun, 12 Jul 2020 16:44:45 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6636B9CC for ; Sun, 12 Jul 2020 16:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594565085; bh=7pvIDD3iJYGX9B31F62a+AXTUr7R/RkrFkc8hhBS5hs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uytcLn6Gv0dNYhquyRqoCotk294UnLXTjPcZ9jZnOfH0/G1CmvrnKbCuy92cDEQlE N3QRP6K+iryf3Zc0+zI2rq/AlFKfvrGERnLtyVUQ9nKWainWH1xuLCgVS7LA0dA4/Q Qbx5Lvbwth5kmTQ8magcgK5tFaBSMeMjI1iO3c9M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Jul 2020 17:44:17 +0300 Message-Id: <20200712144419.21457-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> References: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] test: file: Add read/write tests 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" Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- test/file.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/test/file.cpp b/test/file.cpp index 287831f3ef37..7688a9dc224a 100644 --- a/test/file.cpp +++ b/test/file.cpp @@ -30,11 +30,9 @@ protected: if (fd == -1) return TestFail; - ssize_t ret = write(fd, "libcamera", 9); - close(fd); - return ret == 9 ? TestPass : TestFail; + return TestPass; } int run() @@ -191,7 +189,68 @@ protected: return TestFail; } + file.close(); + + /* Test read and write. */ + std::array buffer = { 0 }; + + strncpy(reinterpret_cast(buffer.data()), "libcamera", + buffer.size()); + + file.setFileName(fileName_); + + if (file.read(buffer) >= 0) { + cerr << "Read succeeded on closed file" << endl; + return TestFail; + } + + if (file.write(buffer) >= 0) { + cerr << "Write succeeded on closed file" << endl; + return TestFail; + } + + file.open(File::ReadOnly); + + if (file.write(buffer) >= 0) { + cerr << "Write succeeded on read-only file" << endl; + return TestFail; + } + + file.close(); + + file.open(File::ReadWrite); + + if (file.write({ buffer.data(), 9 }) != 9) { + cerr << "Write test failed" << endl; + return TestFail; + } + + if (file.read(buffer) != 0) { + cerr << "Read at end of file test failed" << endl; + return TestFail; + } + + if (file.seek(0) != 0) { + cerr << "Seek test failed" << endl; + return TestFail; + } + + if (file.read(buffer) != 9) { + cerr << "Read test failed" << endl; + return TestFail; + } + + if (file.pos() != 9) { + cerr << "Position test failed" << endl; + return TestFail; + } + + file.close(); + /* Test mapping and unmapping. */ + file.setFileName("/proc/self/exe"); + file.open(File::ReadOnly); + Span data = file.map(); if (data.empty()) { cerr << "Mapping of complete file failed" << endl;