| 1 |
|
| 2 |
"""abdiff.py -- differential A/B regression hunter for rsync. |
| 3 |
|
| 4 |
Runs the same transfer with two rsync binaries (A = the build under test, e.g. |
| 5 |
./rsync; B = a baseline, e.g. old_versions/rsync_3.4.1) and compares the |
| 6 |
OUTCOME: exit code, error output, --stats "Literal data", the destination tree |
| 7 |
(content + full metadata), and the --itemize change list. |
| 8 |
|
| 9 |
Core oracle: for a BENIGN input a correctness/behaviour change between the two |
| 10 |
builds must be invisible, so A and B must produce an identical destination tree |
| 11 |
and both exit 0. Any divergence is a regression candidate (e.g. a refactor that |
| 12 |
silently changes what a benign `rsync -a` transfers). |
| 13 |
|
| 14 |
This is a developer tool, NOT a runtests.py test (it does not end in _test.py and |
| 15 |
imports nothing from the test harness). Findings are printed and appended to a |
| 16 |
log; minimize each into a testsuite/*_test.py. |
| 17 |
|
| 18 |
Usage: |
| 19 |
testsuite/abdiff.py [--rsync-a ./rsync] [--rsync-b old_versions/rsync_3.4.1] |
| 20 |
[--sweep options|pathshape|all] [--workdir DIR] [--keep] |
| 21 |
[--findings abdiff-findings.txt] [--only NAME] [--list] |
| 22 |
Exit 0 iff no regression candidates were found. |
| 23 |
""" |
| 24 |
|
| 25 |
from __future__ import annotations |
| 26 |
|
| 27 |
import argparse |
| 28 |
import hashlib |
| 29 |
import itertools |
| 30 |
import os |
| 31 |
import random |
| 32 |
import re |
| 33 |
import shutil |
| 34 |
import signal |
| 35 |
import stat |
| 36 |
import subprocess |
| 37 |
import sys |
| 38 |
import threading |
| 39 |
import time |
| 40 |
from concurrent.futures import (FIRST_COMPLETED, ThreadPoolExecutor, |
| 41 |
as_completed, wait) |
| 42 |
from pathlib import Path |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
RSYNC_A = "./rsync" |
| 47 |
RSYNC_B = "old_versions/rsync_3.4.1" |
| 48 |
RRSYNC_A = None |
| 49 |
RRSYNC_B = None |
| 50 |
KEEP = False |
| 51 |
REPEAT = 2 |
| 52 |
CMD_TIMEOUT = 120 |
| 53 |
COST = False |
| 54 |
SCALE_N = 2000 |
| 55 |
_supports_cache: dict = {} |
| 56 |
_supports_lock = threading.Lock() |
| 57 |
_tls = threading.local() |
| 58 |
_PAGE = os.sysconf("SC_PAGE_SIZE") |
| 59 |
|
| 60 |
|
| 61 |
def _group_rss(pgid): |
| 62 |
"""Summed RSS (bytes) of every live process in process group pgid -- catches |
| 63 |
rsync's forked generator/receiver/sender (and ssh/daemon children), which a |
| 64 |
direct-child measure (/usr/bin/time) would miss.""" |
| 65 |
total = 0 |
| 66 |
for pid in os.listdir("/proc"): |
| 67 |
if not pid.isdigit(): |
| 68 |
continue |
| 69 |
try: |
| 70 |
with open(f"/proc/{pid}/stat") as f: |
| 71 |
fields = f.read().split() |
| 72 |
if int(fields[4]) != pgid: |
| 73 |
continue |
| 74 |
with open(f"/proc/{pid}/statm") as f: |
| 75 |
total += int(f.read().split()[1]) * _PAGE |
| 76 |
except (OSError, ValueError, IndexError): |
| 77 |
continue |
| 78 |
return total |
| 79 |
|
| 80 |
|
| 81 |
def sh(cmd, cwd=None, env=None, timeout=None): |
| 82 |
"""Run cmd capturing stdout/stderr. Runs in its own process group with a |
| 83 |
wall-clock timeout so a wedged rsync (or its ssh/daemon children) can't hang a |
| 84 |
worker forever -- on timeout the whole group is killed and rc 124 returned.""" |
| 85 |
if timeout is None: |
| 86 |
timeout = CMD_TIMEOUT |
| 87 |
p = subprocess.Popen(cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, |
| 88 |
stderr=subprocess.PIPE, text=True, start_new_session=True) |
| 89 |
|
| 90 |
|
| 91 |
measure = getattr(_tls, "measure", False) |
| 92 |
stop = peak = poller = None |
| 93 |
if measure: |
| 94 |
peak = [0] |
| 95 |
stop = threading.Event() |
| 96 |
pgid = os.getpgid(p.pid) |
| 97 |
|
| 98 |
def _poll(): |
| 99 |
while not stop.is_set(): |
| 100 |
peak[0] = max(peak[0], _group_rss(pgid)) |
| 101 |
stop.wait(0.03) |
| 102 |
poller = threading.Thread(target=_poll, daemon=True) |
| 103 |
poller.start() |
| 104 |
try: |
| 105 |
out, err = p.communicate(timeout=timeout or None) |
| 106 |
rc = p.returncode |
| 107 |
except subprocess.TimeoutExpired: |
| 108 |
try: |
| 109 |
os.killpg(os.getpgid(p.pid), signal.SIGKILL) |
| 110 |
except OSError: |
| 111 |
pass |
| 112 |
out, err = p.communicate() |
| 113 |
rc = 124 |
| 114 |
err = "[abdiff: TIMEOUT]\n" + (err or "") |
| 115 |
if measure: |
| 116 |
stop.set() |
| 117 |
poller.join(timeout=1) |
| 118 |
_tls.rss = peak[0] or None |
| 119 |
return subprocess.CompletedProcess(cmd, rc, out or "", err or "") |
| 120 |
|
| 121 |
|
| 122 |
def supports(binary, opt): |
| 123 |
key = (binary, opt) |
| 124 |
with _supports_lock: |
| 125 |
if key in _supports_cache: |
| 126 |
return _supports_cache[key] |
| 127 |
r = sh([binary, opt, "--version"]) |
| 128 |
bad = any(m in (r.stderr or "").lower() |
| 129 |
for m in ("unknown option", "unrecognized option", "no such option")) |
| 130 |
val = not bad |
| 131 |
with _supports_lock: |
| 132 |
_supports_cache[key] = val |
| 133 |
return val |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
ERR_MARKERS = ("rsync error", "failed to open", "rsync: ", "Invalid argument", |
| 140 |
"No such file", "Operation not permitted", "cannot ") |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
ALLOWLIST = [] |
| 147 |
|
| 148 |
|
| 149 |
def _xattrs(path): |
| 150 |
try: |
| 151 |
names = sorted(os.listxattr(path, follow_symlinks=False)) |
| 152 |
except (OSError, AttributeError): |
| 153 |
return {} |
| 154 |
out = {} |
| 155 |
for n in names: |
| 156 |
if n.startswith("system.posix_acl_"): |
| 157 |
continue |
| 158 |
try: |
| 159 |
out[n] = os.getxattr(path, n, follow_symlinks=False).hex() |
| 160 |
except OSError: |
| 161 |
out[n] = "?" |
| 162 |
return out |
| 163 |
|
| 164 |
|
| 165 |
def _acl(path, is_dir): |
| 166 |
r = sh(["getfacl", "-pcEn", path]) if shutil.which("getfacl") else None |
| 167 |
if not r or r.returncode != 0: |
| 168 |
return None |
| 169 |
lines = [ln for ln in r.stdout.splitlines() if ln and not ln.startswith("#")] |
| 170 |
return "\n".join(sorted(lines)) or None |
| 171 |
|
| 172 |
|
| 173 |
def snapshot(root: Path): |
| 174 |
"""Map rel-path -> attribute dict for every entry under root (root itself |
| 175 |
excluded). Symlinks/specials are recorded, never followed.""" |
| 176 |
root = Path(root) |
| 177 |
snap = {} |
| 178 |
inode_of = {} |
| 179 |
if not root.exists(): |
| 180 |
return snap |
| 181 |
stack = [root] |
| 182 |
while stack: |
| 183 |
d = stack.pop() |
| 184 |
try: |
| 185 |
entries = sorted(os.scandir(d), key=lambda e: e.name) |
| 186 |
except OSError: |
| 187 |
continue |
| 188 |
for e in entries: |
| 189 |
p = Path(e.path) |
| 190 |
rel = str(p.relative_to(root)) |
| 191 |
try: |
| 192 |
st = os.lstat(p) |
| 193 |
except OSError: |
| 194 |
snap[rel] = {"type": "GONE"} |
| 195 |
continue |
| 196 |
m = st.st_mode |
| 197 |
a = { |
| 198 |
"mode": stat.S_IMODE(m), |
| 199 |
"uid": st.st_uid, "gid": st.st_gid, |
| 200 |
"mtime": int(st.st_mtime), |
| 201 |
} |
| 202 |
if stat.S_ISDIR(m): |
| 203 |
a["type"] = "d" |
| 204 |
stack.append(p) |
| 205 |
elif stat.S_ISLNK(m): |
| 206 |
a["type"] = "l" |
| 207 |
a["target"] = os.readlink(p) |
| 208 |
elif stat.S_ISREG(m): |
| 209 |
a["type"] = "f" |
| 210 |
a["size"] = st.st_size |
| 211 |
a["blocks"] = st.st_blocks |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
a["linked"] = st.st_nlink > 1 |
| 217 |
if st.st_nlink > 1: |
| 218 |
key = (st.st_dev, st.st_ino) |
| 219 |
a["hardlink"] = inode_of.setdefault(key, rel) |
| 220 |
h = hashlib.sha256() |
| 221 |
try: |
| 222 |
with open(p, "rb") as fh: |
| 223 |
for chunk in iter(lambda: fh.read(1 << 20), b""): |
| 224 |
h.update(chunk) |
| 225 |
a["sha"] = h.hexdigest() |
| 226 |
except OSError as ex: |
| 227 |
a["sha"] = f"ERR:{ex.errno}" |
| 228 |
elif stat.S_ISFIFO(m): |
| 229 |
a["type"] = "p" |
| 230 |
elif stat.S_ISSOCK(m): |
| 231 |
a["type"] = "s" |
| 232 |
elif stat.S_ISBLK(m) or stat.S_ISCHR(m): |
| 233 |
a["type"] = "b" if stat.S_ISBLK(m) else "c" |
| 234 |
a["rdev"] = (os.major(st.st_rdev), os.minor(st.st_rdev)) |
| 235 |
else: |
| 236 |
a["type"] = "?" |
| 237 |
xa = _xattrs(p) |
| 238 |
if xa: |
| 239 |
a["xattr"] = xa |
| 240 |
ac = _acl(p, stat.S_ISDIR(m)) |
| 241 |
if ac: |
| 242 |
a["acl"] = ac |
| 243 |
snap[rel] = a |
| 244 |
return snap |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
def diff_snapshots(sa, sb, ignore_mtime=False, ignore_mtime_types=()): |
| 252 |
diffs = [] |
| 253 |
for rel in sorted(set(sa) | set(sb)): |
| 254 |
a, b = sa.get(rel), sb.get(rel) |
| 255 |
if a is None: |
| 256 |
diffs.append(f" only in B(baseline): {rel} ({b.get('type')})") |
| 257 |
continue |
| 258 |
if b is None: |
| 259 |
diffs.append(f" only in A(under-test): {rel} ({a.get('type')})") |
| 260 |
continue |
| 261 |
for k in sorted(set(a) | set(b)): |
| 262 |
if k == "mtime" and (ignore_mtime |
| 263 |
or a.get("type") in ignore_mtime_types): |
| 264 |
continue |
| 265 |
if a.get(k) != b.get(k): |
| 266 |
diffs.append(f" {rel}: {k} A={a.get(k)!r} B={b.get(k)!r}") |
| 267 |
return diffs |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
def run_xfer(binary, workdir, opts, src_args, dest, cwd=None, pre=None): |
| 274 |
"""Run `binary opts src_args dest` (cwd default=workdir). Returns |
| 275 |
(rc, stderr, literal_data, itemize).""" |
| 276 |
cwd = cwd or workdir |
| 277 |
argv = [binary, "--stats", "-i", *opts, *src_args, dest] |
| 278 |
return _parse_out(sh(argv, cwd=cwd)) |
| 279 |
|
| 280 |
|
| 281 |
def _parse_out(r): |
| 282 |
literal = None |
| 283 |
for ln in r.stdout.splitlines(): |
| 284 |
if ln.startswith("Literal data:"): |
| 285 |
literal = ln.split(":", 1)[1].strip() |
| 286 |
itemize = "\n".join(sorted( |
| 287 |
ln for ln in r.stdout.splitlines() |
| 288 |
if len(ln) > 11 and ln[1] in "fdLDS" and ln[0] in "<>ch.*" |
| 289 |
and ln[11:].strip() != "./")) |
| 290 |
return r.returncode, (r.stderr or "").strip(), literal, itemize, (r.stdout or "") |
| 291 |
|
| 292 |
|
| 293 |
_NOISE = re.compile(r'bytes/sec|speedup is|^sent .*received |^total size is|' |
| 294 |
r'^Number of |^Total |^Literal data:|^Matched data:|' |
| 295 |
r'^File list |^total:|^created |^deleting ') |
| 296 |
|
| 297 |
|
| 298 |
def _norm_out(text, wd, dest): |
| 299 |
"""Normalised stdout for A/B compare: canonicalise the workdir/dest paths and |
| 300 |
drop bench-variant stats lines (keeps itemize/listing/warning lines).""" |
| 301 |
text = text.replace(str(dest), "DEST").replace(str(wd), "WD") |
| 302 |
return "\n".join(ln for ln in text.splitlines() if ln and not _NOISE.search(ln)) |
| 303 |
|
| 304 |
|
| 305 |
def _norm_err(text, wd, dest): |
| 306 |
"""Normalised stderr TEXT for A/B compare: canonicalise paths, strip the |
| 307 |
version-dependent role tag ([sender=3.4.x], [client=VERSION]) and at-FILE(LINE) |
| 308 |
source location (line numbers shift between versions) so only the MESSAGE is |
| 309 |
compared.""" |
| 310 |
text = text.replace(str(dest), "DEST").replace(str(wd), "WD") |
| 311 |
text = re.sub(r'\[(?:sender|receiver|generator|client|server' |
| 312 |
r'|Sender|Receiver|Generator|Client|Server)=[^\]]*\]', |
| 313 |
'[ROLE]', text) |
| 314 |
text = re.sub(r' at [\w./-]+\(\d+\)', ' at LOC', text) |
| 315 |
return text.strip() |
| 316 |
|
| 317 |
|
| 318 |
def _wait_port(port, timeout=10.0): |
| 319 |
import socket as _sock |
| 320 |
end = time.time() + timeout |
| 321 |
while time.time() < end: |
| 322 |
try: |
| 323 |
_sock.create_connection(("127.0.0.1", port), 0.3).close() |
| 324 |
return True |
| 325 |
except OSError: |
| 326 |
time.sleep(0.05) |
| 327 |
return False |
| 328 |
|
| 329 |
|
| 330 |
def run_daemon_xfer(binary, wd, module_path, opts, src_args, port, chroot="no"): |
| 331 |
"""Push src_args into a [m] module served by `binary --daemon` over a PRIVATE |
| 332 |
STDIO PIPE (RSYNC_CONNECT_PROG) -- no TCP port, so no port-bind/startup race |
| 333 |
(the old TCP path was nondeterministic under load). `port` only uniquifies |
| 334 |
the per-invocation config filename. Same (rc, err, lit, item) as run_xfer.""" |
| 335 |
conf = Path(wd) / f"rsyncd_{port}.conf" |
| 336 |
Path(module_path).mkdir(parents=True, exist_ok=True) |
| 337 |
conf.write_text( |
| 338 |
f"use chroot = {chroot}\n" |
| 339 |
f"[m]\n path = {module_path}\n read only = no\n" |
| 340 |
f" hosts allow = 127.0.0.1\n") |
| 341 |
env = {**os.environ, |
| 342 |
"RSYNC_CONNECT_PROG": f"{binary} --config={conf} --daemon"} |
| 343 |
argv = [binary, "--stats", "-i", *opts, *src_args, "rsync://localhost/m/"] |
| 344 |
return _parse_out(sh(argv, cwd=str(wd), env=env)) |
| 345 |
|
| 346 |
|
| 347 |
def run_daemon_pull(binary, wd, served, opts, localdest, port, chroot="no"): |
| 348 |
"""PULL from a read-only [m] module (the daemon SENDER side) over a private |
| 349 |
stdio pipe into localdest. `served` is the served directory.""" |
| 350 |
conf = Path(wd) / f"rsyncd_{port}.conf" |
| 351 |
Path(served).mkdir(parents=True, exist_ok=True) |
| 352 |
Path(localdest).mkdir(parents=True, exist_ok=True) |
| 353 |
conf.write_text( |
| 354 |
f"use chroot = {chroot}\n" |
| 355 |
f"[m]\n path = {served}\n read only = yes\n" |
| 356 |
f" hosts allow = 127.0.0.1\n") |
| 357 |
env = {**os.environ, |
| 358 |
"RSYNC_CONNECT_PROG": f"{binary} --config={conf} --daemon"} |
| 359 |
argv = [binary, "--stats", "-i", *opts, "rsync://localhost/m/", |
| 360 |
str(localdest) + "/"] |
| 361 |
return _parse_out(sh(argv, cwd=str(wd), env=env)) |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
_SUPPORT = Path(__file__).resolve().parent.parent / "support" |
| 366 |
_LSH = str(_SUPPORT / "lsh.sh") |
| 367 |
|
| 368 |
|
| 369 |
def run_ssh_xfer(binary, wd, opts, src_args, dest): |
| 370 |
"""PUSH over a remote-shell split via support/lsh.sh (host 'lh' = no chdir); |
| 371 |
the remote side runs the same binary via --rsync-path. Real client+server |
| 372 |
processes + protocol, unlike a both-paths-local copy.""" |
| 373 |
argv = [binary, "--stats", "-i", "-e", f"sh {_LSH}", |
| 374 |
f"--rsync-path={binary}", *opts, *src_args, f"lh:{dest}/"] |
| 375 |
return _parse_out(sh(argv, cwd=wd)) |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
_RRSH = str(_SUPPORT / "rrsh.sh") |
| 380 |
_RRSYNC_SRC = _SUPPORT / "rrsync" |
| 381 |
|
| 382 |
|
| 383 |
def _patch_rrsync(binary, rrsync_src, wd): |
| 384 |
"""A copy of `rrsync_src` (the version's rrsync wrapper) whose RSYNC points at |
| 385 |
`binary`, so the rrsync-launched server is the binary under test. rrsync is |
| 386 |
SHIPPED PER VERSION, so A and B use their OWN rrsync (the regressions live in |
| 387 |
the script, not just the binary) -- keyed per (binary, src) to keep them |
| 388 |
distinct in a shared workdir.""" |
| 389 |
key = abs(hash((binary, str(rrsync_src)))) % 1000000 |
| 390 |
dst = Path(wd) / f"rrsync-{key}" |
| 391 |
if not dst.exists(): |
| 392 |
txt = Path(rrsync_src).read_text() |
| 393 |
txt = re.sub(r"^RSYNC = '[^']*'", f"RSYNC = {binary!r}", txt, count=1, |
| 394 |
flags=re.M) |
| 395 |
dst.write_text(txt) |
| 396 |
dst.chmod(0o755) |
| 397 |
return dst |
| 398 |
|
| 399 |
|
| 400 |
def run_rrsync_push(binary, rrsync_src, wd, opts, src_args, dest): |
| 401 |
"""PUSH through `rrsync <restricted>` (the dest's parent is the restricted |
| 402 |
root; the client writes into the <dest-name>/ subdir, so rrsync's subdir |
| 403 |
restrictions are exercised). Exercises rrsync option/path validation.""" |
| 404 |
dest = Path(dest) |
| 405 |
rr = _patch_rrsync(binary, rrsync_src, wd) |
| 406 |
dest.parent.mkdir(parents=True, exist_ok=True) |
| 407 |
argv = [binary, "--stats", "-i", "-e", f"sh {_RRSH} {rr} {dest.parent}", |
| 408 |
*opts, *src_args, f"lh:{dest.name}/"] |
| 409 |
return _parse_out(sh(argv, cwd=str(wd))) |
| 410 |
|
| 411 |
|
| 412 |
def run_rrsync_pull(binary, rrsync_src, wd, served, opts, localdest): |
| 413 |
"""PULL through `rrsync <restricted>` (rrsync's --sender side): the served |
| 414 |
dir's parent is the restricted root, the client reads the <served-name>/ |
| 415 |
subdir into localdest.""" |
| 416 |
served = Path(served) |
| 417 |
rr = _patch_rrsync(binary, rrsync_src, wd) |
| 418 |
Path(localdest).mkdir(parents=True, exist_ok=True) |
| 419 |
argv = [binary, "--stats", "-i", "-e", f"sh {_RRSH} {rr} {served.parent}", |
| 420 |
*opts, f"lh:{served.name}/", str(localdest) + "/"] |
| 421 |
return _parse_out(sh(argv, cwd=str(wd))) |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
_port_lock = threading.Lock() |
| 426 |
_next_port = [40000] |
| 427 |
|
| 428 |
|
| 429 |
def _alloc_port(): |
| 430 |
"""A free localhost TCP port, bind-probed under a lock so concurrent workers |
| 431 |
don't collide (the real-daemon path needs a real port, unlike the stdio one).""" |
| 432 |
import socket as _s |
| 433 |
with _port_lock: |
| 434 |
for _ in range(4000): |
| 435 |
p = _next_port[0] |
| 436 |
_next_port[0] = 40000 if p >= 60000 else p + 1 |
| 437 |
s = _s.socket(_s.AF_INET, _s.SOCK_STREAM) |
| 438 |
try: |
| 439 |
s.setsockopt(_s.SOL_SOCKET, _s.SO_REUSEADDR, 1) |
| 440 |
s.bind(("127.0.0.1", p)) |
| 441 |
return p |
| 442 |
except OSError: |
| 443 |
continue |
| 444 |
finally: |
| 445 |
s.close() |
| 446 |
return _next_port[0] |
| 447 |
|
| 448 |
|
| 449 |
def _tcp_daemon(binary, wd, module_path, opts, src_args, localdest=None, |
| 450 |
pull=False, chroot="no", auth=False): |
| 451 |
"""Start a real `binary --daemon` on a bound TCP port and run the client over |
| 452 |
rsync://127.0.0.1:PORT/m/ -- exercises the genuine socket path / greeting / |
| 453 |
handshake (and, with auth, the challenge-response) that the stdio-pipe daemon |
| 454 |
lane bypasses.""" |
| 455 |
port = _alloc_port() |
| 456 |
conf = Path(wd) / f"tcpd_{port}.conf" |
| 457 |
Path(module_path).mkdir(parents=True, exist_ok=True) |
| 458 |
authlines = "" |
| 459 |
env = dict(os.environ) |
| 460 |
if auth: |
| 461 |
sp = Path(wd) / f"tcpd_{port}.secrets" |
| 462 |
sp.write_text("abuser:abpass\n") |
| 463 |
sp.chmod(0o600) |
| 464 |
authlines = f" auth users = abuser\n secrets file = {sp}\n" |
| 465 |
env["RSYNC_PASSWORD"] = "abpass" |
| 466 |
conf.write_text( |
| 467 |
f"use chroot = {chroot}\nport = {port}\n" |
| 468 |
f"log file = {wd}/tcpd_{port}.log\npid file = {wd}/tcpd_{port}.pid\n" |
| 469 |
f"[m]\n path = {module_path}\n read only = {'yes' if pull else 'no'}\n" |
| 470 |
f" hosts allow = 127.0.0.1\n{authlines}") |
| 471 |
proc = subprocess.Popen( |
| 472 |
[binary, "--daemon", "--no-detach", f"--config={conf}", |
| 473 |
f"--port={port}", "--address=127.0.0.1"], |
| 474 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, |
| 475 |
start_new_session=True) |
| 476 |
try: |
| 477 |
if not _wait_port(port): |
| 478 |
return (99, "tcp daemon failed to start", None, "", "") |
| 479 |
user = "abuser@" if auth else "" |
| 480 |
url = f"rsync://{user}127.0.0.1:{port}/m/" |
| 481 |
if pull: |
| 482 |
Path(localdest).mkdir(parents=True, exist_ok=True) |
| 483 |
argv = [binary, "--stats", "-i", *opts, url, str(localdest) + "/"] |
| 484 |
else: |
| 485 |
argv = [binary, "--stats", "-i", *opts, *src_args, url] |
| 486 |
return _parse_out(sh(argv, cwd=str(wd), env=env)) |
| 487 |
finally: |
| 488 |
proc.terminate() |
| 489 |
try: |
| 490 |
proc.wait(timeout=5) |
| 491 |
except subprocess.TimeoutExpired: |
| 492 |
proc.kill() |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
def _write(p: Path, data: bytes): |
| 499 |
p.parent.mkdir(parents=True, exist_ok=True) |
| 500 |
p.write_bytes(data) |
| 501 |
|
| 502 |
|
| 503 |
def build_kitchen(src: Path): |
| 504 |
"""A benign 'kitchen-sink' tree: regular/empty/large/sparse files, nested |
| 505 |
and empty dirs, in-tree + dangling symlinks, a dir-symlink, a hardlink pair, |
| 506 |
odd modes, and a user.* xattr. No attacker paths.""" |
| 507 |
src.mkdir(parents=True, exist_ok=True) |
| 508 |
_write(src / "empty", b"") |
| 509 |
_write(src / "small.txt", b"hello world\n") |
| 510 |
_write(src / "data.bin", bytes((i * 7) & 0xFF for i in range(200000))) |
| 511 |
_write(src / "dir/a.txt", b"a" * 100) |
| 512 |
_write(src / "dir/sub/b.txt", b"b" * 100) |
| 513 |
(src / "emptydir").mkdir(exist_ok=True) |
| 514 |
|
| 515 |
with open(src / "sparse.bin", "wb") as f: |
| 516 |
f.seek(1 << 20) |
| 517 |
f.write(b"END") |
| 518 |
|
| 519 |
_write(src / "hl_a", b"hardlinked\n") |
| 520 |
try: |
| 521 |
os.link(src / "hl_a", src / "hl_b") |
| 522 |
except OSError: |
| 523 |
pass |
| 524 |
|
| 525 |
os.symlink("small.txt", src / "rel_link") |
| 526 |
os.symlink("dir", src / "dir_link") |
| 527 |
os.symlink("nonexistent", src / "dangling") |
| 528 |
|
| 529 |
os.chmod(src / "small.txt", 0o4755) |
| 530 |
os.chmod(src / "dir", 0o2775) |
| 531 |
|
| 532 |
try: |
| 533 |
os.setxattr(src / "data.bin", "user.abtest", b"v1") |
| 534 |
except OSError: |
| 535 |
pass |
| 536 |
|
| 537 |
|
| 538 |
def build_relfile(src: Path): |
| 539 |
"""Minimal nested file for path-shape tests.""" |
| 540 |
_write(src / "sub/deep/file", b"relative content\n") |
| 541 |
os.symlink("file", src / "sub/deep/link") |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
class Scenario: |
| 548 |
def __init__(self, name, setup, opts, src_args, dest="destX/", |
| 549 |
cwd_is_workdir=True, pre_dest=None, abspath=False, |
| 550 |
dest_prep=None, snap_dest=None, dest_arg=None, daemon=None, |
| 551 |
ssh=False): |
| 552 |
self.name = name |
| 553 |
self.setup = setup |
| 554 |
self.opts = opts |
| 555 |
self.src_args = src_args |
| 556 |
self.dest = dest |
| 557 |
self.cwd_is_workdir = cwd_is_workdir |
| 558 |
self.pre_dest = pre_dest |
| 559 |
self.abspath = abspath |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
self.dest_prep = dest_prep |
| 564 |
self.snap_dest = snap_dest |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
self.dest_arg = dest_arg |
| 569 |
|
| 570 |
|
| 571 |
self.daemon = daemon |
| 572 |
|
| 573 |
|
| 574 |
self.ssh = ssh |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
self.rrsync = None |
| 579 |
|
| 580 |
|
| 581 |
def _liftable(scn): |
| 582 |
"""A benign push-into-dest scenario whose transport can be swapped for free: |
| 583 |
no dest_prep/dest_arg (those need local dest-path semantics), not already a |
| 584 |
daemon/ssh scenario, and a list src_args that ends by pushing src/ -> dest.""" |
| 585 |
return (not scn.dest_prep and not scn.dest_arg and not scn.abspath |
| 586 |
and scn.daemon is None and not scn.ssh and scn.rrsync is None |
| 587 |
and isinstance(scn.src_args, list) and scn.src_args |
| 588 |
and scn.src_args[-1] in ("src/", "src")) |
| 589 |
|
| 590 |
|
| 591 |
def _clone_transport(scn, mode): |
| 592 |
import copy |
| 593 |
c = copy.copy(scn) |
| 594 |
c.name = f"{scn.name}@{mode}" |
| 595 |
if mode == "ssh": |
| 596 |
c.ssh = True |
| 597 |
elif mode == "daemon": |
| 598 |
c.daemon = {"chroot": "no"} |
| 599 |
return c |
| 600 |
|
| 601 |
|
| 602 |
def lift_transports(scns, modes=("ssh", "daemon")): |
| 603 |
"""Make transport an ORTHOGONAL axis: keep each local scenario and, for the |
| 604 |
liftable ones, also run it over ssh and a daemon module. This is where the |
| 605 |
daemon/ssh-only regression family hides -- a feature broken only over the |
| 606 |
wire is invisible to a local-only sweep.""" |
| 607 |
out = [] |
| 608 |
for scn in scns: |
| 609 |
out.append(scn) |
| 610 |
if _liftable(scn): |
| 611 |
out += [_clone_transport(scn, m) for m in modes] |
| 612 |
return out |
| 613 |
|
| 614 |
|
| 615 |
def options_sweep(): |
| 616 |
"""-a plus one option at a time, over the kitchen-sink, relative trailing |
| 617 |
slash source -> dest. The bread-and-butter single-option regression check.""" |
| 618 |
base = ["-a"] |
| 619 |
variants = [ |
| 620 |
["-a"], ["-aH"], ["-aHS"], ["-a", "--sparse"], ["-a", "--inplace"], |
| 621 |
["-a", "-A"], ["-a", "-X"], ["-a", "-AX"], ["-a", "-U"], ["-a", "-N"], |
| 622 |
["-a", "-l"], ["-a", "-L"], ["-a", "-k"], ["-a", "-K"], |
| 623 |
["-a", "--copy-unsafe-links"], ["-a", "--safe-links"], |
| 624 |
["-a", "--munge-links"], ["-a", "-z"], ["-a", "--compress-choice=zstd"], |
| 625 |
["-a", "--compress-choice=zlib"], ["-a", "-c"], |
| 626 |
["-a", "--checksum-choice=md5"], ["-a", "-W"], ["-a", "--no-whole-file"], |
| 627 |
["-a", "-O"], ["-a", "-J"], ["-a", "--numeric-ids"], ["-a", "-E"], |
| 628 |
["-a", "--no-inc-recursive"], ["-a", "--fake-super"], |
| 629 |
["-a", "--chmod=u+rwx"], ["-rlptD"], ["-rtz"], |
| 630 |
["-a", "-B", "1024"], ["-a", "--max-size=1000"], ["-a", "--min-size=50"], |
| 631 |
["-a", "--exclude=*.bin"], ["-a", "-C"], ["-a", "--prune-empty-dirs"], |
| 632 |
] |
| 633 |
scns = [] |
| 634 |
for v in variants: |
| 635 |
nm = "opt:" + "_".join(x.lstrip("-") for x in v if x != "-a") or "opt:a" |
| 636 |
scns.append(Scenario("opt:" + "+".join(v), build_kitchen, v, |
| 637 |
["src/"], "dest/")) |
| 638 |
return scns |
| 639 |
|
| 640 |
|
| 641 |
def pathshape_sweep(): |
| 642 |
"""The --relative class: same content under many source-path shapes.""" |
| 643 |
scns = [] |
| 644 |
|
| 645 |
def absfile(wd): |
| 646 |
return [str(Path(wd) / "src/sub/deep/file")] |
| 647 |
|
| 648 |
scns += [ |
| 649 |
Scenario("path:rel-dir-slash", build_relfile, ["-a"], ["src/"], "dest/"), |
| 650 |
Scenario("path:rel-dir-noslash", build_relfile, ["-a"], ["src"], "dest/"), |
| 651 |
Scenario("path:rel-file", build_relfile, ["-a"], ["src/sub/deep/file"], "dest/"), |
| 652 |
Scenario("path:abs-file", build_relfile, ["-a"], absfile, "dest/"), |
| 653 |
Scenario("path:abs-dir", build_relfile, ["-a"], |
| 654 |
lambda wd: [str(Path(wd) / "src") + "/"], "dest/"), |
| 655 |
Scenario("path:R-rel-file", build_relfile, ["-aR"], ["src/sub/deep/file"], "dest/"), |
| 656 |
Scenario("path:R-abs-file", build_relfile, ["-aR"], absfile, "dest/"), |
| 657 |
Scenario("path:R-dot", build_relfile, ["-aR"], ["./src/sub/deep/file"], "dest/"), |
| 658 |
Scenario("path:R-rel-dir", build_relfile, ["-aR"], ["src/sub/"], "dest/"), |
| 659 |
Scenario("path:R-noimplied", build_relfile, ["-aR", "--no-implied-dirs"], |
| 660 |
["src/sub/deep/file"], "dest/"), |
| 661 |
Scenario("path:multi-src", build_relfile, ["-a"], |
| 662 |
["src/sub/deep/file", "src/sub/deep/link"], "dest/"), |
| 663 |
Scenario("path:link-as-src", build_relfile, ["-a"], ["src/sub/deep/link"], "dest/"), |
| 664 |
Scenario("path:L-link-as-src", build_relfile, ["-aL"], ["src/sub/deep/link"], "dest/"), |
| 665 |
] |
| 666 |
return scns |
| 667 |
|
| 668 |
|
| 669 |
T_OLD = 1000000000 |
| 670 |
T_NEW = 1700000000 |
| 671 |
|
| 672 |
|
| 673 |
def _ut(p, t=T_NEW): |
| 674 |
os.utime(p, (t, t)) |
| 675 |
|
| 676 |
|
| 677 |
def build_recvtree(src: Path): |
| 678 |
"""Small, interpretable source tree for receiver/stateful scenarios.""" |
| 679 |
_write(src / "file1.txt", b"NEW content line\n" * 3) |
| 680 |
_write(src / "dir/file2.txt", b"data2\n") |
| 681 |
_write(src / "big.bin", bytes((i * 3) & 0xFF for i in range(60000))) |
| 682 |
os.symlink("file1.txt", src / "slink") |
| 683 |
_write(src / "hl1", b"hard\n") |
| 684 |
try: |
| 685 |
os.link(src / "hl1", src / "hl2") |
| 686 |
except OSError: |
| 687 |
pass |
| 688 |
for f in ("file1.txt", "dir/file2.txt", "big.bin", "hl1", "hl2"): |
| 689 |
_ut(src / f) |
| 690 |
_ut(src / "dir") |
| 691 |
_ut(src) |
| 692 |
|
| 693 |
|
| 694 |
def setup_with_basis(src: Path): |
| 695 |
"""src plus an identical sibling basis/ (for --link-dest/--copy-dest/etc.).""" |
| 696 |
build_recvtree(src) |
| 697 |
basis = src.parent / "basis" |
| 698 |
build_recvtree(basis) |
| 699 |
|
| 700 |
|
| 701 |
def stale_dest(dest: Path): |
| 702 |
"""Pre-populate a dest as an OLDER state: file1 differs (older mtime), |
| 703 |
big.bin differs (older), an extra obsolete file, file2 already current.""" |
| 704 |
_write(dest / "file1.txt", b"OLD content\n") |
| 705 |
_ut(dest / "file1.txt", T_OLD) |
| 706 |
_write(dest / "dir/file2.txt", b"data2\n") |
| 707 |
_ut(dest / "dir/file2.txt") |
| 708 |
_ut(dest / "dir") |
| 709 |
_write(dest / "big.bin", bytes((i * 5) & 0xFF for i in range(60000))) |
| 710 |
_ut(dest / "big.bin", T_OLD) |
| 711 |
_write(dest / "obsolete.txt", b"remove me\n") |
| 712 |
_ut(dest / "obsolete.txt", T_OLD) |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
MODES = [0o000, 0o400, 0o200, 0o644, 0o755, 0o4755, 0o2755, 0o1777] |
| 726 |
|
| 727 |
SIZES = [0, 1, 699, 700, 701, 100003] |
| 728 |
|
| 729 |
|
| 730 |
def _mk_reg(p, n, mode=0o644, t=T_NEW, fill=7): |
| 731 |
p.parent.mkdir(parents=True, exist_ok=True) |
| 732 |
with open(p, "wb") as f: |
| 733 |
f.write(bytes((i * fill) & 0xFF for i in range(n))) |
| 734 |
os.chmod(p, mode) |
| 735 |
_ut(p, t) |
| 736 |
|
| 737 |
|
| 738 |
def _mk_sparse(p, hole=1 << 20, tail=b"end"): |
| 739 |
p.parent.mkdir(parents=True, exist_ok=True) |
| 740 |
with open(p, "wb") as f: |
| 741 |
f.seek(hole) |
| 742 |
f.write(tail) |
| 743 |
_ut(p) |
| 744 |
|
| 745 |
|
| 746 |
def _mk_fifo(p): |
| 747 |
p.parent.mkdir(parents=True, exist_ok=True) |
| 748 |
os.mkfifo(p) |
| 749 |
|
| 750 |
|
| 751 |
def _mk_sock(p): |
| 752 |
import socket as _s |
| 753 |
p.parent.mkdir(parents=True, exist_ok=True) |
| 754 |
s = _s.socket(_s.AF_UNIX) |
| 755 |
try: |
| 756 |
s.bind(str(p)) |
| 757 |
finally: |
| 758 |
s.close() |
| 759 |
|
| 760 |
|
| 761 |
def mode_sweep(): |
| 762 |
"""One representative file per interesting permission edge (+ a setgid/sticky |
| 763 |
dir), plain -a and -a --chmod. Boundary values, not 100 files of one mode.""" |
| 764 |
s = [] |
| 765 |
for m in MODES: |
| 766 |
def setup(src, m=m): |
| 767 |
_mk_reg(src / "f", 64, mode=m) |
| 768 |
os.mkdir(src / "d") |
| 769 |
os.chmod(src / "d", 0o2755 if m == 0o2755 else |
| 770 |
(0o1777 if m == 0o1777 else 0o755)) |
| 771 |
_ut(src / "d") |
| 772 |
s.append(Scenario(f"mode:{m:04o}", setup, ["-a"], ["src/"], "dest/")) |
| 773 |
s.append(Scenario("mode:chmod-Dg-Fo", lambda src: _mk_reg(src / "f", 8), |
| 774 |
["-a", "--chmod=D2755,F644"], ["src/"], "dest/")) |
| 775 |
return s |
| 776 |
|
| 777 |
|
| 778 |
def size_sweep(): |
| 779 |
"""One file per size edge around the block boundary, plain and --inplace |
| 780 |
(delta path), -c (whole-file checksum), -S on a sparse file.""" |
| 781 |
s = [] |
| 782 |
for n in SIZES: |
| 783 |
s.append(Scenario(f"size:{n}", lambda src, n=n: _mk_reg(src / "f", n), |
| 784 |
["-a"], ["src/"], "dest/")) |
| 785 |
s.append(Scenario(f"size:{n}+inplace", |
| 786 |
lambda src, n=n: _mk_reg(src / "f", n), |
| 787 |
["-a", "--inplace", "--no-whole-file"], ["src/"], "dest/")) |
| 788 |
s.append(Scenario("size:sparse", lambda src: _mk_sparse(src / "sp.bin"), |
| 789 |
["-aS"], ["src/"], "dest/")) |
| 790 |
s.append(Scenario("size:sparse-inplace", lambda src: _mk_sparse(src / "sp.bin"), |
| 791 |
["-aS", "--inplace"], ["src/"], "dest/")) |
| 792 |
return s |
| 793 |
|
| 794 |
|
| 795 |
def filetype_sweep(): |
| 796 |
"""One representative per file type/symlink shape, each with the option(s) |
| 797 |
that actually exercise it. Specials/devices are in priv_sweep (root).""" |
| 798 |
def base(src): |
| 799 |
_mk_reg(src / "anchor", 16) |
| 800 |
|
| 801 |
def f_emptydir(src): |
| 802 |
base(src) |
| 803 |
os.makedirs(src / "empty") |
| 804 |
_ut(src / "empty") |
| 805 |
|
| 806 |
def f_intree(src): |
| 807 |
base(src) |
| 808 |
_mk_reg(src / "real", 20) |
| 809 |
os.symlink("real", src / "lnk") |
| 810 |
|
| 811 |
def f_dirlink(src): |
| 812 |
base(src) |
| 813 |
_mk_reg(src / "rd/inner", 20) |
| 814 |
os.symlink("rd", src / "dl") |
| 815 |
|
| 816 |
def f_abslink(src): |
| 817 |
base(src) |
| 818 |
os.symlink("/etc/hostname", src / "abs") |
| 819 |
|
| 820 |
def f_dangling(src): |
| 821 |
base(src) |
| 822 |
os.symlink("nonexistent", src / "dead") |
| 823 |
|
| 824 |
def f_chain(src): |
| 825 |
base(src) |
| 826 |
_mk_reg(src / "real", 20) |
| 827 |
os.symlink("real", src / "l1") |
| 828 |
os.symlink("l1", src / "l2") |
| 829 |
|
| 830 |
def f_hardlinks(src): |
| 831 |
_mk_reg(src / "a", 40) |
| 832 |
os.link(src / "a", src / "b") |
| 833 |
os.link(src / "a", src / "c") |
| 834 |
base(src) |
| 835 |
|
| 836 |
def f_fifo(src): |
| 837 |
base(src) |
| 838 |
_mk_fifo(src / "pipe") |
| 839 |
|
| 840 |
def f_sock(src): |
| 841 |
base(src) |
| 842 |
_mk_sock(src / "sock") |
| 843 |
|
| 844 |
return [ |
| 845 |
Scenario("ft:emptydir", f_emptydir, ["-a"], ["src/"], "dest/"), |
| 846 |
Scenario("ft:intree-l", f_intree, ["-a"], ["src/"], "dest/"), |
| 847 |
Scenario("ft:intree-L", f_intree, ["-aL"], ["src/"], "dest/"), |
| 848 |
Scenario("ft:dirlink-l", f_dirlink, ["-a"], ["src/"], "dest/"), |
| 849 |
Scenario("ft:dirlink-k", f_dirlink, ["-ak"], ["src/"], "dest/"), |
| 850 |
Scenario("ft:dirlink-L", f_dirlink, ["-aL"], ["src/"], "dest/"), |
| 851 |
Scenario("ft:abslink-l", f_abslink, ["-a"], ["src/"], "dest/"), |
| 852 |
Scenario("ft:abslink-L", f_abslink, ["-aL"], ["src/"], "dest/"), |
| 853 |
Scenario("ft:abslink-safe", f_abslink, ["-a", "--safe-links"], ["src/"], "dest/"), |
| 854 |
Scenario("ft:abslink-munge", f_abslink, ["-a", "--munge-links"], ["src/"], "dest/"), |
| 855 |
Scenario("ft:dangling", f_dangling, ["-a"], ["src/"], "dest/"), |
| 856 |
Scenario("ft:chain-l", f_chain, ["-a"], ["src/"], "dest/"), |
| 857 |
Scenario("ft:chain-L", f_chain, ["-aL"], ["src/"], "dest/"), |
| 858 |
Scenario("ft:hardlinks", f_hardlinks, ["-aH"], ["src/"], "dest/"), |
| 859 |
Scenario("ft:fifo", f_fifo, ["-a"], ["src/"], "dest/"), |
| 860 |
Scenario("ft:sock", f_sock, ["-a"], ["src/"], "dest/"), |
| 861 |
] |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
def _pc_tree(src): |
| 866 |
_mk_reg(src / "f", 100) |
| 867 |
_mk_reg(src / "dir/g", 50) |
| 868 |
_ut(src / "dir") |
| 869 |
_ut(src) |
| 870 |
|
| 871 |
|
| 872 |
def _setup_samemeta(src): |
| 873 |
_mk_reg(src / "f", 100, t=T_NEW, fill=7) |
| 874 |
_mk_reg(src / "keep", 20, t=T_NEW, fill=7) |
| 875 |
|
| 876 |
|
| 877 |
def _pre_samemeta(dest): |
| 878 |
_mk_reg(dest / "f", 100, t=T_NEW, fill=200) |
| 879 |
_mk_reg(dest / "keep", 20, t=T_NEW, fill=200) |
| 880 |
|
| 881 |
|
| 882 |
def _setup_older(src): |
| 883 |
_mk_reg(src / "f", 100, t=T_OLD, fill=7) |
| 884 |
|
| 885 |
|
| 886 |
def _pre_newer(dest): |
| 887 |
_mk_reg(dest / "f", 60, t=T_NEW, fill=200) |
| 888 |
|
| 889 |
|
| 890 |
def _setup_mixed(src): |
| 891 |
_mk_reg(src / "exist", 30, t=T_NEW, fill=7) |
| 892 |
_mk_reg(src / "newfile", 30, t=T_NEW, fill=7) |
| 893 |
|
| 894 |
|
| 895 |
def _pre_existing(dest): |
| 896 |
_mk_reg(dest / "exist", 99, t=T_OLD, fill=200) |
| 897 |
|
| 898 |
|
| 899 |
def _setup_sizes(src): |
| 900 |
_mk_reg(src / "small", 50) |
| 901 |
_mk_reg(src / "big", 5000) |
| 902 |
|
| 903 |
|
| 904 |
def _setup_emptydirs(src): |
| 905 |
os.makedirs(src / "empty/sub") |
| 906 |
_mk_reg(src / "keep/f", 10) |
| 907 |
_ut(src / "keep") |
| 908 |
_ut(src / "empty/sub") |
| 909 |
_ut(src / "empty") |
| 910 |
|
| 911 |
|
| 912 |
def _setup_append(src): |
| 913 |
_mk_reg(src / "f", 200, t=T_NEW, fill=7) |
| 914 |
|
| 915 |
|
| 916 |
def _pre_append(dest): |
| 917 |
with open(dest / "f", "wb") as fh: |
| 918 |
fh.write(bytes((i * 7) & 0xFF for i in range(80))) |
| 919 |
_ut(dest / "f", T_OLD) |
| 920 |
|
| 921 |
|
| 922 |
def _setup_kdest(src): |
| 923 |
_mk_reg(src / "dir/f1", 10) |
| 924 |
_mk_reg(src / "dir/f2", 10) |
| 925 |
_mk_reg(src / "top", 5) |
| 926 |
|
| 927 |
|
| 928 |
def _prep_kdest(dest): |
| 929 |
dest.mkdir(parents=True, exist_ok=True) |
| 930 |
(dest / "realdir").mkdir(exist_ok=True) |
| 931 |
if not (dest / "dir").is_symlink(): |
| 932 |
os.symlink("realdir", dest / "dir") |
| 933 |
|
| 934 |
|
| 935 |
def selection_sweep(): |
| 936 |
"""File-selection / timestamp / size options at the boundary that makes the |
| 937 |
comparison non-trivial (same size+mtime but different content, newer dest, |
| 938 |
existing-vs-new, size limits).""" |
| 939 |
plain = "src/" |
| 940 |
s = [ |
| 941 |
Scenario("sel:checksum", _setup_samemeta, ["-a", "-c"], [plain], "dest/", pre_dest=_pre_samemeta), |
| 942 |
Scenario("sel:ignore-times", _setup_samemeta, ["-a", "-I"], [plain], "dest/", pre_dest=_pre_samemeta), |
| 943 |
Scenario("sel:size-only", _setup_samemeta, ["-a", "--size-only"], [plain], "dest/", pre_dest=_pre_samemeta), |
| 944 |
Scenario("sel:quickcheck", _setup_samemeta, ["-a"], [plain], "dest/", pre_dest=_pre_samemeta), |
| 945 |
Scenario("sel:update", _setup_older, ["-a", "-u"], [plain], "dest/", pre_dest=_pre_newer), |
| 946 |
Scenario("sel:modify-window", _setup_samemeta, ["-a", "--modify-window=2"], [plain], "dest/", pre_dest=_pre_samemeta), |
| 947 |
Scenario("sel:existing", _setup_mixed, ["-a", "--existing"], [plain], "dest/", pre_dest=_pre_existing), |
| 948 |
Scenario("sel:ignore-existing", _setup_mixed, ["-a", "--ignore-existing"], [plain], "dest/", pre_dest=_pre_existing), |
| 949 |
Scenario("sel:max-size", _setup_sizes, ["-a", "--max-size=1000"], [plain], "dest/"), |
| 950 |
Scenario("sel:min-size", _setup_sizes, ["-a", "--min-size=1000"], [plain], "dest/"), |
| 951 |
Scenario("sel:times-only", _pc_tree, ["-rlpt"], [plain], "dest/"), |
| 952 |
Scenario("sel:atimes", _pc_tree, ["-a", "--atimes"], [plain], "dest/"), |
| 953 |
Scenario("sel:crtimes", _pc_tree, ["-a", "--crtimes"], [plain], "dest/"), |
| 954 |
Scenario("sel:open-noatime", _pc_tree, ["-a", "--open-noatime"], [plain], "dest/"), |
| 955 |
] |
| 956 |
return lift_transports(s) |
| 957 |
|
| 958 |
|
| 959 |
def behavior_sweep(): |
| 960 |
"""Behaviour options at their active preconditions (overwrite/backup/delete/ |
| 961 |
inplace/append/keep-dirlinks-dest/prune-empty/mkpath/dirs).""" |
| 962 |
return [ |
| 963 |
Scenario("beh:backup", build_recvtree, ["-ab"], ["src/"], "dest/", pre_dest=stale_dest), |
| 964 |
Scenario("beh:delete", build_recvtree, ["-a", "--delete"], ["src/"], "dest/", pre_dest=stale_dest), |
| 965 |
Scenario("beh:delete-before", build_recvtree, ["-a", "--delete-before"], ["src/"], "dest/", pre_dest=stale_dest), |
| 966 |
Scenario("beh:delete-after", build_recvtree, ["-a", "--delete-after"], ["src/"], "dest/", pre_dest=stale_dest), |
| 967 |
Scenario("beh:delete-delay", build_recvtree, ["-a", "--delete-delay"], ["src/"], "dest/", pre_dest=stale_dest), |
| 968 |
Scenario("beh:delete-excluded", build_recvtree, |
| 969 |
["-a", "--delete", "--delete-excluded", "--exclude=obsolete.txt"], |
| 970 |
["src/"], "dest/", pre_dest=stale_dest), |
| 971 |
Scenario("beh:prune-empty", _setup_emptydirs, ["-a", "-m"], ["src/"], "dest/"), |
| 972 |
Scenario("beh:inplace", build_recvtree, ["-a", "--inplace"], ["src/"], "dest/", pre_dest=stale_dest), |
| 973 |
Scenario("beh:append", _setup_append, ["-a", "--append"], ["src/"], "dest/", pre_dest=_pre_append), |
| 974 |
Scenario("beh:numeric-ids", build_recvtree, ["-a", "--numeric-ids"], ["src/"], "dest/"), |
| 975 |
Scenario("beh:delay-updates", build_recvtree, ["-a", "--delay-updates"], ["src/"], "dest/", pre_dest=stale_dest), |
| 976 |
Scenario("beh:dirs", _pc_tree, ["-dlpt"], ["src/"], "dest/"), |
| 977 |
Scenario("beh:mkpath", _pc_tree, ["-a", "--mkpath"], ["src/"], "dest/", |
| 978 |
dest_arg=lambda d: str(d) + "/made/sub/"), |
| 979 |
Scenario("beh:keep-dirlinks-dest", _setup_kdest, ["-aK"], ["src/"], "dest/", |
| 980 |
dest_prep=_prep_kdest, snap_dest=lambda d: d / "realdir"), |
| 981 |
] |
| 982 |
|
| 983 |
|
| 984 |
def _auxp(dest, where, name): |
| 985 |
"""Aux path INSIDE the dest tree, or OUTSIDE it (sibling under the workdir).""" |
| 986 |
dest = Path(dest) |
| 987 |
return str((dest / name) if where == "inside" else (dest.parent / f"aux_{name}")) |
| 988 |
|
| 989 |
|
| 990 |
def placement_sweep(): |
| 991 |
"""Options that take a DIR/path, each with the aux location INSIDE vs OUTSIDE |
| 992 |
the destination tree -- the edge most likely to expose confinement/escape |
| 993 |
regressions. backup/temp/partial-dir + link/compare/copy-dest.""" |
| 994 |
s = [] |
| 995 |
for where in ("inside", "outside"): |
| 996 |
s.append(Scenario(f"place:backup-dir-{where}", build_recvtree, |
| 997 |
(lambda wd, dest, w=where: ["-ab", f"--backup-dir={_auxp(dest, w, 'bak')}"]), |
| 998 |
["src/"], "dest/", pre_dest=stale_dest)) |
| 999 |
|
| 1000 |
def _prep_temp(dest, w=where): |
| 1001 |
dest.mkdir(parents=True, exist_ok=True) |
| 1002 |
os.makedirs(_auxp(dest, w, "tmp"), exist_ok=True) |
| 1003 |
s.append(Scenario(f"place:temp-dir-{where}", build_recvtree, |
| 1004 |
(lambda wd, dest, w=where: ["-a", f"--temp-dir={_auxp(dest, w, 'tmp')}"]), |
| 1005 |
["src/"], "dest/", dest_prep=_prep_temp)) |
| 1006 |
s.append(Scenario(f"place:partial-dir-{where}", build_recvtree, |
| 1007 |
(lambda wd, dest, w=where: ["-a", "--partial", f"--partial-dir={_auxp(dest, w, 'part')}"]), |
| 1008 |
["src/"], "dest/")) |
| 1009 |
|
| 1010 |
for opt in ("link-dest", "compare-dest", "copy-dest"): |
| 1011 |
s.append(Scenario(f"place:{opt}-abs", setup_with_basis, |
| 1012 |
(lambda wd, dest, o=opt: ["-a", f"--{o}={wd}/basis"]), ["src/"], "dest/")) |
| 1013 |
s.append(Scenario(f"place:{opt}-rel", setup_with_basis, |
| 1014 |
(lambda wd, dest, o=opt: ["-a", f"--{o}=../basis"]), ["src/"], "dest/")) |
| 1015 |
return lift_transports(s) |
| 1016 |
|
| 1017 |
|
| 1018 |
def wire_sweep(): |
| 1019 |
"""Protocol / wire / algorithm options (checksum & compress choice, old/ |
| 1020 |
secluded args, iconv, odd block sizes).""" |
| 1021 |
bt = build_recvtree |
| 1022 |
return [ |
| 1023 |
Scenario("wire:cc-md5", bt, ["-a", "--checksum-choice=md5"], ["src/"], "dest/"), |
| 1024 |
Scenario("wire:cc-md4", bt, ["-a", "--checksum-choice=md4"], ["src/"], "dest/"), |
| 1025 |
Scenario("wire:cc-xxh64", bt, ["-a", "--checksum-choice=xxh64"], ["src/"], "dest/"), |
| 1026 |
Scenario("wire:zc-zstd", bt, ["-a", "-z", "--compress-choice=zstd"], ["src/"], "dest/"), |
| 1027 |
Scenario("wire:zc-zlib", bt, ["-a", "-z", "--compress-choice=zlib"], ["src/"], "dest/"), |
| 1028 |
Scenario("wire:zc-zlibx", bt, ["-a", "-z", "--compress-choice=zlibx"], ["src/"], "dest/"), |
| 1029 |
Scenario("wire:old-args", bt, ["-a", "--old-args"], ["src/"], "dest/"), |
| 1030 |
Scenario("wire:secluded-args", bt, ["-a", "-s"], ["src/"], "dest/"), |
| 1031 |
Scenario("wire:iconv", bt, ["-a", "--iconv=utf8,latin1"], ["src/"], "dest/"), |
| 1032 |
Scenario("wire:block-1024", bt, ["-a", "-B", "1024"], ["src/"], "dest/"), |
| 1033 |
Scenario("wire:block-999", bt, ["-a", "-B", "999"], ["src/"], "dest/"), |
| 1034 |
] |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
def _ft_intree(src): |
| 1039 |
_mk_reg(src / "real", 20) |
| 1040 |
os.symlink("real", src / "lnk") |
| 1041 |
_mk_reg(src / "anchor", 10) |
| 1042 |
|
| 1043 |
|
| 1044 |
def _ft_dirlink(src): |
| 1045 |
_mk_reg(src / "rd/inner", 20) |
| 1046 |
os.symlink("rd", src / "dl") |
| 1047 |
_mk_reg(src / "anchor", 10) |
| 1048 |
_ut(src / "rd") |
| 1049 |
|
| 1050 |
|
| 1051 |
def _ft_hardlinks(src): |
| 1052 |
_mk_reg(src / "a", 40) |
| 1053 |
os.link(src / "a", src / "b") |
| 1054 |
os.link(src / "a", src / "c") |
| 1055 |
_mk_reg(src / "anchor", 10) |
| 1056 |
|
| 1057 |
|
| 1058 |
def _ft_sparse(src): |
| 1059 |
_mk_sparse(src / "sp.bin") |
| 1060 |
_mk_reg(src / "anchor", 10) |
| 1061 |
|
| 1062 |
|
| 1063 |
def pairwise_sweep(): |
| 1064 |
"""Guided pairwise: curated feature interactions (domain knowledge about where |
| 1065 |
two options collide), plus an auto option x file-type covering set.""" |
| 1066 |
s = [ |
| 1067 |
Scenario("pair:delete+dirlink-dest", _setup_kdest, ["-aK", "--delete"], |
| 1068 |
["src/"], "dest/", dest_prep=_prep_kdest, snap_dest=lambda d: d / "realdir"), |
| 1069 |
Scenario("pair:backup-inside+delete", build_recvtree, |
| 1070 |
(lambda wd, dest: ["-ab", "--delete", f"--backup-dir={_auxp(dest, 'inside', 'bak')}"]), |
| 1071 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1072 |
Scenario("pair:inplace+sparse", _ft_sparse, |
| 1073 |
["-aS", "--inplace", "--no-whole-file"], ["src/"], "dest/"), |
| 1074 |
Scenario("pair:link-dest+hardlinks", setup_with_basis, |
| 1075 |
(lambda wd, dest: ["-aH", f"--link-dest={wd}/basis"]), ["src/"], "dest/"), |
| 1076 |
Scenario("pair:copy-links+dirlink", _ft_dirlink, ["-aL"], ["src/"], "dest/"), |
| 1077 |
Scenario("pair:keepdirlinks+delete-excluded", _setup_kdest, |
| 1078 |
["-aK", "--delete", "--delete-excluded", "--exclude=top"], |
| 1079 |
["src/"], "dest/", dest_prep=_prep_kdest, snap_dest=lambda d: d / "realdir"), |
| 1080 |
Scenario("pair:sparse+whole-file", _ft_sparse, ["-aS", "-W"], ["src/"], "dest/"), |
| 1081 |
Scenario("pair:partial-inside+delete", build_recvtree, |
| 1082 |
(lambda wd, dest: ["-a", "--delete", "--partial", |
| 1083 |
f"--partial-dir={_auxp(dest, 'inside', 'part')}"]), |
| 1084 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1085 |
] |
| 1086 |
|
| 1087 |
fts = [("intree", _ft_intree), ("dirlink", _ft_dirlink), |
| 1088 |
("hardlinks", _ft_hardlinks), ("sparse", _ft_sparse)] |
| 1089 |
opts = ["-c", "-z", "-b", "--inplace", "-H", "-L", "-k", "--checksum-choice=md5"] |
| 1090 |
for ftn, ftfn in fts: |
| 1091 |
for o in opts: |
| 1092 |
tag = o.lstrip("-").split("=")[0] |
| 1093 |
s.append(Scenario(f"pair:{tag}x{ftn}", ftfn, ["-a", o], ["src/"], "dest/")) |
| 1094 |
return s |
| 1095 |
|
| 1096 |
|
| 1097 |
def recv_sweep(): |
| 1098 |
"""Receiver/generator + stateful scenarios: existing-dest update/delete, |
| 1099 |
backup, dest-variants (link/compare/copy-dest), inplace, temp-dir. These |
| 1100 |
exercise the receiver's existing-dest / basis / temp-dir paths that the |
| 1101 |
single-transfer-into-empty-dest sweeps don't reach.""" |
| 1102 |
s = [] |
| 1103 |
s += [ |
| 1104 |
Scenario("recv:update", build_recvtree, ["-a"], ["src/"], "dest/", |
| 1105 |
pre_dest=stale_dest), |
| 1106 |
Scenario("recv:update-W", build_recvtree, ["-a", "-W"], ["src/"], "dest/", |
| 1107 |
pre_dest=stale_dest), |
| 1108 |
Scenario("recv:update-delete", build_recvtree, ["-a", "--delete"], |
| 1109 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1110 |
Scenario("recv:delete-during", build_recvtree, ["-a", "--delete-during"], |
| 1111 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1112 |
Scenario("recv:delete-after", build_recvtree, ["-a", "--delete-after"], |
| 1113 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1114 |
Scenario("recv:delete-delay", build_recvtree, ["-a", "--delete-delay"], |
| 1115 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1116 |
Scenario("recv:backup", build_recvtree, ["-a", "-b"], ["src/"], "dest/", |
| 1117 |
pre_dest=stale_dest), |
| 1118 |
Scenario("recv:backup-dir", build_recvtree, ["-a", "-b", "--backup-dir=bak"], |
| 1119 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1120 |
Scenario("recv:backup-suffix", build_recvtree, ["-a", "-b", "--suffix=.old"], |
| 1121 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1122 |
Scenario("recv:inplace", build_recvtree, ["-a", "--inplace", "--no-whole-file"], |
| 1123 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1124 |
Scenario("recv:delay-updates", build_recvtree, ["-a", "--delay-updates"], |
| 1125 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1126 |
Scenario("recv:temp-dir", build_recvtree, ["-a", "--temp-dir=tmpd"], |
| 1127 |
["src/"], "dest/", pre_dest=lambda d: (stale_dest(d), (d / "tmpd").mkdir(exist_ok=True))), |
| 1128 |
Scenario("recv:partial-dir", build_recvtree, ["-a", "--partial-dir=.part"], |
| 1129 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1130 |
Scenario("recv:fuzzy", build_recvtree, ["-a", "--fuzzy"], ["src/"], "dest/", |
| 1131 |
pre_dest=stale_dest), |
| 1132 |
|
| 1133 |
Scenario("recv:link-dest-rel", setup_with_basis, ["-a", "--link-dest=../basis"], |
| 1134 |
["src/"], "dest/"), |
| 1135 |
Scenario("recv:link-dest-abs", setup_with_basis, ["-a"], |
| 1136 |
lambda wd: ["--link-dest=" + str(Path(wd) / "basis"), "src/"], "dest/"), |
| 1137 |
Scenario("recv:compare-dest-rel", setup_with_basis, |
| 1138 |
["-a", "--compare-dest=../basis"], ["src/"], "dest/"), |
| 1139 |
Scenario("recv:copy-dest-rel", setup_with_basis, |
| 1140 |
["-a", "--copy-dest=../basis"], ["src/"], "dest/"), |
| 1141 |
] |
| 1142 |
return lift_transports(s) |
| 1143 |
|
| 1144 |
|
| 1145 |
def destshape_sweep(): |
| 1146 |
"""Destination path shapes (symlinked dest dir, --mkpath) that stress the |
| 1147 |
receiver's destination-path handling.""" |
| 1148 |
def symlinked_dest(dest: Path): |
| 1149 |
real = Path(str(dest) + "_real") |
| 1150 |
real.mkdir(parents=True, exist_ok=True) |
| 1151 |
if not dest.is_symlink(): |
| 1152 |
os.symlink(real.name, dest) |
| 1153 |
|
| 1154 |
def real_of(dest: Path): |
| 1155 |
return Path(str(dest) + "_real") |
| 1156 |
|
| 1157 |
def via_symlink_parent(dest: Path): |
| 1158 |
|
| 1159 |
|
| 1160 |
real = Path(str(dest) + "_rb") |
| 1161 |
real.mkdir(parents=True, exist_ok=True) |
| 1162 |
link = Path(str(dest) + "_lnk") |
| 1163 |
if not link.is_symlink(): |
| 1164 |
os.symlink(real.name, link) |
| 1165 |
return link |
| 1166 |
|
| 1167 |
s = [ |
| 1168 |
Scenario("dest:symlinked-dir", build_recvtree, ["-a"], ["src/"], "dest/", |
| 1169 |
dest_prep=symlinked_dest, snap_dest=real_of), |
| 1170 |
Scenario("dest:mkpath", build_recvtree, ["-a", "--mkpath"], ["src/"], |
| 1171 |
"dest/new/deep/", snap_dest=lambda d: d), |
| 1172 |
] |
| 1173 |
return s |
| 1174 |
|
| 1175 |
|
| 1176 |
def name_sweep(): |
| 1177 |
"""Unusual but benign filenames (arg-handling / secluded-args).""" |
| 1178 |
names = ["a space", "two spaces", "café_ünïcode", "semi;colon", |
| 1179 |
"dollar$sign", "paren(s)", "quote'name", "amp&and", "back\\slash", |
| 1180 |
"newline\nname", "tab\tname", "trailing ", "leaddash"] |
| 1181 |
|
| 1182 |
def setup(src: Path): |
| 1183 |
for i, n in enumerate(names): |
| 1184 |
_write(src / n, f"content {i}\n".encode()) |
| 1185 |
|
| 1186 |
_write(src / "-leadingdash.txt", b"dash\n") |
| 1187 |
os.symlink("a space", src / "link to spaced") |
| 1188 |
|
| 1189 |
return [Scenario("name:weird", setup, ["-a"], ["src/"], "dest/")] |
| 1190 |
|
| 1191 |
|
| 1192 |
def filesfrom_sweep(): |
| 1193 |
"""--files-from with relative & absolute name lists, and --from0. |
| 1194 |
|
| 1195 |
The list files live in the workdir, which is also rsync's cwd, so the |
| 1196 |
--files-from arg is a BARE filename (cwd-relative) -- referencing it via |
| 1197 |
str(wd) double-resolves and silently fails when --workdir is relative, which |
| 1198 |
makes the whole scenario a vacuous pass. The absolute list uses src.resolve() |
| 1199 |
so the "/" transfer-root case works regardless of workdir.""" |
| 1200 |
def setup(src: Path): |
| 1201 |
build_recvtree(src) |
| 1202 |
wd = src.parent |
| 1203 |
asrc = src.resolve() |
| 1204 |
(wd / "list_rel.txt").write_text("file1.txt\ndir/file2.txt\nslink\n") |
| 1205 |
(wd / "list_abs.txt").write_text( |
| 1206 |
f"{asrc}/file1.txt\n{asrc}/dir/file2.txt\n") |
| 1207 |
(wd / "list0.txt").write_bytes(b"file1.txt\0dir/file2.txt\0") |
| 1208 |
|
| 1209 |
s = [ |
| 1210 |
Scenario("ff:rel", setup, ["-a"], |
| 1211 |
["--files-from=list_rel.txt", "src/"], "dest/"), |
| 1212 |
Scenario("ff:rel-R", setup, ["-aR"], |
| 1213 |
["--files-from=list_rel.txt", "src/"], "dest/"), |
| 1214 |
Scenario("ff:abs", setup, ["-a"], |
| 1215 |
["--files-from=list_abs.txt", "/"], "dest/"), |
| 1216 |
Scenario("ff:from0", setup, ["-a", "--from0"], |
| 1217 |
["--files-from=list0.txt", "src/"], "dest/"), |
| 1218 |
] |
| 1219 |
return lift_transports(s) |
| 1220 |
|
| 1221 |
|
| 1222 |
def build_privtree(src: Path): |
| 1223 |
"""Root-only fixture: owned files, special perms, FIFO, devices. Falls back |
| 1224 |
gracefully to what the euid can create.""" |
| 1225 |
build_recvtree(src) |
| 1226 |
os.chmod(src / "file1.txt", 0o4755) |
| 1227 |
os.chmod(src / "dir", 0o2755) |
| 1228 |
try: |
| 1229 |
os.mkfifo(src / "fifo") |
| 1230 |
except OSError: |
| 1231 |
pass |
| 1232 |
if os.geteuid() == 0: |
| 1233 |
try: |
| 1234 |
os.mknod(src / "chardev", stat.S_IFCHR | 0o644, os.makedev(1, 3)) |
| 1235 |
os.mknod(src / "blockdev", stat.S_IFBLK | 0o644, os.makedev(7, 0)) |
| 1236 |
except OSError: |
| 1237 |
pass |
| 1238 |
|
| 1239 |
try: |
| 1240 |
os.chown(src / "dir/file2.txt", 1, 1) |
| 1241 |
except OSError: |
| 1242 |
pass |
| 1243 |
|
| 1244 |
|
| 1245 |
def priv_sweep(): |
| 1246 |
"""Run as root (sudo): owner/group, devices/specials, fake-super.""" |
| 1247 |
return [ |
| 1248 |
Scenario("priv:archive", build_privtree, ["-a"], ["src/"], "dest/"), |
| 1249 |
Scenario("priv:devices", build_privtree, ["-aD"], ["src/"], "dest/"), |
| 1250 |
Scenario("priv:HD", build_privtree, ["-aHD"], ["src/"], "dest/"), |
| 1251 |
Scenario("priv:numeric-ids", build_privtree, ["-a", "--numeric-ids"], |
| 1252 |
["src/"], "dest/"), |
| 1253 |
Scenario("priv:fake-super", build_privtree, ["-a", "--fake-super"], |
| 1254 |
["src/"], "dest/"), |
| 1255 |
Scenario("priv:specials", build_privtree, ["-a", "--specials"], |
| 1256 |
["src/"], "dest/"), |
| 1257 |
Scenario("priv:acls-xattrs", build_privtree, ["-aAX"], ["src/"], "dest/"), |
| 1258 |
] |
| 1259 |
|
| 1260 |
|
| 1261 |
def intree_sweep(): |
| 1262 |
"""Traverse an IN-TREE dir-symlink as a path component (source via a |
| 1263 |
dir-symlink, dest through a dir-symlink, keep-dirlinks, alt-basis via a |
| 1264 |
dir-symlink) -- a path-handling shape that varies across builds/platforms.""" |
| 1265 |
def src_dirlink(src: Path): |
| 1266 |
_write(src / "real/f1", b"in real\n") |
| 1267 |
_write(src / "real/sub/f2", b"deep\n") |
| 1268 |
os.symlink("real", src / "link") |
| 1269 |
|
| 1270 |
def dirtree(src: Path): |
| 1271 |
_write(src / "dir/f1", b"one\n") |
| 1272 |
_write(src / "dir/f2", b"two\n") |
| 1273 |
_write(src / "top.txt", b"top\n") |
| 1274 |
|
| 1275 |
def dest_dirlink_prep(dest: Path): |
| 1276 |
dest.mkdir(parents=True, exist_ok=True) |
| 1277 |
(dest / "real").mkdir(exist_ok=True) |
| 1278 |
if not (dest / "link").is_symlink(): |
| 1279 |
os.symlink("real", dest / "link") |
| 1280 |
|
| 1281 |
def keepdir_prep(dest: Path): |
| 1282 |
dest.mkdir(parents=True, exist_ok=True) |
| 1283 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1284 |
if not (dest / "dir").is_symlink(): |
| 1285 |
os.symlink("realdir", dest / "dir") |
| 1286 |
|
| 1287 |
def basis_dirlink(src: Path): |
| 1288 |
build_recvtree(src) |
| 1289 |
build_recvtree(src.parent / "realbasis") |
| 1290 |
os.symlink("realbasis", src.parent / "basislink") |
| 1291 |
|
| 1292 |
return [ |
| 1293 |
Scenario("intree:src-via-dirlink", src_dirlink, ["-a"], ["src/link/"], "dest/"), |
| 1294 |
Scenario("intree:src-dirlink-noslash", src_dirlink, ["-a"], ["src/link"], "dest/"), |
| 1295 |
Scenario("intree:dest-via-dirlink", build_recvtree, ["-a"], ["src/"], "dest/", |
| 1296 |
dest_prep=dest_dirlink_prep, |
| 1297 |
dest_arg=lambda d: str(d / "link") + "/", |
| 1298 |
snap_dest=lambda d: d / "real"), |
| 1299 |
Scenario("intree:keep-dirlinks", dirtree, ["-aK"], ["src/"], "dest/", |
| 1300 |
dest_prep=keepdir_prep, snap_dest=lambda d: d / "realdir"), |
| 1301 |
Scenario("intree:link-dest-dirlink", basis_dirlink, ["-a"], |
| 1302 |
lambda wd: ["--link-dest=" + str(Path(wd) / "basislink"), "src/"], |
| 1303 |
"dest/"), |
| 1304 |
Scenario("intree:compare-dest-dirlink", basis_dirlink, ["-a"], |
| 1305 |
lambda wd: ["--compare-dest=" + str(Path(wd) / "basislink"), "src/"], |
| 1306 |
"dest/"), |
| 1307 |
] |
| 1308 |
|
| 1309 |
|
| 1310 |
def intree2_sweep(): |
| 1311 |
"""More in-tree dir-symlink traversal: -k/copy-dirlinks on the source, |
| 1312 |
source files under a symlinked PARENT, and -K update/delete through a |
| 1313 |
symlinked dest dir.""" |
| 1314 |
def src_with_dirlink(src: Path): |
| 1315 |
_write(src / "realdir/a", b"aa\n") |
| 1316 |
_write(src / "realdir/b", b"bb\n") |
| 1317 |
_write(src / "top.txt", b"top\n") |
| 1318 |
os.symlink("realdir", src / "dl") |
| 1319 |
|
| 1320 |
def src_symlink_parent(src: Path): |
| 1321 |
_write(src / "real/sub/file", b"under symlinked parent\n") |
| 1322 |
os.symlink("real", src / "link") |
| 1323 |
|
| 1324 |
def kupd_prep(dest: Path): |
| 1325 |
|
| 1326 |
dest.mkdir(parents=True, exist_ok=True) |
| 1327 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1328 |
_write(dest / "realdir/f1", b"OLD\n") |
| 1329 |
_ut(dest / "realdir/f1", T_OLD) |
| 1330 |
_write(dest / "realdir/extra", b"extra\n") |
| 1331 |
_ut(dest / "realdir/extra", T_OLD) |
| 1332 |
if not (dest / "dir").is_symlink(): |
| 1333 |
os.symlink("realdir", dest / "dir") |
| 1334 |
|
| 1335 |
def dirtree2(src: Path): |
| 1336 |
_write(src / "dir/f1", b"new1\n") |
| 1337 |
_write(src / "dir/f2", b"new2\n") |
| 1338 |
_ut(src / "dir/f1"); _ut(src / "dir/f2"); _ut(src / "dir") |
| 1339 |
|
| 1340 |
return [ |
| 1341 |
Scenario("intree2:copy-dirlinks-k", src_with_dirlink, ["-a", "-k"], |
| 1342 |
["src/"], "dest/"), |
| 1343 |
Scenario("intree2:copy-links-L", src_with_dirlink, ["-a", "-L"], |
| 1344 |
["src/"], "dest/"), |
| 1345 |
Scenario("intree2:src-symlink-parent", src_symlink_parent, ["-a"], |
| 1346 |
["src/link/sub/file"], "dest/"), |
| 1347 |
Scenario("intree2:src-symlink-parent-R", src_symlink_parent, ["-aR"], |
| 1348 |
["src/link/sub/file"], "dest/"), |
| 1349 |
Scenario("intree2:src-symlink-parent-dir", src_symlink_parent, ["-a"], |
| 1350 |
["src/link/sub/"], "dest/"), |
| 1351 |
Scenario("intree2:K-update", dirtree2, ["-aK"], ["src/"], "dest/", |
| 1352 |
dest_prep=kupd_prep, snap_dest=lambda d: d / "realdir"), |
| 1353 |
Scenario("intree2:K-delete", dirtree2, ["-aK", "--delete"], ["src/"], |
| 1354 |
"dest/", dest_prep=kupd_prep, snap_dest=lambda d: d / "realdir"), |
| 1355 |
] |
| 1356 |
|
| 1357 |
|
| 1358 |
def proto_sweep(): |
| 1359 |
"""Older protocol versions (negotiation / wire-format regressions).""" |
| 1360 |
s = [] |
| 1361 |
for p in (29, 30, 31): |
| 1362 |
for opt in (["-a"], ["-aH"], ["-aHS"], ["-az"], |
| 1363 |
["-a", "--no-inc-recursive"]): |
| 1364 |
tag = "+".join(o.lstrip("-") for o in opt if o != "-a") or "a" |
| 1365 |
s.append(Scenario(f"proto{p}:{tag}", build_kitchen, |
| 1366 |
opt + [f"--protocol={p}"], ["src/"], "dest/")) |
| 1367 |
return s |
| 1368 |
|
| 1369 |
|
| 1370 |
def combo_sweep(): |
| 1371 |
"""Pairs of options over a stale dest (so update/backup/inplace actually |
| 1372 |
fire) -- non-symlink option-interaction regressions.""" |
| 1373 |
import itertools |
| 1374 |
flags = ["-H", "-S", "--inplace", "-z", "-c", "-b", "-O", "-J", |
| 1375 |
"--numeric-ids", "-A", "-X", "-E", "--no-whole-file", "-I", |
| 1376 |
"--size-only", "-u"] |
| 1377 |
s = [] |
| 1378 |
for x, y in itertools.combinations(flags, 2): |
| 1379 |
s.append(Scenario(f"combo:{x},{y}", build_recvtree, ["-a", x, y], |
| 1380 |
["src/"], "dest/", pre_dest=stale_dest)) |
| 1381 |
return s |
| 1382 |
|
| 1383 |
|
| 1384 |
def scale_sweep(): |
| 1385 |
"""Content scale: many small files, deep nesting, a large file.""" |
| 1386 |
def many(src: Path): |
| 1387 |
for i in range(500): |
| 1388 |
_write(src / f"d{i % 12}" / f"f{i:04d}", f"file {i}\n".encode()) |
| 1389 |
|
| 1390 |
def deep(src: Path): |
| 1391 |
p = src |
| 1392 |
for i in range(40): |
| 1393 |
p = p / f"d{i}" |
| 1394 |
_write(p / "leaf", b"deep\n") |
| 1395 |
_write(src / "shallow", b"s\n") |
| 1396 |
|
| 1397 |
def big(src: Path): |
| 1398 |
_write(src / "big.bin", bytes((i * 7) & 0xFF for i in range(3_000_000))) |
| 1399 |
_write(src / "small", b"x\n") |
| 1400 |
|
| 1401 |
return [ |
| 1402 |
Scenario("scale:many", many, ["-a"], ["src/"], "dest/"), |
| 1403 |
Scenario("scale:many-H", many, ["-aH"], ["src/"], "dest/"), |
| 1404 |
Scenario("scale:deep", deep, ["-a"], ["src/"], "dest/"), |
| 1405 |
Scenario("scale:big", big, ["-a"], ["src/"], "dest/"), |
| 1406 |
Scenario("scale:big-inplace", big, ["-a", "--inplace", "--no-whole-file"], |
| 1407 |
["src/"], "dest/"), |
| 1408 |
Scenario("scale:big-z", big, ["-az"], ["src/"], "dest/"), |
| 1409 |
] |
| 1410 |
|
| 1411 |
|
| 1412 |
def _daemon_scns(chroot): |
| 1413 |
"""PUSH scenarios to a [m] daemon module (the daemon receiver path).""" |
| 1414 |
D = {"chroot": chroot} |
| 1415 |
pfx = "daemonchroot" if chroot == "yes" else "daemon" |
| 1416 |
|
| 1417 |
def kt(src: Path): |
| 1418 |
_write(src / "dir/f1", b"n1\n") |
| 1419 |
_write(src / "dir/f2", b"n2\n") |
| 1420 |
_write(src / "top", b"t\n") |
| 1421 |
|
| 1422 |
def kprep(dest: Path): |
| 1423 |
dest.mkdir(parents=True, exist_ok=True) |
| 1424 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1425 |
if not (dest / "dir").is_symlink(): |
| 1426 |
os.symlink("realdir", dest / "dir") |
| 1427 |
|
| 1428 |
return [ |
| 1429 |
Scenario(f"{pfx}:push", build_recvtree, ["-a"], ["src/"], daemon=D), |
| 1430 |
Scenario(f"{pfx}:push-H", build_recvtree, ["-aH"], ["src/"], daemon=D), |
| 1431 |
Scenario(f"{pfx}:push-X", build_recvtree, ["-aX"], ["src/"], daemon=D), |
| 1432 |
Scenario(f"{pfx}:push-update", build_recvtree, ["-a"], ["src/"], |
| 1433 |
pre_dest=stale_dest, daemon=D), |
| 1434 |
Scenario(f"{pfx}:push-delete", build_recvtree, ["-a", "--delete"], |
| 1435 |
["src/"], pre_dest=stale_dest, daemon=D), |
| 1436 |
Scenario(f"{pfx}:push-K-symlinkdir", kt, ["-aK"], ["src/"], |
| 1437 |
dest_prep=kprep, snap_dest=lambda d: d / "realdir", daemon=D), |
| 1438 |
] |
| 1439 |
|
| 1440 |
|
| 1441 |
def daemon_sweep(): |
| 1442 |
return _daemon_scns("no") |
| 1443 |
|
| 1444 |
|
| 1445 |
def daemonchroot_sweep(): |
| 1446 |
"""use chroot = yes (root-only): the daemon chroots into the module path.""" |
| 1447 |
return _daemon_scns("yes") |
| 1448 |
|
| 1449 |
|
| 1450 |
def gaps_sweep(): |
| 1451 |
"""Scenarios observable mainly via the stdout/stderr/itemize signals rather |
| 1452 |
than the dest tree: --list-only listings, --dry-run plans (incl. |
| 1453 |
--mkpath+--dry-run file-to-file), and type-change updates.""" |
| 1454 |
def t_tree(src): |
| 1455 |
_mk_reg(src / "f", 100) |
| 1456 |
_mk_reg(src / "dir/g", 50) |
| 1457 |
os.symlink("f", src / "l") |
| 1458 |
_ut(src / "dir") |
| 1459 |
|
| 1460 |
def t_one(src): |
| 1461 |
_mk_reg(src / "file", 50) |
| 1462 |
|
| 1463 |
def t_typesrc(src): |
| 1464 |
_mk_reg(src / "x", 30) |
| 1465 |
_mk_reg(src / "keep", 10) |
| 1466 |
|
| 1467 |
def pre_typedir(dest): |
| 1468 |
os.makedirs(dest / "x") |
| 1469 |
_mk_reg(dest / "x" / "inner", 5) |
| 1470 |
_ut(dest / "x") |
| 1471 |
|
| 1472 |
return [ |
| 1473 |
Scenario("gap:list-only", t_tree, ["--list-only", "-a"], ["src/"], "dest/"), |
| 1474 |
Scenario("gap:dry-run", t_tree, ["-ai", "--dry-run"], ["src/"], "dest/"), |
| 1475 |
Scenario("gap:mkpath-dryrun-f2f", t_one, ["-ai", "--mkpath", "--dry-run"], |
| 1476 |
["src/file"], "dest/", dest_arg=lambda d: str(d) + "/newdir/file"), |
| 1477 |
Scenario("gap:dry-run-delete", build_recvtree, ["-ai", "--dry-run", "--delete"], |
| 1478 |
["src/"], "dest/", pre_dest=stale_dest), |
| 1479 |
Scenario("gap:typechange-force", t_typesrc, ["-a", "--force"], ["src/"], "dest/", |
| 1480 |
pre_dest=pre_typedir), |
| 1481 |
Scenario("gap:typechange-delete", t_typesrc, ["-a", "--delete"], ["src/"], "dest/", |
| 1482 |
pre_dest=pre_typedir), |
| 1483 |
] |
| 1484 |
|
| 1485 |
|
| 1486 |
def misc_sweep(): |
| 1487 |
"""Genuinely-untested subsystems: filter/include-exclude rules, per-dir merge, |
| 1488 |
CVS-exclude, fuzzy, write-batch, xattr, -R dot-anchoring -- looking for NEW |
| 1489 |
root-cause families beyond the daemon-symlink cluster.""" |
| 1490 |
def t_filter(src): |
| 1491 |
_mk_reg(src / "keep.txt", 10) |
| 1492 |
_mk_reg(src / "skip.log", 10) |
| 1493 |
_mk_reg(src / "sub/keep2.txt", 10) |
| 1494 |
_mk_reg(src / "sub/skip2.log", 10) |
| 1495 |
_ut(src / "sub") |
| 1496 |
|
| 1497 |
def t_dirmerge(src): |
| 1498 |
_mk_reg(src / "a.txt", 10) |
| 1499 |
_mk_reg(src / "b.log", 10) |
| 1500 |
_write(src / ".rsync-filter", b"- *.log\n") |
| 1501 |
_ut(src / ".rsync-filter") |
| 1502 |
|
| 1503 |
def t_cvs(src): |
| 1504 |
_mk_reg(src / "keep", 10) |
| 1505 |
_mk_reg(src / "core", 10) |
| 1506 |
_mk_reg(src / "obj.o", 10) |
| 1507 |
|
| 1508 |
def t_fuzzy(src): |
| 1509 |
_mk_reg(src / "file.txt", 5000, t=T_NEW) |
| 1510 |
|
| 1511 |
def pre_fuzzy(dest): |
| 1512 |
_mk_reg(dest / "file.txt.bak", 5000, t=T_OLD, fill=7) |
| 1513 |
|
| 1514 |
def t_xattr(src): |
| 1515 |
_mk_reg(src / "f", 10) |
| 1516 |
try: |
| 1517 |
os.setxattr(src / "f", "user.test", b"val") |
| 1518 |
except OSError: |
| 1519 |
pass |
| 1520 |
|
| 1521 |
def t_reldot(src): |
| 1522 |
_mk_reg(src / "sub/deep/f", 10) |
| 1523 |
_ut(src / "sub/deep") |
| 1524 |
_ut(src / "sub") |
| 1525 |
|
| 1526 |
return [ |
| 1527 |
Scenario("misc:exclude", t_filter, ["-a", "--exclude=*.log"], ["src/"], "dest/"), |
| 1528 |
Scenario("misc:filter-rule", t_filter, ["-a", "-f", "- *.log"], ["src/"], "dest/"), |
| 1529 |
Scenario("misc:filter-incl", t_filter, ["-a", "-f", "+ */", "-f", "+ *.txt", "-f", "- *"], ["src/"], "dest/"), |
| 1530 |
Scenario("misc:dirmerge-F", t_dirmerge, ["-a", "-F"], ["src/"], "dest/"), |
| 1531 |
Scenario("misc:cvs-C", t_cvs, ["-a", "-C"], ["src/"], "dest/"), |
| 1532 |
Scenario("misc:fuzzy", t_fuzzy, ["-a", "--fuzzy"], ["src/"], "dest/", pre_dest=pre_fuzzy), |
| 1533 |
Scenario("misc:write-batch", build_recvtree, |
| 1534 |
(lambda wd, dest: ["-a", f"--write-batch={wd}/batch"]), ["src/"], "dest/"), |
| 1535 |
Scenario("misc:xattr", t_xattr, ["-aX"], ["src/"], "dest/"), |
| 1536 |
Scenario("misc:relative-dot", t_reldot, ["-aR"], ["src/./sub/deep/f"], "dest/"), |
| 1537 |
] |
| 1538 |
|
| 1539 |
|
| 1540 |
def daemon_sym_sweep(): |
| 1541 |
"""PUSH symlink/dirlink/keep-dirlinks scenarios to a daemon module -- the |
| 1542 |
daemon receiver/keep-dirlinks path. Enumerates the family: -K through a |
| 1543 |
symlinked dest dir (plain/nested/update/delete), and -L/-k/-l/--safe-links/ |
| 1544 |
--munge-links/--copy-unsafe-links of in-tree and out-of-tree symlinks pushed |
| 1545 |
into a module.""" |
| 1546 |
D = {"chroot": "no"} |
| 1547 |
|
| 1548 |
def kt(src): |
| 1549 |
_mk_reg(src / "dir/f1", 10) |
| 1550 |
_mk_reg(src / "dir/f2", 10) |
| 1551 |
_mk_reg(src / "top", 5) |
| 1552 |
|
| 1553 |
def kt_nested(src): |
| 1554 |
_mk_reg(src / "dir/sub/f", 10) |
| 1555 |
_mk_reg(src / "top", 5) |
| 1556 |
|
| 1557 |
def kprep(dest): |
| 1558 |
dest.mkdir(parents=True, exist_ok=True) |
| 1559 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1560 |
if not (dest / "dir").is_symlink(): |
| 1561 |
os.symlink("realdir", dest / "dir") |
| 1562 |
|
| 1563 |
def kprep_nested(dest): |
| 1564 |
dest.mkdir(parents=True, exist_ok=True) |
| 1565 |
(dest / "realdir" / "sub").mkdir(parents=True, exist_ok=True) |
| 1566 |
if not (dest / "dir").is_symlink(): |
| 1567 |
os.symlink("realdir", dest / "dir") |
| 1568 |
|
| 1569 |
def kprep_update(dest): |
| 1570 |
kprep(dest) |
| 1571 |
_mk_reg(dest / "realdir" / "f1", 3, t=T_OLD) |
| 1572 |
|
| 1573 |
def kprep_delete(dest): |
| 1574 |
kprep(dest) |
| 1575 |
_mk_reg(dest / "realdir" / "extra", 3) |
| 1576 |
|
| 1577 |
def src_dirlink(src): |
| 1578 |
_mk_reg(src / "rd/inner", 10) |
| 1579 |
os.symlink("rd", src / "dl") |
| 1580 |
_mk_reg(src / "anchor", 5) |
| 1581 |
_ut(src / "rd") |
| 1582 |
|
| 1583 |
def src_abslink(src): |
| 1584 |
os.symlink("/etc/hostname", src / "abs") |
| 1585 |
_mk_reg(src / "anchor", 5) |
| 1586 |
|
| 1587 |
rd = lambda d: d / "realdir" |
| 1588 |
return [ |
| 1589 |
Scenario("dsym:K-dirlink", kt, ["-aK"], ["src/"], "dest/", dest_prep=kprep, snap_dest=rd, daemon=D), |
| 1590 |
Scenario("dsym:K-nested", kt_nested, ["-aK"], ["src/"], "dest/", dest_prep=kprep_nested, snap_dest=rd, daemon=D), |
| 1591 |
Scenario("dsym:K-update", kt, ["-aK"], ["src/"], "dest/", dest_prep=kprep_update, snap_dest=rd, daemon=D), |
| 1592 |
Scenario("dsym:K-delete", kt, ["-aK", "--delete"], ["src/"], "dest/", dest_prep=kprep_delete, snap_dest=rd, daemon=D), |
| 1593 |
Scenario("dsym:L-src-dirlink", src_dirlink, ["-aL"], ["src/"], "dest/", daemon=D), |
| 1594 |
Scenario("dsym:k-src-dirlink", src_dirlink, ["-ak"], ["src/"], "dest/", daemon=D), |
| 1595 |
Scenario("dsym:l-src", src_dirlink, ["-al"], ["src/"], "dest/", daemon=D), |
| 1596 |
Scenario("dsym:safe-links", src_abslink, ["-a", "--safe-links"], ["src/"], "dest/", daemon=D), |
| 1597 |
Scenario("dsym:munge", src_abslink, ["-a", "--munge-links"], ["src/"], "dest/", daemon=D), |
| 1598 |
Scenario("dsym:copy-unsafe", src_abslink, ["-a", "--copy-unsafe-links"], ["src/"], "dest/", daemon=D), |
| 1599 |
] |
| 1600 |
|
| 1601 |
|
| 1602 |
def daemon_escape_sweep(): |
| 1603 |
"""Daemon following symlinks that point OUTSIDE the module (absolute, or ../ |
| 1604 |
escape), via -L / --copy-links / --copy-unsafe-links / --safe-links, on both |
| 1605 |
the sender (pull) and receiver (push) side -- the daemon symlink-safety |
| 1606 |
behaviour.""" |
| 1607 |
Dpull = {"chroot": "no", "pull": True} |
| 1608 |
Dpush = {"chroot": "no"} |
| 1609 |
|
| 1610 |
def s_abs(src): |
| 1611 |
os.symlink("/etc/hostname", src / "abslnk") |
| 1612 |
_mk_reg(src / "anchor", 5) |
| 1613 |
|
| 1614 |
def s_escape(src): |
| 1615 |
_mk_reg(src.parent / "secret", 7) |
| 1616 |
os.symlink("../secret", src / "esc") |
| 1617 |
_mk_reg(src / "anchor", 5) |
| 1618 |
|
| 1619 |
def s_filelink(src): |
| 1620 |
_mk_reg(src / "real", 10) |
| 1621 |
os.symlink("real", src / "fl") |
| 1622 |
_mk_reg(src / "anchor", 5) |
| 1623 |
|
| 1624 |
def s_absdir(src): |
| 1625 |
out = src.parent / "outdir" |
| 1626 |
_mk_reg(out / "x", 8) |
| 1627 |
_mk_reg(out / "y", 8) |
| 1628 |
os.symlink(str(out), src / "extdir") |
| 1629 |
_mk_reg(src / "anchor", 5) |
| 1630 |
|
| 1631 |
pull = [ |
| 1632 |
("dpull:L-abs", s_abs, ["-aL"]), |
| 1633 |
("dpull:L-escape", s_escape, ["-aL"]), |
| 1634 |
("dpull:copyunsafe-escape", s_escape, ["-a", "--copy-unsafe-links"]), |
| 1635 |
("dpull:L-filelink", s_filelink, ["-aL"]), |
| 1636 |
("dpull:safe-escape", s_escape, ["-a", "--safe-links"]), |
| 1637 |
("dpull:copylinks-abs", s_abs, ["-a", "--copy-links"]), |
| 1638 |
("dpull:L-absdir", s_absdir, ["-aL"]), |
| 1639 |
("dpull:k-absdir", s_absdir, ["-ak"]), |
| 1640 |
("dpull:copydirlinks-absdir", s_absdir, ["-a", "--copy-dirlinks"]), |
| 1641 |
("dpull:copyunsafe-absdir", s_absdir, ["-a", "--copy-unsafe-links"]), |
| 1642 |
] |
| 1643 |
push = [ |
| 1644 |
("dpush:L-abs", s_abs, ["-aL"]), |
| 1645 |
("dpush:L-escape", s_escape, ["-aL"]), |
| 1646 |
("dpush:copyunsafe-abs", s_abs, ["-a", "--copy-unsafe-links"]), |
| 1647 |
("dpush:copyunsafe-escape", s_escape, ["-a", "--copy-unsafe-links"]), |
| 1648 |
("dpush:L-filelink", s_filelink, ["-aL"]), |
| 1649 |
] |
| 1650 |
s = [Scenario(n, fn, o, ["src/"], "dest/", daemon=Dpull) for n, fn, o in pull] |
| 1651 |
s += [Scenario(n, fn, o, ["src/"], "dest/", daemon=Dpush) for n, fn, o in push] |
| 1652 |
return s |
| 1653 |
|
| 1654 |
|
| 1655 |
def daemon_pull_sym_sweep(): |
| 1656 |
"""PULL symlink/dirlink scenarios FROM a daemon module (the daemon SENDER |
| 1657 |
side -- untested until now). Served source contains the symlinks; the client |
| 1658 |
pulls with -L/-k/-l/-K/--safe-links/--munge-links/--copy-unsafe-links.""" |
| 1659 |
D = {"chroot": "no", "pull": True} |
| 1660 |
|
| 1661 |
def served_dirlink(src): |
| 1662 |
_mk_reg(src / "rd/inner", 10) |
| 1663 |
os.symlink("rd", src / "dl") |
| 1664 |
_mk_reg(src / "anchor", 5) |
| 1665 |
_ut(src / "rd") |
| 1666 |
|
| 1667 |
def served_intree(src): |
| 1668 |
_mk_reg(src / "real", 10) |
| 1669 |
os.symlink("real", src / "lnk") |
| 1670 |
_mk_reg(src / "anchor", 5) |
| 1671 |
|
| 1672 |
def served_abslink(src): |
| 1673 |
os.symlink("/etc/hostname", src / "abs") |
| 1674 |
_mk_reg(src / "anchor", 5) |
| 1675 |
|
| 1676 |
def served_dir(src): |
| 1677 |
_mk_reg(src / "dir/f1", 10) |
| 1678 |
_mk_reg(src / "dir/f2", 10) |
| 1679 |
_mk_reg(src / "top", 5) |
| 1680 |
|
| 1681 |
def kprep(dest): |
| 1682 |
dest.mkdir(parents=True, exist_ok=True) |
| 1683 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1684 |
if not (dest / "dir").is_symlink(): |
| 1685 |
os.symlink("realdir", dest / "dir") |
| 1686 |
|
| 1687 |
return [ |
| 1688 |
Scenario("dpull:plain", build_recvtree, ["-a"], ["src/"], "dest/", daemon=D), |
| 1689 |
Scenario("dpull:L-dirlink", served_dirlink, ["-aL"], ["src/"], "dest/", daemon=D), |
| 1690 |
Scenario("dpull:k-dirlink", served_dirlink, ["-ak"], ["src/"], "dest/", daemon=D), |
| 1691 |
Scenario("dpull:l", served_dirlink, ["-al"], ["src/"], "dest/", daemon=D), |
| 1692 |
Scenario("dpull:L-intree", served_intree, ["-aL"], ["src/"], "dest/", daemon=D), |
| 1693 |
Scenario("dpull:safe-links", served_abslink, ["-a", "--safe-links"], ["src/"], "dest/", daemon=D), |
| 1694 |
Scenario("dpull:munge", served_abslink, ["-a", "--munge-links"], ["src/"], "dest/", daemon=D), |
| 1695 |
Scenario("dpull:copy-unsafe", served_abslink, ["-a", "--copy-unsafe-links"], ["src/"], "dest/", daemon=D), |
| 1696 |
Scenario("dpull:K-dest-dirlink", served_dir, ["-aK"], ["src/"], "dest/", dest_prep=kprep, snap_dest=lambda d: d / "realdir", daemon=D), |
| 1697 |
Scenario("dpull:hardlinks", build_recvtree, ["-aH"], ["src/"], "dest/", daemon=D), |
| 1698 |
] |
| 1699 |
|
| 1700 |
|
| 1701 |
_COMBO_FLAGS = ["-H", "-S", "--inplace", "-z", "-c", "-b", "-O", "-J", |
| 1702 |
"--numeric-ids", "-A", "-X", "-E", "--no-whole-file", "-I", |
| 1703 |
"--size-only", "-u"] |
| 1704 |
|
| 1705 |
|
| 1706 |
def combo3_sweep(): |
| 1707 |
"""Option TRIPLES over a stale dest -- deeper interaction coverage.""" |
| 1708 |
import itertools |
| 1709 |
return [Scenario(f"combo3:{x},{y},{z}", build_recvtree, ["-a", x, y, z], |
| 1710 |
["src/"], "dest/", pre_dest=stale_dest) |
| 1711 |
for x, y, z in itertools.combinations(_COMBO_FLAGS, 3)] |
| 1712 |
|
| 1713 |
|
| 1714 |
def combo4_sweep(): |
| 1715 |
"""Option QUADRUPLES over a stale dest (C(16,4)=1820).""" |
| 1716 |
import itertools |
| 1717 |
return [Scenario(f"combo4:{w},{x},{y},{z}", build_recvtree, |
| 1718 |
["-a", w, x, y, z], ["src/"], "dest/", pre_dest=stale_dest) |
| 1719 |
for w, x, y, z in itertools.combinations(_COMBO_FLAGS, 4)] |
| 1720 |
|
| 1721 |
|
| 1722 |
def ssh_sweep(): |
| 1723 |
"""PUSH over a remote-shell split (support/lsh.sh) -- exercises the real |
| 1724 |
client+server processes / protocol / arg passing, and confirms whether the |
| 1725 |
in-tree-symlink regressions also manifest over the wire.""" |
| 1726 |
def kt(src: Path): |
| 1727 |
_write(src / "dir/f1", b"n1\n") |
| 1728 |
_write(src / "dir/f2", b"n2\n") |
| 1729 |
_write(src / "top", b"t\n") |
| 1730 |
|
| 1731 |
def kprep(dest: Path): |
| 1732 |
dest.mkdir(parents=True, exist_ok=True) |
| 1733 |
(dest / "realdir").mkdir(exist_ok=True) |
| 1734 |
if not (dest / "dir").is_symlink(): |
| 1735 |
os.symlink("realdir", dest / "dir") |
| 1736 |
|
| 1737 |
def sym_parent(src: Path): |
| 1738 |
_write(src / "real/sub/file", b"under symlinked parent\n") |
| 1739 |
os.symlink("real", src / "link") |
| 1740 |
|
| 1741 |
return [ |
| 1742 |
Scenario("ssh:push", build_recvtree, ["-a"], ["src/"], ssh=True), |
| 1743 |
Scenario("ssh:push-H", build_recvtree, ["-aH"], ["src/"], ssh=True), |
| 1744 |
Scenario("ssh:push-X", build_recvtree, ["-aX"], ["src/"], ssh=True), |
| 1745 |
Scenario("ssh:push-z", build_recvtree, ["-az"], ["src/"], ssh=True), |
| 1746 |
Scenario("ssh:push-update", build_recvtree, ["-a"], ["src/"], |
| 1747 |
pre_dest=stale_dest, ssh=True), |
| 1748 |
Scenario("ssh:push-delete", build_recvtree, ["-a", "--delete"], ["src/"], |
| 1749 |
pre_dest=stale_dest, ssh=True), |
| 1750 |
Scenario("ssh:push-protect-args", build_recvtree, ["-a", "-s"], ["src/"], |
| 1751 |
ssh=True), |
| 1752 |
Scenario("ssh:K-symlinkdir", kt, ["-aK"], ["src/"], dest_prep=kprep, |
| 1753 |
snap_dest=lambda d: d / "realdir", ssh=True), |
| 1754 |
Scenario("ssh:R-symlink-parent", sym_parent, ["-aR"], |
| 1755 |
["src/link/sub/file"], ssh=True), |
| 1756 |
] |
| 1757 |
|
| 1758 |
|
| 1759 |
def redo_sweep(): |
| 1760 |
"""Resume / redo state machine: a partial or corrupted prior dest forces the |
| 1761 |
delta + verify + resume path (inplace / append-verify / partial-dir, the |
| 1762 |
latter both relative AND absolute). Generalises the single-pass model -- the |
| 1763 |
'failed verification, update discarded' loop and the discard-path NULL-deref |
| 1764 |
both live here. Lifted across transports too.""" |
| 1765 |
def big(src: Path): |
| 1766 |
_mk_reg(src / "f", 120000, t=T_NEW, fill=7) |
| 1767 |
_mk_reg(src / "keep", 200, t=T_NEW, fill=3) |
| 1768 |
|
| 1769 |
def pre_truncated(dest: Path): |
| 1770 |
_mk_reg(dest / "f", 40000, t=T_OLD, fill=7) |
| 1771 |
|
| 1772 |
def pre_corrupt(dest: Path): |
| 1773 |
_mk_reg(dest / "f", 120000, t=T_OLD, fill=200) |
| 1774 |
|
| 1775 |
def pre_abs_partial(dest: Path): |
| 1776 |
pre_corrupt(dest) |
| 1777 |
pdir = dest.parent / (dest.name + "_part") |
| 1778 |
pdir.mkdir(parents=True, exist_ok=True) |
| 1779 |
_mk_reg(pdir / "f", 60000, t=T_OLD, fill=7) |
| 1780 |
|
| 1781 |
abs_part = lambda wd, dest: ["-a", "--no-whole-file", "--partial", |
| 1782 |
f"--partial-dir={Path(dest).parent}/{Path(dest).name}_part"] |
| 1783 |
s = [ |
| 1784 |
Scenario("redo:inplace-corrupt", big, ["-a", "--inplace", "--no-whole-file"], |
| 1785 |
["src/"], "dest/", pre_dest=pre_corrupt), |
| 1786 |
Scenario("redo:append-verify", big, ["-a", "--append-verify"], |
| 1787 |
["src/"], "dest/", pre_dest=pre_truncated), |
| 1788 |
Scenario("redo:append", big, ["-a", "--append"], |
| 1789 |
["src/"], "dest/", pre_dest=pre_truncated), |
| 1790 |
Scenario("redo:partialdir-rel", big, |
| 1791 |
["-a", "--no-whole-file", "--partial", "--partial-dir=.part"], |
| 1792 |
["src/"], "dest/", pre_dest=pre_corrupt), |
| 1793 |
Scenario("redo:checksum-corrupt", big, ["-a", "-c", "--no-whole-file"], |
| 1794 |
["src/"], "dest/", pre_dest=pre_corrupt), |
| 1795 |
] |
| 1796 |
s = lift_transports(s) |
| 1797 |
|
| 1798 |
s.append(Scenario("redo:partialdir-abs", big, abs_part, ["src/"], "dest/", |
| 1799 |
pre_dest=pre_abs_partial)) |
| 1800 |
return s |
| 1801 |
|
| 1802 |
|
| 1803 |
def typetrans_sweep(): |
| 1804 |
"""Type-transition: the existing dest entry has a DIFFERENT type than the |
| 1805 |
source (file/dir/symlink/fifo), crossed with the selection options whose job |
| 1806 |
is to decide whether to replace it. Generalises 'update skips a file of a |
| 1807 |
different type'. The stale-dest sweeps only ever vary content, never type.""" |
| 1808 |
def src_file(src: Path): |
| 1809 |
_mk_reg(src / "x", 60, t=T_NEW) |
| 1810 |
_mk_reg(src / "keep", 10, t=T_NEW) |
| 1811 |
|
| 1812 |
def src_dir(src: Path): |
| 1813 |
_mk_reg(src / "x/inner", 30, t=T_NEW) |
| 1814 |
_mk_reg(src / "keep", 10, t=T_NEW) |
| 1815 |
_ut(src / "x") |
| 1816 |
|
| 1817 |
def src_link(src: Path): |
| 1818 |
_mk_reg(src / "real", 30, t=T_NEW) |
| 1819 |
os.symlink("real", src / "x") |
| 1820 |
_mk_reg(src / "keep", 10, t=T_NEW) |
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
T_NEWER = T_NEW + 10**7 |
| 1827 |
|
| 1828 |
def d_dir(dest: Path): |
| 1829 |
os.makedirs(dest / "x") |
| 1830 |
_mk_reg(dest / "x/old", 5, t=T_NEWER) |
| 1831 |
_ut(dest / "x", T_NEWER) |
| 1832 |
|
| 1833 |
def d_file(dest: Path): |
| 1834 |
_mk_reg(dest / "x", 99, t=T_NEWER, fill=200) |
| 1835 |
|
| 1836 |
def d_link(dest: Path): |
| 1837 |
os.symlink("keep", dest / "x") |
| 1838 |
os.utime(dest / "x", (T_NEWER, T_NEWER), follow_symlinks=False) |
| 1839 |
|
| 1840 |
def d_fifo(dest: Path): |
| 1841 |
_mk_fifo(dest / "x") |
| 1842 |
os.utime(dest / "x", (T_NEWER, T_NEWER)) |
| 1843 |
|
| 1844 |
srcs = [("file", src_file), ("dir", src_dir), ("link", src_link)] |
| 1845 |
dests = [("Ddir", d_dir), ("Dfile", d_file), ("Dlink", d_link), ("Dfifo", d_fifo)] |
| 1846 |
opts = [("plain", ["-a"]), ("update", ["-a", "-u"]), |
| 1847 |
("existing", ["-a", "--existing"]), |
| 1848 |
("ignore-existing", ["-a", "--ignore-existing"]), |
| 1849 |
("force", ["-a", "--force"]), ("delete", ["-a", "--delete"])] |
| 1850 |
s = [] |
| 1851 |
for sn, sf in srcs: |
| 1852 |
for dn, df in dests: |
| 1853 |
for on, ov in opts: |
| 1854 |
|
| 1855 |
if (sn, dn) in (("file", "Dfile"), ("dir", "Ddir"), ("link", "Dlink")): |
| 1856 |
continue |
| 1857 |
s.append(Scenario(f"type:{sn}-vs-{dn}-{on}", sf, ov, ["src/"], |
| 1858 |
"dest/", pre_dest=df)) |
| 1859 |
return lift_transports(s) |
| 1860 |
|
| 1861 |
|
| 1862 |
def tsprec_sweep(): |
| 1863 |
"""Timestamp precision: sub-second mtimes at nanosecond boundaries, crossed |
| 1864 |
with the time-handling options. Exercises the nsec validate/convert path that |
| 1865 |
integer-second fixtures never reach (caught via rc/error/content/itemize -- |
| 1866 |
snapshot records whole-second mtimes, so this is a code-path exerciser).""" |
| 1867 |
NS = [0, 1, 4999, 500000000, 999999999, 999999001] |
| 1868 |
|
| 1869 |
def mk(src: Path, nsec): |
| 1870 |
_mk_reg(src / "f", 100) |
| 1871 |
os.utime(src / "f", ns=(T_NEW * 10**9 + nsec, T_NEW * 10**9 + nsec)) |
| 1872 |
os.makedirs(src / "d", exist_ok=True) |
| 1873 |
_mk_reg(src / "d/g", 50) |
| 1874 |
os.utime(src / "d/g", ns=(T_NEW * 10**9 + nsec, T_NEW * 10**9 + nsec)) |
| 1875 |
|
| 1876 |
s = [] |
| 1877 |
for nsec in NS: |
| 1878 |
s.append(Scenario(f"ts:nsec{nsec}", lambda src, n=nsec: mk(src, n), |
| 1879 |
["-a"], ["src/"], "dest/")) |
| 1880 |
s += [ |
| 1881 |
Scenario("ts:modwindow", lambda src: mk(src, 999999999), |
| 1882 |
["-a", "--modify-window=1"], ["src/"], "dest/"), |
| 1883 |
Scenario("ts:atimes", lambda src: mk(src, 123456789), |
| 1884 |
["-a", "--atimes"], ["src/"], "dest/"), |
| 1885 |
Scenario("ts:crtimes", lambda src: mk(src, 123456789), |
| 1886 |
["-a", "--crtimes"], ["src/"], "dest/"), |
| 1887 |
] |
| 1888 |
return s |
| 1889 |
|
| 1890 |
|
| 1891 |
def bigscale_sweep(): |
| 1892 |
"""Scale escalation: many empty dirs / many files at SCALE_N (--scale). Pairs |
| 1893 |
with the --cost peak-RSS oracle -- a per-entry allocation/footprint regression |
| 1894 |
only shows up at scale and is invisible to functional outcome alone.""" |
| 1895 |
n = max(1, SCALE_N) |
| 1896 |
|
| 1897 |
def emptydirs(src: Path): |
| 1898 |
for i in range(n): |
| 1899 |
(src / f"d{i:07d}").mkdir() |
| 1900 |
|
| 1901 |
def manyfiles(src: Path): |
| 1902 |
for i in range(n): |
| 1903 |
_write(src / f"b{i % 64:02d}" / f"f{i:07d}", b"x\n") |
| 1904 |
|
| 1905 |
def deepdirs(src: Path): |
| 1906 |
for i in range(n): |
| 1907 |
(src / f"a{i % 50:02d}" / f"b{(i // 50) % 50:02d}" / f"c{i:07d}").mkdir(parents=True) |
| 1908 |
|
| 1909 |
return [ |
| 1910 |
Scenario("scale:emptydirs", emptydirs, ["-a"], ["src/"], "dest/"), |
| 1911 |
Scenario("scale:emptydirs-nir", emptydirs, ["-a", "--no-inc-recursive"], |
| 1912 |
["src/"], "dest/"), |
| 1913 |
Scenario("scale:manyfiles", manyfiles, ["-a"], ["src/"], "dest/"), |
| 1914 |
Scenario("scale:deepdirs", deepdirs, ["-a"], ["src/"], "dest/"), |
| 1915 |
] |
| 1916 |
|
| 1917 |
|
| 1918 |
def rrsync_sweep(): |
| 1919 |
"""rrsync lane: route the remote side through the restricted rrsync wrapper |
| 1920 |
(subdir-restricted, so its option/path validation is exercised) -- a whole |
| 1921 |
subsystem the other lanes never drive. Covers `-a` and an `-rlpt` control, |
| 1922 |
push and pull. rrsync ships per version, so each build is paired with its own |
| 1923 |
rrsync via --rrsync-a/--rrsync-b.""" |
| 1924 |
bt = build_recvtree |
| 1925 |
|
| 1926 |
def tree(src: Path): |
| 1927 |
_mk_reg(src / "dir/f1", 50) |
| 1928 |
_mk_reg(src / "dir/f2", 50) |
| 1929 |
_mk_reg(src / "top", 20) |
| 1930 |
os.symlink("top", src / "lnk") |
| 1931 |
_ut(src / "dir") |
| 1932 |
|
| 1933 |
def abslink(src: Path): |
| 1934 |
_mk_reg(src / "anchor", 10) |
| 1935 |
os.symlink("/etc/hostname", src / "abs") |
| 1936 |
|
| 1937 |
def mk(name, setup, opts, pull=False, pre_dest=None): |
| 1938 |
sc = Scenario(name, setup, opts, ["src/"], "dest/", pre_dest=pre_dest) |
| 1939 |
sc.rrsync = {"pull": pull} |
| 1940 |
return sc |
| 1941 |
|
| 1942 |
return [ |
| 1943 |
mk("rr:push-a", bt, ["-a"]), |
| 1944 |
mk("rr:push-rlpt", tree, ["-rlpt"]), |
| 1945 |
mk("rr:push-rlptD", tree, ["-rlptD"]), |
| 1946 |
mk("rr:push-update", bt, ["-a"], pre_dest=stale_dest), |
| 1947 |
mk("rr:push-copy-unsafe", abslink, ["-rlpt", "--copy-unsafe-links"]), |
| 1948 |
mk("rr:pull-a", bt, ["-a"], pull=True), |
| 1949 |
mk("rr:pull-rlpt", tree, ["-rlpt"], pull=True), |
| 1950 |
mk("rr:pull-symlink", tree, ["-rlpt"], pull=True), |
| 1951 |
] |
| 1952 |
|
| 1953 |
|
| 1954 |
def tcpdaemon_sweep(): |
| 1955 |
"""Real-TCP-daemon lane: a genuine `rsync --daemon` on a bound port (greeting/ |
| 1956 |
handshake/socket path), and an auth variant (challenge-response) -- the daemon |
| 1957 |
code the stdio-pipe lane bypasses. Push + pull, with/without auth.""" |
| 1958 |
bt = build_recvtree |
| 1959 |
|
| 1960 |
def mk(name, opts, pull=False, auth=False, pre_dest=None): |
| 1961 |
sc = Scenario(name, bt, opts, ["src/"], "dest/", pre_dest=pre_dest) |
| 1962 |
sc.daemon = {"tcp": True, "pull": pull, "auth": auth} |
| 1963 |
return sc |
| 1964 |
|
| 1965 |
return [ |
| 1966 |
mk("tcp:push", ["-a"]), |
| 1967 |
mk("tcp:push-H", ["-aH"]), |
| 1968 |
mk("tcp:push-X", ["-aX"]), |
| 1969 |
mk("tcp:push-update", ["-a"], pre_dest=stale_dest), |
| 1970 |
mk("tcp:push-delete", ["-a", "--delete"], pre_dest=stale_dest), |
| 1971 |
mk("tcp:pull", ["-a"], pull=True), |
| 1972 |
mk("tcp:pull-H", ["-aH"], pull=True), |
| 1973 |
mk("tcp:push-auth", ["-a"], auth=True), |
| 1974 |
mk("tcp:pull-auth", ["-a"], pull=True, auth=True), |
| 1975 |
] |
| 1976 |
|
| 1977 |
|
| 1978 |
SWEEPS = {"options": options_sweep, "pathshape": pathshape_sweep, |
| 1979 |
"recv": recv_sweep, "destshape": destshape_sweep, |
| 1980 |
"name": name_sweep, "filesfrom": filesfrom_sweep, |
| 1981 |
"intree": intree_sweep, "intree2": intree2_sweep, |
| 1982 |
"proto": proto_sweep, "combo": combo_sweep, "combo3": combo3_sweep, |
| 1983 |
"combo4": combo4_sweep, "scale": scale_sweep, "ssh": ssh_sweep, |
| 1984 |
"daemon": daemon_sweep, "daemonchroot": daemonchroot_sweep, |
| 1985 |
"mode": mode_sweep, "size": size_sweep, "filetype": filetype_sweep, |
| 1986 |
"selection": selection_sweep, "behavior": behavior_sweep, |
| 1987 |
"placement": placement_sweep, "wire": wire_sweep, |
| 1988 |
"pairwise": pairwise_sweep, "daemonsym": daemon_sym_sweep, "daemonpull": daemon_pull_sym_sweep, "daemonesc": daemon_escape_sweep, "misc": misc_sweep, "gaps": gaps_sweep, |
| 1989 |
"redo": redo_sweep, "typetrans": typetrans_sweep, "tsprec": tsprec_sweep, |
| 1990 |
"bigscale": bigscale_sweep, "rrsync": rrsync_sweep, |
| 1991 |
"tcpdaemon": tcpdaemon_sweep, |
| 1992 |
"priv": priv_sweep} |
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
ALL_SWEEPS = ["options", "pathshape", "recv", "destshape", "name", "filesfrom", |
| 2000 |
"intree", "intree2", "proto", "combo", "combo3", "scale", "ssh", |
| 2001 |
"daemon", "mode", "size", "filetype", "selection", "behavior", |
| 2002 |
"placement", "wire", "pairwise", "daemonsym", "daemonpull", |
| 2003 |
"daemonesc", "misc", "gaps", "redo", "typetrans", "tsprec", |
| 2004 |
"rrsync", "tcpdaemon"] |
| 2005 |
|
| 2006 |
|
| 2007 |
def _compare(a, b, has_times=True, ign_types=(), incl_item=True, incl_lit=True, |
| 2008 |
incl_out=False, incl_err=False): |
| 2009 |
"""Issue list for one result vs another (A-vs-B, and the per-binary stability |
| 2010 |
check). incl_item/incl_lit/incl_out/incl_err drop the itemize / Literal-data / |
| 2011 |
normalised-stdout / normalised-stderr-text signals (used when those are |
| 2012 |
themselves nondeterministic, or for content-only checks). Empty list == |
| 2013 |
indistinguishable on the requested signals.""" |
| 2014 |
issues = [] |
| 2015 |
if a["rc"] != b["rc"]: |
| 2016 |
issues.append(f" exit: A={a['rc']} B={b['rc']}") |
| 2017 |
a_err = any(m in a["err"] for m in ERR_MARKERS) |
| 2018 |
b_err = any(m in b["err"] for m in ERR_MARKERS) |
| 2019 |
if a_err != b_err: |
| 2020 |
issues.append(f" stderr-error: A={a_err!r} B={b_err!r}\n A:{a['err'][:300]}") |
| 2021 |
if incl_lit and a["lit"] != b["lit"]: |
| 2022 |
issues.append(f" Literal-data: A={a['lit']} B={b['lit']}") |
| 2023 |
issues += diff_snapshots(a["snap"], b["snap"], ignore_mtime=not has_times, |
| 2024 |
ignore_mtime_types=ign_types) |
| 2025 |
if incl_item and a["item"] != b["item"]: |
| 2026 |
issues.append(" itemize differs:\n A=" + repr(a["item"]) |
| 2027 |
+ "\n B=" + repr(b["item"])) |
| 2028 |
if incl_err and a.get("errn", "") != b.get("errn", ""): |
| 2029 |
issues.append(" stderr-text differs:\n A:" + a.get("errn", "")[:300] |
| 2030 |
+ "\n B:" + b.get("errn", "")[:300]) |
| 2031 |
if incl_out and a.get("out", "") != b.get("out", ""): |
| 2032 |
issues.append(" stdout differs:\n A:" + a.get("out", "")[:300] |
| 2033 |
+ "\n B:" + b.get("out", "")[:300]) |
| 2034 |
return issues |
| 2035 |
|
| 2036 |
|
| 2037 |
def run_scenario(scn: Scenario, workroot: Path): |
| 2038 |
wd = workroot / scn.name.replace("/", "_").replace(":", "_").replace("+", "_") |
| 2039 |
if wd.exists(): |
| 2040 |
shutil.rmtree(wd, ignore_errors=True) |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
def resolve_opts(dest): |
| 2045 |
return scn.opts(str(wd), str(dest)) if callable(scn.opts) else scn.opts |
| 2046 |
opts0 = resolve_opts(wd / "dest_A") |
| 2047 |
|
| 2048 |
for o in opts0: |
| 2049 |
flag = o.split("=", 1)[0] |
| 2050 |
if flag.startswith("--"): |
| 2051 |
if not (supports(RSYNC_A, flag) and supports(RSYNC_B, flag)): |
| 2052 |
return ("SKIP", f"a binary lacks {flag}") |
| 2053 |
|
| 2054 |
src = wd / "src" |
| 2055 |
src.mkdir(parents=True, exist_ok=True) |
| 2056 |
scn.setup(src) |
| 2057 |
src_args = scn.src_args(str(wd)) if callable(scn.src_args) else scn.src_args |
| 2058 |
|
| 2059 |
|
| 2060 |
has_times = any(o in ("-a", "-t", "-rlptD", "--times") or |
| 2061 |
(o.startswith("-") and not o.startswith("--") and "t" in o) |
| 2062 |
for o in opts0) |
| 2063 |
ign_types = _ign(opts0) |
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
if isinstance(src_args, list) and any(a == "/" or a.startswith("/") |
| 2069 |
for a in src_args): |
| 2070 |
ign_types = set(ign_types) | {"d"} |
| 2071 |
|
| 2072 |
def one_run(tag, binary, rep): |
| 2073 |
dest = wd / f"dest_{tag}{rep}" |
| 2074 |
optr = resolve_opts(dest) |
| 2075 |
if scn.dest_prep: |
| 2076 |
scn.dest_prep(dest) |
| 2077 |
elif scn.pre_dest: |
| 2078 |
dest.mkdir(parents=True, exist_ok=True) |
| 2079 |
scn.pre_dest(dest) |
| 2080 |
_tls.measure = COST |
| 2081 |
_tls.rss = None |
| 2082 |
if scn.daemon is not None: |
| 2083 |
port = (20000 + (abs(hash(scn.name)) % 2000) * 16 |
| 2084 |
+ (0 if tag == "A" else 8) + rep) |
| 2085 |
D = scn.daemon |
| 2086 |
if D.get("tcp"): |
| 2087 |
rc, err, lit, item, out = _tcp_daemon( |
| 2088 |
binary, str(wd), str(wd / "src") if D.get("pull") else str(dest), |
| 2089 |
optr, src_args, localdest=str(dest), pull=D.get("pull", False), |
| 2090 |
chroot=D.get("chroot", "no"), auth=D.get("auth", False)) |
| 2091 |
elif D.get("pull"): |
| 2092 |
rc, err, lit, item, out = run_daemon_pull( |
| 2093 |
binary, str(wd), str(wd / "src"), optr, str(dest), port, |
| 2094 |
chroot=D.get("chroot", "no")) |
| 2095 |
else: |
| 2096 |
rc, err, lit, item, out = run_daemon_xfer( |
| 2097 |
binary, str(wd), str(dest), optr, src_args, port, |
| 2098 |
chroot=D.get("chroot", "no")) |
| 2099 |
elif scn.rrsync is not None: |
| 2100 |
rrs = (RRSYNC_A if tag == "A" else RRSYNC_B) or str(_RRSYNC_SRC) |
| 2101 |
if scn.rrsync.get("pull"): |
| 2102 |
rc, err, lit, item, out = run_rrsync_pull( |
| 2103 |
binary, rrs, str(wd), str(wd / "src"), optr, str(dest)) |
| 2104 |
else: |
| 2105 |
rc, err, lit, item, out = run_rrsync_push( |
| 2106 |
binary, rrs, str(wd), optr, src_args, str(dest)) |
| 2107 |
elif scn.ssh: |
| 2108 |
rc, err, lit, item, out = run_ssh_xfer(binary, str(wd), optr, |
| 2109 |
src_args, str(dest)) |
| 2110 |
else: |
| 2111 |
dest_arg = scn.dest_arg(dest) if scn.dest_arg else str(dest) + "/" |
| 2112 |
rc, err, lit, item, out = run_xfer(binary, str(wd), optr, src_args, |
| 2113 |
dest_arg) |
| 2114 |
_tls.measure = False |
| 2115 |
snap_target = scn.snap_dest(dest) if scn.snap_dest else dest |
| 2116 |
return dict(rc=rc, err=err, lit=lit, item=item, snap=snapshot(snap_target), |
| 2117 |
out=_norm_out(out, wd, dest), errn=_norm_err(err, wd, dest), |
| 2118 |
rss=getattr(_tls, "rss", None)) |
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
def content_unstable(rs): |
| 2130 |
for other in rs[1:]: |
| 2131 |
d = _compare(rs[0], other, has_times=False, ign_types=set(), |
| 2132 |
incl_item=False, incl_lit=False) |
| 2133 |
if d: |
| 2134 |
return d |
| 2135 |
return None |
| 2136 |
|
| 2137 |
def attr_stable(rs, k): |
| 2138 |
return all(rs[0][k] == r[k] for r in rs[1:]) |
| 2139 |
|
| 2140 |
base = max(1, REPEAT) |
| 2141 |
ra = [one_run("A", RSYNC_A, r) for r in range(base)] |
| 2142 |
rb = [one_run("B", RSYNC_B, r) for r in range(base)] |
| 2143 |
item_ok = lit_ok = out_ok = err_ok = True |
| 2144 |
if base >= 2: |
| 2145 |
|
| 2146 |
|
| 2147 |
if _compare(ra[0], rb[0], has_times, ign_types, incl_out=True, incl_err=True): |
| 2148 |
confirm = max(base, 5) |
| 2149 |
ra += [one_run("A", RSYNC_A, r) for r in range(base, confirm)] |
| 2150 |
rb += [one_run("B", RSYNC_B, r) for r in range(base, confirm)] |
| 2151 |
cu = content_unstable(ra) or content_unstable(rb) |
| 2152 |
if cu: |
| 2153 |
if not KEEP: |
| 2154 |
shutil.rmtree(wd, ignore_errors=True) |
| 2155 |
return ("FLAKY", [" scenario content is nondeterministic across " |
| 2156 |
"repeats (quarantined, not a regression):"] + cu[:6]) |
| 2157 |
|
| 2158 |
|
| 2159 |
item_ok = attr_stable(ra, "item") and attr_stable(rb, "item") |
| 2160 |
lit_ok = attr_stable(ra, "lit") and attr_stable(rb, "lit") |
| 2161 |
out_ok = attr_stable(ra, "out") and attr_stable(rb, "out") |
| 2162 |
err_ok = attr_stable(ra, "errn") and attr_stable(rb, "errn") |
| 2163 |
a, b = ra[0], rb[0] |
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
both_failed = (any(m in a["err"] for m in ERR_MARKERS) |
| 2170 |
and any(m in b["err"] for m in ERR_MARKERS)) |
| 2171 |
issues = _compare(a, b, has_times, ign_types, |
| 2172 |
incl_item=item_ok and not both_failed, |
| 2173 |
incl_lit=lit_ok and not both_failed, |
| 2174 |
incl_out=out_ok and not both_failed, |
| 2175 |
incl_err=err_ok and not both_failed) |
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
if COST: |
| 2180 |
arss = [r["rss"] for r in ra if r.get("rss")] |
| 2181 |
brss = [r["rss"] for r in rb if r.get("rss")] |
| 2182 |
if arss and brss: |
| 2183 |
amin, bmax = min(arss), max(brss) |
| 2184 |
if amin > 3 * bmax and (amin - bmax) > 64 * 1024 * 1024: |
| 2185 |
issues.append(f" peak-RSS blow-up: A>={amin // (1<<20)}MB " |
| 2186 |
f"B<={bmax // (1<<20)}MB ({amin / bmax:.1f}x)") |
| 2187 |
if not (KEEP or issues): |
| 2188 |
shutil.rmtree(wd, ignore_errors=True) |
| 2189 |
if not issues: |
| 2190 |
return ("OK", issues) |
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
for sub, note in ALLOWLIST: |
| 2195 |
if sub in a["err"] and sub not in b["err"]: |
| 2196 |
return ("ALLOW", [f" intentional behaviour change: {note}", |
| 2197 |
f" A:{a['err'][:200]}"] ) |
| 2198 |
|
| 2199 |
a_ok = a["rc"] == 0 and not any(m in a["err"] for m in ERR_MARKERS) |
| 2200 |
b_ok = b["rc"] == 0 and not any(m in b["err"] for m in ERR_MARKERS) |
| 2201 |
if a_ok and not b_ok: |
| 2202 |
return ("ABETTER", [" A succeeds where B FAILS -- an " |
| 2203 |
"improvement/behaviour change, not a regression:", |
| 2204 |
f" B:{b['err'][:200]}"]) |
| 2205 |
return ("DIFF", issues) |
| 2206 |
|
| 2207 |
|
| 2208 |
_mport = [25500] |
| 2209 |
|
| 2210 |
|
| 2211 |
def _ssh1(cbin, sbin, wd, opts, src, dest, pull): |
| 2212 |
e = ["-e", f"sh {_LSH}", f"--rsync-path={sbin}"] |
| 2213 |
if pull: |
| 2214 |
argv = [cbin, "--stats", "-i", *e, *opts, f"lh:{src}/", f"{dest}/"] |
| 2215 |
else: |
| 2216 |
argv = [cbin, "--stats", "-i", *e, *opts, f"{src}/", f"lh:{dest}/"] |
| 2217 |
return _parse_out(sh(argv, cwd=str(wd))) |
| 2218 |
|
| 2219 |
|
| 2220 |
def _daemon1(cbin, sbin, wd, module, opts, localdir, pull): |
| 2221 |
_mport[0] += 1 |
| 2222 |
port = _mport[0] |
| 2223 |
conf = Path(wd) / f"d{port}.conf" |
| 2224 |
Path(module).mkdir(parents=True, exist_ok=True) |
| 2225 |
conf.write_text(f"use chroot = no\nport = {port}\nlog file = {wd}/d{port}.log\n" |
| 2226 |
f"pid file = {wd}/d{port}.pid\n[m]\n path = {module}\n" |
| 2227 |
f" read only = no\n hosts allow = 127.0.0.1\n") |
| 2228 |
proc = subprocess.Popen([sbin, "--daemon", "--no-detach", f"--config={conf}", |
| 2229 |
f"--port={port}", "--address=127.0.0.1"], |
| 2230 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 2231 |
try: |
| 2232 |
if not _wait_port(port): |
| 2233 |
return (99, "daemon failed to start", None, "") |
| 2234 |
url = f"rsync://127.0.0.1:{port}/m/" |
| 2235 |
if pull: |
| 2236 |
argv = [cbin, "--stats", "-i", *opts, url, f"{localdir}/"] |
| 2237 |
else: |
| 2238 |
argv = [cbin, "--stats", "-i", *opts, f"{localdir}/", url] |
| 2239 |
return _parse_out(sh(argv, cwd=str(wd))) |
| 2240 |
finally: |
| 2241 |
proc.terminate() |
| 2242 |
try: |
| 2243 |
proc.wait(timeout=5) |
| 2244 |
except subprocess.TimeoutExpired: |
| 2245 |
proc.kill() |
| 2246 |
|
| 2247 |
|
| 2248 |
def run_matrix(workroot, logf): |
| 2249 |
"""Cross-build role matrix: mixed A<->B over the wire, both directions |
| 2250 |
(push/pull => which build is sender vs receiver), both transports |
| 2251 |
(ssh/daemon). Each config's dest is compared to the PURE-B baseline; an |
| 2252 |
A-involved config that is WORSE than pure-B is a regression (protocol/interop |
| 2253 |
or role-specific).""" |
| 2254 |
A, B = RSYNC_A, RSYNC_B |
| 2255 |
scns = [("basic", build_recvtree, ["-a"]), |
| 2256 |
("H", build_recvtree, ["-aH"]), |
| 2257 |
("X", build_recvtree, ["-aX"]), |
| 2258 |
("z", build_recvtree, ["-az"]), |
| 2259 |
("c", build_recvtree, ["-ac"])] |
| 2260 |
combos = [("Ac_As", A, A), ("Ac_Bs", A, B), ("Bc_As", B, A)] |
| 2261 |
nreg = 0 |
| 2262 |
|
| 2263 |
def one(cbin, sbin, wd, tag, transport, direction, opts): |
| 2264 |
dest = Path(wd) / f"d_{tag}" |
| 2265 |
if transport == "ssh": |
| 2266 |
rc, err, lit, item, _out = _ssh1(cbin, sbin, wd, opts, Path(wd) / "src", |
| 2267 |
dest, pull=(direction == "pull")) |
| 2268 |
else: |
| 2269 |
if direction == "pull": |
| 2270 |
rc, err, lit, item, _out = _daemon1(cbin, sbin, wd, Path(wd) / "src", |
| 2271 |
opts, dest, pull=True) |
| 2272 |
else: |
| 2273 |
rc, err, lit, item, _out = _daemon1(cbin, sbin, wd, dest, opts, |
| 2274 |
Path(wd) / "src", pull=False) |
| 2275 |
return rc, err, snapshot(dest) |
| 2276 |
|
| 2277 |
for name, setup, opts in scns: |
| 2278 |
for transport in ("ssh", "daemon"): |
| 2279 |
for direction in ("push", "pull"): |
| 2280 |
wd = workroot / f"mx_{name}_{transport}_{direction}" |
| 2281 |
shutil.rmtree(wd, ignore_errors=True) |
| 2282 |
(wd / "src").mkdir(parents=True) |
| 2283 |
setup(wd / "src") |
| 2284 |
brc, berr, bsnap = one(B, B, wd, "base", transport, direction, opts) |
| 2285 |
bok = brc == 0 and not any(m in berr for m in ERR_MARKERS) |
| 2286 |
for tag, cv, sv in combos: |
| 2287 |
rc, err, snap = one(cv, sv, wd, tag, transport, direction, opts) |
| 2288 |
ok = rc == 0 and not any(m in err for m in ERR_MARKERS) |
| 2289 |
diffs = diff_snapshots(snap, bsnap) |
| 2290 |
label = f"matrix:{name}/{transport}/{direction}/{tag}" |
| 2291 |
if not diffs and ok == bok: |
| 2292 |
print(f"OK {label}") |
| 2293 |
continue |
| 2294 |
if ok and not bok: |
| 2295 |
print(f"BETTER {label} (A cfg ok; pure-B failed)") |
| 2296 |
continue |
| 2297 |
nreg += 1 |
| 2298 |
kind = "exit/err" if ok != bok else "tree" |
| 2299 |
print(f"DIFF {label} [{kind}; client={cv.split('/')[-1]} " |
| 2300 |
f"server={sv.split('/')[-1]}]") |
| 2301 |
detail = ([f" exit/err: cfg ok={ok} (rc={rc}) base ok={bok}", |
| 2302 |
f" err:{err[:200]}"] if ok != bok else []) + diffs[:8] |
| 2303 |
for ln in detail: |
| 2304 |
print(ln) |
| 2305 |
logf.write(f"\nMATRIX-DIFF {label} opts:{' '.join(opts)} " |
| 2306 |
f"vs pure-B *** REGRESSION CANDIDATE ***\n") |
| 2307 |
for ln in detail: |
| 2308 |
logf.write(ln + "\n") |
| 2309 |
logf.flush() |
| 2310 |
print(f"\n=== matrix: {nreg} cross-version regression candidates ===") |
| 2311 |
return nreg |
| 2312 |
|
| 2313 |
|
| 2314 |
def _fx_hardlinks(src): |
| 2315 |
for i in range(6): |
| 2316 |
_write(src / f"f{i}", f"data{i % 3}\n".encode()) |
| 2317 |
for i in range(6): |
| 2318 |
try: |
| 2319 |
os.link(src / f"f{i % 3}", src / f"hl{i}") |
| 2320 |
except OSError: |
| 2321 |
pass |
| 2322 |
os.symlink("f0", src / "sl") |
| 2323 |
|
| 2324 |
|
| 2325 |
def _fx_weird(src): |
| 2326 |
for n in ["a space", "café", "semi;colon", "dollar$x", "paren(s)", "-dash", |
| 2327 |
"tab\tt"]: |
| 2328 |
_write(src / n, b"x\n") |
| 2329 |
|
| 2330 |
|
| 2331 |
def _fx_deep(src): |
| 2332 |
p = src |
| 2333 |
for i in range(25): |
| 2334 |
p = p / f"d{i}" |
| 2335 |
_write(p / "leaf", b"deep\n") |
| 2336 |
_write(src / "top", b"t\n") |
| 2337 |
|
| 2338 |
|
| 2339 |
def _fx_sparse(src): |
| 2340 |
with open(src / "sp.bin", "wb") as f: |
| 2341 |
f.seek(2 << 20) |
| 2342 |
f.write(b"end") |
| 2343 |
_write(src / "reg", b"r\n") |
| 2344 |
|
| 2345 |
|
| 2346 |
def _fx_many(src): |
| 2347 |
for i in range(200): |
| 2348 |
_write(src / f"d{i % 8}" / f"f{i:03d}", f"{i}\n".encode()) |
| 2349 |
|
| 2350 |
|
| 2351 |
FUZZ_FIXTURES = [("recvtree", build_recvtree), ("kitchen", build_kitchen), |
| 2352 |
("hardlinks", _fx_hardlinks), ("weird", _fx_weird), |
| 2353 |
("deep", _fx_deep), ("sparse", _fx_sparse), ("many", _fx_many)] |
| 2354 |
FUZZ_FLAGS = ["-H", "-S", "--inplace", "-z", "-c", "-b", "-O", "-J", |
| 2355 |
"--numeric-ids", "-A", "-X", "-E", "--no-whole-file", "-I", |
| 2356 |
"--size-only", "-u", "-k", "-K", "-L", "--copy-unsafe-links", |
| 2357 |
"--safe-links", "--munge-links", "--delete", "--existing", |
| 2358 |
"--ignore-existing", "--max-size=100000", "--compress-choice=zstd", |
| 2359 |
"--no-inc-recursive", "--checksum-choice=md5"] |
| 2360 |
|
| 2361 |
|
| 2362 |
def _perturb(src, dest): |
| 2363 |
"""dest = an older/partial copy of src (so update/backup/delete/-u/-I bite).""" |
| 2364 |
shutil.copytree(src, dest, symlinks=True) |
| 2365 |
for p in sorted(dest.rglob("*")): |
| 2366 |
if p.is_file() and not p.is_symlink(): |
| 2367 |
p.write_bytes(b"OLDER CONTENT\n") |
| 2368 |
os.utime(p, (T_OLD, T_OLD)) |
| 2369 |
break |
| 2370 |
(dest / "_obsolete").write_text("x\n") |
| 2371 |
os.utime(dest / "_obsolete", (T_OLD, T_OLD)) |
| 2372 |
|
| 2373 |
|
| 2374 |
def _fuzz_run(sndr, rcvr, transport, direction, wd, tag, opts, src): |
| 2375 |
dest = wd / f"d_{tag}" |
| 2376 |
_perturb(src, dest) |
| 2377 |
if transport == "ssh": |
| 2378 |
if direction == "push": |
| 2379 |
rc, err, _, _, _ = _ssh1(sndr, rcvr, wd, opts, src, dest, pull=False) |
| 2380 |
else: |
| 2381 |
rc, err, _, _, _ = _ssh1(rcvr, sndr, wd, opts, src, dest, pull=True) |
| 2382 |
else: |
| 2383 |
if direction == "push": |
| 2384 |
rc, err, _, _, _ = _daemon1(sndr, rcvr, wd, dest, opts, src, pull=False) |
| 2385 |
else: |
| 2386 |
rc, err, _, _, _ = _daemon1(rcvr, sndr, wd, src, opts, dest, pull=True) |
| 2387 |
return rc, err, snapshot(dest) |
| 2388 |
|
| 2389 |
|
| 2390 |
def run_fuzz(workroot, logf, n, seed): |
| 2391 |
"""Stochastic differential fuzzer: random fixture x option-subset x transport |
| 2392 |
x direction x build-pair, each compared to the pure-B baseline for the same |
| 2393 |
config. Finds cross-build / option-interaction regressions broadly.""" |
| 2394 |
import random |
| 2395 |
rnd = random.Random(seed) |
| 2396 |
A, B = RSYNC_A, RSYNC_B |
| 2397 |
seen = set() |
| 2398 |
nreg = nrun = 0 |
| 2399 |
print(f"fuzz: {n} iterations, seed={seed}") |
| 2400 |
for i in range(n): |
| 2401 |
fxname, fx = rnd.choice(FUZZ_FIXTURES) |
| 2402 |
flags = sorted(rnd.sample(FUZZ_FLAGS, rnd.randint(0, 4))) |
| 2403 |
opts = ["-a"] + flags |
| 2404 |
transport = rnd.choice(["ssh", "daemon"]) |
| 2405 |
direction = rnd.choice(["push", "pull"]) |
| 2406 |
sndr, rcvr = rnd.choice([(A, A), (A, B), (B, A)]) |
| 2407 |
|
| 2408 |
if any(o.startswith("--") and not (supports(A, o.split("=")[0]) |
| 2409 |
and supports(B, o.split("=")[0])) for o in opts): |
| 2410 |
continue |
| 2411 |
wd = workroot / f"fz{i}" |
| 2412 |
shutil.rmtree(wd, ignore_errors=True) |
| 2413 |
(wd / "src").mkdir(parents=True) |
| 2414 |
fx(wd / "src") |
| 2415 |
try: |
| 2416 |
brc, berr, bsnap = _fuzz_run(B, B, transport, direction, wd, "base", |
| 2417 |
opts, wd / "src") |
| 2418 |
crc, cerr, csnap = _fuzz_run(sndr, rcvr, transport, direction, wd, |
| 2419 |
"cfg", opts, wd / "src") |
| 2420 |
except Exception as ex: |
| 2421 |
continue |
| 2422 |
nrun += 1 |
| 2423 |
bok = brc == 0 and not any(m in berr for m in ERR_MARKERS) |
| 2424 |
cok = crc == 0 and not any(m in cerr for m in ERR_MARKERS) |
| 2425 |
diffs = diff_snapshots(csnap, bsnap, ignore_mtime_types=_ign(opts)) |
| 2426 |
if not diffs and cok == bok: |
| 2427 |
if not KEEP: |
| 2428 |
shutil.rmtree(wd, ignore_errors=True) |
| 2429 |
continue |
| 2430 |
if cok and not bok: |
| 2431 |
if not KEEP: |
| 2432 |
shutil.rmtree(wd, ignore_errors=True) |
| 2433 |
continue |
| 2434 |
which = f"sndr={'A' if sndr==A else 'B'} rcvr={'A' if rcvr==A else 'B'}" |
| 2435 |
sig = (fxname, tuple(flags), transport, direction, |
| 2436 |
"exit" if cok != bok else "tree") |
| 2437 |
if sig in seen: |
| 2438 |
if not KEEP: |
| 2439 |
shutil.rmtree(wd, ignore_errors=True) |
| 2440 |
continue |
| 2441 |
seen.add(sig) |
| 2442 |
nreg += 1 |
| 2443 |
label = f"fuzz:{fxname}/{transport}/{direction}/[{' '.join(opts)}]/{which}" |
| 2444 |
print(f"DIFF {label}") |
| 2445 |
detail = ([f" exit: cfg rc={crc}(ok={cok}) base rc={brc}(ok={bok})", |
| 2446 |
f" err:{cerr[:200]}"] if cok != bok else []) + diffs[:8] |
| 2447 |
for ln in detail: |
| 2448 |
print(ln) |
| 2449 |
logf.write(f"\nFUZZ-DIFF {label} *** REGRESSION CANDIDATE ***\n") |
| 2450 |
for ln in detail: |
| 2451 |
logf.write(ln + "\n") |
| 2452 |
logf.flush() |
| 2453 |
print(f"\n=== fuzz: {nrun} configs run, {nreg} distinct regression candidates ===") |
| 2454 |
return nreg |
| 2455 |
|
| 2456 |
|
| 2457 |
def _ign(opts): |
| 2458 |
s = set() |
| 2459 |
if "--omit-dir-times" in opts or any(o[:1] == "-" and o[1:2] != "-" and "O" in o for o in opts): |
| 2460 |
s.add("d") |
| 2461 |
if "--omit-link-times" in opts or any(o[:1] == "-" and o[1:2] != "-" and "J" in o for o in opts): |
| 2462 |
s.add("l") |
| 2463 |
if "--backup" in opts or any(o[:1] == "-" and o[1:2] != "-" and "b" in o for o in opts): |
| 2464 |
s.add("d") |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
if any(o.startswith(("--temp-dir", "--partial-dir", "--backup-dir", |
| 2469 |
"--partial", "--mkpath")) |
| 2470 |
for o in opts): |
| 2471 |
s.add("d") |
| 2472 |
return s |
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
_RAND_FLAGS = _COMBO_FLAGS + ["-k", "-K", "-L", "-l", "--copy-unsafe-links", |
| 2480 |
"--safe-links", "--munge-links", "--delete", |
| 2481 |
"--existing", "--ignore-existing", |
| 2482 |
"--no-inc-recursive", "--compress-choice=zstd", |
| 2483 |
"--checksum-choice=md5", "--sparse", "--fuzzy"] |
| 2484 |
|
| 2485 |
|
| 2486 |
def _random_scenarios(rnd, seen): |
| 2487 |
"""Infinite stream of randomized benign A/B scenarios: random fixture x random |
| 2488 |
option subset (size 2-6), optional stale dest. Deduped by signature, fed |
| 2489 |
through the same A/B oracle as the fixed sweeps.""" |
| 2490 |
idx = 0 |
| 2491 |
while True: |
| 2492 |
fxname, fx = rnd.choice(FUZZ_FIXTURES) |
| 2493 |
k = rnd.randint(2, 6) |
| 2494 |
flags = tuple(sorted(rnd.sample(_RAND_FLAGS, k))) |
| 2495 |
stale = fxname == "recvtree" and rnd.random() < 0.5 |
| 2496 |
sig = ("rand", fxname, flags, stale) |
| 2497 |
if sig in seen: |
| 2498 |
continue |
| 2499 |
seen.add(sig) |
| 2500 |
idx += 1 |
| 2501 |
nm = (f"rand{idx}:{fxname}:" + "_".join(f.lstrip("-") for f in flags) |
| 2502 |
+ ("+stale" if stale else "")) |
| 2503 |
yield Scenario(nm, fx, ["-a", *flags], ["src/"], "dest/", |
| 2504 |
pre_dest=(stale_dest if stale else None)) |
| 2505 |
|
| 2506 |
|
| 2507 |
def _systematic_combos(seen): |
| 2508 |
"""Infinite stream walking the option-combination ladder combo2->3->4->... |
| 2509 |
over a stale dest; when the top order is exhausted the ladder restarts.""" |
| 2510 |
k = 2 |
| 2511 |
while True: |
| 2512 |
for combo in itertools.combinations(_COMBO_FLAGS, k): |
| 2513 |
sig = ("sys", combo) |
| 2514 |
if sig in seen: |
| 2515 |
continue |
| 2516 |
seen.add(sig) |
| 2517 |
yield Scenario(f"sys{k}:" + ",".join(combo), build_recvtree, |
| 2518 |
["-a", *combo], ["src/"], "dest/", pre_dest=stale_dest) |
| 2519 |
k += 1 |
| 2520 |
if k > len(_COMBO_FLAGS): |
| 2521 |
for s in [s for s in seen if s and s[0] == "sys"]: |
| 2522 |
seen.discard(s) |
| 2523 |
k = 2 |
| 2524 |
|
| 2525 |
|
| 2526 |
def _mixed_scenarios(rnd, seen): |
| 2527 |
"""Alternate random / systematic so a parallel pool runs ~half of each.""" |
| 2528 |
rg = _random_scenarios(rnd, seen) |
| 2529 |
sg = _systematic_combos(seen) |
| 2530 |
while True: |
| 2531 |
yield next(rg) |
| 2532 |
yield next(sg) |
| 2533 |
|
| 2534 |
|
| 2535 |
class _Tee: |
| 2536 |
"""Minimal write/flush fan-out so matrix/fuzz diffs land in both the curated |
| 2537 |
findings log and the full per-run log.""" |
| 2538 |
def __init__(self, *files): |
| 2539 |
self._f = files |
| 2540 |
|
| 2541 |
def write(self, s): |
| 2542 |
for f in self._f: |
| 2543 |
f.write(s) |
| 2544 |
|
| 2545 |
def flush(self): |
| 2546 |
for f in self._f: |
| 2547 |
f.flush() |
| 2548 |
|
| 2549 |
|
| 2550 |
def main(): |
| 2551 |
global RSYNC_A, RSYNC_B, RRSYNC_A, RRSYNC_B, KEEP, REPEAT, CMD_TIMEOUT, COST, SCALE_N |
| 2552 |
ap = argparse.ArgumentParser() |
| 2553 |
ap.add_argument("--rsync-a", default="./rsync") |
| 2554 |
ap.add_argument("--rsync-b", default="old_versions/rsync_3.4.1") |
| 2555 |
ap.add_argument("--rrsync-a", default=None, |
| 2556 |
help="rrsync wrapper script paired with A for the rrsync lane " |
| 2557 |
"(default: in-tree support/rrsync)") |
| 2558 |
ap.add_argument("--rrsync-b", default=None, |
| 2559 |
help="rrsync wrapper paired with B (e.g. a baseline version's " |
| 2560 |
"rrsync); rrsync regressions live in the script, so this " |
| 2561 |
"must match B's version to A/B the rrsync lane") |
| 2562 |
ap.add_argument("--sweep", default="all", |
| 2563 |
choices=["options", "pathshape", "recv", "destshape", |
| 2564 |
"name", "filesfrom", "intree", "intree2", "proto", |
| 2565 |
"combo", "combo3", "combo4", "scale", "ssh", |
| 2566 |
"daemon", "daemonchroot", "mode", "size", |
| 2567 |
"filetype", "selection", "behavior", "placement", |
| 2568 |
"wire", "pairwise", "daemonsym", "daemonpull", |
| 2569 |
"daemonesc", "misc", "gaps", "redo", "typetrans", |
| 2570 |
"tsprec", "bigscale", "rrsync", "tcpdaemon", |
| 2571 |
"priv", "all"]) |
| 2572 |
ap.add_argument("--workdir", default="/tmp/abdiff") |
| 2573 |
ap.add_argument("--findings", default="abdiff-findings.txt") |
| 2574 |
ap.add_argument("--only", default=None, help="run only scenarios containing this substring") |
| 2575 |
ap.add_argument("--keep", action="store_true") |
| 2576 |
ap.add_argument("--list", action="store_true") |
| 2577 |
ap.add_argument("--matrix", action="store_true", |
| 2578 |
help="run the cross-build role matrix (mixed A<->B, " |
| 2579 |
"push+pull, ssh+daemon) instead of the sweeps") |
| 2580 |
ap.add_argument("--fuzz", type=int, default=0, metavar="N", |
| 2581 |
help="stochastic differential fuzzer: N random " |
| 2582 |
"fixture/option/transport/direction/version-pair configs") |
| 2583 |
ap.add_argument("--seed", type=int, default=1, help="fuzz RNG seed") |
| 2584 |
ap.add_argument("--repeat", type=int, default=REPEAT, metavar="N", |
| 2585 |
help="stability gate: run each binary N times per scenario; " |
| 2586 |
"scenarios whose own runs disagree are quarantined FLAKY " |
| 2587 |
"(default 2; use 1 to disable, 3+ to catch rarer flakes)") |
| 2588 |
ap.add_argument("-j", "--jobs", type=int, default=20, metavar="N", |
| 2589 |
help="run N scenarios in parallel (default 20)") |
| 2590 |
ap.add_argument("--loop", action="store_true", |
| 2591 |
help="after the fixed sweeps, keep generating new randomized + " |
| 2592 |
"higher-order-combo scenarios indefinitely (Ctrl-C to stop)") |
| 2593 |
ap.add_argument("--cmd-timeout", type=int, default=CMD_TIMEOUT, metavar="SECS", |
| 2594 |
help="per-rsync wall-clock timeout; 0 disables (default 120)") |
| 2595 |
ap.add_argument("--log-dir", default=".", |
| 2596 |
help="directory for the full per-run abdiff-log_<TIME>.txt " |
| 2597 |
"(default: current directory)") |
| 2598 |
ap.add_argument("--cost", action="store_true", |
| 2599 |
help="also compare peak process-group RSS (resource oracle); " |
| 2600 |
"flags only gross, stable A-worse blow-ups. Pair with " |
| 2601 |
"--sweep bigscale --scale N.") |
| 2602 |
ap.add_argument("--scale", type=int, default=SCALE_N, metavar="N", |
| 2603 |
help=f"element count for the bigscale fixtures (default {SCALE_N}; " |
| 2604 |
"use e.g. 100000 with --cost to surface footprint regressions)") |
| 2605 |
ap.add_argument("--timelimit", type=float, default=0, metavar="SECS", |
| 2606 |
help="stop after SECS seconds (0 = no limit); in --loop it ends " |
| 2607 |
"the loop, in a finite sweep it stops queuing new scenarios. " |
| 2608 |
"In-flight scenarios finish, then a summary is written.") |
| 2609 |
ap.add_argument("--root-extra", dest="root_extra", action="store_true", |
| 2610 |
default=None, |
| 2611 |
help="with --sweep all, also include the root-only sweeps " |
| 2612 |
"(priv, daemonchroot); auto-on when running as root") |
| 2613 |
args = ap.parse_args() |
| 2614 |
RSYNC_A = os.path.abspath(args.rsync_a) |
| 2615 |
RSYNC_B = os.path.abspath(args.rsync_b) |
| 2616 |
RRSYNC_A = os.path.abspath(args.rrsync_a) if args.rrsync_a else None |
| 2617 |
RRSYNC_B = os.path.abspath(args.rrsync_b) if args.rrsync_b else None |
| 2618 |
KEEP = args.keep |
| 2619 |
REPEAT = args.repeat |
| 2620 |
CMD_TIMEOUT = args.cmd_timeout |
| 2621 |
COST = args.cost |
| 2622 |
SCALE_N = args.scale |
| 2623 |
|
| 2624 |
if args.matrix or args.fuzz: |
| 2625 |
workroot = Path(args.workdir) |
| 2626 |
workroot.mkdir(parents=True, exist_ok=True) |
| 2627 |
fp = Path(args.findings) |
| 2628 |
fp.parent.mkdir(parents=True, exist_ok=True) |
| 2629 |
logf = open(fp, "a", buffering=1) |
| 2630 |
ld = Path(args.log_dir) |
| 2631 |
ld.mkdir(parents=True, exist_ok=True) |
| 2632 |
runlog_path = ld / f"abdiff-log_{time.strftime('%Y%m%d_%H%M%S')}.txt" |
| 2633 |
runlog = open(runlog_path, "a", buffering=1) |
| 2634 |
mode = "FUZZ" if args.fuzz else "MATRIX" |
| 2635 |
header = (f"\n===== abdiff {mode} {time.strftime('%Y-%m-%d %H:%M:%S')} " |
| 2636 |
f"A={RSYNC_A} B={RSYNC_B} =====\n") |
| 2637 |
logf.write(header) |
| 2638 |
runlog.write(header) |
| 2639 |
print(f"A (under test): {RSYNC_A}\nB (baseline): {RSYNC_B}\n" |
| 2640 |
f"full log: {runlog_path}\n") |
| 2641 |
tee = _Tee(logf, runlog) |
| 2642 |
n = (run_fuzz(workroot, tee, args.fuzz, args.seed) if args.fuzz |
| 2643 |
else run_matrix(workroot, tee)) |
| 2644 |
logf.close() |
| 2645 |
runlog.close() |
| 2646 |
return 1 if n else 0 |
| 2647 |
|
| 2648 |
sweeps = ALL_SWEEPS if args.sweep == "all" else [args.sweep] |
| 2649 |
|
| 2650 |
|
| 2651 |
root_extra = args.root_extra if args.root_extra is not None else (os.geteuid() == 0) |
| 2652 |
if args.sweep == "all" and root_extra: |
| 2653 |
sweeps = sweeps + ["priv", "daemonchroot"] |
| 2654 |
if COST: |
| 2655 |
sweeps = sweeps + ["bigscale"] |
| 2656 |
scns = [] |
| 2657 |
for s in sweeps: |
| 2658 |
scns += SWEEPS[s]() |
| 2659 |
if args.only: |
| 2660 |
scns = [s for s in scns if args.only in s.name] |
| 2661 |
if args.list: |
| 2662 |
for s in scns: |
| 2663 |
print(s.name, s.opts) |
| 2664 |
return 0 |
| 2665 |
|
| 2666 |
print(f"A (under test): {RSYNC_A} ({sh([RSYNC_A,'--version']).stdout.splitlines()[0] if sh([RSYNC_A,'--version']).returncode==0 else '?'})") |
| 2667 |
print(f"B (baseline): {RSYNC_B} ({sh([RSYNC_B,'--version']).stdout.splitlines()[0]})") |
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
workroot = Path(os.path.abspath(args.workdir)) |
| 2673 |
workroot.mkdir(parents=True, exist_ok=True) |
| 2674 |
|
| 2675 |
|
| 2676 |
fp = Path(args.findings) |
| 2677 |
fp.parent.mkdir(parents=True, exist_ok=True) |
| 2678 |
logf = open(fp, "a", buffering=1) |
| 2679 |
logf.write(f"\n===== abdiff run {time.strftime('%Y-%m-%d %H:%M:%S')} " |
| 2680 |
f"sweep={args.sweep} A={RSYNC_A} B={RSYNC_B} jobs={args.jobs}" |
| 2681 |
f"{' loop' if args.loop else ''} =====\n") |
| 2682 |
logf.flush() |
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
ld = Path(args.log_dir) |
| 2687 |
ld.mkdir(parents=True, exist_ok=True) |
| 2688 |
runlog_path = ld / f"abdiff-log_{time.strftime('%Y%m%d_%H%M%S')}.txt" |
| 2689 |
runlog = open(runlog_path, "a", buffering=1) |
| 2690 |
runlog.write(f"# abdiff findings {time.strftime('%Y-%m-%d %H:%M:%S')}\n" |
| 2691 |
f"# A={RSYNC_A}\n# B={RSYNC_B}\n" |
| 2692 |
f"# sweep={args.sweep} jobs={args.jobs} repeat={REPEAT} " |
| 2693 |
f"loop={args.loop} cmd_timeout={CMD_TIMEOUT}\n") |
| 2694 |
runlog.flush() |
| 2695 |
print(f"findings log: {runlog_path}\njobs: {args.jobs}" |
| 2696 |
f"{' (loop: Ctrl-C to stop)' if args.loop else ''}") |
| 2697 |
|
| 2698 |
def ostr(s): |
| 2699 |
return ' '.join(s.opts) if not callable(s.opts) else '(dynamic)' |
| 2700 |
|
| 2701 |
LABEL = {"OK": "OK ", "SKIP": "SKIP ", "FLAKY": "FLAKY", "ABETTER": "BETTER", |
| 2702 |
"ALLOW": "ALLOW", "DIFF": "DIFF ", "TIMEOUT": "TIME ", "ERROR": "ERROR"} |
| 2703 |
counts = {k: 0 for k in LABEL} |
| 2704 |
done = [0] |
| 2705 |
rec_lock = threading.Lock() |
| 2706 |
|
| 2707 |
def progress(total=None): |
| 2708 |
sys.stdout.write(f"test {done[0]}{('/' + str(total)) if total else ''}" |
| 2709 |
f"{(' ' + str(counts['DIFF']) + ' DIFF') if counts['DIFF'] else ''}\r") |
| 2710 |
sys.stdout.flush() |
| 2711 |
|
| 2712 |
def record(s, status, info, total=None): |
| 2713 |
if isinstance(info, str): |
| 2714 |
info = [info] |
| 2715 |
|
| 2716 |
|
| 2717 |
if status == "DIFF" and any("[abdiff: TIMEOUT]" in ln for ln in info): |
| 2718 |
status = "TIMEOUT" |
| 2719 |
with rec_lock: |
| 2720 |
counts[status] = counts.get(status, 0) + 1 |
| 2721 |
done[0] += 1 |
| 2722 |
if status not in ("OK", "SKIP"): |
| 2723 |
sys.stdout.write("\r") |
| 2724 |
print(f"{LABEL.get(status, status)} {s.name} [#{done[0]}]") |
| 2725 |
for line in info: |
| 2726 |
print(line) |
| 2727 |
suffix = (" *** REGRESSION CANDIDATE ***" |
| 2728 |
if status in ("DIFF", "TIMEOUT", "ERROR") else "") |
| 2729 |
for f in (runlog, logf): |
| 2730 |
f.write(f"\n{status} {s.name} opts: {ostr(s)}{suffix}\n") |
| 2731 |
for line in info: |
| 2732 |
f.write(line + "\n") |
| 2733 |
f.flush() |
| 2734 |
progress(total) |
| 2735 |
|
| 2736 |
def worker(s): |
| 2737 |
try: |
| 2738 |
return run_scenario(s, workroot) |
| 2739 |
except Exception as ex: |
| 2740 |
return ("ERROR", [f" exception: {ex!r}"]) |
| 2741 |
|
| 2742 |
def summary_line(prefix): |
| 2743 |
return (f"{prefix} {counts['OK']} OK, {counts['SKIP']} skipped, " |
| 2744 |
f"{counts['FLAKY']} FLAKY, {counts['ALLOW']} ALLOW (intentional), " |
| 2745 |
f"{counts['ABETTER']} BETTER (A>B), {counts['TIMEOUT']} TIMEOUT, " |
| 2746 |
f"{counts['ERROR']} ERROR, {counts['DIFF']} DIFF " |
| 2747 |
f"(regression candidates) ===") |
| 2748 |
|
| 2749 |
deadline = (time.time() + args.timelimit) if args.timelimit else None |
| 2750 |
if deadline: |
| 2751 |
print(f"time limit: {args.timelimit:.0f}s\n") |
| 2752 |
|
| 2753 |
if not args.loop: |
| 2754 |
total = len(scns) |
| 2755 |
print(f"scenarios: {total}\n") |
| 2756 |
with ThreadPoolExecutor(max_workers=args.jobs) as ex: |
| 2757 |
futs = {ex.submit(worker, s): s for s in scns} |
| 2758 |
for fut in as_completed(futs): |
| 2759 |
status, info = fut.result() |
| 2760 |
record(futs[fut], status, info, total=total) |
| 2761 |
if deadline and time.time() > deadline: |
| 2762 |
print("\n[time limit reached -- cancelling pending scenarios]") |
| 2763 |
for p in futs: |
| 2764 |
p.cancel() |
| 2765 |
break |
| 2766 |
summary = summary_line("===") |
| 2767 |
print("\n" + summary) |
| 2768 |
runlog.write("\n" + summary + "\n") |
| 2769 |
logf.write(summary + "\n") |
| 2770 |
runlog.close() |
| 2771 |
logf.close() |
| 2772 |
return 1 if (counts['DIFF'] or counts['TIMEOUT'] or counts['ERROR']) else 0 |
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
rnd = random.Random(args.seed) |
| 2777 |
seen = set() |
| 2778 |
mixed = _mixed_scenarios(rnd, seen) |
| 2779 |
fixed = iter(scns) |
| 2780 |
|
| 2781 |
def next_scn(): |
| 2782 |
try: |
| 2783 |
return next(fixed) |
| 2784 |
except StopIteration: |
| 2785 |
return next(mixed) |
| 2786 |
|
| 2787 |
ex = ThreadPoolExecutor(max_workers=args.jobs) |
| 2788 |
inflight = {} |
| 2789 |
|
| 2790 |
def submit_one(): |
| 2791 |
s = next_scn() |
| 2792 |
inflight[ex.submit(worker, s)] = s |
| 2793 |
|
| 2794 |
try: |
| 2795 |
for _ in range(args.jobs * 2): |
| 2796 |
submit_one() |
| 2797 |
while True: |
| 2798 |
fdone, _pending = wait(list(inflight), return_when=FIRST_COMPLETED) |
| 2799 |
for fut in fdone: |
| 2800 |
s = inflight.pop(fut) |
| 2801 |
status, info = fut.result() |
| 2802 |
record(s, status, info) |
| 2803 |
if not (deadline and time.time() > deadline): |
| 2804 |
submit_one() |
| 2805 |
if deadline and time.time() > deadline and not inflight: |
| 2806 |
print("\n[time limit reached -- writing summary]") |
| 2807 |
break |
| 2808 |
except KeyboardInterrupt: |
| 2809 |
print("\n[interrupted -- cancelling pending, writing summary]") |
| 2810 |
ex.shutdown(wait=False, cancel_futures=True) |
| 2811 |
finally: |
| 2812 |
summary = summary_line("=== loop stopped:") |
| 2813 |
print("\n" + summary) |
| 2814 |
runlog.write("\n" + summary + "\n") |
| 2815 |
runlog.flush() |
| 2816 |
logf.write(summary + "\n") |
| 2817 |
logf.flush() |
| 2818 |
runlog.close() |
| 2819 |
logf.close() |
| 2820 |
return 1 if counts['DIFF'] else 0 |
| 2821 |
|
| 2822 |
|
| 2823 |
if __name__ == "__main__": |
| 2824 |
sys.exit(main()) |