github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/fuse/linux/release_test.cc (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <errno.h> 16 #include <fcntl.h> 17 #include <linux/fuse.h> 18 #include <sys/mount.h> 19 #include <sys/stat.h> 20 #include <sys/statfs.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 24 #include <string> 25 #include <vector> 26 27 #include "gtest/gtest.h" 28 #include "test/fuse/linux/fuse_base.h" 29 #include "test/util/fuse_util.h" 30 #include "test/util/test_util.h" 31 32 namespace gvisor { 33 namespace testing { 34 35 namespace { 36 37 class ReleaseTest : public FuseTest { 38 protected: 39 const std::string test_file_ = "test_file"; 40 }; 41 42 TEST_F(ReleaseTest, RegularFile) { 43 const std::string test_file_path = 44 JoinPath(mount_point_.path().c_str(), test_file_); 45 SetServerInodeLookup(test_file_, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO); 46 47 struct fuse_out_header out_header = { 48 .len = sizeof(struct fuse_out_header) + sizeof(struct fuse_open_out), 49 }; 50 struct fuse_open_out out_payload = { 51 .fh = 1, 52 .open_flags = O_RDWR, 53 }; 54 auto iov_out = FuseGenerateIovecs(out_header, out_payload); 55 SetServerResponse(FUSE_OPEN, iov_out); 56 FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(Open(test_file_path, O_RDWR)); 57 SkipServerActualRequest(); 58 ASSERT_THAT(close(fd.release()), SyscallSucceeds()); 59 60 struct fuse_in_header in_header; 61 struct fuse_release_in in_payload; 62 auto iov_in = FuseGenerateIovecs(in_header, in_payload); 63 GetServerActualRequest(iov_in); 64 65 EXPECT_EQ(in_header.len, sizeof(in_header) + sizeof(in_payload)); 66 EXPECT_EQ(in_header.opcode, FUSE_RELEASE); 67 EXPECT_EQ(in_payload.flags, O_RDWR); 68 EXPECT_EQ(in_payload.fh, 1); 69 } 70 71 } // namespace 72 73 } // namespace testing 74 } // namespace gvisor