svn commit: r345119 - projects/fuse2/tests/sys/fs/fuse
Alan Somers
asomers at FreeBSD.org
Thu Mar 14 00:13:03 UTC 2019
Author: asomers
Date: Thu Mar 14 00:12:59 2019
New Revision: 345119
URL: https://svnweb.freebsd.org/changeset/base/345119
Log:
fuse(4): combine common code in the tests
Combine a bunch of mostly similar expect_* methods into utils.cc, and only
define FH in a single place.
Sponsored by: The FreeBSD Foundation
Modified:
projects/fuse2/tests/sys/fs/fuse/access.cc
projects/fuse2/tests/sys/fs/fuse/create.cc
projects/fuse2/tests/sys/fs/fuse/flush.cc
projects/fuse2/tests/sys/fs/fuse/fsync.cc
projects/fuse2/tests/sys/fs/fuse/fsyncdir.cc
projects/fuse2/tests/sys/fs/fuse/getattr.cc
projects/fuse2/tests/sys/fs/fuse/link.cc
projects/fuse2/tests/sys/fs/fuse/locks.cc
projects/fuse2/tests/sys/fs/fuse/lookup.cc
projects/fuse2/tests/sys/fs/fuse/mkdir.cc
projects/fuse2/tests/sys/fs/fuse/open.cc
projects/fuse2/tests/sys/fs/fuse/opendir.cc
projects/fuse2/tests/sys/fs/fuse/read.cc
projects/fuse2/tests/sys/fs/fuse/readdir.cc
projects/fuse2/tests/sys/fs/fuse/readlink.cc
projects/fuse2/tests/sys/fs/fuse/release.cc
projects/fuse2/tests/sys/fs/fuse/releasedir.cc
projects/fuse2/tests/sys/fs/fuse/rename.cc
projects/fuse2/tests/sys/fs/fuse/rmdir.cc
projects/fuse2/tests/sys/fs/fuse/unlink.cc
projects/fuse2/tests/sys/fs/fuse/utils.cc
projects/fuse2/tests/sys/fs/fuse/utils.hh
projects/fuse2/tests/sys/fs/fuse/write.cc
Modified: projects/fuse2/tests/sys/fs/fuse/access.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/access.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/access.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -39,7 +39,13 @@ extern "C" {
using namespace testing;
-class Access: public FuseTest {};
+class Access: public FuseTest {
+public:
+void expect_lookup(const char *relpath, uint64_t ino)
+{
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
+}
+};
/* TODO: test methods for the default_permissions mount option */
@@ -52,12 +58,7 @@ TEST_F(Access, DISABLED_eaccess)
uint64_t ino = 42;
mode_t access_mode = X_OK;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- }));
+ expect_lookup(RELPATH, ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_ACCESS &&
@@ -81,12 +82,7 @@ TEST_F(Access, DISABLED_ok)
uint64_t ino = 42;
mode_t access_mode = R_OK;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- }));
+ expect_lookup(RELPATH, ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_ACCESS &&
Modified: projects/fuse2/tests/sys/fs/fuse/create.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/create.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/create.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -295,14 +295,7 @@ TEST_F(Create, DISABLED_entry_cache_negative_purge)
ASSERT_LE(0, fd) << strerror(errno);
/* Finally, a subsequent lookup should query the daemon */
- EXPECT_LOOKUP(1, RELPATH).Times(1)
- .WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.error = 0;
- out->body.entry.nodeid = ino;
- out->body.entry.attr.mode = S_IFREG | mode;
- SET_OUT_HEADER_LEN(out, entry);
- }));
+ expect_lookup(RELPATH, ino, S_IFREG | mode, 1);
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
/* Deliberately leak fd. close(2) will be tested in release.cc */
Modified: projects/fuse2/tests/sys/fs/fuse/flush.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/flush.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/flush.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -40,8 +40,6 @@ using namespace testing;
class Flush: public FuseTest {
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
-
public:
void expect_flush(uint64_t ino, int times, ProcessMockerT r)
{
@@ -49,60 +47,18 @@ void expect_flush(uint64_t ino, int times, ProcessMock
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_FLUSH &&
in->header.nodeid == ino &&
- in->body.flush.fh == Flush::FH);
+ in->body.flush.fh == FH);
}, Eq(true)),
_)
).Times(times)
.WillRepeatedly(Invoke(r));
}
-void expect_getattr(uint64_t ino)
-{
- /* Until the attr cache is working, we may send an additional GETATTR */
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, attr);
- out->body.attr.attr.ino = ino; // Must match nodeid
- out->body.attr.attr.mode = S_IFREG | 0644;
- }));
-
-}
-
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
}
-void expect_open(uint64_t ino, int times)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPEN &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).Times(times)
- .WillRepeatedly(Invoke([](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = Flush::FH;
- }));
-
-}
-
/*
* When testing FUSE_FLUSH, the FUSE_RELEASE calls are uninteresting. This
* expectation will silence googlemock warnings
@@ -130,8 +86,8 @@ TEST_F(Flush, DISABLED_dup)
int fd, fd2;
expect_lookup(RELPATH, ino);
- expect_open(ino, 1);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_flush(ino, 2, ReturnErrno(0));
expect_release();
@@ -161,8 +117,8 @@ TEST_F(Flush, DISABLED_eio)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino, 1);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_flush(ino, 1, ReturnErrno(EIO));
expect_release();
@@ -182,8 +138,8 @@ TEST_F(Flush, DISABLED_flush)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino, 1);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_flush(ino, 1, ReturnErrno(0));
expect_release();
Modified: projects/fuse2/tests/sys/fs/fuse/fsync.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/fsync.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/fsync.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -50,7 +50,6 @@ using namespace testing;
class Fsync: public FuseTest {
public:
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
void expect_fsync(uint64_t ino, uint32_t flags, int error)
{
EXPECT_CALL(*m_mock, process(
@@ -65,79 +64,14 @@ void expect_fsync(uint64_t ino, uint32_t flags, int er
).WillOnce(Invoke(ReturnErrno(error)));
}
-void expect_getattr(uint64_t ino)
-{
- /* Until the attr cache is working, we may send an additional GETATTR */
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, attr);
- out->body.attr.attr.ino = ino; // Must match nodeid
- out->body.attr.attr.mode = S_IFREG | 0644;
- out->body.attr.attr_valid = UINT64_MAX;
- }));
-}
-
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
}
-void expect_open(uint64_t ino)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPEN &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = FH;
- }));
-}
-
-void expect_release(uint64_t ino)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_RELEASE &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke(ReturnErrno(0)));
-}
-
void expect_write(uint64_t ino, uint64_t size, const void *contents)
{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- const char *buf = (const char*)in->body.bytes +
- sizeof(struct fuse_write_in);
-
- return (in->header.opcode == FUSE_WRITE &&
- in->header.nodeid == ino &&
- 0 == bcmp(buf, contents, size));
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, write);
- out->body.write.size = size;
- }));
+ FuseTest::expect_write(ino, 0, size, size, 0, contents);
}
};
@@ -156,8 +90,8 @@ TEST_F(Fsync, DISABLED_aio_fsync)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_write(ino, bufsize, CONTENTS);
expect_fsync(ino, 0, 0);
@@ -190,8 +124,8 @@ TEST_F(Fsync, close)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_write(ino, bufsize, CONTENTS);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
@@ -209,7 +143,7 @@ TEST_F(Fsync, close)
}, Eq(true)),
_)
).Times(0);
- expect_release(ino);
+ expect_release(ino, 1, 0);
fd = open(FULLPATH, O_RDWR);
ASSERT_LE(0, fd) << strerror(errno);
@@ -228,8 +162,8 @@ TEST_F(Fsync, DISABLED_eio)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_write(ino, bufsize, CONTENTS);
expect_fsync(ino, FUSE_FSYNC_FDATASYNC, EIO);
@@ -253,8 +187,8 @@ TEST_F(Fsync, DISABLED_fdatasync)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_write(ino, bufsize, CONTENTS);
expect_fsync(ino, FUSE_FSYNC_FDATASYNC, 0);
@@ -278,8 +212,8 @@ TEST_F(Fsync, DISABLED_fsync)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
expect_write(ino, bufsize, CONTENTS);
expect_fsync(ino, 0, 0);
@@ -303,8 +237,8 @@ TEST_F(Fsync, DISABLED_fsync_metadata_only)
mode_t mode = 0755;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_SETATTR);
@@ -335,8 +269,8 @@ TEST_F(Fsync, nop)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
fd = open(FULLPATH, O_WRONLY);
ASSERT_LE(0, fd) << strerror(errno);
@@ -346,4 +280,4 @@ TEST_F(Fsync, nop)
/* Deliberately leak fd. close(2) will be tested in release.cc */
}
-
+// TODO: ENOSYS test
Modified: projects/fuse2/tests/sys/fs/fuse/fsyncdir.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/fsyncdir.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/fsyncdir.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -50,7 +50,6 @@ using namespace testing;
class FsyncDir: public FuseTest {
public:
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
void expect_fsyncdir(uint64_t ino, uint32_t flags, int error)
{
EXPECT_CALL(*m_mock, process(
@@ -67,29 +66,7 @@ void expect_fsyncdir(uint64_t ino, uint32_t flags, int
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFDIR | 0755;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
-}
-
-void expect_opendir(uint64_t ino)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPENDIR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = FH;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFDIR | 0755, 1);
}
};
Modified: projects/fuse2/tests/sys/fs/fuse/getattr.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/getattr.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/getattr.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -45,7 +45,6 @@ TEST_F(Getattr, DISABLED_attr_cache)
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
- const uint64_t generation = 13;
struct stat sb;
EXPECT_LOOKUP(1, RELPATH).WillRepeatedly(Invoke([=](auto in, auto out) {
@@ -53,7 +52,6 @@ TEST_F(Getattr, DISABLED_attr_cache)
SET_OUT_HEADER_LEN(out, entry);
out->body.entry.attr.mode = S_IFREG | 0644;
out->body.entry.nodeid = ino;
- out->body.entry.generation = generation;
}));
EXPECT_CALL(*m_mock, process(
ResultOf([](auto in) {
@@ -84,7 +82,6 @@ TEST_F(Getattr, attr_cache_timeout)
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
- const uint64_t generation = 13;
struct stat sb;
/*
* The timeout should be longer than the longest plausible time the
@@ -92,14 +89,7 @@ TEST_F(Getattr, attr_cache_timeout)
*/
long timeout_ns = 250'000'000;
- EXPECT_LOOKUP(1, RELPATH).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.entry_valid = UINT64_MAX;
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.generation = generation;
- }));
+ expect_lookup(RELPATH, ino, S_IFREG | 0644, 2);
EXPECT_CALL(*m_mock, process(
ResultOf([](auto in) {
return (in->header.opcode == FUSE_GETATTR &&
@@ -128,13 +118,7 @@ TEST_F(Getattr, enoent)
struct stat sb;
const uint64_t ino = 42;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = 0100644;
- out->body.entry.nodeid = ino;
- }));
-
+ expect_lookup(RELPATH, ino, S_IFREG | 0644, 1);
EXPECT_CALL(*m_mock, process(
ResultOf([](auto in) {
return (in->header.opcode == FUSE_GETATTR &&
@@ -151,16 +135,9 @@ TEST_F(Getattr, ok)
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
- const uint64_t generation = 13;
struct stat sb;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.generation = generation;
- }));
+ expect_lookup(RELPATH, ino, S_IFREG | 0644, 1);
EXPECT_CALL(*m_mock, process(
ResultOf([](auto in) {
return (in->header.opcode == FUSE_GETATTR &&
@@ -201,9 +178,6 @@ TEST_F(Getattr, ok)
EXPECT_EQ(12ul, sb.st_rdev);
EXPECT_EQ(ino, sb.st_ino);
EXPECT_EQ(S_IFREG | 0644, sb.st_mode);
-
- // fuse(4) does not _yet_ support inode generations
- //EXPECT_EQ(generation, sb.st_gen);
//st_birthtim and st_flags are not supported by protocol 7.8. They're
//only supported as OS-specific extensions to OSX.
Modified: projects/fuse2/tests/sys/fs/fuse/link.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/link.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/link.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -37,7 +37,13 @@ extern "C" {
using namespace testing;
-class Link: public FuseTest {};
+class Link: public FuseTest {
+public:
+void expect_lookup(const char *relpath, uint64_t ino)
+{
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
+}
+};
TEST_F(Link, emlink)
{
@@ -48,12 +54,7 @@ TEST_F(Link, emlink)
uint64_t dst_ino = 42;
EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
- EXPECT_LOOKUP(1, RELDST).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = dst_ino;
- SET_OUT_HEADER_LEN(out, entry);
- }));
+ expect_lookup(RELDST, dst_ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
@@ -80,12 +81,7 @@ TEST_F(Link, ok)
const uint64_t ino = 42;
EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
- EXPECT_LOOKUP(1, RELDST).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = dst_ino;
- SET_OUT_HEADER_LEN(out, entry);
- }));
+ expect_lookup(RELDST, dst_ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
Modified: projects/fuse2/tests/sys/fs/fuse/locks.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/locks.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/locks.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -43,53 +43,12 @@ using namespace testing;
/* For testing filesystems without posix locking support */
class Fallback: public FuseTest {
public:
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
-void expect_getattr(uint64_t ino)
-{
- /* Until the attr cache is working, we may send an additional GETATTR */
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, attr);
- out->body.attr.attr.ino = ino; // Must match nodeid
- out->body.attr.attr.mode = S_IFREG | 0644;
- out->body.attr.attr_valid = UINT64_MAX;
- }));
-}
-
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
}
-void expect_open(uint64_t ino)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPEN &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = FH;
- }));
-}
-
};
/* For testing filesystems with posix locking support */
@@ -120,8 +79,8 @@ TEST_F(GetlkFallback, local)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
fd = open(FULLPATH, O_RDWR);
ASSERT_LE(0, fd) << strerror(errno);
@@ -150,8 +109,8 @@ TEST_F(Getlk, DISABLED_no_locks)
pid_t pid = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_GETLK &&
@@ -197,8 +156,8 @@ TEST_F(Getlk, DISABLED_lock_exists)
pid_t pid2 = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_GETLK &&
@@ -251,8 +210,8 @@ TEST_F(SetlkFallback, local)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
fd = open(FULLPATH, O_RDWR);
ASSERT_LE(0, fd) << strerror(errno);
@@ -278,8 +237,8 @@ TEST_F(Setlk, DISABLED_set)
pid_t pid = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_SETLK &&
@@ -323,8 +282,8 @@ TEST_F(Setlk, DISABLED_set_eof)
pid_t pid = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_SETLK &&
@@ -368,8 +327,8 @@ TEST_F(Setlk, DISABLED_eagain)
pid_t pid = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_SETLK &&
@@ -410,8 +369,8 @@ TEST_F(SetlkwFallback, local)
int fd;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
fd = open(FULLPATH, O_RDWR);
ASSERT_LE(0, fd) << strerror(errno);
@@ -441,8 +400,8 @@ TEST_F(Setlkw, DISABLED_set)
pid_t pid = 1234;
expect_lookup(RELPATH, ino);
- expect_open(ino);
- expect_getattr(ino);
+ expect_open(ino, 0, 1);
+ expect_getattr(ino, 0);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_SETLK &&
Modified: projects/fuse2/tests/sys/fs/fuse/lookup.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/lookup.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/lookup.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -49,6 +49,7 @@ TEST_F(Lookup, DISABLED_attr_cache)
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
const uint64_t ino = 42;
+ const uint64_t generation = 13;
struct stat sb;
EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
@@ -70,6 +71,7 @@ TEST_F(Lookup, DISABLED_attr_cache)
out->body.entry.attr.uid = 10;
out->body.entry.attr.gid = 11;
out->body.entry.attr.rdev = 12;
+ out->body.entry.generation = generation;
}));
/* stat(2) issues a VOP_LOOKUP followed by a VOP_GETATTR */
ASSERT_EQ(0, stat(FULLPATH, &sb)) << strerror(errno);
@@ -124,18 +126,7 @@ TEST_F(Lookup, attr_cache_timeout)
out->body.entry.attr.ino = ino; // Must match nodeid
out->body.entry.attr.mode = S_IFREG | 0644;
}));
- EXPECT_CALL(*m_mock, process(
- ResultOf([](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, attr);
- out->body.attr.attr.ino = ino; // Must match nodeid
- out->body.attr.attr.mode = S_IFREG | 0644;
- }));
+ expect_getattr(ino, 0);
/* access(2) will issue a VOP_LOOKUP but not a VOP_GETATTR */
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
@@ -245,6 +236,12 @@ TEST_F(Lookup, DISABLED_entry_cache_timeout)
/* The cache has timed out; VOP_LOOKUP should query the daemon*/
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
}
+
+// TODO: export_support
+// After upgrading the protocol to 7.10, check that the kernel will only
+// attempt to lookup "." and ".." if the filesystem sets FUSE_EXPORT_SUPPORT in
+// the init flags. If not, then all lookups for those entries will return
+// ESTALE.
TEST_F(Lookup, ok)
{
Modified: projects/fuse2/tests/sys/fs/fuse/mkdir.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/mkdir.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/mkdir.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -145,14 +145,7 @@ TEST_F(Mkdir, DISABLED_entry_cache_negative_purge)
ASSERT_EQ(0, mkdir(FULLPATH, mode)) << strerror(errno);
/* Finally, a subsequent lookup should query the daemon */
- EXPECT_LOOKUP(1, RELPATH).Times(1)
- .WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.error = 0;
- out->body.entry.nodeid = ino;
- out->body.entry.attr.mode = S_IFDIR | mode;
- SET_OUT_HEADER_LEN(out, entry);
- }));
+ expect_lookup(RELPATH, ino, S_IFDIR | mode, 1);
ASSERT_EQ(0, access(FULLPATH, F_OK)) << strerror(errno);
}
Modified: projects/fuse2/tests/sys/fs/fuse/open.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/open.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/open.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -48,14 +48,7 @@ void test_ok(int os_flags, int fuse_flags) {
uint64_t ino = 42;
int fd;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
-
+ FuseTest::expect_lookup(RELPATH, ino, S_IFREG | 0644, 1);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_OPEN &&
@@ -101,13 +94,7 @@ TEST_F(Open, enoent)
const char RELPATH[] = "some_file.txt";
uint64_t ino = 42;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- }));
-
+ expect_lookup(RELPATH, ino, S_IFREG | 0644, 1);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_OPEN &&
@@ -129,13 +116,7 @@ TEST_F(Open, eperm)
const char RELPATH[] = "some_file.txt";
uint64_t ino = 42;
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- }));
-
+ expect_lookup(RELPATH, ino, S_IFREG | 0644, 1);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
return (in->header.opcode == FUSE_OPEN &&
Modified: projects/fuse2/tests/sys/fs/fuse/opendir.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/opendir.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/opendir.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -42,13 +42,7 @@ class Opendir: public FuseTest {
public:
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFDIR | 0755;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFDIR | 0755, 1);
}
};
Modified: projects/fuse2/tests/sys/fs/fuse/read.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/read.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/read.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -48,72 +48,9 @@ using namespace testing;
class Read: public FuseTest {
public:
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
-void expect_getattr(uint64_t ino, uint64_t size)
-{
- /* Until the attr cache is working, we may send an additional GETATTR */
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, attr);
- out->body.attr.attr.ino = ino; // Must match nodeid
- out->body.attr.attr.mode = S_IFREG | 0644;
- out->body.attr.attr.size = size;
- }));
-
-}
-
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFREG | 0644;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
-}
-
-void expect_open(uint64_t ino, uint32_t flags, int times)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPEN &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).Times(times)
- .WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = Read::FH;
- out->body.open.open_flags = flags;
- }));
-}
-
-void expect_read(uint64_t ino, uint64_t offset, uint64_t isize, uint64_t osize,
- const void *contents)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_READ &&
- in->header.nodeid == ino &&
- in->body.read.fh == Read::FH &&
- in->body.read.offset == offset &&
- in->body.read.size == isize);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(struct fuse_out_header) + osize;
- memmove(out->body.bytes, contents, osize);
- })).RetiresOnSaturation();
+ FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 1);
}
};
Modified: projects/fuse2/tests/sys/fs/fuse/readdir.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/readdir.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/readdir.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -40,43 +40,10 @@ using namespace testing;
using namespace std;
class Readdir: public FuseTest {
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
public:
void expect_lookup(const char *relpath, uint64_t ino)
{
- EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFDIR | 0755;
- out->body.entry.nodeid = ino;
- out->body.entry.attr_valid = UINT64_MAX;
- }));
-}
-
-void expect_opendir(uint64_t ino)
-{
- EXPECT_CALL(*m_mock, process(
- ResultOf([](auto in) {
- return (in->header.opcode == FUSE_STATFS);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, statfs);
- }));
-
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_OPENDIR &&
- in->header.nodeid == ino);
- }, Eq(true)),
- _)
- ).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- out->header.len = sizeof(out->header);
- SET_OUT_HEADER_LEN(out, open);
- out->body.open.fh = FH;
- }));
+ FuseTest::expect_lookup(relpath, ino, S_IFDIR | 0755, 1);
}
void expect_readdir(uint64_t ino, uint64_t off, vector<struct dirent> &ents)
Modified: projects/fuse2/tests/sys/fs/fuse/readlink.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/readlink.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/readlink.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -37,7 +37,13 @@ extern "C" {
using namespace testing;
-class Readlink: public FuseTest {};
+class Readlink: public FuseTest {
+public:
+void expect_lookup(const char *relpath, uint64_t ino)
+{
+ FuseTest::expect_lookup(relpath, ino, S_IFLNK | 0777, 1);
+}
+};
TEST_F(Readlink, eloop)
{
@@ -46,12 +52,7 @@ TEST_F(Readlink, eloop)
const uint64_t ino = 42;
char buf[80];
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFLNK | 0777;
- out->body.entry.nodeid = ino;
- }));
+ expect_lookup(RELPATH, ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
@@ -73,12 +74,7 @@ TEST_F(Readlink, ok)
const uint64_t ino = 42;
char buf[80];
- EXPECT_LOOKUP(1, RELPATH).WillOnce(Invoke([=](auto in, auto out) {
- out->header.unique = in->header.unique;
- SET_OUT_HEADER_LEN(out, entry);
- out->body.entry.attr.mode = S_IFLNK | 0777;
- out->body.entry.nodeid = ino;
- }));
+ expect_lookup(RELPATH, ino);
EXPECT_CALL(*m_mock, process(
ResultOf([=](auto in) {
Modified: projects/fuse2/tests/sys/fs/fuse/release.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/release.cc Wed Mar 13 22:16:00 2019 (r345118)
+++ projects/fuse2/tests/sys/fs/fuse/release.cc Thu Mar 14 00:12:59 2019 (r345119)
@@ -40,68 +40,11 @@ using namespace testing;
class Release: public FuseTest {
-const static uint64_t FH = 0xdeadbeef1a7ebabe;
-
public:
-void expect_getattr(uint64_t ino)
+void expect_lookup(const char *relpath, uint64_t ino, int times)
{
- /* Until the attr cache is working, we may send an additional GETATTR */
- EXPECT_CALL(*m_mock, process(
- ResultOf([=](auto in) {
- return (in->header.opcode == FUSE_GETATTR &&
- in->header.nodeid == ino);
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-projects
mailing list