diff --git a/src/test/fspp/fuse/access/FuseAccessErrorTest.cpp b/src/test/fspp/fuse/access/FuseAccessErrorTest.cpp index d9d29b8d..28c042a3 100644 --- a/src/test/fspp/fuse/access/FuseAccessErrorTest.cpp +++ b/src/test/fspp/fuse/access/FuseAccessErrorTest.cpp @@ -21,7 +21,6 @@ TEST_P(FuseAccessErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, access(StrEq(FILENAME), _)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = AccessFileAllowError(FILENAME, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = AccessFileReturnError(FILENAME, 0); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp b/src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp index 68926079..c1206ce2 100644 --- a/src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp +++ b/src/test/fspp/fuse/access/testutils/FuseAccessTest.cpp @@ -1,13 +1,18 @@ #include "FuseAccessTest.h" void FuseAccessTest::AccessFile(const char *filename, int mode) { - int retval = AccessFileAllowError(filename, mode); - EXPECT_EQ(0, retval); + int error = AccessFileReturnError(filename, mode); + EXPECT_EQ(0, error); } -int FuseAccessTest::AccessFileAllowError(const char *filename, int mode) { +int FuseAccessTest::AccessFileReturnError(const char *filename, int mode) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; - return ::access(realpath.c_str(), mode); + int retval = ::access(realpath.c_str(), mode); + if (retval == 0) { + return 0; + } else { + return errno; + } } diff --git a/src/test/fspp/fuse/access/testutils/FuseAccessTest.h b/src/test/fspp/fuse/access/testutils/FuseAccessTest.h index cadc4d1a..405b7fcb 100644 --- a/src/test/fspp/fuse/access/testutils/FuseAccessTest.h +++ b/src/test/fspp/fuse/access/testutils/FuseAccessTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void AccessFile(const char *filename, int mode); - int AccessFileAllowError(const char *filename, int mode); + int AccessFileReturnError(const char *filename, int mode); }; #endif diff --git a/src/test/fspp/fuse/createAndOpenFile/FuseCreateAndOpenErrorTest.cpp b/src/test/fspp/fuse/createAndOpenFile/FuseCreateAndOpenErrorTest.cpp index 59ceff87..214a939c 100644 --- a/src/test/fspp/fuse/createAndOpenFile/FuseCreateAndOpenErrorTest.cpp +++ b/src/test/fspp/fuse/createAndOpenFile/FuseCreateAndOpenErrorTest.cpp @@ -21,17 +21,14 @@ TEST_F(FuseCreateAndOpenErrorTest, ReturnNoError) { //For the syscall to succeed, we also need to give an fstat implementation. ReturnIsFileOnFstat(1); - errno = 0; - int retval = CreateAndOpenFileAllowError(FILENAME, O_RDONLY); - EXPECT_EQ(errno, 0); - EXPECT_GE(retval, 0); + int error = CreateAndOpenFileReturnError(FILENAME, O_RDONLY); + EXPECT_EQ(0, error); } TEST_P(FuseCreateAndOpenErrorTest, ReturnError) { ReturnDoesntExistOnLstat(FILENAME); EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = CreateAndOpenFileAllowError(FILENAME, O_RDONLY); - EXPECT_EQ(retval, -1); - EXPECT_EQ(GetParam(), errno); + int error = CreateAndOpenFileReturnError(FILENAME, O_RDONLY); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp index 2bc08a45..a7a81796 100644 --- a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp +++ b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.cpp @@ -8,9 +8,23 @@ int FuseCreateAndOpenTest::CreateAndOpenFile(const char *filename, int flags) { return fd; } +int FuseCreateAndOpenTest::CreateAndOpenFileReturnError(const char *filename, int flags) { + int fd = CreateAndOpenFileAllowError(filename, flags); + if (fd >= 0) { + return 0; + } else { + return -fd; + } +} + int FuseCreateAndOpenTest::CreateAndOpenFileAllowError(const char *filename, int flags) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; - return ::open(realpath.c_str(), flags | O_CREAT); + int fd = ::open(realpath.c_str(), flags | O_CREAT); + if (fd >= 0) { + return fd; + } else { + return -errno; + } } diff --git a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h index f81b544a..c2ce85bc 100644 --- a/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h +++ b/src/test/fspp/fuse/createAndOpenFile/testutils/FuseCreateAndOpenTest.h @@ -9,6 +9,8 @@ public: const char *FILENAME = "/myfile"; int CreateAndOpenFile(const char *FILENAME, int flags); + int CreateAndOpenFileReturnError(const char *FILENAME, int flags); +private: int CreateAndOpenFileAllowError(const char *FILENAME, int flags); }; diff --git a/src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp b/src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp index e0eec2fb..0780f8f6 100644 --- a/src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp +++ b/src/test/fspp/fuse/fdatasync/FuseFdatasyncErrorTest.cpp @@ -22,7 +22,6 @@ TEST_P(FuseFdatasyncErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, fdatasync(0)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = FdatasyncFileAllowError(FILENAME); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = FdatasyncFileReturnError(FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp b/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp index 681894a6..69695c13 100644 --- a/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp +++ b/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.cpp @@ -1,15 +1,20 @@ #include "FuseFdatasyncTest.h" void FuseFdatasyncTest::FdatasyncFile(const char *filename) { - int retval = FdatasyncFileAllowError(filename); - EXPECT_EQ(0, retval); + int error = FdatasyncFileReturnError(filename); + EXPECT_EQ(0, error); } -int FuseFdatasyncTest::FdatasyncFileAllowError(const char *filename) { +int FuseFdatasyncTest::FdatasyncFileReturnError(const char *filename) { auto fs = TestFS(); int fd = OpenFile(fs.get(), filename); - return ::fdatasync(fd); + int retval = ::fdatasync(fd); + if (retval == 0) { + return 0; + } else { + return errno; + } } int FuseFdatasyncTest::OpenFile(const TempTestFS *fs, const char *filename) { diff --git a/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h b/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h index f6536b24..7b04a833 100644 --- a/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h +++ b/src/test/fspp/fuse/fdatasync/testutils/FuseFdatasyncTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void FdatasyncFile(const char *filename); - int FdatasyncFileAllowError(const char *filename); + int FdatasyncFileReturnError(const char *filename); private: int OpenFile(const TempTestFS *fs, const char *filename); diff --git a/src/test/fspp/fuse/flush/FuseFlushErrorTest.cpp b/src/test/fspp/fuse/flush/FuseFlushErrorTest.cpp index 0770d954..54be24c6 100644 --- a/src/test/fspp/fuse/flush/FuseFlushErrorTest.cpp +++ b/src/test/fspp/fuse/flush/FuseFlushErrorTest.cpp @@ -27,6 +27,6 @@ TEST_P(FuseFlushErrorTest, ReturnErrorFromFlush) { int fd = OpenFile(fs.get(), FILENAME); int close_result = ::close(fd); - EXPECT_EQ(-1, close_result); EXPECT_EQ(GetParam(), errno); + EXPECT_EQ(-1, close_result); } diff --git a/src/test/fspp/fuse/flush/testutils/FuseFlushTest.cpp b/src/test/fspp/fuse/flush/testutils/FuseFlushTest.cpp new file mode 100644 index 00000000..1000ca56 --- /dev/null +++ b/src/test/fspp/fuse/flush/testutils/FuseFlushTest.cpp @@ -0,0 +1,19 @@ +#include "FuseFlushTest.h" + +void FuseFlushTest::OpenAndCloseFile(const std::string &filename) { + auto fs = TestFS(); + int fd = OpenFile(fs.get(), filename); + CloseFile(fd); +} + +int FuseFlushTest::OpenFile(const TempTestFS *fs, const std::string &filename) { + auto real_path = fs->mountDir() / filename; + int fd = ::open(real_path.c_str(), O_RDONLY); + EXPECT_GE(fd, 0) << "Opening file failed"; + return fd; +} + +void FuseFlushTest::CloseFile(int fd) { + int retval = ::close(fd); + EXPECT_EQ(0, retval); +} diff --git a/src/test/fspp/fuse/flush/testutils/FuseFlushTest.h b/src/test/fspp/fuse/flush/testutils/FuseFlushTest.h index 609e7b09..7c622164 100644 --- a/src/test/fspp/fuse/flush/testutils/FuseFlushTest.h +++ b/src/test/fspp/fuse/flush/testutils/FuseFlushTest.h @@ -11,23 +11,9 @@ class FuseFlushTest: public FuseTest { public: const std::string FILENAME = "/myfile"; - void OpenAndCloseFile(const std::string &filename) { - auto fs = TestFS(); - int fd = OpenFile(fs.get(), filename); - CloseFile(fd); - } - - int OpenFile(const TempTestFS *fs, const std::string &filename) { - auto real_path = fs->mountDir() / filename; - int fd = ::open(real_path.c_str(), O_RDONLY); - EXPECT_GE(fd, 0) << "Opening file failed"; - return fd; - } - - void CloseFile(int fd) { - int retval = ::close(fd); - EXPECT_EQ(0, retval); - } + void OpenAndCloseFile(const std::string &filename); + int OpenFile(const TempTestFS *fs, const std::string &filename); + void CloseFile(int fd); }; diff --git a/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp b/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp index a8b07606..d2fa4b6d 100644 --- a/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp +++ b/src/test/fspp/fuse/fstat/FuseFstatErrorTest.cpp @@ -34,7 +34,6 @@ TEST_P(FuseFstatErrorTest, ReturnedErrorCodeIsCorrect) { auto fs = TestFS(); - int fd = CreateFileAllowErrors(fs.get(), FILENAME); - EXPECT_EQ(-1, fd); - EXPECT_EQ(GetParam(), errno); + int error = CreateFileReturnError(fs.get(), FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp index 778ca0af..0953e26b 100644 --- a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp +++ b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.cpp @@ -10,9 +10,23 @@ int FuseFstatTest::CreateFile(const TempTestFS *fs, const std::string &filename) return fd; } +int FuseFstatTest::CreateFileReturnError(const TempTestFS *fs, const std::string &filename) { + int fd = CreateFileAllowErrors(fs, filename); + if (fd >= 0) { + return 0; + } else { + return -fd; + } +} + int FuseFstatTest::CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename) { auto real_path = fs->mountDir() / filename; - return ::open(real_path.c_str(), O_RDWR | O_CREAT); + int fd = ::open(real_path.c_str(), O_RDWR | O_CREAT); + if (fd >= 0) { + return fd; + } else { + return -errno; + } } void FuseFstatTest::OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor) { diff --git a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h index 58a76706..c8824f6a 100644 --- a/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h +++ b/src/test/fspp/fuse/fstat/testutils/FuseFstatTest.h @@ -7,8 +7,10 @@ class FuseFstatTest: public FuseTest { public: int CreateFile(const TempTestFS *fs, const std::string &filename); - int CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename); + int CreateFileReturnError(const TempTestFS *fs, const std::string &filename); void OnCreateAndOpenReturnFileDescriptor(const char *filename, int descriptor); +private: + int CreateFileAllowErrors(const TempTestFS *fs, const std::string &filename); }; diff --git a/src/test/fspp/fuse/fsync/FuseFsyncErrorTest.cpp b/src/test/fspp/fuse/fsync/FuseFsyncErrorTest.cpp index ace07189..071a3332 100644 --- a/src/test/fspp/fuse/fsync/FuseFsyncErrorTest.cpp +++ b/src/test/fspp/fuse/fsync/FuseFsyncErrorTest.cpp @@ -22,7 +22,6 @@ TEST_P(FuseFsyncErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, fsync(0)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = FsyncFileAllowError(FILENAME); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = FsyncFileReturnError(FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.cpp b/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.cpp index ba62cca9..97de440c 100644 --- a/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.cpp +++ b/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.cpp @@ -1,15 +1,20 @@ #include "FuseFsyncTest.h" void FuseFsyncTest::FsyncFile(const char *filename) { - int retval = FsyncFileAllowError(filename); - EXPECT_EQ(0, retval); + int error = FsyncFileReturnError(filename); + EXPECT_EQ(0, error); } -int FuseFsyncTest::FsyncFileAllowError(const char *filename) { +int FuseFsyncTest::FsyncFileReturnError(const char *filename) { auto fs = TestFS(); int fd = OpenFile(fs.get(), filename); - return ::fsync(fd); + int retval = ::fsync(fd); + if (retval == 0) { + return 0; + } else { + return errno; + } } int FuseFsyncTest::OpenFile(const TempTestFS *fs, const char *filename) { diff --git a/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.h b/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.h index 104f1bda..55e36303 100644 --- a/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.h +++ b/src/test/fspp/fuse/fsync/testutils/FuseFsyncTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void FsyncFile(const char *filename); - int FsyncFileAllowError(const char *filename); + int FsyncFileReturnError(const char *filename); private: int OpenFile(const TempTestFS *fs, const char *filename); diff --git a/src/test/fspp/fuse/ftruncate/FuseFTruncateErrorTest.cpp b/src/test/fspp/fuse/ftruncate/FuseFTruncateErrorTest.cpp index 2fbac786..b577ce43 100644 --- a/src/test/fspp/fuse/ftruncate/FuseFTruncateErrorTest.cpp +++ b/src/test/fspp/fuse/ftruncate/FuseFTruncateErrorTest.cpp @@ -24,7 +24,6 @@ TEST_P(FuseFTruncateErrorTest, ReturnedErrorIsCorrect) { //Needed to make ::ftruncate system call return successfully ReturnIsFileOnFstat(0); - int retval = FTruncateFileAllowError(FILENAME, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = FTruncateFileReturnError(FILENAME, 0); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.cpp b/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.cpp index 36178401..7adcfa2b 100644 --- a/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.cpp +++ b/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.cpp @@ -1,15 +1,20 @@ #include "FuseFTruncateTest.h" void FuseFTruncateTest::FTruncateFile(const char *filename, off_t size) { - int retval = FTruncateFileAllowError(filename, size); - EXPECT_EQ(0, retval); + int error = FTruncateFileReturnError(filename, size); + EXPECT_EQ(0, error); } -int FuseFTruncateTest::FTruncateFileAllowError(const char *filename, off_t size) { +int FuseFTruncateTest::FTruncateFileReturnError(const char *filename, off_t size) { auto fs = TestFS(); int fd = OpenFile(fs.get(), filename); - return ::ftruncate(fd, size); + int retval = ::ftruncate(fd, size); + if (0 == retval) { + return 0; + } else { + return errno; + } } int FuseFTruncateTest::OpenFile(const TempTestFS *fs, const char *filename) { diff --git a/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.h b/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.h index b27cec5c..4942eab7 100644 --- a/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.h +++ b/src/test/fspp/fuse/ftruncate/testutils/FuseFTruncateTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void FTruncateFile(const char *filename, off_t size); - int FTruncateFileAllowError(const char *filename, off_t size); + int FTruncateFileReturnError(const char *filename, off_t size); private: int OpenFile(const TempTestFS *fs, const char *filename); diff --git a/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp b/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp index d2ba6b3c..d3cdca96 100644 --- a/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp +++ b/src/test/fspp/fuse/lstat/FuseLstatErrorTest.cpp @@ -18,14 +18,12 @@ INSTANTIATE_TEST_CASE_P(LstatErrorCodes, FuseLstatErrorTest, Values(EACCES, EBAD TEST_F(FuseLstatErrorTest, ReturnNoError) { EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(ReturnIsFile); errno = 0; - int retval = LstatPathAllowErrors(FILENAME); - EXPECT_EQ(errno, 0); - EXPECT_EQ(retval, 0); + int error = LstatPathReturnError(FILENAME); + EXPECT_EQ(0, error); } TEST_P(FuseLstatErrorTest, ReturnError) { EXPECT_CALL(fsimpl, lstat(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = LstatPathAllowErrors(FILENAME); - EXPECT_EQ(retval, -1); - EXPECT_EQ(GetParam(), errno); + int error = LstatPathReturnError(FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp index d207726b..ebfda067 100644 --- a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.cpp @@ -10,21 +10,26 @@ void FuseLstatTest::LstatPath(const std::string &path) { LstatPath(path, &dummy); } -int FuseLstatTest::LstatPathAllowErrors(const std::string &path) { +int FuseLstatTest::LstatPathReturnError(const std::string &path) { struct stat dummy; - return LstatPathAllowErrors(path, &dummy); + return LstatPathReturnError(path, &dummy); } void FuseLstatTest::LstatPath(const std::string &path, struct stat *result) { - int retval = LstatPathAllowErrors(path, result); - EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno; + int error = LstatPathReturnError(path, result); + EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << error; } -int FuseLstatTest::LstatPathAllowErrors(const std::string &path, struct stat *result) { +int FuseLstatTest::LstatPathReturnError(const std::string &path, struct stat *result) { auto fs = TestFS(); auto realpath = fs->mountDir() / path; - return ::lstat(realpath.c_str(), result); + int retval = ::lstat(realpath.c_str(), result); + if (retval == 0) { + return 0; + } else { + return errno; + } } struct stat FuseLstatTest::CallFileLstatWithImpl(function implementation) { diff --git a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h index 961d56fb..04074dc2 100644 --- a/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h +++ b/src/test/fspp/fuse/lstat/testutils/FuseLstatTest.h @@ -22,9 +22,9 @@ protected: void LstatPath(const std::string &path, struct stat *result); // These two functions are the same as LstatPath above, but they don't fail the test when the lstat syscall - // crashes. Instead, they return the result value of the lstat syscall. - int LstatPathAllowErrors(const std::string &path); - int LstatPathAllowErrors(const std::string &path, struct stat *result); + // crashes. Instead, they return the value of errno after calling ::lstat. + int LstatPathReturnError(const std::string &path); + int LstatPathReturnError(const std::string &path, struct stat *result); // You can specify an implementation, which can modify the (struct stat *) result, // our fuse mock filesystem implementation will then return this to fuse on an lstat call. diff --git a/src/test/fspp/fuse/mkdir/FuseMkdirErrorTest.cpp b/src/test/fspp/fuse/mkdir/FuseMkdirErrorTest.cpp index 0e4d03a4..f4719737 100644 --- a/src/test/fspp/fuse/mkdir/FuseMkdirErrorTest.cpp +++ b/src/test/fspp/fuse/mkdir/FuseMkdirErrorTest.cpp @@ -16,12 +16,20 @@ class FuseMkdirErrorTest: public FuseMkdirTest, public WithParamInterface { }; INSTANTIATE_TEST_CASE_P(FuseMkdirErrorTest, FuseMkdirErrorTest, Values(EACCES, EDQUOT, EEXIST, EFAULT, ELOOP, EMLINK, ENAMETOOLONG, ENOENT, ENOMEM, ENOSPC, ENOTDIR, EPERM, EROFS, EBADF)); +TEST_F(FuseMkdirErrorTest, NoError) { + ReturnDoesntExistOnLstat(DIRNAME); + EXPECT_CALL(fsimpl, mkdir(StrEq(DIRNAME), _)) + .Times(1).WillOnce(FromNowOnReturnIsDirOnLstat()); + + int error = MkdirReturnError(DIRNAME, 0); + EXPECT_EQ(0, error); +} + TEST_P(FuseMkdirErrorTest, ReturnedErrorIsCorrect) { ReturnDoesntExistOnLstat(DIRNAME); EXPECT_CALL(fsimpl, mkdir(StrEq(DIRNAME), _)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = MkdirAllowError(DIRNAME, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = MkdirReturnError(DIRNAME, 0); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.cpp b/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.cpp index a92e9cec..33044323 100644 --- a/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.cpp +++ b/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.cpp @@ -4,15 +4,20 @@ using ::testing::Action; using ::testing::Invoke; void FuseMkdirTest::Mkdir(const char *dirname, mode_t mode) { - int retval = MkdirAllowError(dirname, mode); - EXPECT_EQ(0, retval); + int error = MkdirReturnError(dirname, mode); + EXPECT_EQ(0, error); } -int FuseMkdirTest::MkdirAllowError(const char *dirname, mode_t mode) { +int FuseMkdirTest::MkdirReturnError(const char *dirname, mode_t mode) { auto fs = TestFS(); auto realpath = fs->mountDir() / dirname; - return ::mkdir(realpath.c_str(), mode); + int retval = ::mkdir(realpath.c_str(), mode); + if (retval == 0) { + return 0; + } else { + return errno; + } } Action FuseMkdirTest::FromNowOnReturnIsDirOnLstat() { diff --git a/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.h b/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.h index ec861a90..0baff266 100644 --- a/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.h +++ b/src/test/fspp/fuse/mkdir/testutils/FuseMkdirTest.h @@ -9,7 +9,7 @@ public: const char *DIRNAME = "/mydir"; void Mkdir(const char *dirname, mode_t mode); - int MkdirAllowError(const char *dirname, mode_t mode); + int MkdirReturnError(const char *dirname, mode_t mode); ::testing::Action FromNowOnReturnIsDirOnLstat(); }; diff --git a/src/test/fspp/fuse/openFile/FuseOpenErrorTest.cpp b/src/test/fspp/fuse/openFile/FuseOpenErrorTest.cpp index 5829dec8..4ab7653a 100644 --- a/src/test/fspp/fuse/openFile/FuseOpenErrorTest.cpp +++ b/src/test/fspp/fuse/openFile/FuseOpenErrorTest.cpp @@ -13,21 +13,19 @@ using namespace fspp::fuse; class FuseOpenErrorTest: public FuseOpenTest, public WithParamInterface { }; -INSTANTIATE_TEST_CASE_P(OpenErrorCodes, FuseOpenErrorTest, Values(EACCES, EDQUOT, EEXIST, EFAULT, EFBIG, EINTR, EOVERFLOW, EINVAL, EISDIR, ELOOP, EMFILE, ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOMEM, ENOSPC, ENOTDIR, ENXIO, EOPNOTSUPP, EPERM, EROFS, ETXTBSY, EWOULDBLOCK, EBADF, ENOTDIR)); +INSTANTIATE_TEST_CASE_P(FuseOpenErrorTest, FuseOpenErrorTest, Values(EACCES, EDQUOT, EEXIST, EFAULT, EFBIG, EINTR, EOVERFLOW, EINVAL, EISDIR, ELOOP, EMFILE, ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOMEM, ENOSPC, ENOTDIR, ENXIO, EOPNOTSUPP, EPERM, EROFS, ETXTBSY, EWOULDBLOCK, EBADF, ENOTDIR)); TEST_F(FuseOpenErrorTest, ReturnNoError) { ReturnIsFileOnLstat(FILENAME); EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Return(1)); errno = 0; - int retval = OpenFileAllowError(FILENAME, O_RDONLY); - EXPECT_EQ(errno, 0); - EXPECT_GE(retval, 0); + int error = OpenFileReturnError(FILENAME, O_RDONLY); + EXPECT_EQ(0, error); } TEST_P(FuseOpenErrorTest, ReturnError) { ReturnIsFileOnLstat(FILENAME); EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = OpenFileAllowError(FILENAME, O_RDONLY); - EXPECT_EQ(retval, -1); - EXPECT_EQ(GetParam(), errno); + int error = OpenFileReturnError(FILENAME, O_RDONLY); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.cpp b/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.cpp index 176aaaf7..6a307b7f 100644 --- a/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.cpp +++ b/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.cpp @@ -6,9 +6,23 @@ int FuseOpenTest::OpenFile(const char *filename, int flags) { return fd; } +int FuseOpenTest::OpenFileReturnError(const char *filename, int flags) { + int fd = OpenFileAllowError(filename, flags); + if (fd >= 0) { + return 0; + } else { + return -fd; + } +} + int FuseOpenTest::OpenFileAllowError(const char *filename, int flags) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; - return ::open(realpath.c_str(), flags); + int fd = ::open(realpath.c_str(), flags); + if (fd >= 0) { + return fd; + } else { + return -errno; + } } diff --git a/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.h b/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.h index 943e9650..0d504985 100644 --- a/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.h +++ b/src/test/fspp/fuse/openFile/testutils/FuseOpenTest.h @@ -9,6 +9,8 @@ public: const char *FILENAME = "/myfile"; int OpenFile(const char *FILENAME, int flags); + int OpenFileReturnError(const char *FILENAME, int flags); +private: int OpenFileAllowError(const char *FILENAME, int flags); }; diff --git a/src/test/fspp/fuse/read/FuseReadErrorTest.cpp b/src/test/fspp/fuse/read/FuseReadErrorTest.cpp index 14d3d16f..07c6e0a2 100644 --- a/src/test/fspp/fuse/read/FuseReadErrorTest.cpp +++ b/src/test/fspp/fuse/read/FuseReadErrorTest.cpp @@ -33,10 +33,8 @@ TEST_P(FuseReadErrorTest, ReturnErrorOnFirstReadCall) { .WillRepeatedly(Throw(FuseErrnoException(GetParam()))); char *buf = new char[READCOUNT]; - errno = 0; - int retval = ReadFileAllowError(FILENAME, buf, READCOUNT, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0); + EXPECT_EQ(GetParam(), retval.error); delete[] buf; } @@ -56,9 +54,8 @@ TEST_P(FuseReadErrorTest, ReturnErrorOnSecondReadCall) { .WillRepeatedly(Throw(FuseErrnoException(GetParam()))); char *buf = new char[READCOUNT]; - errno = 0; - size_t retval = ReadFileAllowError(FILENAME, buf, READCOUNT, 0); - EXPECT_EQ(0, errno); - EXPECT_EQ(successfullyReadBytes, retval); // Check that we're getting the number of successfully read bytes (the first read call) returned + auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0); + EXPECT_EQ(0, retval.error); + EXPECT_EQ(successfullyReadBytes, retval.read_bytes); // Check that we're getting the number of successfully read bytes (the first read call) returned delete[] buf; } diff --git a/src/test/fspp/fuse/read/FuseReadOverflowTest.cpp b/src/test/fspp/fuse/read/FuseReadOverflowTest.cpp index a1bf067e..78175d65 100644 --- a/src/test/fspp/fuse/read/FuseReadOverflowTest.cpp +++ b/src/test/fspp/fuse/read/FuseReadOverflowTest.cpp @@ -29,12 +29,12 @@ public: TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromBeginning) { char buf[READSIZE]; - size_t read_bytes = ReadFileAllowError(FILENAME, buf, READSIZE, 0); - EXPECT_EQ(FILESIZE, read_bytes); + auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, 0); + EXPECT_EQ(FILESIZE, retval.read_bytes); } TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) { char buf[READSIZE]; - size_t read_bytes = ReadFileAllowError(FILENAME, buf, READSIZE, OFFSET); - EXPECT_EQ(FILESIZE-OFFSET, read_bytes); + auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET); + EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes); } diff --git a/src/test/fspp/fuse/read/testutils/FuseReadTest.cpp b/src/test/fspp/fuse/read/testutils/FuseReadTest.cpp index 32c8e1ed..20345393 100644 --- a/src/test/fspp/fuse/read/testutils/FuseReadTest.cpp +++ b/src/test/fspp/fuse/read/testutils/FuseReadTest.cpp @@ -1,15 +1,21 @@ #include "FuseReadTest.h" void FuseReadTest::ReadFile(const char *filename, void *buf, size_t count, off_t offset) { - size_t retval = ReadFileAllowError(filename, buf, count, offset); - EXPECT_EQ(count, retval); + auto retval = ReadFileReturnError(filename, buf, count, offset); + EXPECT_EQ(0, retval.error); + EXPECT_EQ(count, retval.read_bytes); } -size_t FuseReadTest::ReadFileAllowError(const char *filename, void *buf, size_t count, off_t offset) { +FuseReadTest::ReadError FuseReadTest::ReadFileReturnError(const char *filename, void *buf, size_t count, off_t offset) { auto fs = TestFS(); int fd = OpenFile(fs.get(), filename); - return ::pread(fd, buf, count, offset); + + ReadError result; + errno = 0; + result.read_bytes = ::pread(fd, buf, count, offset); + result.error = errno; + return result; } int FuseReadTest::OpenFile(const TempTestFS *fs, const char *filename) { diff --git a/src/test/fspp/fuse/read/testutils/FuseReadTest.h b/src/test/fspp/fuse/read/testutils/FuseReadTest.h index 45c0fa70..b5ce456c 100644 --- a/src/test/fspp/fuse/read/testutils/FuseReadTest.h +++ b/src/test/fspp/fuse/read/testutils/FuseReadTest.h @@ -8,8 +8,13 @@ class FuseReadTest: public FuseTest { public: const char *FILENAME = "/myfile"; + struct ReadError { + int error; + size_t read_bytes; + }; + void ReadFile(const char *filename, void *buf, size_t count, off_t offset); - size_t ReadFileAllowError(const char *filename, void *buf, size_t count, off_t offset); + ReadError ReadFileReturnError(const char *filename, void *buf, size_t count, off_t offset); ::testing::Action ReturnSuccessfulRead = ::testing::Invoke([](int, void *, size_t count, off_t) { diff --git a/src/test/fspp/fuse/rename/FuseRenameErrorTest.cpp b/src/test/fspp/fuse/rename/FuseRenameErrorTest.cpp index aacb0a69..9866fb7c 100644 --- a/src/test/fspp/fuse/rename/FuseRenameErrorTest.cpp +++ b/src/test/fspp/fuse/rename/FuseRenameErrorTest.cpp @@ -22,7 +22,6 @@ TEST_P(FuseRenameErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, rename(StrEq(FILENAME1), StrEq(FILENAME2))) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = RenameAllowError(FILENAME1, FILENAME2); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = RenameReturnError(FILENAME1, FILENAME2); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/rename/testutils/FuseRenameTest.cpp b/src/test/fspp/fuse/rename/testutils/FuseRenameTest.cpp index d3786fee..b0e1732c 100644 --- a/src/test/fspp/fuse/rename/testutils/FuseRenameTest.cpp +++ b/src/test/fspp/fuse/rename/testutils/FuseRenameTest.cpp @@ -4,14 +4,19 @@ using ::testing::Action; using ::testing::Invoke; void FuseRenameTest::Rename(const char *from, const char *to) { - int retval = RenameAllowError(from, to); - EXPECT_EQ(0, retval); + int error = RenameReturnError(from, to); + EXPECT_EQ(0, error); } -int FuseRenameTest::RenameAllowError(const char *from, const char *to) { +int FuseRenameTest::RenameReturnError(const char *from, const char *to) { auto fs = TestFS(); auto realfrom = fs->mountDir() / from; auto realto = fs->mountDir() / to; - return ::rename(realfrom.c_str(), realto.c_str()); + int retval = ::rename(realfrom.c_str(), realto.c_str()); + if (0 == retval) { + return 0; + } else { + return errno; + } } diff --git a/src/test/fspp/fuse/rename/testutils/FuseRenameTest.h b/src/test/fspp/fuse/rename/testutils/FuseRenameTest.h index 2c86b40c..fe1366eb 100644 --- a/src/test/fspp/fuse/rename/testutils/FuseRenameTest.h +++ b/src/test/fspp/fuse/rename/testutils/FuseRenameTest.h @@ -10,7 +10,7 @@ public: const char *FILENAME2 = "/myfile2"; void Rename(const char *from, const char *to); - int RenameAllowError(const char *from, const char *to); + int RenameReturnError(const char *from, const char *to); }; #endif diff --git a/src/test/fspp/fuse/rmdir/FuseRmdirErrorTest.cpp b/src/test/fspp/fuse/rmdir/FuseRmdirErrorTest.cpp index 53f56c82..ac64f18d 100644 --- a/src/test/fspp/fuse/rmdir/FuseRmdirErrorTest.cpp +++ b/src/test/fspp/fuse/rmdir/FuseRmdirErrorTest.cpp @@ -21,7 +21,6 @@ TEST_P(FuseRmdirErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, rmdir(StrEq(DIRNAME))) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = RmdirAllowError(DIRNAME); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = RmdirReturnError(DIRNAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.cpp b/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.cpp index d59d1459..a655594c 100644 --- a/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.cpp +++ b/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.cpp @@ -4,15 +4,20 @@ using ::testing::Action; using ::testing::Invoke; void FuseRmdirTest::Rmdir(const char *dirname) { - int retval = RmdirAllowError(dirname); - EXPECT_EQ(0, retval); + int error = RmdirReturnError(dirname); + EXPECT_EQ(0, error); } -int FuseRmdirTest::RmdirAllowError(const char *dirname) { +int FuseRmdirTest::RmdirReturnError(const char *dirname) { auto fs = TestFS(); auto realpath = fs->mountDir() / dirname; - return ::rmdir(realpath.c_str()); + int retval = ::rmdir(realpath.c_str()); + if (retval == 0) { + return 0; + } else { + return errno; + } } Action FuseRmdirTest::FromNowOnReturnDoesntExistOnLstat() { diff --git a/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.h b/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.h index ae156d25..90d9d69c 100644 --- a/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.h +++ b/src/test/fspp/fuse/rmdir/testutils/FuseRmdirTest.h @@ -9,7 +9,7 @@ public: const char *DIRNAME = "/mydir"; void Rmdir(const char *dirname); - int RmdirAllowError(const char *dirname); + int RmdirReturnError(const char *dirname); ::testing::Action FromNowOnReturnDoesntExistOnLstat(); }; diff --git a/src/test/fspp/fuse/statfs/FuseStatfsErrorTest.cpp b/src/test/fspp/fuse/statfs/FuseStatfsErrorTest.cpp index 9bae9797..44d24f4a 100644 --- a/src/test/fspp/fuse/statfs/FuseStatfsErrorTest.cpp +++ b/src/test/fspp/fuse/statfs/FuseStatfsErrorTest.cpp @@ -19,16 +19,13 @@ INSTANTIATE_TEST_CASE_P(FuseStatfsErrorTest, FuseStatfsErrorTest, Values(EACCES, TEST_F(FuseStatfsErrorTest, ReturnNoError) { ReturnIsFileOnLstat(FILENAME); EXPECT_CALL(fsimpl, statfs(StrEq(FILENAME), _)).Times(1).WillOnce(Return()); - errno = 0; - int retval = StatfsAllowErrors(FILENAME); - EXPECT_EQ(errno, 0); - EXPECT_EQ(retval, 0); + int error = StatfsReturnError(FILENAME); + EXPECT_EQ(0, error); } TEST_P(FuseStatfsErrorTest, ReturnError) { ReturnIsFileOnLstat(FILENAME); EXPECT_CALL(fsimpl, statfs(StrEq(FILENAME), _)).Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = StatfsAllowErrors(FILENAME); - EXPECT_EQ(retval, -1); - EXPECT_EQ(GetParam(), errno); + int error = StatfsReturnError(FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.cpp b/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.cpp index 13e6c599..7d0e09bd 100644 --- a/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.cpp +++ b/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.cpp @@ -10,21 +10,26 @@ void FuseStatfsTest::Statfs(const std::string &path) { Statfs(path, &dummy); } -int FuseStatfsTest::StatfsAllowErrors(const std::string &path) { +int FuseStatfsTest::StatfsReturnError(const std::string &path) { struct ::statvfs dummy; - return StatfsAllowErrors(path, &dummy); + return StatfsReturnError(path, &dummy); } void FuseStatfsTest::Statfs(const std::string &path, struct ::statvfs *result) { - int retval = StatfsAllowErrors(path, result); - EXPECT_EQ(0, retval) << "lstat syscall failed. errno: " << errno; + int error = StatfsReturnError(path, result); + EXPECT_EQ(0, error) << "lstat syscall failed. errno: " << errno; } -int FuseStatfsTest::StatfsAllowErrors(const std::string &path, struct ::statvfs *result) { +int FuseStatfsTest::StatfsReturnError(const std::string &path, struct ::statvfs *result) { auto fs = TestFS(); auto realpath = fs->mountDir() / path; - return ::statvfs(realpath.c_str(), result); + int retval = ::statvfs(realpath.c_str(), result); + if (retval == 0) { + return 0; + } else { + return errno; + } } struct ::statvfs FuseStatfsTest::CallStatfsWithImpl(function implementation) { diff --git a/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.h b/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.h index 4f1a18a5..406c205f 100644 --- a/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.h +++ b/src/test/fspp/fuse/statfs/testutils/FuseStatfsTest.h @@ -23,8 +23,8 @@ protected: // These two functions are the same as Statfs above, but they don't fail the test when the statfs syscall // crashes. Instead, they return the result value of the statfs syscall. - int StatfsAllowErrors(const std::string &path); - int StatfsAllowErrors(const std::string &path, struct ::statvfs *result); + int StatfsReturnError(const std::string &path); + int StatfsReturnError(const std::string &path, struct ::statvfs *result); // You can specify an implementation, which can modify the (struct statfs *) result, // our fuse mock filesystem implementation will then return this to fuse on an statfs call. diff --git a/src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp b/src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp index 0daf39e2..67295eb4 100644 --- a/src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp +++ b/src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp @@ -21,7 +21,6 @@ TEST_P(FuseTruncateErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = TruncateFileAllowError(FILENAME, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = TruncateFileReturnError(FILENAME, 0); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp b/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp index d7753899..49516025 100644 --- a/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp +++ b/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp @@ -1,13 +1,18 @@ #include "FuseTruncateTest.h" void FuseTruncateTest::TruncateFile(const char *filename, off_t size) { - int retval = TruncateFileAllowError(filename, size); - EXPECT_EQ(0, retval); + int error = TruncateFileReturnError(filename, size); + EXPECT_EQ(0, error); } -int FuseTruncateTest::TruncateFileAllowError(const char *filename, off_t size) { +int FuseTruncateTest::TruncateFileReturnError(const char *filename, off_t size) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; - return ::truncate(realpath.c_str(), size); + int retval = ::truncate(realpath.c_str(), size); + if (retval == 0) { + return 0; + } else { + return errno; + } } diff --git a/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h b/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h index 33666846..9291cad0 100644 --- a/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h +++ b/src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void TruncateFile(const char *filename, off_t size); - int TruncateFileAllowError(const char *filename, off_t size); + int TruncateFileReturnError(const char *filename, off_t size); }; #endif diff --git a/src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp b/src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp index 60401835..f1a31514 100644 --- a/src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp +++ b/src/test/fspp/fuse/unlink/FuseUnlinkErrorTest.cpp @@ -21,7 +21,6 @@ TEST_P(FuseUnlinkErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, unlink(StrEq(FILENAME))) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = UnlinkAllowError(FILENAME); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = UnlinkReturnError(FILENAME); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp b/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp index 38bf93f7..37b990ae 100644 --- a/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp +++ b/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.cpp @@ -4,15 +4,20 @@ using ::testing::Action; using ::testing::Invoke; void FuseUnlinkTest::Unlink(const char *filename) { - int retval = UnlinkAllowError(filename); - EXPECT_EQ(0, retval); + int error = UnlinkReturnError(filename); + EXPECT_EQ(0, error); } -int FuseUnlinkTest::UnlinkAllowError(const char *filename) { +int FuseUnlinkTest::UnlinkReturnError(const char *filename) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; - return ::unlink(realpath.c_str()); + int retval = ::unlink(realpath.c_str()); + if (0 == retval) { + return 0; + } else { + return errno; + } } Action FuseUnlinkTest::FromNowOnReturnDoesntExistOnLstat() { diff --git a/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h b/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h index 9ca70b82..2e12b817 100644 --- a/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h +++ b/src/test/fspp/fuse/unlink/testutils/FuseUnlinkTest.h @@ -9,7 +9,7 @@ public: const char *FILENAME = "/myfile"; void Unlink(const char *filename); - int UnlinkAllowError(const char *filename); + int UnlinkReturnError(const char *filename); ::testing::Action FromNowOnReturnDoesntExistOnLstat(); }; diff --git a/src/test/fspp/fuse/utimens/FuseUtimensErrorTest.cpp b/src/test/fspp/fuse/utimens/FuseUtimensErrorTest.cpp index 61128119..c8488bbf 100644 --- a/src/test/fspp/fuse/utimens/FuseUtimensErrorTest.cpp +++ b/src/test/fspp/fuse/utimens/FuseUtimensErrorTest.cpp @@ -21,7 +21,6 @@ TEST_P(FuseUtimensErrorTest, ReturnedErrorIsCorrect) { EXPECT_CALL(fsimpl, utimens(StrEq(FILENAME), _)) .Times(1).WillOnce(Throw(FuseErrnoException(GetParam()))); - int retval = UtimensAllowError(FILENAME, TIMEVALUES); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + int error = UtimensReturnError(FILENAME, TIMEVALUES); + EXPECT_EQ(GetParam(), error); } diff --git a/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.cpp b/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.cpp index 6bf32478..a4a0b9c6 100644 --- a/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.cpp +++ b/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.cpp @@ -4,11 +4,11 @@ #include void FuseUtimensTest::Utimens(const char *filename, const timespec times[2]) { - int retval = UtimensAllowError(filename, times); - EXPECT_EQ(0, retval); + int error = UtimensReturnError(filename, times); + EXPECT_EQ(0, error); } -int FuseUtimensTest::UtimensAllowError(const char *filename, const timespec times[2]) { +int FuseUtimensTest::UtimensReturnError(const char *filename, const timespec times[2]) { auto fs = TestFS(); auto realpath = fs->mountDir() / filename; @@ -16,7 +16,12 @@ int FuseUtimensTest::UtimensAllowError(const char *filename, const timespec time struct timeval casted_times[2]; TIMESPEC_TO_TIMEVAL(&casted_times[0], ×[0]); TIMESPEC_TO_TIMEVAL(&casted_times[1], ×[1]); - return ::utimes(realpath.c_str(), casted_times); + int retval = ::utimes(realpath.c_str(), casted_times); + if (0 == retval) { + return 0; + } else { + return errno; + } } struct timespec FuseUtimensTest::makeTimespec(time_t tv_sec, long tv_nsec) { diff --git a/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.h b/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.h index 4852d2d9..18285913 100644 --- a/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.h +++ b/src/test/fspp/fuse/utimens/testutils/FuseUtimensTest.h @@ -10,7 +10,7 @@ public: struct timespec TIMEVALUES[2] = {makeTimespec(0,0), makeTimespec(0,0)}; void Utimens(const char *filename, const timespec times[2]); - int UtimensAllowError(const char *filename, const timespec times[2]); + int UtimensReturnError(const char *filename, const timespec times[2]); static struct timespec makeTimespec(time_t tv_sec, long tv_nsec); }; diff --git a/src/test/fspp/fuse/write/FuseWriteErrorTest.cpp b/src/test/fspp/fuse/write/FuseWriteErrorTest.cpp index 41dca2c6..a6c31407 100644 --- a/src/test/fspp/fuse/write/FuseWriteErrorTest.cpp +++ b/src/test/fspp/fuse/write/FuseWriteErrorTest.cpp @@ -33,10 +33,8 @@ TEST_P(FuseWriteErrorTest, ReturnErrorOnFirstWriteCall) { .WillRepeatedly(Throw(FuseErrnoException(GetParam()))); char *buf = new char[WRITECOUNT]; - errno = 0; - int retval = WriteFileAllowError(FILENAME, buf, WRITECOUNT, 0); - EXPECT_EQ(GetParam(), errno); - EXPECT_EQ(-1, retval); + auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0); + EXPECT_EQ(GetParam(), retval.error); delete[] buf; } @@ -55,10 +53,9 @@ TEST_P(FuseWriteErrorTest, ReturnErrorOnSecondWriteCall) { .WillRepeatedly(Throw(FuseErrnoException(GetParam()))); char *buf = new char[WRITECOUNT]; - errno = 0; - size_t retval = WriteFileAllowError(FILENAME, buf, WRITECOUNT, 0); - EXPECT_EQ(0, errno); - EXPECT_EQ(successfullyWrittenBytes, retval); // Check that we're getting the number of successfully written bytes (the first write call) returned + auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0); + EXPECT_EQ(0, retval.error); + EXPECT_EQ(successfullyWrittenBytes, retval.written_bytes); // Check that we're getting the number of successfully written bytes (the first write call) returned delete[] buf; } diff --git a/src/test/fspp/fuse/write/testutils/FuseWriteTest.cpp b/src/test/fspp/fuse/write/testutils/FuseWriteTest.cpp index 9fd51a57..9f464fdb 100644 --- a/src/test/fspp/fuse/write/testutils/FuseWriteTest.cpp +++ b/src/test/fspp/fuse/write/testutils/FuseWriteTest.cpp @@ -1,15 +1,21 @@ #include "FuseWriteTest.h" void FuseWriteTest::WriteFile(const char *filename, const void *buf, size_t count, off_t offset) { - size_t retval = WriteFileAllowError(filename, buf, count, offset); - EXPECT_EQ(count, retval); + auto retval = WriteFileReturnError(filename, buf, count, offset); + EXPECT_EQ(0, retval.error); + EXPECT_EQ(count, retval.written_bytes); } -size_t FuseWriteTest::WriteFileAllowError(const char *filename, const void *buf, size_t count, off_t offset) { +FuseWriteTest::WriteError FuseWriteTest::WriteFileReturnError(const char *filename, const void *buf, size_t count, off_t offset) { auto fs = TestFS(); int fd = OpenFile(fs.get(), filename); - return ::pwrite(fd, buf, count, offset); + + WriteError result; + errno = 0; + result.written_bytes = ::pwrite(fd, buf, count, offset); + result.error = errno; + return result; } int FuseWriteTest::OpenFile(const TempTestFS *fs, const char *filename) { diff --git a/src/test/fspp/fuse/write/testutils/FuseWriteTest.h b/src/test/fspp/fuse/write/testutils/FuseWriteTest.h index 5430e682..65becf98 100644 --- a/src/test/fspp/fuse/write/testutils/FuseWriteTest.h +++ b/src/test/fspp/fuse/write/testutils/FuseWriteTest.h @@ -8,8 +8,13 @@ class FuseWriteTest: public FuseTest { public: const char *FILENAME = "/myfile"; + struct WriteError { + int error; + size_t written_bytes; + }; + void WriteFile(const char *filename, const void *buf, size_t count, off_t offset); - size_t WriteFileAllowError(const char *filename, const void *buf, size_t count, off_t offset); + WriteError WriteFileReturnError(const char *filename, const void *buf, size_t count, off_t offset); private: int OpenFile(const TempTestFS *fs, const char *filename);