summaryrefslogtreecommitdiffhomepage
path: root/test/fuse/linux/fuse_base.h
diff options
context:
space:
mode:
authorCraig Chi <craigchi@google.com>2020-08-17 10:05:10 -0700
committerAndrei Vagin <avagin@gmail.com>2020-09-11 13:35:25 -0700
commit1aa1bb9aad6f1984e32f11a5e8c8bfd98746dc85 (patch)
treee59f7195496314d29b55d41dc8601414abb8df5f /test/fuse/linux/fuse_base.h
parent1cdca36e8f4af13a1fa73ea39452cd1eaa141abd (diff)
Add function to create a fake inode in FUSE integration test
Adds a function for the testing thread to set up a fake inode with a specific path under mount point. After this function is called, each subsequent FUSE_LOOKUP request with the same path will be served with the fixed stub response. Fixes #3539
Diffstat (limited to 'test/fuse/linux/fuse_base.h')
-rw-r--r--test/fuse/linux/fuse_base.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/fuse/linux/fuse_base.h b/test/fuse/linux/fuse_base.h
index 3f2522977..a21b4bb8d 100644
--- a/test/fuse/linux/fuse_base.h
+++ b/test/fuse/linux/fuse_base.h
@@ -17,9 +17,11 @@
#include <linux/fuse.h>
#include <string.h>
+#include <sys/stat.h>
#include <sys/uio.h>
#include <iostream>
+#include <unordered_map>
#include <vector>
#include "gtest/gtest.h"
@@ -35,6 +37,7 @@ constexpr char kMountOpts[] = "rootmode=755,user_id=0,group_id=0";
// server. See test/fuse/README.md for further detail.
enum class FuseTestCmd {
kSetResponse = 0,
+ kSetInodeLookup,
kGetRequest,
kGetNumUnconsumedRequests,
kGetNumUnsentResponses,
@@ -114,6 +117,9 @@ class FuseMemBuffer {
// to manipulate with it. Refer to test/fuse/README.md for detailed explanation.
class FuseTest : public ::testing::Test {
public:
+ // nodeid_ is the ID of a fake inode. We starts from 2 since 1 is occupied by
+ // the mount point.
+ FuseTest() : nodeid_(2) {}
void SetUp() override;
void TearDown() override;
@@ -122,6 +128,16 @@ class FuseTest : public ::testing::Test {
// expected FUSE reactions.
void SetServerResponse(uint32_t opcode, std::vector<struct iovec>& iovecs);
+ // Called by the testing thread to install a fake path under the mount point.
+ // e.g. a file under /mnt/dir/file and moint point is /mnt, then it will look
+ // up "dir/file" in this case.
+ //
+ // It sets a fixed response to the FUSE_LOOKUP requests issued with this
+ // path, pretending there is an inode and avoid ENOENT when testing. If mode
+ // is not given, it creates a regular file with mode 0600.
+ void SetServerInodeLookup(const std::string& path,
+ mode_t mode = S_IFREG | S_IRUSR | S_IWUSR);
+
// Called by the testing thread to ask the FUSE server for its next received
// FUSE request. Be sure to use the corresponding struct of iovec to receive
// data from server.
@@ -182,6 +198,11 @@ class FuseTest : public ::testing::Test {
// memory queue.
void ServerReceiveResponse();
+ // The FUSE server side's corresponding code of `SetServerInodeLookup()`.
+ // Handles `kSetInodeLookup` command. Receives an expected file mode and
+ // file path under the mount point.
+ void ServerReceiveInodeLookup();
+
// The FUSE server side's corresponding code of `GetServerActualRequest()`.
// Handles `kGetRequest` command. Sends the next received request pointed by
// the cursor.
@@ -203,8 +224,12 @@ class FuseTest : public ::testing::Test {
int dev_fd_;
int sock_[2];
+ uint64_t nodeid_;
+ std::unordered_map<std::string, FuseMemBlock> lookup_map_;
+
FuseMemBuffer requests_;
FuseMemBuffer responses_;
+ FuseMemBuffer lookups_;
};
} // namespace testing