From e63abd82ddfbaeb35c1dfc7c553db3d78207b037 Mon Sep 17 00:00:00 2001 From: Craig Chi Date: Fri, 28 Aug 2020 11:25:19 -0700 Subject: 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. --- test/fuse/linux/stat_test.cc | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'test/fuse/linux/stat_test.cc') 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(atime.tv_sec), - .mtime = static_cast(mtime.tv_sec), - .ctime = static_cast(ctime.tv_sec), - .atimensec = static_cast(atime.tv_nsec), - .mtimensec = static_cast(mtime.tv_nsec), - .ctimensec = static_cast(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(attr.size), .st_blksize = attr.blksize, .st_blocks = static_cast(attr.blocks), - .st_atim = atime, - .st_mtim = mtime, - .st_ctim = ctime, + .st_atim = (struct timespec){.tv_sec = static_cast(attr.atime), + .tv_nsec = attr.atimensec}, + .st_mtim = (struct timespec){.tv_sec = static_cast(attr.mtime), + .tv_nsec = attr.mtimensec}, + .st_ctim = (struct timespec){.tv_sec = static_cast(attr.ctime), + .tv_nsec = attr.ctimensec}, }; EXPECT_TRUE(StatsAreEqual(stat_buf, expected_stat)); -- cgit v1.2.3