3 # Tests of the fuse mount functionality.
9 pytestmark = pytest.mark.skipif(
10 not util.have_fuse(), reason="bcachefs not built with fuse support.")
12 def test_mount(bfuse):
17 @pytest.mark.skipif(util.ENABLE_VALGRIND, reason="test broken")
18 def test_remount(bfuse):
25 def test_lostfound(bfuse):
28 lf = bfuse.mnt / "lost+found"
32 assert st.st_mode == 0o40700
37 def test_create(bfuse):
40 path = bfuse.mnt / "file"
42 with util.Timestamp() as ts:
43 fd = os.open(path, os.O_CREAT, 0o700)
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)
58 dst = bfuse.mnt.stat()
59 assert dst.st_mtime == dst.st_ctime
60 assert ts.contains(dst.st_mtime)
65 def test_mkdir(bfuse):
68 path = bfuse.mnt / "dir"
70 with util.Timestamp() as ts:
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)
83 dst = bfuse.mnt.stat()
84 assert dst.st_mtime == dst.st_ctime
85 assert ts.contains(dst.st_mtime)
90 def test_unlink(bfuse):
93 path = bfuse.mnt / "file"
94 path.touch(mode=0o600, exist_ok=False)
96 with util.Timestamp() as ts:
99 assert not path.exists()
102 dst = bfuse.mnt.stat()
103 assert dst.st_mtime == dst.st_ctime
104 assert ts.contains(dst.st_mtime)
109 def test_rmdir(bfuse):
112 path = bfuse.mnt / "dir"
113 path.mkdir(mode=0o700, exist_ok=False)
115 with util.Timestamp() as ts:
118 assert not path.exists()
121 dst = bfuse.mnt.stat()
122 assert dst.st_mtime == dst.st_ctime
123 assert ts.contains(dst.st_mtime)
128 def test_rename(bfuse):
133 path = srcdir / "file"
134 path.touch(mode=0o600, exist_ok=False)
136 destdir = srcdir / "dir"
137 destdir.mkdir(mode=0o700, exist_ok=False)
139 destpath = destdir / "file"
141 path_pre_st = path.stat()
143 with util.Timestamp() as ts:
144 os.rename(path, destpath)
146 assert not path.exists()
147 assert destpath.is_file()
150 src_st = srcdir.stat()
151 assert src_st.st_mtime == src_st.st_ctime
152 assert ts.contains(src_st.st_mtime)
154 dest_st = destdir.stat()
155 assert dest_st.st_mtime == dest_st.st_ctime
156 assert ts.contains(dest_st.st_mtime)
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)
167 def test_link(bfuse):
172 path = srcdir / "file"
173 path.touch(mode=0o600, exist_ok=False)
175 destdir = srcdir / "dir"
176 destdir.mkdir(mode=0o700, exist_ok=False)
178 destpath = destdir / "file"
180 path_pre_st = path.stat()
181 srcdir_pre_st = srcdir.stat()
183 with util.Timestamp() as ts:
184 os.link(path, destpath)
187 assert destpath.is_file()
189 # Verify source dir is unchanged.
190 srcdir_post_st = srcdir.stat()
191 assert srcdir_pre_st == srcdir_post_st
194 destdir_st = destdir.stat()
195 assert destdir_st.st_mtime == destdir_st.st_ctime
196 assert ts.contains(destdir_st.st_mtime)
199 path_post_st = path.stat()
200 destpath_post_st = destpath.stat()
201 assert path_post_st == destpath_post_st
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)
210 def test_write(bfuse):
213 path = bfuse.mnt / "file"
214 path.touch(mode=0o600, exist_ok=False)
218 fd = os.open(path, os.O_WRONLY)
221 with util.Timestamp() as ts:
222 written = os.write(fd, b'test')
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)
233 assert path.read_bytes() == b'test'