diff options
author | Craig Chi <craigchi@google.com> | 2020-08-14 10:17:08 -0700 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2020-09-11 13:35:25 -0700 |
commit | 1cdca36e8f4af13a1fa73ea39452cd1eaa141abd (patch) | |
tree | 31e293ed070a67be970713a15fb4981682b76cd4 /test/fuse | |
parent | 38c3fb66d7e6242d76aa332bf60a53ea307bab29 (diff) |
Add function generating array of iovec with different FUSE structs
This commit adds a function in the newly created fuse_util library,
which accepts a variable number of arguments and data structures.
Fixes #3609
Diffstat (limited to 'test/fuse')
-rw-r--r-- | test/fuse/linux/BUILD | 2 | ||||
-rw-r--r-- | test/fuse/linux/fuse_base.cc | 10 | ||||
-rw-r--r-- | test/fuse/linux/stat_test.cc | 31 |
3 files changed, 14 insertions, 29 deletions
diff --git a/test/fuse/linux/BUILD b/test/fuse/linux/BUILD index 4871bb531..e4a614e11 100644 --- a/test/fuse/linux/BUILD +++ b/test/fuse/linux/BUILD @@ -12,6 +12,7 @@ cc_binary( deps = [ gtest, ":fuse_base", + "//test/util:fuse_util", "//test/util:test_main", "//test/util:test_util", ], @@ -24,6 +25,7 @@ cc_library( hdrs = ["fuse_base.h"], deps = [ gtest, + "//test/util:fuse_util", "//test/util:posix_error", "//test/util:temp_path", "//test/util:test_util", diff --git a/test/fuse/linux/fuse_base.cc b/test/fuse/linux/fuse_base.cc index b1897cf88..c354e1dcb 100644 --- a/test/fuse/linux/fuse_base.cc +++ b/test/fuse/linux/fuse_base.cc @@ -26,6 +26,7 @@ #include "absl/strings/str_format.h" #include "gtest/gtest.h" +#include "test/util/fuse_util.h" #include "test/util/posix_error.h" #include "test/util/temp_path.h" #include "test/util/test_util.h" @@ -137,7 +138,6 @@ PosixError FuseTest::ServerConsumeFuseInit() { RETURN_ERROR_IF_SYSCALL_FAIL( RetryEINTR(read)(dev_fd_, buf.data(), buf.size())); - struct iovec iov_out[2]; struct fuse_out_header out_header = { .len = sizeof(struct fuse_out_header) + sizeof(struct fuse_init_out), .error = 0, @@ -148,12 +148,10 @@ PosixError FuseTest::ServerConsumeFuseInit() { struct fuse_init_out out_payload = { .major = 7, }; - iov_out[0].iov_len = sizeof(out_header); - iov_out[0].iov_base = &out_header; - iov_out[1].iov_len = sizeof(out_payload); - iov_out[1].iov_base = &out_payload; + auto iov_out = FuseGenerateIovecs(out_header, out_payload); - RETURN_ERROR_IF_SYSCALL_FAIL(RetryEINTR(writev)(dev_fd_, iov_out, 2)); + RETURN_ERROR_IF_SYSCALL_FAIL( + RetryEINTR(writev)(dev_fd_, iov_out.data(), iov_out.size())); return NoError(); } diff --git a/test/fuse/linux/stat_test.cc b/test/fuse/linux/stat_test.cc index c2e5bd1cf..9ab53f8d2 100644 --- a/test/fuse/linux/stat_test.cc +++ b/test/fuse/linux/stat_test.cc @@ -24,6 +24,7 @@ #include "gtest/gtest.h" #include "test/fuse/linux/fuse_base.h" +#include "test/util/fuse_util.h" #include "test/util/test_util.h" namespace gvisor { @@ -43,16 +44,10 @@ class StatTest : public FuseTest { TEST_F(StatTest, StatNormal) { // Set up fixture. - std::vector<struct iovec> iov_in(2); - std::vector<struct iovec> iov_out(2); 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_out_header out_header = { - .len = sizeof(struct fuse_out_header) + sizeof(struct fuse_attr_out), - .error = 0, - }; struct fuse_attr attr = { .ino = 1, .size = 512, @@ -70,14 +65,13 @@ TEST_F(StatTest, StatNormal) { .rdev = 12, .blksize = 4096, }; + struct fuse_out_header out_header = { + .len = sizeof(struct fuse_out_header) + sizeof(struct fuse_attr_out), + }; struct fuse_attr_out out_payload = { .attr = attr, }; - iov_out[0].iov_len = sizeof(out_header); - iov_out[0].iov_base = &out_header; - iov_out[1].iov_len = sizeof(out_payload); - iov_out[1].iov_base = &out_payload; - + auto iov_out = FuseGenerateIovecs(out_header, out_payload); SetServerResponse(FUSE_GETATTR, iov_out); // Do integration test. @@ -104,10 +98,7 @@ TEST_F(StatTest, StatNormal) { // Check FUSE request. struct fuse_in_header in_header; struct fuse_getattr_in in_payload; - iov_in[0].iov_len = sizeof(in_header); - iov_in[0].iov_base = &in_header; - iov_in[1].iov_len = sizeof(in_payload); - iov_in[1].iov_base = &in_payload; + auto iov_in = FuseGenerateIovecs(in_header, in_payload); GetServerActualRequest(iov_in); EXPECT_EQ(in_header.opcode, FUSE_GETATTR); @@ -117,14 +108,11 @@ TEST_F(StatTest, StatNormal) { TEST_F(StatTest, StatNotFound) { // Set up fixture. - std::vector<struct iovec> iov_in(2); - std::vector<struct iovec> iov_out(1); struct fuse_out_header out_header = { .len = sizeof(struct fuse_out_header), .error = -ENOENT, }; - iov_out[0].iov_len = sizeof(out_header); - iov_out[0].iov_base = &out_header; + auto iov_out = FuseGenerateIovecs(out_header); SetServerResponse(FUSE_GETATTR, iov_out); // Do integration test. @@ -135,10 +123,7 @@ TEST_F(StatTest, StatNotFound) { // Check FUSE request. struct fuse_in_header in_header; struct fuse_getattr_in in_payload; - iov_in[0].iov_len = sizeof(in_header); - iov_in[0].iov_base = &in_header; - iov_in[1].iov_len = sizeof(in_payload); - iov_in[1].iov_base = &in_payload; + auto iov_in = FuseGenerateIovecs(in_header, in_payload); GetServerActualRequest(iov_in); EXPECT_EQ(in_header.opcode, FUSE_GETATTR); |