[{"id":4394,"web_url":"https://patchwork.libcamera.org/comment/4394/","msgid":"<20200407202404.GJ1716317@oden.dyn.berto.se>","date":"2020-04-07T20:24:04","subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-04-04 04:56:17 +0300, Laurent Pinchart wrote:\n> Add tests for the File class API.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  test/file.cpp    | 285 +++++++++++++++++++++++++++++++++++++++++++++++\n>  test/meson.build |   1 +\n>  2 files changed, 286 insertions(+)\n>  create mode 100644 test/file.cpp\n> \n> diff --git a/test/file.cpp b/test/file.cpp\n> new file mode 100644\n> index 000000000000..c046bced1c13\n> --- /dev/null\n> +++ b/test/file.cpp\n> @@ -0,0 +1,285 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2020, Google Inc.\n> + *\n> + * file.cpp - File I/O operations tests\n> + */\n> +\n> +#include <fstream>\n> +#include <iostream>\n> +#include <string>\n> +#include <string.h>\n> +#include <sys/types.h>\n> +#include <unistd.h>\n> +\n> +#include \"file.h\"\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class FileTest : public Test\n> +{\n> +protected:\n> +\tint init()\n> +\t{\n> +\t\tfileName_ = \"/tmp/libcamera.test.\" + std::to_string(getpid());\n\nI think this should use mktemp(), not everyone have the same /tmp ;-P\n\nAs the File interface uses an API where the error is signaled using \nFile::error() shall it not be tested here as well? But we can always add \nthat on top.\n\nWith mktemp() sorted,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> +\n> +\t\tstd::ofstream ostrm(fileName_, ios::binary);\n> +\t\tostrm << \"libcamera\";\n> +\t\tostrm.close();\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run()\n> +\t{\n> +\t\t/* Test static functions. */\n> +\t\tif (!File::exists(\"/dev/null\")) {\n> +\t\t\tcerr << \"Valid file not found\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (File::exists(\"/dev/null/invalid\")) {\n> +\t\t\tcerr << \"Invalid file should not exist\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test unnamed file. */\n> +\t\tFile file;\n> +\n> +\t\tif (!file.fileName().empty()) {\n> +\t\t\tcerr << \"Unnamed file has non-empty file name\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.exists()) {\n> +\t\t\tcerr << \"Unnamed file exists\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.isOpen()) {\n> +\t\t\tcerr << \"File is open after construction\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.openMode() != File::NotOpen) {\n> +\t\t\tcerr << \"File has invalid open mode after construction\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.size() >= 0) {\n> +\t\t\tcerr << \"Unnamed file has a size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.open(File::ReadWrite)) {\n> +\t\t\tcerr << \"Opening unnamed file succeeded\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test named file referring to an invalid file. */\n> +\t\tfile.setFileName(\"/dev/null/invalid\");\n> +\n> +\t\tif (file.fileName() != \"/dev/null/invalid\") {\n> +\t\t\tcerr << \"File reports incorrect file name\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.exists()) {\n> +\t\t\tcerr << \"Invalid file exists\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.isOpen()) {\n> +\t\t\tcerr << \"Invalid file is open after construction\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.openMode() != File::NotOpen) {\n> +\t\t\tcerr << \"Invalid file has invalid open mode after construction\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.size() >= 0) {\n> +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.open(File::ReadWrite)) {\n> +\t\t\tcerr << \"Opening invalid file succeeded\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test named file referring to a valid file. */\n> +\t\tfile.setFileName(\"/dev/null\");\n> +\n> +\t\tif (!file.exists()) {\n> +\t\t\tcerr << \"Valid file does not exist\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.isOpen()) {\n> +\t\t\tcerr << \"Valid file is open after construction\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.openMode() != File::NotOpen) {\n> +\t\t\tcerr << \"Valid file has invalid open mode after construction\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.size() >= 0) {\n> +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test open and close. */\n> +\t\tif (!file.open(File::ReadWrite)) {\n> +\t\t\tcerr << \"Opening file failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!file.isOpen()) {\n> +\t\t\tcerr << \"Open file reported as closed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.openMode() != File::ReadWrite) {\n> +\t\t\tcerr << \"Open file has invalid open mode\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tfile.close();\n> +\n> +\t\tif (file.isOpen()) {\n> +\t\t\tcerr << \"Closed file reported as open\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (file.openMode() != File::NotOpen) {\n> +\t\t\tcerr << \"Closed file has invalid open mode\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test size(). */\n> +\t\tfile.setFileName(\"/proc/self/exe\");\n> +\n> +\t\tif (file.size() >= 0) {\n> +\t\t\tcerr << \"File has valid size before open\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tfile.open(File::ReadOnly);\n> +\n> +\t\tssize_t size = file.size();\n> +\t\tif (size <= 0) {\n> +\t\t\tcerr << \"File has invalid size after open\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test mapping and unmapping. */\n> +\t\tSpan<uint8_t> data = file.map();\n> +\t\tif (data.empty()) {\n> +\t\t\tcerr << \"Mapping of complete file failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (data.size() != static_cast<size_t>(size)) {\n> +\t\t\tcerr << \"Mapping  of complete file has invalid size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!file.unmap(data.data())) {\n> +\t\t\tcerr << \"Unmapping of complete file failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tdata = file.map(4096, 8192);\n> +\t\tif (data.empty()) {\n> +\t\t\tcerr << \"Mapping of file region failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (data.size() != 8192) {\n> +\t\t\tcerr << \"Mapping of file region has invalid size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!file.unmap(data.data())) {\n> +\t\t\tcerr << \"Unmapping of file region failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tfile.close();\n> +\n> +\t\t/* Test private mapping. */\n> +\t\tfile.setFileName(fileName_);\n> +\t\tfile.open(File::ReadWrite);\n> +\n> +\t\tdata = file.map(0, -1, File::MapPrivate);\n> +\t\tif (data.empty()) {\n> +\t\t\tcerr << \"Private mapping failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tstd::string str{ reinterpret_cast<char *>(data.data()), data.size() };\n> +\t\tif (str != \"libcamera\") {\n> +\t\t\tcerr << \"Invalid contents of private mapping\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> +\n> +\t\tif (!file.unmap(data.data())) {\n> +\t\t\tcerr << \"Private unmapping failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tdata = file.map();\n> +\n> +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> +\t\tif (str != \"libcamera\") {\n> +\t\t\tcerr << \"Private mapping changed file contents\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test shared mapping. */\n> +\t\tdata = file.map();\n> +\t\tif (data.empty()) {\n> +\t\t\tcerr << \"Shared mapping failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> +\n> +\t\tif (!file.unmap(data.data())) {\n> +\t\t\tcerr << \"Shared unmapping failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tdata = file.map();\n> +\n> +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> +\t\tif (str != \"LIBCAMERA\") {\n> +\t\t\tcerr << \"Shared mapping failed to change file contents\"\n> +\t\t\t     << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tunlink(fileName_.c_str());\n> +\t}\n> +\n> +private:\n> +\tstd::string fileName_;\n> +};\n> +\n> +TEST_REGISTER(FileTest)\n> diff --git a/test/meson.build b/test/meson.build\n> index 8ab58ac15a2a..5a45a85effd3 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -26,6 +26,7 @@ internal_tests = [\n>      ['event',                           'event.cpp'],\n>      ['event-dispatcher',                'event-dispatcher.cpp'],\n>      ['event-thread',                    'event-thread.cpp'],\n> +    ['file',                            'file.cpp'],\n>      ['file-descriptor',                 'file-descriptor.cpp'],\n>      ['message',                         'message.cpp'],\n>      ['object',                          'object.cpp'],\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com\n\t[IPv6:2a00:1450:4864:20::12a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CEB5F600F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Apr 2020 22:24:06 +0200 (CEST)","by mail-lf1-x12a.google.com with SMTP id f8so3376502lfe.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Apr 2020 13:24:06 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\tv22sm12264496ljc.79.2020.04.07.13.24.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Apr 2020 13:24:05 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"l/oeT2qW\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=tCmn7QD4nP9PgrpntMyp4u8i9Mbpn2gae8jBCqyKpZc=;\n\tb=l/oeT2qWvSccLkmcq+eQbwjvvzG+YwU+GcR5qgNmq+UuD9ChO9QWwAVcfeHP2kBTZb\n\tE/Hw/S7LiVUGn1Tkpda7P80B/KYYsrdEbxcYlzgwZXZmq3gOo6SIWAVqD44uboXa16F3\n\tl4c1rtq0VzE51aXfVTGwtq6nshZXSjDx3ltxAtGu3iKN+Wpx0Ac/dzfq3KJsPEbH3JEt\n\tMN4l/gqJXfyLv8z6jzaQIeRTCES3gG1i/w13eiCjWQ/XeeR+ZToQvGhl3jbNbAgSybRO\n\tuqylFD9S1OvhYWaW4+3e8AWDeFt0fphtnuzpPUBUH77pS5biINFo1WOhfyHu0J+9iBpQ\n\tDvUQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=tCmn7QD4nP9PgrpntMyp4u8i9Mbpn2gae8jBCqyKpZc=;\n\tb=Fq4PdtjaYehMUkcwQns8yLieP6ez0kKSxxevCFZwDCMSTK2hQHi8AlzLMhxFt9ZwYT\n\t1l/IPnf5v/r27JsEPGEos9NOkjW451nqeN2H9BUQRtyVNQ8tOkPNHEAOHyyZCq9JEumb\n\tJ1byQpaRg816+PrIpglzgq1JuRXovn0MViqQxs3FZAXSfmPHFg1jrny6snycfF1QEsrQ\n\tfIRjh2ncqpxdNIUFg5nkmuj44Uz74qwL3wta2lRraGVhcWcjLJxYvqlWDKDgPX9f7Eix\n\twa3m3bzcN2HXZgvVUJmBaV8gPajH1BOqeXVl+0lhc1OdreV1xsMFHlcnVtqaZh1ksiCE\n\taizA==","X-Gm-Message-State":"AGi0PuYhtY7tbovUUakvODX/BwHG2wK91goEG5kkKd7/TCKuSnnZx4/R\n\t8EyqvemCanhAXd6GSnB0lvMaRdbnELg=","X-Google-Smtp-Source":"APiQypKxH76e+e4c7lEN7HkpyTM+1c1+4V+2pmu4usVGBpdgJwv382KglItP0n5NDd6yUrRQQUcWYQ==","X-Received":"by 2002:a19:4cc2:: with SMTP id z185mr2511290lfa.0.1586291046023;\n\tTue, 07 Apr 2020 13:24:06 -0700 (PDT)","Date":"Tue, 7 Apr 2020 22:24:04 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407202404.GJ1716317@oden.dyn.berto.se>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200404015624.30440-5-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 07 Apr 2020 20:24:07 -0000"}},{"id":4412,"web_url":"https://patchwork.libcamera.org/comment/4412/","msgid":"<20200407232857.GN4751@pendragon.ideasonboard.com>","date":"2020-04-07T23:28:57","subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nOn Tue, Apr 07, 2020 at 10:24:04PM +0200, Niklas Söderlund wrote:\n> On 2020-04-04 04:56:17 +0300, Laurent Pinchart wrote:\n> > Add tests for the File class API.\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  test/file.cpp    | 285 +++++++++++++++++++++++++++++++++++++++++++++++\n> >  test/meson.build |   1 +\n> >  2 files changed, 286 insertions(+)\n> >  create mode 100644 test/file.cpp\n> > \n> > diff --git a/test/file.cpp b/test/file.cpp\n> > new file mode 100644\n> > index 000000000000..c046bced1c13\n> > --- /dev/null\n> > +++ b/test/file.cpp\n> > @@ -0,0 +1,285 @@\n> > +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > +/*\n> > + * Copyright (C) 2020, Google Inc.\n> > + *\n> > + * file.cpp - File I/O operations tests\n> > + */\n> > +\n> > +#include <fstream>\n> > +#include <iostream>\n> > +#include <string>\n> > +#include <string.h>\n> > +#include <sys/types.h>\n> > +#include <unistd.h>\n> > +\n> > +#include \"file.h\"\n> > +#include \"test.h\"\n> > +\n> > +using namespace std;\n> > +using namespace libcamera;\n> > +\n> > +class FileTest : public Test\n> > +{\n> > +protected:\n> > +\tint init()\n> > +\t{\n> > +\t\tfileName_ = \"/tmp/libcamera.test.\" + std::to_string(getpid());\n> \n> I think this should use mktemp(), not everyone have the same /tmp ;-P\n\nI'll go for mkstemp() as mktemp() is marked as \"never use this function\"\n:-) This however doesn't handle the temporary directory issue, as both\nmktemp() and mkstemp() both take an absolute path as their template\nargument.\n\n> As the File interface uses an API where the error is signaled using \n> File::error() shall it not be tested here as well? But we can always add \n> that on top.\n\nI'll add an error() test.\n\n> With mktemp() sorted,\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> > +\n> > +\t\tstd::ofstream ostrm(fileName_, ios::binary);\n> > +\t\tostrm << \"libcamera\";\n> > +\t\tostrm.close();\n> > +\n> > +\t\treturn TestPass;\n> > +\t}\n> > +\n> > +\tint run()\n> > +\t{\n> > +\t\t/* Test static functions. */\n> > +\t\tif (!File::exists(\"/dev/null\")) {\n> > +\t\t\tcerr << \"Valid file not found\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (File::exists(\"/dev/null/invalid\")) {\n> > +\t\t\tcerr << \"Invalid file should not exist\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test unnamed file. */\n> > +\t\tFile file;\n> > +\n> > +\t\tif (!file.fileName().empty()) {\n> > +\t\t\tcerr << \"Unnamed file has non-empty file name\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.exists()) {\n> > +\t\t\tcerr << \"Unnamed file exists\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.isOpen()) {\n> > +\t\t\tcerr << \"File is open after construction\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.openMode() != File::NotOpen) {\n> > +\t\t\tcerr << \"File has invalid open mode after construction\"\n> > +\t\t\t     << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.size() >= 0) {\n> > +\t\t\tcerr << \"Unnamed file has a size\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.open(File::ReadWrite)) {\n> > +\t\t\tcerr << \"Opening unnamed file succeeded\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test named file referring to an invalid file. */\n> > +\t\tfile.setFileName(\"/dev/null/invalid\");\n> > +\n> > +\t\tif (file.fileName() != \"/dev/null/invalid\") {\n> > +\t\t\tcerr << \"File reports incorrect file name\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.exists()) {\n> > +\t\t\tcerr << \"Invalid file exists\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.isOpen()) {\n> > +\t\t\tcerr << \"Invalid file is open after construction\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.openMode() != File::NotOpen) {\n> > +\t\t\tcerr << \"Invalid file has invalid open mode after construction\"\n> > +\t\t\t     << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.size() >= 0) {\n> > +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.open(File::ReadWrite)) {\n> > +\t\t\tcerr << \"Opening invalid file succeeded\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test named file referring to a valid file. */\n> > +\t\tfile.setFileName(\"/dev/null\");\n> > +\n> > +\t\tif (!file.exists()) {\n> > +\t\t\tcerr << \"Valid file does not exist\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.isOpen()) {\n> > +\t\t\tcerr << \"Valid file is open after construction\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.openMode() != File::NotOpen) {\n> > +\t\t\tcerr << \"Valid file has invalid open mode after construction\"\n> > +\t\t\t     << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.size() >= 0) {\n> > +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test open and close. */\n> > +\t\tif (!file.open(File::ReadWrite)) {\n> > +\t\t\tcerr << \"Opening file failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (!file.isOpen()) {\n> > +\t\t\tcerr << \"Open file reported as closed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.openMode() != File::ReadWrite) {\n> > +\t\t\tcerr << \"Open file has invalid open mode\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tfile.close();\n> > +\n> > +\t\tif (file.isOpen()) {\n> > +\t\t\tcerr << \"Closed file reported as open\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (file.openMode() != File::NotOpen) {\n> > +\t\t\tcerr << \"Closed file has invalid open mode\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test size(). */\n> > +\t\tfile.setFileName(\"/proc/self/exe\");\n> > +\n> > +\t\tif (file.size() >= 0) {\n> > +\t\t\tcerr << \"File has valid size before open\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tfile.open(File::ReadOnly);\n> > +\n> > +\t\tssize_t size = file.size();\n> > +\t\tif (size <= 0) {\n> > +\t\t\tcerr << \"File has invalid size after open\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test mapping and unmapping. */\n> > +\t\tSpan<uint8_t> data = file.map();\n> > +\t\tif (data.empty()) {\n> > +\t\t\tcerr << \"Mapping of complete file failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (data.size() != static_cast<size_t>(size)) {\n> > +\t\t\tcerr << \"Mapping  of complete file has invalid size\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (!file.unmap(data.data())) {\n> > +\t\t\tcerr << \"Unmapping of complete file failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tdata = file.map(4096, 8192);\n> > +\t\tif (data.empty()) {\n> > +\t\t\tcerr << \"Mapping of file region failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (data.size() != 8192) {\n> > +\t\t\tcerr << \"Mapping of file region has invalid size\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tif (!file.unmap(data.data())) {\n> > +\t\t\tcerr << \"Unmapping of file region failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tfile.close();\n> > +\n> > +\t\t/* Test private mapping. */\n> > +\t\tfile.setFileName(fileName_);\n> > +\t\tfile.open(File::ReadWrite);\n> > +\n> > +\t\tdata = file.map(0, -1, File::MapPrivate);\n> > +\t\tif (data.empty()) {\n> > +\t\t\tcerr << \"Private mapping failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tstd::string str{ reinterpret_cast<char *>(data.data()), data.size() };\n> > +\t\tif (str != \"libcamera\") {\n> > +\t\t\tcerr << \"Invalid contents of private mapping\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> > +\n> > +\t\tif (!file.unmap(data.data())) {\n> > +\t\t\tcerr << \"Private unmapping failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tdata = file.map();\n> > +\n> > +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> > +\t\tif (str != \"libcamera\") {\n> > +\t\t\tcerr << \"Private mapping changed file contents\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\t/* Test shared mapping. */\n> > +\t\tdata = file.map();\n> > +\t\tif (data.empty()) {\n> > +\t\t\tcerr << \"Shared mapping failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> > +\n> > +\t\tif (!file.unmap(data.data())) {\n> > +\t\t\tcerr << \"Shared unmapping failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\tdata = file.map();\n> > +\n> > +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> > +\t\tif (str != \"LIBCAMERA\") {\n> > +\t\t\tcerr << \"Shared mapping failed to change file contents\"\n> > +\t\t\t     << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> > +\t\treturn TestPass;\n> > +\t}\n> > +\n> > +\tvoid cleanup()\n> > +\t{\n> > +\t\tunlink(fileName_.c_str());\n> > +\t}\n> > +\n> > +private:\n> > +\tstd::string fileName_;\n> > +};\n> > +\n> > +TEST_REGISTER(FileTest)\n> > diff --git a/test/meson.build b/test/meson.build\n> > index 8ab58ac15a2a..5a45a85effd3 100644\n> > --- a/test/meson.build\n> > +++ b/test/meson.build\n> > @@ -26,6 +26,7 @@ internal_tests = [\n> >      ['event',                           'event.cpp'],\n> >      ['event-dispatcher',                'event-dispatcher.cpp'],\n> >      ['event-thread',                    'event-thread.cpp'],\n> > +    ['file',                            'file.cpp'],\n> >      ['file-descriptor',                 'file-descriptor.cpp'],\n> >      ['message',                         'message.cpp'],\n> >      ['object',                          'object.cpp'],","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D82B8600F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2020 01:29:07 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5548359E;\n\tWed,  8 Apr 2020 01:29:07 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"c9koO4su\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1586302147;\n\tbh=KHTHzCfy3PvXuiAKN4OW94g8T6wiU4kwsBMHup7oiAk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=c9koO4su2jSOfs8CMLlGjl6LGnt7vi/Uy1F6+MX6D0tkoE16SWJgxo/Os0UxSR3WD\n\tgn/haPZKzlMK62EgGyapSxJBrqr295NIvCf4aj/Jn323ITEuS+aUZBL0u89TTsOq5x\n\tV1+QgObCz8A1kliMyjqYM80klgj1UrO7a3R2r7ZY=","Date":"Wed, 8 Apr 2020 02:28:57 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407232857.GN4751@pendragon.ideasonboard.com>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-5-laurent.pinchart@ideasonboard.com>\n\t<20200407202404.GJ1716317@oden.dyn.berto.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200407202404.GJ1716317@oden.dyn.berto.se>","Subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 07 Apr 2020 23:29:08 -0000"}},{"id":4414,"web_url":"https://patchwork.libcamera.org/comment/4414/","msgid":"<20200407233259.GD1716317@oden.dyn.berto.se>","date":"2020-04-07T23:32:59","subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nOn 2020-04-08 02:28:57 +0300, Laurent Pinchart wrote:\n> Hi Niklas,\n> \n> On Tue, Apr 07, 2020 at 10:24:04PM +0200, Niklas Söderlund wrote:\n> > On 2020-04-04 04:56:17 +0300, Laurent Pinchart wrote:\n> > > Add tests for the File class API.\n> > > \n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  test/file.cpp    | 285 +++++++++++++++++++++++++++++++++++++++++++++++\n> > >  test/meson.build |   1 +\n> > >  2 files changed, 286 insertions(+)\n> > >  create mode 100644 test/file.cpp\n> > > \n> > > diff --git a/test/file.cpp b/test/file.cpp\n> > > new file mode 100644\n> > > index 000000000000..c046bced1c13\n> > > --- /dev/null\n> > > +++ b/test/file.cpp\n> > > @@ -0,0 +1,285 @@\n> > > +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> > > +/*\n> > > + * Copyright (C) 2020, Google Inc.\n> > > + *\n> > > + * file.cpp - File I/O operations tests\n> > > + */\n> > > +\n> > > +#include <fstream>\n> > > +#include <iostream>\n> > > +#include <string>\n> > > +#include <string.h>\n> > > +#include <sys/types.h>\n> > > +#include <unistd.h>\n> > > +\n> > > +#include \"file.h\"\n> > > +#include \"test.h\"\n> > > +\n> > > +using namespace std;\n> > > +using namespace libcamera;\n> > > +\n> > > +class FileTest : public Test\n> > > +{\n> > > +protected:\n> > > +\tint init()\n> > > +\t{\n> > > +\t\tfileName_ = \"/tmp/libcamera.test.\" + std::to_string(getpid());\n> > \n> > I think this should use mktemp(), not everyone have the same /tmp ;-P\n> \n> I'll go for mkstemp() as mktemp() is marked as \"never use this function\"\n> :-) This however doesn't handle the temporary directory issue, as both\n> mktemp() and mkstemp() both take an absolute path as their template\n> argument.\n\nOps, poor mktemp() ;-)\n\n> \n> > As the File interface uses an API where the error is signaled using \n> > File::error() shall it not be tested here as well? But we can always add \n> > that on top.\n> \n> I'll add an error() test.\n> \n> > With mktemp() sorted,\n> > \n> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > \n> > > +\n> > > +\t\tstd::ofstream ostrm(fileName_, ios::binary);\n> > > +\t\tostrm << \"libcamera\";\n> > > +\t\tostrm.close();\n> > > +\n> > > +\t\treturn TestPass;\n> > > +\t}\n> > > +\n> > > +\tint run()\n> > > +\t{\n> > > +\t\t/* Test static functions. */\n> > > +\t\tif (!File::exists(\"/dev/null\")) {\n> > > +\t\t\tcerr << \"Valid file not found\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (File::exists(\"/dev/null/invalid\")) {\n> > > +\t\t\tcerr << \"Invalid file should not exist\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test unnamed file. */\n> > > +\t\tFile file;\n> > > +\n> > > +\t\tif (!file.fileName().empty()) {\n> > > +\t\t\tcerr << \"Unnamed file has non-empty file name\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.exists()) {\n> > > +\t\t\tcerr << \"Unnamed file exists\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.isOpen()) {\n> > > +\t\t\tcerr << \"File is open after construction\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.openMode() != File::NotOpen) {\n> > > +\t\t\tcerr << \"File has invalid open mode after construction\"\n> > > +\t\t\t     << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.size() >= 0) {\n> > > +\t\t\tcerr << \"Unnamed file has a size\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.open(File::ReadWrite)) {\n> > > +\t\t\tcerr << \"Opening unnamed file succeeded\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test named file referring to an invalid file. */\n> > > +\t\tfile.setFileName(\"/dev/null/invalid\");\n> > > +\n> > > +\t\tif (file.fileName() != \"/dev/null/invalid\") {\n> > > +\t\t\tcerr << \"File reports incorrect file name\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.exists()) {\n> > > +\t\t\tcerr << \"Invalid file exists\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.isOpen()) {\n> > > +\t\t\tcerr << \"Invalid file is open after construction\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.openMode() != File::NotOpen) {\n> > > +\t\t\tcerr << \"Invalid file has invalid open mode after construction\"\n> > > +\t\t\t     << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.size() >= 0) {\n> > > +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.open(File::ReadWrite)) {\n> > > +\t\t\tcerr << \"Opening invalid file succeeded\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test named file referring to a valid file. */\n> > > +\t\tfile.setFileName(\"/dev/null\");\n> > > +\n> > > +\t\tif (!file.exists()) {\n> > > +\t\t\tcerr << \"Valid file does not exist\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.isOpen()) {\n> > > +\t\t\tcerr << \"Valid file is open after construction\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.openMode() != File::NotOpen) {\n> > > +\t\t\tcerr << \"Valid file has invalid open mode after construction\"\n> > > +\t\t\t     << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.size() >= 0) {\n> > > +\t\t\tcerr << \"Invalid file has a size\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test open and close. */\n> > > +\t\tif (!file.open(File::ReadWrite)) {\n> > > +\t\t\tcerr << \"Opening file failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (!file.isOpen()) {\n> > > +\t\t\tcerr << \"Open file reported as closed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.openMode() != File::ReadWrite) {\n> > > +\t\t\tcerr << \"Open file has invalid open mode\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tfile.close();\n> > > +\n> > > +\t\tif (file.isOpen()) {\n> > > +\t\t\tcerr << \"Closed file reported as open\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (file.openMode() != File::NotOpen) {\n> > > +\t\t\tcerr << \"Closed file has invalid open mode\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test size(). */\n> > > +\t\tfile.setFileName(\"/proc/self/exe\");\n> > > +\n> > > +\t\tif (file.size() >= 0) {\n> > > +\t\t\tcerr << \"File has valid size before open\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tfile.open(File::ReadOnly);\n> > > +\n> > > +\t\tssize_t size = file.size();\n> > > +\t\tif (size <= 0) {\n> > > +\t\t\tcerr << \"File has invalid size after open\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test mapping and unmapping. */\n> > > +\t\tSpan<uint8_t> data = file.map();\n> > > +\t\tif (data.empty()) {\n> > > +\t\t\tcerr << \"Mapping of complete file failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (data.size() != static_cast<size_t>(size)) {\n> > > +\t\t\tcerr << \"Mapping  of complete file has invalid size\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (!file.unmap(data.data())) {\n> > > +\t\t\tcerr << \"Unmapping of complete file failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tdata = file.map(4096, 8192);\n> > > +\t\tif (data.empty()) {\n> > > +\t\t\tcerr << \"Mapping of file region failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (data.size() != 8192) {\n> > > +\t\t\tcerr << \"Mapping of file region has invalid size\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tif (!file.unmap(data.data())) {\n> > > +\t\t\tcerr << \"Unmapping of file region failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tfile.close();\n> > > +\n> > > +\t\t/* Test private mapping. */\n> > > +\t\tfile.setFileName(fileName_);\n> > > +\t\tfile.open(File::ReadWrite);\n> > > +\n> > > +\t\tdata = file.map(0, -1, File::MapPrivate);\n> > > +\t\tif (data.empty()) {\n> > > +\t\t\tcerr << \"Private mapping failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tstd::string str{ reinterpret_cast<char *>(data.data()), data.size() };\n> > > +\t\tif (str != \"libcamera\") {\n> > > +\t\t\tcerr << \"Invalid contents of private mapping\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> > > +\n> > > +\t\tif (!file.unmap(data.data())) {\n> > > +\t\t\tcerr << \"Private unmapping failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tdata = file.map();\n> > > +\n> > > +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> > > +\t\tif (str != \"libcamera\") {\n> > > +\t\t\tcerr << \"Private mapping changed file contents\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\t/* Test shared mapping. */\n> > > +\t\tdata = file.map();\n> > > +\t\tif (data.empty()) {\n> > > +\t\t\tcerr << \"Shared mapping failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tmemcpy(data.data(), \"LIBCAMERA\", 9);\n> > > +\n> > > +\t\tif (!file.unmap(data.data())) {\n> > > +\t\t\tcerr << \"Shared unmapping failed\" << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\tdata = file.map();\n> > > +\n> > > +\t\tstr = { reinterpret_cast<char *>(data.data()), data.size() };\n> > > +\t\tif (str != \"LIBCAMERA\") {\n> > > +\t\t\tcerr << \"Shared mapping failed to change file contents\"\n> > > +\t\t\t     << endl;\n> > > +\t\t\treturn TestFail;\n> > > +\t\t}\n> > > +\n> > > +\t\treturn TestPass;\n> > > +\t}\n> > > +\n> > > +\tvoid cleanup()\n> > > +\t{\n> > > +\t\tunlink(fileName_.c_str());\n> > > +\t}\n> > > +\n> > > +private:\n> > > +\tstd::string fileName_;\n> > > +};\n> > > +\n> > > +TEST_REGISTER(FileTest)\n> > > diff --git a/test/meson.build b/test/meson.build\n> > > index 8ab58ac15a2a..5a45a85effd3 100644\n> > > --- a/test/meson.build\n> > > +++ b/test/meson.build\n> > > @@ -26,6 +26,7 @@ internal_tests = [\n> > >      ['event',                           'event.cpp'],\n> > >      ['event-dispatcher',                'event-dispatcher.cpp'],\n> > >      ['event-thread',                    'event-thread.cpp'],\n> > > +    ['file',                            'file.cpp'],\n> > >      ['file-descriptor',                 'file-descriptor.cpp'],\n> > >      ['message',                         'message.cpp'],\n> > >      ['object',                          'object.cpp'],\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 54C62600F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  8 Apr 2020 01:33:01 +0200 (CEST)","by mail-lj1-x243.google.com with SMTP id z26so1522815ljz.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 07 Apr 2020 16:33:01 -0700 (PDT)","from localhost (h-200-138.A463.priv.bahnhof.se. [176.10.200.138])\n\tby smtp.gmail.com with ESMTPSA id\n\to16sm12989470ljp.53.2020.04.07.16.32.59\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 07 Apr 2020 16:32:59 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"uSQC9kwc\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=nSZo/h03T/HC90nj6VbtW9fJHkqO+JeCZc+Ose2uL6I=;\n\tb=uSQC9kwcTBAujimtOufrw7PugKaJIxqaU1N892nIqY+ld235XNRXM+FJ8NLuRPCVoJ\n\thHRMGWteGEwcamikvbfvRQ2ZPMmWAjrs8AZXGbpd44/oxhff9ikg5+aukxFmrlTj5iwm\n\tudi2nZzMI4nW1BKoQvKA9h4UP77b+3EjSDljcLdo6/EvtHrUGLZUonDtrKfuhmOrX2QH\n\tQ5Wc86PgvkR8ZfboS9F1pGYCUwoThuhcznaAp8J7wzjs5hDGV6zqHgwNuwELJbg/JZBA\n\txjSN0e5QNvPn1DDXqjmpcWcwyCHgYpTTm9siYr3aunsVobO7FBHmjujr4UNu5iBabYVJ\n\tn9Mg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=nSZo/h03T/HC90nj6VbtW9fJHkqO+JeCZc+Ose2uL6I=;\n\tb=AhTxzTWibfJgxzPYBlEwX0cIVt8Wvo3ND8Pr3pqBACuOZCOaSqDtWpMKk5PqptJjNF\n\t6qj/Rp655Mu+DekJGYVB3BRimfb/simqFGqqHYw1AtI3nawlL/7XeHUXVuBzvt97pZGz\n\tB9Xpso1dbR468URmHe5Xl3NAmSw0Y18syEcI/FfazDHynUBcG+QRe6a/UpAQa7uIeqF2\n\tvUvYmgKUoT52q4Mbne1T8A9W2vOY0tGy31kF+JdDO1HchIgQD+VE0H0ed5tJF/0aeoBe\n\tbd7ZN4xBSKRycRKic/3nVJWPxlFXEy+PJcFKi7VNrAixj7hQmBXFEAG5T1AiKEYd7tI7\n\tt+1w==","X-Gm-Message-State":"AGi0PuZivt0p6WERDagmiG/+jHDdM5fVt0K08/sx4SvFz3LlEh7qWtV+\n\t0JjaKIAHfYf3e50YTq3BYMmsh/MEC60=","X-Google-Smtp-Source":"APiQypIXvkZunYIrNnQaxGlV8BNMRXi62AIjEC8VaQDhLOjGrIiNaF/5CacW9f9tpXGN8MAoiI4gMQ==","X-Received":"by 2002:a2e:81c9:: with SMTP id s9mr3092588ljg.69.1586302380559; \n\tTue, 07 Apr 2020 16:33:00 -0700 (PDT)","Date":"Wed, 8 Apr 2020 01:32:59 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200407233259.GD1716317@oden.dyn.berto.se>","References":"<20200404015624.30440-1-laurent.pinchart@ideasonboard.com>\n\t<20200404015624.30440-5-laurent.pinchart@ideasonboard.com>\n\t<20200407202404.GJ1716317@oden.dyn.berto.se>\n\t<20200407232857.GN4751@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200407232857.GN4751@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 04/11] test: Add File class tests","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 07 Apr 2020 23:33:01 -0000"}}]