From 1222cd8de62d762bce0993751ab0609faab4f226 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Fri, 27 Nov 2015 17:43:21 +0100 Subject: [PATCH] Fix test cases for older libfuse versions --- .../FuseCreateAndOpenFileDescriptorTest.cpp | 11 ++++++----- test/fuse/openFile/FuseOpenFileDescriptorTest.cpp | 10 ++++++---- test/fuse/read/FuseReadFileDescriptorTest.cpp | 4 ++-- test/testutils/FuseTest.cpp | 13 +++++++++++++ test/testutils/FuseTest.h | 4 +++- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/test/fuse/createAndOpenFile/FuseCreateAndOpenFileDescriptorTest.cpp b/test/fuse/createAndOpenFile/FuseCreateAndOpenFileDescriptorTest.cpp index 7c2ef920..3d970b2c 100644 --- a/test/fuse/createAndOpenFile/FuseCreateAndOpenFileDescriptorTest.cpp +++ b/test/fuse/createAndOpenFile/FuseCreateAndOpenFileDescriptorTest.cpp @@ -19,7 +19,7 @@ private: int CreateAndOpenFile(const TempTestFS *fs, const char *filename) { auto realpath = fs->mountDir() / filename; #if __GNUC__ == 4 && __GNUC_MINOR__ == 8 - int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH); #else int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT); #endif @@ -27,8 +27,9 @@ private: return fd; } void ReadFile(int fd) { - int retval = ::read(fd, nullptr, 0); - EXPECT_EQ(0, retval) << "Reading file failed"; + uint8_t buf; + int retval = ::read(fd, &buf, 1); + EXPECT_EQ(1, retval) << "Reading file failed"; } }; INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024)); @@ -37,9 +38,9 @@ TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) { ReturnDoesntExistOnLstat(FILENAME); EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _)) .Times(1).WillOnce(Return(GetParam())); - EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(0)); + EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(1)); //For the syscall to succeed, we also need to give an fstat implementation. - ReturnIsFileOnFstat(GetParam()); + ReturnIsFileOnFstatWithSize(GetParam(), 1); CreateAndOpenAndReadFile(FILENAME); } diff --git a/test/fuse/openFile/FuseOpenFileDescriptorTest.cpp b/test/fuse/openFile/FuseOpenFileDescriptorTest.cpp index 8bc93416..18212aba 100644 --- a/test/fuse/openFile/FuseOpenFileDescriptorTest.cpp +++ b/test/fuse/openFile/FuseOpenFileDescriptorTest.cpp @@ -23,17 +23,19 @@ private: return fd; } void ReadFile(int fd) { - int retval = ::read(fd, nullptr, 0); - EXPECT_EQ(0, retval) << "Reading file failed"; + uint8_t buf; + int retval = ::read(fd, &buf, 1); + EXPECT_EQ(1, retval) << "Reading file failed"; } }; INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024)); TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) { - ReturnIsFileOnLstat(FILENAME); + ReturnIsFileOnLstatWithSize(FILENAME, 1); EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)) .Times(1).WillOnce(Return(GetParam())); - EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(0)); + EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(1)); OpenAndReadFile(FILENAME); } + diff --git a/test/fuse/read/FuseReadFileDescriptorTest.cpp b/test/fuse/read/FuseReadFileDescriptorTest.cpp index 6efec9bc..f3aedc91 100644 --- a/test/fuse/read/FuseReadFileDescriptorTest.cpp +++ b/test/fuse/read/FuseReadFileDescriptorTest.cpp @@ -19,11 +19,11 @@ INSTANTIATE_TEST_CASE_P(FuseReadFileDescriptorTest, FuseReadFileDescriptorTest, TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) { - ReturnIsFileOnLstat(FILENAME); + ReturnIsFileOnLstatWithSize(FILENAME, 1); OnOpenReturnFileDescriptor(FILENAME, GetParam()); EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _)) .Times(1).WillOnce(ReturnSuccessfulRead); char buf[1]; - ReadFile(FILENAME, buf, 0, 0); + ReadFile(FILENAME, buf, 1, 0); } diff --git a/test/testutils/FuseTest.cpp b/test/testutils/FuseTest.cpp index 1676eabd..8ef07a91 100644 --- a/test/testutils/FuseTest.cpp +++ b/test/testutils/FuseTest.cpp @@ -81,6 +81,15 @@ Action FuseTest::ReturnIsFileFstat = result->st_nlink = 1; }); +Action FuseTest::ReturnIsFileFstatWithSize(size_t size) { + return Invoke([size](int, struct ::stat *result) { + result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + result->st_nlink = 1; + result->st_size = size; + std::cout << "Return size: " << size < FuseTest::ReturnIsDir = Invoke([](const char*, struct ::stat* result) { result->st_mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH; @@ -112,3 +121,7 @@ void FuseTest::ReturnDoesntExistOnLstat(const bf::path &path) { void FuseTest::ReturnIsFileOnFstat(int descriptor) { EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat); } + +void FuseTest::ReturnIsFileOnFstatWithSize(int descriptor, size_t size) { + EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size)); +} \ No newline at end of file diff --git a/test/testutils/FuseTest.h b/test/testutils/FuseTest.h index c472cfe1..7ea7d6c7 100644 --- a/test/testutils/FuseTest.h +++ b/test/testutils/FuseTest.h @@ -104,11 +104,12 @@ public: MockFilesystem fsimpl; - static ::testing::Action ReturnIsFileWithSize(size_t size); //TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros static ::testing::Action ReturnIsFile; + static ::testing::Action ReturnIsFileWithSize(size_t size); static ::testing::Action ReturnIsFileFstat; + static ::testing::Action ReturnIsFileFstatWithSize(size_t size); static ::testing::Action ReturnIsDir; static ::testing::Action ReturnDoesntExist; @@ -118,6 +119,7 @@ public: void ReturnDoesntExistOnLstat(const boost::filesystem::path &path); void OnOpenReturnFileDescriptor(const char *filename, int descriptor); void ReturnIsFileOnFstat(int descriptor); + void ReturnIsFileOnFstatWithSize(int descriptor, const size_t size); }; #endif