diff options
author | Craig Chi <craigchi@google.com> | 2020-08-28 11:25:19 -0700 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2020-09-16 12:19:30 -0700 |
commit | e63abd82ddfbaeb35c1dfc7c553db3d78207b037 (patch) | |
tree | 20c3d2a94390b7a01e8f4ffed9d5dd1e41c15035 | |
parent | 98faed55e682cf34bb713c37b063a7d1da5e8352 (diff) |
Add default attr in fuse_util
fuse_util provides utilities for fuse testing. Add a function to return
a stub fuse_attr struct with specified mode and nodeid.
-rw-r--r-- | test/fuse/linux/stat_test.cc | 30 | ||||
-rw-r--r-- | test/util/fuse_util.cc | 52 | ||||
-rw-r--r-- | test/util/fuse_util.h | 3 |
3 files changed, 38 insertions, 47 deletions
diff --git a/test/fuse/linux/stat_test.cc b/test/fuse/linux/stat_test.cc index 9ab53f8d2..717fd1fac 100644 --- a/test/fuse/linux/stat_test.cc +++ b/test/fuse/linux/stat_test.cc @@ -45,26 +45,7 @@ class StatTest : public FuseTest { TEST_F(StatTest, StatNormal) { // Set up fixture. mode_t expected_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - struct timespec atime = {.tv_sec = 1595436289, .tv_nsec = 134150844}; - struct timespec mtime = {.tv_sec = 1595436290, .tv_nsec = 134150845}; - struct timespec ctime = {.tv_sec = 1595436291, .tv_nsec = 134150846}; - struct fuse_attr attr = { - .ino = 1, - .size = 512, - .blocks = 4, - .atime = static_cast<uint64_t>(atime.tv_sec), - .mtime = static_cast<uint64_t>(mtime.tv_sec), - .ctime = static_cast<uint64_t>(ctime.tv_sec), - .atimensec = static_cast<uint32_t>(atime.tv_nsec), - .mtimensec = static_cast<uint32_t>(mtime.tv_nsec), - .ctimensec = static_cast<uint32_t>(ctime.tv_nsec), - .mode = expected_mode, - .nlink = 2, - .uid = 1234, - .gid = 4321, - .rdev = 12, - .blksize = 4096, - }; + struct fuse_attr attr = DefaultFuseAttr(expected_mode, 1); struct fuse_out_header out_header = { .len = sizeof(struct fuse_out_header) + sizeof(struct fuse_attr_out), }; @@ -89,9 +70,12 @@ TEST_F(StatTest, StatNormal) { .st_size = static_cast<off_t>(attr.size), .st_blksize = attr.blksize, .st_blocks = static_cast<blkcnt_t>(attr.blocks), - .st_atim = atime, - .st_mtim = mtime, - .st_ctim = ctime, + .st_atim = (struct timespec){.tv_sec = static_cast<int>(attr.atime), + .tv_nsec = attr.atimensec}, + .st_mtim = (struct timespec){.tv_sec = static_cast<int>(attr.mtime), + .tv_nsec = attr.mtimensec}, + .st_ctim = (struct timespec){.tv_sec = static_cast<int>(attr.ctime), + .tv_nsec = attr.ctimensec}, }; EXPECT_TRUE(StatsAreEqual(stat_buf, expected_stat)); diff --git a/test/util/fuse_util.cc b/test/util/fuse_util.cc index 5b10a9e45..4db053335 100644 --- a/test/util/fuse_util.cc +++ b/test/util/fuse_util.cc @@ -22,35 +22,39 @@ namespace gvisor { namespace testing { -// Create response body with specified mode and nodeID. -fuse_entry_out DefaultEntryOut(mode_t mode, uint64_t node_id) { +// Create a default FuseAttr struct with specified mode and inode. +fuse_attr DefaultFuseAttr(mode_t mode, uint64_t inode) { const int time_sec = 1595436289; const int time_nsec = 134150844; + return (struct fuse_attr){ + .ino = inode, + .size = 512, + .blocks = 4, + .atime = time_sec, + .mtime = time_sec, + .ctime = time_sec, + .atimensec = time_nsec, + .mtimensec = time_nsec, + .ctimensec = time_nsec, + .mode = mode, + .nlink = 2, + .uid = 1234, + .gid = 4321, + .rdev = 12, + .blksize = 4096, + }; +} + +// Create response body with specified mode and nodeID. +fuse_entry_out DefaultEntryOut(mode_t mode, uint64_t node_id) { struct fuse_entry_out default_entry_out = { .nodeid = node_id, .generation = 0, - .entry_valid = time_sec, - .attr_valid = time_sec, - .entry_valid_nsec = time_nsec, - .attr_valid_nsec = time_nsec, - .attr = - (struct fuse_attr){ - .ino = node_id, - .size = 512, - .blocks = 4, - .atime = time_sec, - .mtime = time_sec, - .ctime = time_sec, - .atimensec = time_nsec, - .mtimensec = time_nsec, - .ctimensec = time_nsec, - .mode = mode, - .nlink = 2, - .uid = 1234, - .gid = 4321, - .rdev = 12, - .blksize = 4096, - }, + .entry_valid = 0, + .attr_valid = 0, + .entry_valid_nsec = 0, + .attr_valid_nsec = 0, + .attr = DefaultFuseAttr(mode, node_id), }; return default_entry_out; }; diff --git a/test/util/fuse_util.h b/test/util/fuse_util.h index 1f1bf64a4..6b5a8ce1f 100644 --- a/test/util/fuse_util.h +++ b/test/util/fuse_util.h @@ -63,6 +63,9 @@ std::vector<struct iovec> FuseGenerateIovecs(T &first, Types &...args) { return first_iovec; } +// Create a fuse_attr filled with the specified mode and inode. +fuse_attr DefaultFuseAttr(mode_t mode, uint64_t inode); + // Return a fuse_entry_out FUSE server response body. fuse_entry_out DefaultEntryOut(mode_t mode, uint64_t nodeId); |