mergerfs/tests/TEST_release_metadata
Antonio SJ Musumeci 3c02e47e47 build: make NDEBUG=1 and make release build the release profile
- The RELEASE=1 profile replaced 2.42.0's NDEBUG=1 one, but the
  static archives and the container image still build with NDEBUG=1,
  which therefore selected the debug profile: -O0 -g3 with assertions
  on. Both Makefiles accept NDEBUG=1 again, as -O3 -DNDEBUG, and the
  debug profile defines DEBUG. The vendored libfuse follows the same
  profile as mergerfs.
- make release first removes the objects, binaries and stamp under
  build/ and cleans vendored/libfuse, because make only compares
  timestamps: objects from an earlier debug build were otherwise
  linked into the release binary unchanged. Packages and build reports
  in build/pkgs are kept; TEST_release_pkg_preservation checks both.
- make release also builds preload.so. It takes the release defines
  through its own PRELOAD_CPPFLAGS: the global CPPFLAGS add
  _FILE_OFFSET_BITS=64, which would hide its unsuffixed
  open/openat/fopen/creat interposers.
- mergerfs.spec builds the release target, as debian/rules does. The
  distribution's CFLAGS, CXXFLAGS and LDFLAGS still apply.
- The release driver mounts the repository with ":ro,z", not ":ro:z",
  which Podman read as an extra field instead of a mount option.
  TEST_release_metadata runs the driver against a fake podman and
  checks the volume argument and the build report.
- Remove release-installer: build-release has no installer target.
- make help printed a literal "\n" where /bin/sh is bash. Match the
  build.md transcript to its output and document the profiles.

Performance: static archives and the container image go from -O0 with
assertions back to optimized builds, now -O3 -DNDEBUG (2.42.0: -O2
-DNDEBUG). RPM packages keep the distribution's -O2 and no longer
evaluate assertions. A plain make is unoptimized, as before.
2026-11-29 23:10:53 -05:00

139 lines
4.5 KiB
Python
Executable file

#!/usr/bin/env python3
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
BUILD_RELEASE = ROOT / "buildtools" / "build-release"
class ReleaseMetadataTests(unittest.TestCase):
def setUp(self):
tmpdir = os.environ.get("TMPDIR")
tmp = tempfile.TemporaryDirectory(
prefix="mergerfs-release-metadata-", dir=tmpdir
)
self.addCleanup(tmp.cleanup)
self.root = Path(tmp.name)
self.home = self.root / "home"
self.home.mkdir()
def base_env(self):
env = os.environ.copy()
for key in list(env):
if key.startswith("GIT_"):
del env[key]
env.update(
{
"HOME": str(self.home),
"XDG_CONFIG_HOME": str(self.home / ".config"),
"GIT_CONFIG_NOSYSTEM": "1",
"GIT_CONFIG_GLOBAL": os.devnull,
"GIT_AUTHOR_NAME": "Release Test",
"GIT_AUTHOR_EMAIL": "release@example.invalid",
"GIT_COMMITTER_NAME": "Release Test",
"GIT_COMMITTER_EMAIL": "release@example.invalid",
"LC_ALL": "C",
}
)
return env
def run_command(self, args, cwd, env=None, timeout=30):
return subprocess.run(
[str(arg) for arg in args], cwd=str(cwd),
env=env or self.base_env(), stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True, timeout=timeout,
)
def run_driver(self, fail_target="", missing_podman=False, branch="test"):
work = self.root / "driver"
containers = work / "buildtools" / "containerfiles"
containers.mkdir(parents=True)
for name in ("debian-bad", "debian-good"):
(containers / name).write_text("# test fixture\n", encoding="ascii")
repo = work / "repo"
repo.mkdir()
fake_bin = work / "bin"
fake_bin.mkdir()
podman_log = work / "podman-args.jsonl"
podman = fake_bin / "podman"
podman.write_text(
"""#!/usr/bin/env python3
import json
import os
import sys
with open(os.environ["PODMAN_LOG"], "a", encoding="ascii") as stream:
stream.write(json.dumps(sys.argv[1:]) + "\\n")
target = sys.argv[sys.argv.index("-f") + 1]
if os.path.basename(target) == os.environ.get("PODMAN_FAIL_TARGET"):
raise SystemExit(19)
raise SystemExit(0)
""",
encoding="ascii",
)
podman.chmod(0o755)
packages = work / "pkgs"
env = self.base_env()
if missing_podman:
env["PATH"] = str(work / "missing-bin")
else:
env["PATH"] = str(fake_bin) + os.pathsep + env.get("PATH", "")
env["PODMAN_LOG"] = str(podman_log)
env["PODMAN_FAIL_TARGET"] = fail_target
driver_args = [
sys.executable,
BUILD_RELEASE,
"--target=all",
"--git-repo={}".format(repo),
"--pkgdirpath={}".format(packages),
]
if branch is not None:
driver_args.append("--branch={}".format(branch))
rv = self.run_command(driver_args, cwd=work, env=env)
calls = []
if podman_log.exists():
calls = [
json.loads(line)
for line in podman_log.read_text(encoding="ascii").splitlines()
]
report_path = packages / "build-report.txt"
report = ""
if report_path.exists():
report = report_path.read_text(encoding="ascii")
return rv, calls, report.splitlines()
def assert_driver_report(self, lines, bad_status):
self.assertEqual(len(lines), 2)
pattern = r"^debian-bad: branch=test; timestamp=\d+; rv={};$"
self.assertRegex(lines[0], pattern.format(bad_status))
self.assertRegex(
lines[1], r"^debian-good: branch=test; timestamp=\d+; rv=success;$")
def assert_local_volume_syntax(self, calls):
volumes = [
arg for call in calls for arg in call
if arg.endswith(":/tmp/mergerfs.git:ro,z")
]
self.assertEqual(len(volumes), 2)
def test_driver_success(self):
rv, calls, report = self.run_driver()
self.assertEqual(
rv.returncode, 0, msg=rv.stdout + rv.stderr
)
self.assertEqual(len(calls), 2)
self.assert_driver_report(report, "success")
self.assert_local_volume_syntax(calls)
if __name__ == "__main__":
unittest.main()