Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/fs/fusefs/statfs.cc
Show All 27 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
extern "C" { | extern "C" { | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/sysctl.h> | |||||
#include <semaphore.h> | #include <semaphore.h> | ||||
} | } | ||||
#include "mockfs.hh" | #include "mockfs.hh" | ||||
#include "utils.hh" | #include "utils.hh" | ||||
using namespace testing; | using namespace testing; | ||||
class Statfs: public FuseTest {}; | class Statfs: public FuseTest {}; | ||||
class Statfs_cached: public Statfs { | |||||
public: | |||||
virtual void SetUp() { | |||||
m_init_flags |= FUSE_WRITEBACK_CACHE; | |||||
Statfs::SetUp(); | |||||
} | |||||
}; | |||||
TEST_F(Statfs, eio) | TEST_F(Statfs, eio) | ||||
{ | { | ||||
struct statfs statbuf; | struct statfs statbuf; | ||||
EXPECT_CALL(*m_mock, process( | EXPECT_CALL(*m_mock, process( | ||||
ResultOf([](auto in) { | ResultOf([](auto in) { | ||||
return (in.header.opcode == FUSE_STATFS); | return (in.header.opcode == FUSE_STATFS); | ||||
}, Eq(true)), | }, Eq(true)), | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { | ||||
SET_OUT_HEADER_LEN(out, statfs); | SET_OUT_HEADER_LEN(out, statfs); | ||||
out.body.statfs.st.blocks = 1000; | out.body.statfs.st.blocks = 1000; | ||||
out.body.statfs.st.bfree = 100; | out.body.statfs.st.bfree = 100; | ||||
out.body.statfs.st.bavail = 200; | out.body.statfs.st.bavail = 200; | ||||
out.body.statfs.st.files = 5; | out.body.statfs.st.files = 5; | ||||
out.body.statfs.st.ffree = 6; | out.body.statfs.st.ffree = 6; | ||||
out.body.statfs.st.namelen = 128; | out.body.statfs.st.namelen = 128; | ||||
out.body.statfs.st.frsize = 1024; | out.body.statfs.st.frsize = 1024; | ||||
out.body.statfs.st.bsize = 131072; | |||||
}))); | }))); | ||||
ASSERT_NE(nullptr, getcwd(mp, PATH_MAX)) << strerror(errno); | ASSERT_NE(nullptr, getcwd(mp, PATH_MAX)) << strerror(errno); | ||||
strlcat(mp, "/mountpoint", PATH_MAX); | strlcat(mp, "/mountpoint", PATH_MAX); | ||||
ASSERT_EQ(0, statfs("mountpoint", &statbuf)) << strerror(errno); | ASSERT_EQ(0, statfs("mountpoint", &statbuf)) << strerror(errno); | ||||
EXPECT_EQ(1024ul, statbuf.f_bsize); | EXPECT_EQ(1024ul, statbuf.f_bsize); | ||||
/* | |||||
* fuse(4) ignores the filesystem's reported optimal transfer size, and | |||||
* chooses a size that works well with the rest of the system instead | |||||
*/ | |||||
EXPECT_EQ(1000ul, statbuf.f_blocks); | EXPECT_EQ(1000ul, statbuf.f_blocks); | ||||
EXPECT_EQ(100ul, statbuf.f_bfree); | EXPECT_EQ(100ul, statbuf.f_bfree); | ||||
EXPECT_EQ(200l, statbuf.f_bavail); | EXPECT_EQ(200l, statbuf.f_bavail); | ||||
EXPECT_EQ(5ul, statbuf.f_files); | EXPECT_EQ(5ul, statbuf.f_files); | ||||
EXPECT_EQ(6l, statbuf.f_ffree); | EXPECT_EQ(6l, statbuf.f_ffree); | ||||
EXPECT_EQ(131072ul, statbuf.f_iosize); | |||||
EXPECT_EQ(128u, statbuf.f_namemax); | EXPECT_EQ(128u, statbuf.f_namemax); | ||||
EXPECT_EQ(getuid(), statbuf.f_owner); | EXPECT_EQ(getuid(), statbuf.f_owner); | ||||
EXPECT_EQ(0, strcmp("fusefs", statbuf.f_fstypename)); | EXPECT_EQ(0, strcmp("fusefs", statbuf.f_fstypename)); | ||||
EXPECT_EQ(0, strcmp("/dev/fuse", statbuf.f_mntfromname)); | EXPECT_EQ(0, strcmp("/dev/fuse", statbuf.f_mntfromname)); | ||||
EXPECT_EQ(0, strcmp(mp, statbuf.f_mntonname)); | EXPECT_EQ(0, strcmp(mp, statbuf.f_mntonname)); | ||||
} | |||||
/* | |||||
* When not using direct I/O fusefs will choose a minimum f_iosize suitable for | |||||
* the buffer cache. | |||||
*/ | |||||
TEST_F(Statfs_cached, ok) | |||||
{ | |||||
struct statfs statbuf; | |||||
int maxbcachebuf; | |||||
const char *node = "vfs.maxbcachebuf"; | |||||
size_t size = sizeof(maxbcachebuf); | |||||
ASSERT_EQ(0, sysctlbyname(node, &maxbcachebuf, &size, NULL, 0)) | |||||
<< strerror(errno); | |||||
EXPECT_CALL(*m_mock, process( | |||||
ResultOf([](auto in) { | |||||
return (in.header.opcode == FUSE_STATFS); | |||||
}, Eq(true)), | |||||
_) | |||||
).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { | |||||
SET_OUT_HEADER_LEN(out, statfs); | |||||
out.body.statfs.st.blocks = 1000; | |||||
out.body.statfs.st.bfree = 100; | |||||
out.body.statfs.st.bavail = 200; | |||||
out.body.statfs.st.files = 5; | |||||
out.body.statfs.st.ffree = 6; | |||||
out.body.statfs.st.namelen = 128; | |||||
out.body.statfs.st.frsize = 1024; | |||||
out.body.statfs.st.bsize = 8192; | |||||
}))); | |||||
ASSERT_EQ(0, statfs("mountpoint", &statbuf)) << strerror(errno); | |||||
EXPECT_EQ((uint64_t)maxbcachebuf, statbuf.f_iosize); | |||||
cem: As-written, I think this test would fail if vfs.macbcachebuf happened to be < 8192. I agree… | |||||
} | } |
As-written, I think this test would fail if vfs.macbcachebuf happened to be < 8192. I agree this is nonsense, but it's maybe worth calling out our environmental assumptions at least in a comment.