Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Mar 2019 03:27:32 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r344789 - projects/fuse2/tests/sys/fs/fuse
Message-ID:  <201903050327.x253RWCe068758@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Tue Mar  5 03:27:32 2019
New Revision: 344789
URL: https://svnweb.freebsd.org/changeset/base/344789

Log:
  fuse(4): combine some common code in the tests
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  projects/fuse2/tests/sys/fs/fuse/Makefile
  projects/fuse2/tests/sys/fs/fuse/create.cc
  projects/fuse2/tests/sys/fs/fuse/getattr.cc
  projects/fuse2/tests/sys/fs/fuse/lookup.cc
  projects/fuse2/tests/sys/fs/fuse/mknod.cc
  projects/fuse2/tests/sys/fs/fuse/mockfs.cc
  projects/fuse2/tests/sys/fs/fuse/mockfs.hh
  projects/fuse2/tests/sys/fs/fuse/open.cc
  projects/fuse2/tests/sys/fs/fuse/readlink.cc
  projects/fuse2/tests/sys/fs/fuse/setattr.cc
  projects/fuse2/tests/sys/fs/fuse/symlink.cc

Modified: projects/fuse2/tests/sys/fs/fuse/Makefile
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/Makefile	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/Makefile	Tue Mar  5 03:27:32 2019	(r344789)
@@ -7,6 +7,7 @@ TESTSDIR=	${TESTSBASE}/sys/fs/fuse
 ATF_TESTS_CXX+=	create
 ATF_TESTS_CXX+=	getattr
 ATF_TESTS_CXX+=	lookup
+#ATF_TESTS_CXX+=	mkdir
 ATF_TESTS_CXX+=	mknod
 ATF_TESTS_CXX+=	open
 ATF_TESTS_CXX+=	readlink
@@ -27,6 +28,11 @@ SRCS.lookup+=	getmntopts.c
 SRCS.lookup+=	lookup.cc
 SRCS.lookup+=	mockfs.cc
 SRCS.lookup+=	utils.cc
+
+#SRCS.mkdir+=	getmntopts.c
+#SRCS.mkdir+=	mockfs.cc
+#SRCS.mkdir+=	mkdir.cc
+#SRCS.mkdir+=	utils.cc
 
 SRCS.mknod+=	getmntopts.c
 SRCS.mknod+=	mockfs.cc

Modified: projects/fuse2/tests/sys/fs/fuse/create.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/create.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/create.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -51,17 +51,7 @@ TEST_F(Create, DISABLED_attr_cache)
 	uint64_t ino = 42;
 	int fd;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -104,17 +94,7 @@ TEST_F(Create, eexist)
 	const char RELPATH[] = "some_file.txt";
 	mode_t mode = 0755;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -124,11 +104,7 @@ TEST_F(Create, eexist)
 				(0 == strcmp(RELPATH, name)));
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -EEXIST;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(EEXIST)));
 	EXPECT_NE(0, open(FULLPATH, O_CREAT | O_EXCL, mode));
 	EXPECT_EQ(EEXIST, errno);
 }
@@ -146,17 +122,7 @@ TEST_F(Create, DISABLED_Enosys)
 	uint64_t ino = 42;
 	int fd;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -166,11 +132,7 @@ TEST_F(Create, DISABLED_Enosys)
 				(0 == strcmp(RELPATH, name)));
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOSYS;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(ENOSYS)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -235,13 +197,7 @@ TEST_F(Create, DISABLED_entry_cache_negative)
 	int fd;
 
 	/* create will first do a LOOKUP, adding a negative cache entry */
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke([=](auto in, auto out) {
 		/* nodeid means ENOENT and cache it */
 		out->body.entry.nodeid = 0;
 		out->header.unique = in->header.unique;
@@ -304,13 +260,7 @@ TEST_F(Create, DISABLED_entry_cache_negative_purge)
 	int fd;
 
 	/* create will first do a LOOKUP, adding a negative cache entry */
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).Times(1)
+	EXPECT_LOOKUP(RELPATH).Times(1)
 	.WillOnce(Invoke([=](auto in, auto out) {
 		/* nodeid means ENOENT and cache it */
 		out->body.entry.nodeid = 0;
@@ -355,13 +305,7 @@ TEST_F(Create, DISABLED_entry_cache_negative_purge)
 	ASSERT_LE(0, fd) << strerror(errno);
 
 	/* Finally, a subsequent lookup should query the daemon */
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).Times(1)
+	EXPECT_LOOKUP(RELPATH).Times(1)
 	.WillOnce(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		out->header.error = 0;
@@ -384,17 +328,7 @@ TEST_F(Create, eperm)
 	const char RELPATH[] = "some_file.txt";
 	mode_t mode = 0755;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -404,11 +338,7 @@ TEST_F(Create, eperm)
 				(0 == strcmp(RELPATH, name)));
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -EPERM;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(EPERM)));
 	EXPECT_NE(0, open(FULLPATH, O_CREAT | O_EXCL, mode));
 	EXPECT_EQ(EPERM, errno);
 }
@@ -421,17 +351,7 @@ TEST_F(Create, ok)
 	uint64_t ino = 42;
 	int fd;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {

Modified: projects/fuse2/tests/sys/fs/fuse/getattr.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/getattr.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/getattr.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -47,13 +47,7 @@ TEST_F(Getattr, DISABLED_attr_cache)
 	const uint64_t generation = 13;
 	struct stat sb;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillRepeatedly(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -97,13 +91,7 @@ TEST_F(Getattr, attr_cache_timeout)
 	 */
 	long timeout_ns = 250'000'000;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillRepeatedly(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -139,13 +127,7 @@ TEST_F(Getattr, enoent)
 	struct stat sb;
 	const uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -158,11 +140,7 @@ TEST_F(Getattr, enoent)
 				in->header.nodeid == ino);
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(ENOENT)));
 	EXPECT_NE(0, stat(FULLPATH, &sb));
 	EXPECT_EQ(ENOENT, errno);
 }
@@ -175,13 +153,7 @@ TEST_F(Getattr, ok)
 	const uint64_t generation = 13;
 	struct stat sb;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;

Modified: projects/fuse2/tests/sys/fs/fuse/lookup.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/lookup.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/lookup.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -50,13 +50,7 @@ TEST_F(Lookup, DISABLED_attr_cache)
 	const uint64_t ino = 42;
 	struct stat sb;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		SET_OUT_HEADER_LEN(out, entry);
 		out->body.entry.nodeid = ino;
@@ -121,13 +115,7 @@ TEST_F(Lookup, attr_cache_timeout)
 	 */
 	long timeout_ns = 250'000'000;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillRepeatedly(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(RELPATH).WillRepeatedly(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		SET_OUT_HEADER_LEN(out, entry);
 		out->body.entry.nodeid = ino;
@@ -157,17 +145,11 @@ TEST_F(Lookup, attr_cache_timeout)
 
 TEST_F(Lookup, enoent)
 {
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
-	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	const char FULLPATH[] = "mountpoint/does_not_exist";
+	const char RELPATH[] = "does_not_exist";
+
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
+	EXPECT_NE(0, access(FULLPATH, F_OK));
 	EXPECT_EQ(ENOENT, errno);
 }
 
@@ -180,13 +162,7 @@ TEST_F(Lookup, entry_cache)
 	const char FULLPATH[] = "mountpoint/some_file.txt";
 	const char RELPATH[] = "some_file.txt";
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		SET_OUT_HEADER_LEN(out, entry);
 		out->body.entry.entry_valid = UINT64_MAX;
@@ -205,12 +181,7 @@ TEST_F(Lookup, entry_cache)
 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236226 */
 TEST_F(Lookup, DISABLED_entry_cache_negative)
 {
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP);
-		}, Eq(true)),
-		_)
-	).Times(1)
+	EXPECT_LOOKUP("does_not_exist").Times(1)
 	.WillOnce(Invoke([](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		out->header.error = 0;
@@ -227,18 +198,15 @@ TEST_F(Lookup, DISABLED_entry_cache_negative)
 /* Negative entry caches should timeout, too */
 TEST_F(Lookup, entry_cache_negative_timeout)
 {
+	const char *RELPATH = "does_not_exist";
+	const char *FULLPATH = "mountpoint/does_not_exist";
 	/* 
 	 * The timeout should be longer than the longest plausible time the
 	 * daemon would take to complete a write(2) to /dev/fuse, but no longer.
 	 */
 	long timeout_ns = 250'000'000;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP);
-		}, Eq(true)),
-		_)
-	).Times(2)
+	EXPECT_LOOKUP(RELPATH).Times(2)
 	.WillRepeatedly(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		out->header.error = 0;
@@ -246,13 +214,13 @@ TEST_F(Lookup, entry_cache_negative_timeout)
 		out->body.entry.entry_valid_nsec = timeout_ns;
 		SET_OUT_HEADER_LEN(out, entry);
 	}));
-	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_NE(0, access(FULLPATH, F_OK));
 	EXPECT_EQ(ENOENT, errno);
 
 	usleep(2 * timeout_ns / 1000);
 
 	/* The cache has timed out; VOP_LOOKUP should requery the daemon*/
-	EXPECT_NE(0, access("mountpoint/does_not_exist", F_OK));
+	EXPECT_NE(0, access(FULLPATH, F_OK));
 	EXPECT_EQ(ENOENT, errno);
 }
 
@@ -271,13 +239,7 @@ TEST_F(Lookup, DISABLED_entry_cache_timeout)
 	 */
 	long timeout_ns = 250'000'000;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).Times(2)
+	EXPECT_LOOKUP(RELPATH).Times(2)
 	.WillRepeatedly(Invoke([=](auto in, auto out) {
 		out->header.unique = in->header.unique;
 		SET_OUT_HEADER_LEN(out, entry);
@@ -296,13 +258,7 @@ TEST_F(Lookup, ok)
 	const char FULLPATH[] = "mountpoint/some_file.txt";
 	const char RELPATH[] = "some_file.txt";
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;

Modified: projects/fuse2/tests/sys/fs/fuse/mknod.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/mknod.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/mknod.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -54,17 +54,7 @@ void test_ok(mode_t mode, dev_t dev) {
 	const char RELPATH[] = "some_file.txt";
 	uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -118,17 +108,7 @@ TEST_F(Mknod, DISABLED_eperm)
 	const char RELPATH[] = "some_file.txt";
 	mode_t mode = S_IFIFO | 0755;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -139,11 +119,7 @@ TEST_F(Mknod, DISABLED_eperm)
 				(0 == strcmp(RELPATH, name)));
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -EPERM;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(EPERM)));
 	EXPECT_NE(0, mknod(FULLPATH, mode, 0));
 	EXPECT_EQ(EPERM, errno);
 }

Modified: projects/fuse2/tests/sys/fs/fuse/mockfs.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/mockfs.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/mockfs.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -102,6 +102,16 @@ const char* opcode2opname(uint32_t opcode)
 		return (table[opcode]);
 }
 
+std::function<void (const struct mockfs_buf_in *in, struct mockfs_buf_out *out)>
+ReturnErrno(int error)
+{
+	return([=](auto in, auto out) {
+		out->header.unique = in->header.unique;
+		out->header.error = -error;
+		out->header.len = sizeof(out->header);
+	});
+}
+
 void sigint_handler(int __unused sig) {
 	quit = 1;
 }

Modified: projects/fuse2/tests/sys/fs/fuse/mockfs.hh
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/mockfs.hh	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/mockfs.hh	Tue Mar  5 03:27:32 2019	(r344789)
@@ -42,6 +42,22 @@ extern "C" {
 			     sizeof((out)->body.variant)); \
 }
 
+/*
+ * Create an expectation on FUSE_LOOKUP and return it so the caller can set
+ * actions.
+ *
+ * This must be a macro instead of a method because EXPECT_CALL returns a type
+ * with a deleted constructor.
+ */
+#define EXPECT_LOOKUP(path)						\
+	EXPECT_CALL(*m_mock, process(					\
+		ResultOf([=](auto in) {					\
+			return (in->header.opcode == FUSE_LOOKUP &&	\
+				strcmp(in->body.lookup, (path)) == 0);	\
+		}, Eq(true)),						\
+		_)							\
+	)
+
 extern int verbosity;
 
 /* This struct isn't defined by fuse_kernel.h or libfuse, but it should be */
@@ -83,6 +99,13 @@ struct mockfs_buf_out {
 	fuse_out_header		header;
 	union fuse_payloads_out	body;
 };
+
+/*
+ * Helper function used for setting an error expectation for any fuse operation.
+ * The operation will return the supplied error
+ */
+std::function<void (const struct mockfs_buf_in *in, struct mockfs_buf_out *out)>
+ReturnErrno(int error);
 
 /*
  * Fake FUSE filesystem

Modified: projects/fuse2/tests/sys/fs/fuse/open.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/open.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/open.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -49,13 +49,7 @@ TEST_F(Open, enoent)
 	const char RELPATH[] = "some_file.txt";
 	uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -68,11 +62,7 @@ TEST_F(Open, enoent)
 				in->header.nodeid == ino);
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(ENOENT)));
 	EXPECT_NE(0, open(FULLPATH, O_RDONLY));
 	EXPECT_EQ(ENOENT, errno);
 }
@@ -87,13 +77,7 @@ TEST_F(Open, eperm)
 	const char RELPATH[] = "some_file.txt";
 	uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -106,11 +90,7 @@ TEST_F(Open, eperm)
 				in->header.nodeid == ino);
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -EPERM;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(EPERM)));
 	EXPECT_NE(0, open(FULLPATH, O_RDONLY));
 	EXPECT_EQ(EPERM, errno);
 }
@@ -122,13 +102,7 @@ TEST_F(Open, ok)
 	uint64_t ino = 42;
 	int fd;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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;

Modified: projects/fuse2/tests/sys/fs/fuse/readlink.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/readlink.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/readlink.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -45,13 +45,7 @@ TEST_F(Readlink, eloop)
 	const uint64_t ino = 42;
 	char buf[80];
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -64,13 +58,8 @@ TEST_F(Readlink, eloop)
 				in->header.nodeid == ino);
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ELOOP;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(ELOOP)));
 
-
 	EXPECT_EQ(-1, readlink(FULLPATH, buf, sizeof(buf)));
 	EXPECT_EQ(ELOOP, errno);
 }
@@ -83,13 +72,7 @@ TEST_F(Readlink, ok)
 	const uint64_t ino = 42;
 	char buf[80];
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;

Modified: projects/fuse2/tests/sys/fs/fuse/setattr.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/setattr.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/setattr.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -50,13 +50,7 @@ TEST_F(Setattr, chmod)
 	const mode_t oldmode = 0755;
 	const mode_t newmode = 0644;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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 | oldmode;
@@ -94,13 +88,7 @@ TEST_F(Setattr, chown)
 	const uid_t olduser = 33;
 	const uid_t newuser = 44;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -144,13 +132,7 @@ TEST_F(Setattr, eperm)
 	const char RELPATH[] = "some_file.txt";
 	const uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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 | 0777;
@@ -165,11 +147,7 @@ TEST_F(Setattr, eperm)
 				in->header.nodeid == ino);
 		}, Eq(true)),
 		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -EPERM;
-		out->header.len = sizeof(out->header);
-	}));
+	).WillOnce(Invoke(ReturnErrno(EPERM)));
 	EXPECT_NE(0, truncate(FULLPATH, 10));
 	EXPECT_EQ(EPERM, errno);
 }
@@ -184,13 +162,7 @@ TEST_F(Setattr, fchmod)
 	const mode_t oldmode = 0755;
 	const mode_t newmode = 0644;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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 | oldmode;
@@ -258,13 +230,7 @@ TEST_F(Setattr, ftruncate)
 	const off_t oldsize = 99;
 	const off_t newsize = 12345;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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 | 0755;
@@ -333,13 +299,7 @@ TEST_F(Setattr, truncate) {
 	const uint64_t oldsize = 100'000'000;
 	const uint64_t newsize = 20'000'000;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -381,13 +341,7 @@ TEST_F(Setattr, utimensat) {
 		{.tv_sec = 7, .tv_nsec = 8},
 	};
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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;
@@ -463,13 +417,7 @@ TEST_F(Setattr, utimensat_mtime_only) {
 		{.tv_sec = 7, .tv_nsec = 8},
 	};
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([=](auto in, auto out) {
+	EXPECT_LOOKUP(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;

Modified: projects/fuse2/tests/sys/fs/fuse/symlink.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fuse/symlink.cc	Tue Mar  5 02:53:41 2019	(r344788)
+++ projects/fuse2/tests/sys/fs/fuse/symlink.cc	Tue Mar  5 03:27:32 2019	(r344789)
@@ -43,19 +43,8 @@ TEST_F(Symlink, enospc)
 	const char FULLPATH[] = "mountpoint/lnk";
 	const char RELPATH[] = "lnk";
 	const char dst[] = "dst";
-	//const uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {
@@ -84,17 +73,7 @@ TEST_F(Symlink, ok)
 	const char dst[] = "dst";
 	const uint64_t ino = 42;
 
-	EXPECT_CALL(*m_mock, process(
-		ResultOf([=](auto in) {
-			return (in->header.opcode == FUSE_LOOKUP &&
-				strcmp(in->body.lookup, RELPATH) == 0);
-		}, Eq(true)),
-		_)
-	).WillOnce(Invoke([](auto in, auto out) {
-		out->header.unique = in->header.unique;
-		out->header.error = -ENOENT;
-		out->header.len = sizeof(out->header);
-	}));
+	EXPECT_LOOKUP(RELPATH).WillOnce(Invoke(ReturnErrno(ENOENT)));
 
 	EXPECT_CALL(*m_mock, process(
 		ResultOf([=](auto in) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903050327.x253RWCe068758>