Fix test cases for older libfuse versions
This commit is contained in:
parent
e542529104
commit
1222cd8de6
@ -19,7 +19,7 @@ private:
|
|||||||
int CreateAndOpenFile(const TempTestFS *fs, const char *filename) {
|
int CreateAndOpenFile(const TempTestFS *fs, const char *filename) {
|
||||||
auto realpath = fs->mountDir() / filename;
|
auto realpath = fs->mountDir() / filename;
|
||||||
#if __GNUC__ == 4 && __GNUC_MINOR__ == 8
|
#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
|
#else
|
||||||
int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT);
|
int fd = ::open(realpath.c_str(), O_RDONLY | O_CREAT);
|
||||||
#endif
|
#endif
|
||||||
@ -27,8 +27,9 @@ private:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
void ReadFile(int fd) {
|
void ReadFile(int fd) {
|
||||||
int retval = ::read(fd, nullptr, 0);
|
uint8_t buf;
|
||||||
EXPECT_EQ(0, retval) << "Reading file failed";
|
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));
|
INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
||||||
@ -37,9 +38,9 @@ TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
|||||||
ReturnDoesntExistOnLstat(FILENAME);
|
ReturnDoesntExistOnLstat(FILENAME);
|
||||||
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
|
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
|
||||||
.Times(1).WillOnce(Return(GetParam()));
|
.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.
|
//For the syscall to succeed, we also need to give an fstat implementation.
|
||||||
ReturnIsFileOnFstat(GetParam());
|
ReturnIsFileOnFstatWithSize(GetParam(), 1);
|
||||||
|
|
||||||
CreateAndOpenAndReadFile(FILENAME);
|
CreateAndOpenAndReadFile(FILENAME);
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,19 @@ private:
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
void ReadFile(int fd) {
|
void ReadFile(int fd) {
|
||||||
int retval = ::read(fd, nullptr, 0);
|
uint8_t buf;
|
||||||
EXPECT_EQ(0, retval) << "Reading file failed";
|
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));
|
INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
||||||
|
|
||||||
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
||||||
ReturnIsFileOnLstat(FILENAME);
|
ReturnIsFileOnLstatWithSize(FILENAME, 1);
|
||||||
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
|
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
|
||||||
.Times(1).WillOnce(Return(GetParam()));
|
.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);
|
OpenAndReadFile(FILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ INSTANTIATE_TEST_CASE_P(FuseReadFileDescriptorTest, FuseReadFileDescriptorTest,
|
|||||||
|
|
||||||
|
|
||||||
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
|
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
|
||||||
ReturnIsFileOnLstat(FILENAME);
|
ReturnIsFileOnLstatWithSize(FILENAME, 1);
|
||||||
OnOpenReturnFileDescriptor(FILENAME, GetParam());
|
OnOpenReturnFileDescriptor(FILENAME, GetParam());
|
||||||
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
|
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
|
||||||
.Times(1).WillOnce(ReturnSuccessfulRead);
|
.Times(1).WillOnce(ReturnSuccessfulRead);
|
||||||
|
|
||||||
char buf[1];
|
char buf[1];
|
||||||
ReadFile(FILENAME, buf, 0, 0);
|
ReadFile(FILENAME, buf, 1, 0);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,15 @@ Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstat =
|
|||||||
result->st_nlink = 1;
|
result->st_nlink = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Action<void(int, struct ::stat*)> 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 <<std::endl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsDir =
|
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsDir =
|
||||||
Invoke([](const char*, struct ::stat* result) {
|
Invoke([](const char*, struct ::stat* result) {
|
||||||
result->st_mode = S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH;
|
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) {
|
void FuseTest::ReturnIsFileOnFstat(int descriptor) {
|
||||||
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
|
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FuseTest::ReturnIsFileOnFstatWithSize(int descriptor, size_t size) {
|
||||||
|
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size));
|
||||||
|
}
|
@ -104,11 +104,12 @@ public:
|
|||||||
|
|
||||||
MockFilesystem fsimpl;
|
MockFilesystem fsimpl;
|
||||||
|
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> 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
|
//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<void(const char*, struct ::stat*)> ReturnIsFile;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile;
|
||||||
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFileWithSize(size_t size);
|
||||||
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstat;
|
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstat;
|
||||||
|
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstatWithSize(size_t size);
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsDir;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsDir;
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnDoesntExist;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnDoesntExist;
|
||||||
|
|
||||||
@ -118,6 +119,7 @@ public:
|
|||||||
void ReturnDoesntExistOnLstat(const boost::filesystem::path &path);
|
void ReturnDoesntExistOnLstat(const boost::filesystem::path &path);
|
||||||
void OnOpenReturnFileDescriptor(const char *filename, int descriptor);
|
void OnOpenReturnFileDescriptor(const char *filename, int descriptor);
|
||||||
void ReturnIsFileOnFstat(int descriptor);
|
void ReturnIsFileOnFstat(int descriptor);
|
||||||
|
void ReturnIsFileOnFstatWithSize(int descriptor, const size_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user