| 1 |
|
| 2 |
"""Coverage: cheap one-off paths no other test reaches. |
| 3 |
|
| 4 |
usage.c daemon_usage + help-rsyncd.h -- rsync --daemon --help |
| 5 |
main.c show_malloc_stats / |
| 6 |
flist.c show_flist_stats -- --info=stats3 |
| 7 |
util2.c sum_as_hex / |
| 8 |
checksum.c canonical_checksum -- -c --out-format='%C %n' |
| 9 |
(always_checksum branch) and |
| 10 |
--out-format='%C %n' alone |
| 11 |
(ITEM_TRANSFER branch) |
| 12 |
generator.c start_delete_delay_temp / |
| 13 |
flush_delete_delay -- --delete-delay with enough |
| 14 |
queued deletions to overflow |
| 15 |
the BIGPATHBUFLEN*4 in-memory |
| 16 |
buffer into the temp-file path |
| 17 |
|
| 18 |
Each section asserts the observable behaviour, not just exit==0, so the test |
| 19 |
also guards against regressions in those paths. |
| 20 |
""" |
| 21 |
|
| 22 |
import re |
| 23 |
import subprocess |
| 24 |
|
| 25 |
from rsyncfns import ( |
| 26 |
SCRATCHDIR, makepath, rmtree, rsync_argv, test_fail, |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
def run(*argv, ok=(0,)): |
| 31 |
r = subprocess.run(rsync_argv(*argv), capture_output=True, text=True) |
| 32 |
if r.returncode not in ok: |
| 33 |
test_fail(f"rsync {' '.join(argv)} -> rc={r.returncode}\n{r.stderr}") |
| 34 |
return r |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
r = run('--daemon', '--help') |
| 39 |
if '--no-detach' not in r.stdout or 'rsync --daemon' not in r.stdout: |
| 40 |
test_fail(f"--daemon --help did not emit the daemon usage text:\n{r.stdout}") |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
src = SCRATCHDIR / 'stats-src' |
| 45 |
dst = SCRATCHDIR / 'stats-dst' |
| 46 |
rmtree(src); rmtree(dst); makepath(src, dst) |
| 47 |
for i in range(3): |
| 48 |
(src / f'f{i}').write_bytes(b'x' * (64 + i)) |
| 49 |
r = run('-r', '--info=stats3', f'{src}/', f'{dst}/') |
| 50 |
out = r.stdout + r.stderr |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
import platform |
| 56 |
if platform.system() == 'Linux': |
| 57 |
if 'heap statistics' not in out: |
| 58 |
test_fail(f"--info=stats3 did not emit malloc stats:\n{out}") |
| 59 |
|
| 60 |
if out.count('heap statistics') < 3: |
| 61 |
test_fail(f"--info=stats3 emitted fewer than 3 heap-stat blocks:\n{out}") |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
csrc = SCRATCHDIR / 'csum-src' |
| 66 |
cdst = SCRATCHDIR / 'csum-dst' |
| 67 |
rmtree(csrc); rmtree(cdst); makepath(csrc, cdst) |
| 68 |
payload = b'hello, checksum coverage\n' |
| 69 |
(csrc / 'a').write_bytes(payload) |
| 70 |
(csrc / 'b').write_bytes(payload + b'!') |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
HEX = re.compile(r'^([0-9a-f]{16,128}) (\S+)$', re.M) |
| 77 |
|
| 78 |
def check_C(out, label): |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
sums = dict((m[2], m[1]) for m in HEX.finditer(out)) |
| 84 |
if sums: |
| 85 |
if 'a' not in sums or 'b' not in sums or sums['a'] == sums['b']: |
| 86 |
test_fail(f"{label}: per-file digests not distinct:\n{out!r}") |
| 87 |
return 'hex' |
| 88 |
if not re.search(r'^ {8,} a$', out, re.M): |
| 89 |
test_fail(f"{label}: emitted neither a hex digest nor the " |
| 90 |
f"non-canonical-csum spaces fallback:\n{out!r}") |
| 91 |
return 'spaces' |
| 92 |
|
| 93 |
|
| 94 |
r = run('-rc', '--out-format=%C %n', f'{csrc}/', f'{cdst}/') |
| 95 |
kind_a = check_C(r.stdout, '-c %C') |
| 96 |
|
| 97 |
|
| 98 |
rmtree(cdst); makepath(cdst) |
| 99 |
r = run('-r', '--out-format=%C %n', f'{csrc}/', f'{cdst}/') |
| 100 |
kind_b = check_C(r.stdout, '%C (no -c)') |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
ddsrc = SCRATCHDIR / 'dd-src' |
| 108 |
dddst = SCRATCHDIR / 'dd-dst' |
| 109 |
rmtree(ddsrc); rmtree(dddst); makepath(ddsrc, dddst) |
| 110 |
(ddsrc / 'keep').write_bytes(b'k') |
| 111 |
NAME = 'D' * 80 |
| 112 |
N = 300 |
| 113 |
for i in range(N): |
| 114 |
(dddst / f'{NAME}{i:04d}').write_bytes(b'x') |
| 115 |
r = run('-r', '--delete-delay', f'{ddsrc}/', f'{dddst}/') |
| 116 |
remaining = [p for p in dddst.iterdir() if p.name.startswith(NAME)] |
| 117 |
if remaining: |
| 118 |
test_fail(f"--delete-delay left {len(remaining)}/{N} files " |
| 119 |
f"after the temp-file spill path") |
| 120 |
if not (dddst / 'keep').is_file(): |
| 121 |
test_fail("--delete-delay lost the kept file") |
| 122 |
|
| 123 |
|
| 124 |
print(f"misc-coverage: --daemon --help, --info=stats3, " |
| 125 |
f"%C ({kind_a}/{kind_b}), --delete-delay temp-file spill ({N} entries) ok") |