]> git.sesse.net Git - bcachefs-tools-debian/blob - tests/test_fuse.py
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / tests / test_fuse.py
1 #!/usr/bin/python3
2 #
3 # Tests of the fuse mount functionality.
4
5 import pytest
6 import os
7 from tests import util
8
9 pytestmark = pytest.mark.skipif(
10     not util.have_fuse(), reason="bcachefs not built with fuse support.")
11
12 def test_mount(bfuse):
13     bfuse.mount()
14     bfuse.unmount()
15     bfuse.verify()
16
17 @pytest.mark.skipif(util.ENABLE_VALGRIND, reason="test broken")
18 def test_remount(bfuse):
19     bfuse.mount()
20     bfuse.unmount()
21     bfuse.mount()
22     bfuse.unmount()
23     bfuse.verify()
24
25 def test_lostfound(bfuse):
26     bfuse.mount()
27
28     lf = bfuse.mnt / "lost+found"
29     assert lf.is_dir()
30
31     st = lf.stat()
32     assert st.st_mode == 0o40700
33
34     bfuse.unmount()
35     bfuse.verify()
36
37 def test_create(bfuse):
38     bfuse.mount()
39
40     path = bfuse.mnt / "file"
41
42     with util.Timestamp() as ts:
43         fd = os.open(path, os.O_CREAT, 0o700)
44
45     assert fd >= 0
46
47     os.close(fd)
48     assert path.is_file()
49
50     # Verify file.
51     st = path.stat()
52     assert st.st_mode == 0o100700
53     assert st.st_mtime == st.st_ctime
54     assert st.st_mtime == st.st_atime
55     assert ts.contains(st.st_mtime)
56
57     # Verify dir.
58     dst = bfuse.mnt.stat()
59     assert dst.st_mtime == dst.st_ctime
60     assert ts.contains(dst.st_mtime)
61
62     bfuse.unmount()
63     bfuse.verify()
64
65 def test_mkdir(bfuse):
66     bfuse.mount()
67
68     path = bfuse.mnt / "dir"
69
70     with util.Timestamp() as ts:
71         os.mkdir(path, 0o700)
72
73     assert path.is_dir()
74
75     # Verify child.
76     st = path.stat()
77     assert st.st_mode == 0o40700
78     assert st.st_mtime == st.st_ctime
79     assert st.st_mtime == st.st_atime
80     assert ts.contains(st.st_mtime)
81
82     # Verify parent.
83     dst = bfuse.mnt.stat()
84     assert dst.st_mtime == dst.st_ctime
85     assert ts.contains(dst.st_mtime)
86
87     bfuse.unmount()
88     bfuse.verify()
89
90 def test_unlink(bfuse):
91     bfuse.mount()
92
93     path = bfuse.mnt / "file"
94     path.touch(mode=0o600, exist_ok=False)
95
96     with util.Timestamp() as ts:
97         os.unlink(path)
98
99     assert not path.exists()
100
101     # Verify dir.
102     dst = bfuse.mnt.stat()
103     assert dst.st_mtime == dst.st_ctime
104     assert ts.contains(dst.st_mtime)
105
106     bfuse.unmount()
107     bfuse.verify()
108
109 def test_rmdir(bfuse):
110     bfuse.mount()
111
112     path = bfuse.mnt / "dir"
113     path.mkdir(mode=0o700, exist_ok=False)
114
115     with util.Timestamp() as ts:
116         os.rmdir(path)
117
118     assert not path.exists()
119
120     # Verify dir.
121     dst = bfuse.mnt.stat()
122     assert dst.st_mtime == dst.st_ctime
123     assert ts.contains(dst.st_mtime)
124
125     bfuse.unmount()
126     bfuse.verify()
127
128 def test_rename(bfuse):
129     bfuse.mount()
130
131     srcdir = bfuse.mnt
132
133     path = srcdir / "file"
134     path.touch(mode=0o600, exist_ok=False)
135
136     destdir = srcdir / "dir"
137     destdir.mkdir(mode=0o700, exist_ok=False)
138
139     destpath = destdir / "file"
140
141     path_pre_st = path.stat()
142
143     with util.Timestamp() as ts:
144         os.rename(path, destpath)
145
146     assert not path.exists()
147     assert destpath.is_file()
148
149     # Verify dirs.
150     src_st = srcdir.stat()
151     assert src_st.st_mtime == src_st.st_ctime
152     assert ts.contains(src_st.st_mtime)
153
154     dest_st = destdir.stat()
155     assert dest_st.st_mtime == dest_st.st_ctime
156     assert ts.contains(dest_st.st_mtime)
157
158     # Verify file.
159     path_post_st = destpath.stat()
160     assert path_post_st.st_mtime == path_pre_st.st_mtime
161     assert path_post_st.st_atime == path_pre_st.st_atime
162     assert ts.contains(path_post_st.st_ctime)
163
164     bfuse.unmount()
165     bfuse.verify()
166
167 def test_link(bfuse):
168     bfuse.mount()
169
170     srcdir = bfuse.mnt
171
172     path = srcdir / "file"
173     path.touch(mode=0o600, exist_ok=False)
174
175     destdir = srcdir / "dir"
176     destdir.mkdir(mode=0o700, exist_ok=False)
177
178     destpath = destdir / "file"
179
180     path_pre_st = path.stat()
181     srcdir_pre_st = srcdir.stat()
182
183     with util.Timestamp() as ts:
184         os.link(path, destpath)
185
186     assert path.exists()
187     assert destpath.is_file()
188
189     # Verify source dir is unchanged.
190     srcdir_post_st = srcdir.stat()
191     assert srcdir_pre_st == srcdir_post_st
192
193     # Verify dest dir.
194     destdir_st = destdir.stat()
195     assert destdir_st.st_mtime == destdir_st.st_ctime
196     assert ts.contains(destdir_st.st_mtime)
197
198     # Verify file.
199     path_post_st = path.stat()
200     destpath_post_st = destpath.stat()
201     assert path_post_st == destpath_post_st
202
203     assert path_post_st.st_mtime == path_pre_st.st_mtime
204     assert path_post_st.st_atime == path_pre_st.st_atime
205     assert ts.contains(path_post_st.st_ctime)
206
207     bfuse.unmount()
208     bfuse.verify()
209
210 def test_write(bfuse):
211     bfuse.mount()
212
213     path = bfuse.mnt / "file"
214     path.touch(mode=0o600, exist_ok=False)
215
216     pre_st = path.stat()
217
218     fd = os.open(path, os.O_WRONLY)
219     assert fd >= 0
220
221     with util.Timestamp() as ts:
222         written = os.write(fd, b'test')
223
224     os.close(fd)
225
226     assert written == 4
227
228     post_st = path.stat()
229     assert post_st.st_atime == pre_st.st_atime
230     assert post_st.st_mtime == post_st.st_ctime
231     assert ts.contains(post_st.st_mtime)
232
233     assert path.read_bytes() == b'test'
234
235     bfuse.unmount()
236     bfuse.verify()