mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-01 20:36:37 -05:00
Add more integration tests
This commit is contained in:
parent
a78aef36e0
commit
f4b602340b
34 changed files with 3202 additions and 0 deletions
68
tests/TEST_posix_bmap
Executable file
68
tests/TEST_posix_bmap
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import errno
|
||||
import fcntl
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from posix_parity import compare_calls
|
||||
from posix_parity import fail
|
||||
from posix_parity import join
|
||||
from posix_parity import touch
|
||||
|
||||
|
||||
FIBMAP = 1
|
||||
|
||||
|
||||
def fibmap(fd, block=0):
|
||||
buf = struct.pack("i", block)
|
||||
out = fcntl.ioctl(fd, FIBMAP, buf)
|
||||
return struct.unpack("i", out)[0]
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("usage: TEST_posix_bmap <mountpoint>", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
mount = sys.argv[1]
|
||||
|
||||
with tempfile.TemporaryDirectory() as native:
|
||||
merge_file = join(mount, "posix-bmap/file")
|
||||
native_file = join(native, "posix-bmap/file")
|
||||
touch(merge_file, b"x" * 8192)
|
||||
touch(native_file, b"x" * 8192)
|
||||
|
||||
mfd = os.open(merge_file, os.O_RDONLY)
|
||||
nfd = os.open(native_file, os.O_RDONLY)
|
||||
try:
|
||||
# FIBMAP often requires CAP_SYS_RAWIO; compare errno parity if denied.
|
||||
err = compare_calls(
|
||||
"ioctl FIBMAP block0",
|
||||
lambda: fibmap(mfd, 0),
|
||||
lambda: fibmap(nfd, 0),
|
||||
lambda a, b: (a >= 0) == (b >= 0),
|
||||
)
|
||||
if err:
|
||||
# If both denied by privilege checks, compare_calls already passes.
|
||||
return fail(err)
|
||||
finally:
|
||||
os.close(mfd)
|
||||
os.close(nfd)
|
||||
|
||||
# EBADF parity on closed fds.
|
||||
err = compare_calls(
|
||||
"ioctl FIBMAP EBADF",
|
||||
lambda: fibmap(mfd, 0),
|
||||
lambda: fibmap(nfd, 0),
|
||||
)
|
||||
if err:
|
||||
return fail(err)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue