Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import os
|
2026-11-06 11:24:49 -06:00
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
import sys
|
2026-11-06 11:24:49 -06:00
|
|
|
import tempfile
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
from posix_parity import fail
|
2026-11-06 11:24:49 -06:00
|
|
|
from posix_parity import find_fusermount
|
|
|
|
|
from posix_parity import find_mergerfs
|
|
|
|
|
from posix_parity import mount_mergerfs
|
|
|
|
|
from posix_parity import unmount_mergerfs
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
SKIP = 77
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
2026-11-06 11:24:49 -06:00
|
|
|
def test_partial_append():
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="mergerfs-enospc-") as root:
|
|
|
|
|
source, destination, pool = [os.path.join(root, name) for name in ("source", "destination", "pool")]
|
|
|
|
|
for directory in (source, destination, pool):
|
|
|
|
|
os.mkdir(directory)
|
|
|
|
|
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["mount", "-t", "tmpfs", "-o", "size=1m", "tmpfs", source],
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
if result.returncode:
|
|
|
|
|
print(f"constrained tmpfs unavailable: {result.stderr.decode(errors='replace')}", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
mounted = False
|
|
|
|
|
try:
|
|
|
|
|
block_size = os.statvfs(source).f_frsize
|
|
|
|
|
initial = b"initial\n" * (block_size // 8)
|
|
|
|
|
with open(os.path.join(source, "target"), "wb") as stream:
|
|
|
|
|
stream.write(initial)
|
|
|
|
|
|
|
|
|
|
stat = os.statvfs(source)
|
|
|
|
|
remaining = block_size
|
|
|
|
|
available = stat.f_bavail * stat.f_frsize
|
|
|
|
|
with open(os.path.join(source, "filler"), "wb") as stream:
|
|
|
|
|
stream.write(b"F" * (available - remaining))
|
|
|
|
|
|
|
|
|
|
mount_mergerfs(
|
|
|
|
|
[source, destination], pool,
|
|
|
|
|
"minfreespace=0,cache.files=full,cache.writeback=false,moveonenospc=mfs",
|
|
|
|
|
)
|
|
|
|
|
mounted = True
|
|
|
|
|
|
|
|
|
|
# The first write appends a prefix before ENOSPC. Relocation must
|
|
|
|
|
# preserve that progress instead of replaying it on the new branch.
|
|
|
|
|
payload = bytes(range(256)) * (block_size // 64)
|
|
|
|
|
fd = os.open(os.path.join(pool, "target"), os.O_WRONLY | os.O_APPEND)
|
2026-05-07 20:43:42 -05:00
|
|
|
try:
|
2026-11-06 11:24:49 -06:00
|
|
|
written = os.write(fd, payload)
|
|
|
|
|
finally:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
if written != len(payload):
|
|
|
|
|
return fail(f"append returned {written}, expected {len(payload)}")
|
|
|
|
|
|
|
|
|
|
relocated = os.path.join(destination, "target")
|
|
|
|
|
if os.path.exists(os.path.join(source, "target")) or not os.path.isfile(relocated):
|
|
|
|
|
return fail("ENOSPC append did not relocate the file")
|
|
|
|
|
with open(relocated, "rb") as stream:
|
|
|
|
|
actual = stream.read()
|
|
|
|
|
expected = initial + payload
|
|
|
|
|
if actual != expected:
|
|
|
|
|
return fail(f"relocated append corrupted data: expected {len(expected)} bytes, got {len(actual)}")
|
|
|
|
|
with open(os.path.join(pool, "target"), "rb") as stream:
|
|
|
|
|
if stream.read() != expected:
|
|
|
|
|
return fail("relocated append differs through the pool")
|
|
|
|
|
return 0
|
|
|
|
|
finally:
|
|
|
|
|
if mounted:
|
|
|
|
|
unmount_mergerfs(pool)
|
|
|
|
|
subprocess.run(["umount", source], check=True)
|
2026-05-07 20:43:42 -05:00
|
|
|
|
|
|
|
|
|
2026-11-06 11:24:49 -06:00
|
|
|
def main():
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == "--isolated":
|
|
|
|
|
return test_partial_append()
|
|
|
|
|
|
|
|
|
|
if find_mergerfs() is None or find_fusermount() is None:
|
|
|
|
|
print("mergerfs or fusermount unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
if any(shutil.which(tool) is None for tool in ("unshare", "mount", "umount")):
|
|
|
|
|
print("unshare/mount/umount unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
# Limit disk usage inside a private namespace, including for non-root runs.
|
|
|
|
|
namespace = ["unshare", "-Urnm"]
|
|
|
|
|
probe = subprocess.run(namespace + ["true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
if probe.returncode:
|
|
|
|
|
print("private user/mount namespaces unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
return subprocess.run(namespace + [sys.executable, os.path.realpath(__file__), "--isolated"]).returncode
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-04-29 17:44:22 -05:00
|
|
|
raise SystemExit(main())
|