]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/fs/fusefs/utils.hh
fusefs: adapt the tests to the fuse => fusefs rename
[FreeBSD/FreeBSD.git] / tests / sys / fs / fusefs / utils.hh
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2019 The FreeBSD Foundation
5  *
6  * This software was developed by BFF Storage Systems, LLC under sponsorship
7  * from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30
31 /*
32  * TODO: remove FUSE_WRITE_CACHE definition when upgrading to protocol 7.9.
33  * This bit was actually part of kernel protocol version 7.2, but never
34  * documented until 7.9
35  */
36 #ifndef FUSE_WRITE_CACHE
37 #define FUSE_WRITE_CACHE 1
38 #endif
39
40 class FuseTest : public ::testing::Test {
41         protected:
42         uint32_t m_maxreadahead;
43         uint32_t m_init_flags;
44         bool m_default_permissions;
45         bool m_push_symlinks_in;
46         MockFS *m_mock = NULL;
47         const static uint64_t FH = 0xdeadbeef1a7ebabe;
48
49         public:
50         int m_maxbcachebuf;
51
52         FuseTest():
53                 /*
54                  * libfuse's default max_readahead is UINT_MAX, though it can
55                  * be lowered
56                  */
57                 m_maxreadahead(UINT_MAX),
58                 m_init_flags(0),
59                 m_default_permissions(false),
60                 m_push_symlinks_in(false)
61         {}
62
63         virtual void SetUp();
64
65         virtual void TearDown() {
66                 if (m_mock)
67                         delete m_mock;
68         }
69
70         /*
71          * Create an expectation that FUSE_GETATTR will be called for the given
72          * inode any number of times.  It will respond with a few basic
73          * attributes, like the given size and the mode S_IFREG | 0644
74          */
75         void expect_getattr(uint64_t ino, uint64_t size);
76
77         /*
78          * Create an expectation that FUSE_LOOKUP will be called for the given
79          * path exactly times times.  It will respond with inode ino, mode
80          * mode, filesize size, and cache validity forever.
81          */
82         void expect_lookup(const char *relpath, uint64_t ino, mode_t mode,
83                 uint64_t size, int times);
84
85         /*
86          * Create an expectation that FUSE_GETATTR will be called for the given
87          * inode exactly times times.  It will return with open_flags flags and
88          * file handle FH.
89          */
90         void expect_open(uint64_t ino, uint32_t flags, int times);
91
92         /*
93          * Create an expectation that FUSE_OPENDIR will be called exactly once
94          * for inode ino.
95          */
96         void expect_opendir(uint64_t ino);
97
98         /*
99          * Create an expectation that FUSE_READ will be called exactly once for
100          * the given inode, at offset offset and with size isize.  It will
101          * return the first osize bytes from contents
102          */
103         void expect_read(uint64_t ino, uint64_t offset, uint64_t isize,
104                 uint64_t osize, const void *contents);
105
106         /* 
107          * Create an expectation that FUSE_RELEASE will be called times times
108          * for the given inode, returning error error
109          */
110         void expect_release(uint64_t ino, int times, uint64_t lock_owner,
111                 int error);
112
113         /*
114          * Create an expectation that FUSE_WRITE will be called exactly once
115          * for the given inode, at offset offset, with write_flags flags, 
116          * size isize and buffer contents.  It will return osize
117          */
118         void expect_write(uint64_t ino, uint64_t offset, uint64_t isize,
119                 uint64_t osize, uint32_t flags, const void *contents);
120 };