Message ID | 20200712144419.21457-2-laurent.pinchart@ideasonboard.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Laurent, On 12/07/2020 15:44, Laurent Pinchart wrote: I guess we could list the tests being added, but it's not important. > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > 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<uint8_t, 256> buffer = { 0 }; > + > + strncpy(reinterpret_cast<char *>(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; > + } We could test to see that the expected data is actually read back ... but maybe that's overkill... and not needed. > + > + 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<uint8_t> data = file.map(); > if (data.empty()) { > cerr << "Mapping of complete file failed" << endl; > Looks good to me.. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Hi Laurent, Thanks for your work. On 2020-07-12 17:44:17 +0300, Laurent Pinchart wrote: > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > 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<uint8_t, 256> buffer = { 0 }; > + > + strncpy(reinterpret_cast<char *>(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<uint8_t> data = file.map(); > if (data.empty()) { > cerr << "Mapping of complete file failed" << endl; > -- > Regards, > > Laurent Pinchart > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
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<uint8_t, 256> buffer = { 0 }; + + strncpy(reinterpret_cast<char *>(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<uint8_t> data = file.map(); if (data.empty()) { cerr << "Mapping of complete file failed" << endl;
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- test/file.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-)