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
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
from posix_parity import cleanup_dir
|
|
|
|
|
from posix_parity import fail
|
|
|
|
|
from posix_parity import join
|
|
|
|
|
from posix_parity import mergerfs_branches
|
|
|
|
|
from posix_parity import mergerfs_get_option
|
2026-05-07 20:43:42 -05:00
|
|
|
from posix_parity import mergerfs_mount
|
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 mergerfs_set_option
|
|
|
|
|
from posix_parity import temp_dir
|
|
|
|
|
from posix_parity import touch
|
|
|
|
|
|
|
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
SKIP = 77
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def used_percent(path):
|
|
|
|
|
st = os.statvfs(path)
|
|
|
|
|
if st.f_blocks == 0:
|
|
|
|
|
return 1.0
|
|
|
|
|
used = st.f_blocks - st.f_bfree
|
|
|
|
|
return used / st.f_blocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def branch_for_fullpath(branches, fullpath):
|
|
|
|
|
fullpath = os.path.realpath(fullpath)
|
|
|
|
|
for branch in branches:
|
|
|
|
|
branch = os.path.realpath(branch)
|
|
|
|
|
try:
|
|
|
|
|
common = os.path.commonpath([branch, fullpath])
|
|
|
|
|
except ValueError:
|
|
|
|
|
continue
|
|
|
|
|
if common == branch:
|
|
|
|
|
return branch
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def least_used_branches(branches, rel_dir):
|
|
|
|
|
scored = []
|
|
|
|
|
for branch in branches:
|
|
|
|
|
path = join(branch, rel_dir)
|
|
|
|
|
if os.path.isdir(path):
|
|
|
|
|
scored.append((used_percent(path), os.path.realpath(branch)))
|
|
|
|
|
if not scored:
|
|
|
|
|
return set()
|
|
|
|
|
min_used = min(score for score, _ in scored)
|
|
|
|
|
return {branch for score, branch in scored if score == min_used}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
def main():
|
|
|
|
|
try:
|
2026-05-07 20:43:42 -05:00
|
|
|
with mergerfs_mount(num_branches=2) as (mount, branches):
|
|
|
|
|
try:
|
|
|
|
|
orig_create = mergerfs_get_option(mount, "func.create")
|
|
|
|
|
except (PermissionError, FileNotFoundError, OSError):
|
|
|
|
|
print("LUP create policy option unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
orig_search = mergerfs_get_option(mount, "func.search")
|
|
|
|
|
except (PermissionError, FileNotFoundError, OSError):
|
|
|
|
|
print("LUP search policy option unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
if len(branches) < 2:
|
|
|
|
|
print("LUP policy test requires at least 2 branches", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
merge_base = temp_dir(mount)
|
|
|
|
|
rel_base = os.path.relpath(merge_base, mount)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
for branch in branches:
|
|
|
|
|
os.makedirs(join(branch, rel_base), exist_ok=True)
|
|
|
|
|
|
|
|
|
|
mergerfs_set_option(mount, "func.create", "lup")
|
|
|
|
|
mergerfs_set_option(mount, "func.search", "lup")
|
|
|
|
|
|
|
|
|
|
path = join(merge_base, "lup_test_file")
|
|
|
|
|
expected = least_used_branches(branches, rel_base)
|
|
|
|
|
touch(path, b"lup create test")
|
|
|
|
|
if not os.path.exists(path):
|
|
|
|
|
return fail("LUP create: file not created")
|
|
|
|
|
|
|
|
|
|
fullpath = os.getxattr(path, "user.mergerfs.fullpath").decode()
|
|
|
|
|
if not fullpath:
|
|
|
|
|
return fail("LUP create: no fullpath attribute")
|
|
|
|
|
actual = branch_for_fullpath(branches, fullpath)
|
|
|
|
|
if actual not in expected:
|
|
|
|
|
return fail(f"LUP create: selected {actual}, expected one of {sorted(expected)}")
|
|
|
|
|
|
|
|
|
|
path2 = join(merge_base, "lup_test_file2")
|
|
|
|
|
for branch in branches:
|
|
|
|
|
touch(join(branch, rel_base, "lup_test_file2"), b"lup search test")
|
|
|
|
|
expected = least_used_branches(branches, rel_base)
|
|
|
|
|
fullpath2 = os.getxattr(path2, "user.mergerfs.fullpath").decode()
|
|
|
|
|
if not fullpath2:
|
|
|
|
|
return fail("LUP search: no fullpath attribute")
|
|
|
|
|
actual = branch_for_fullpath(branches, fullpath2)
|
|
|
|
|
if actual not in expected:
|
|
|
|
|
return fail(f"LUP search: selected {actual}, expected one of {sorted(expected)}")
|
|
|
|
|
|
|
|
|
|
mergerfs_set_option(mount, "func.create", orig_create)
|
|
|
|
|
mergerfs_set_option(mount, "func.search", orig_search)
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
mergerfs_set_option(mount, "func.create", orig_create)
|
|
|
|
|
mergerfs_set_option(mount, "func.search", orig_search)
|
|
|
|
|
return fail(str(exc))
|
|
|
|
|
finally:
|
|
|
|
|
cleanup_dir(merge_base)
|
|
|
|
|
for branch in branches:
|
|
|
|
|
cleanup_dir(join(branch, rel_base))
|
|
|
|
|
except RuntimeError as exc:
|
|
|
|
|
print(str(exc), end="")
|
|
|
|
|
return 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
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-04-29 17:44:22 -05:00
|
|
|
raise SystemExit(main())
|