Debian Codegraph @

testsuite/compress-options_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Breadth coverage of the algorithm-selection options at depth:
3 --compress-choice / --compress-level / --skip-compress and
4 --checksum-choice / --checksum-seed.
5
6 Compression and checksum choice don't change the result, so each available
7 algorithm is exercised for a clean, byte-identical transfer of a >=3-deep tree
8 (proving the option parses, negotiates and doesn't corrupt data).
9 """
10
11 import json
12 import re
13
14 from rsyncfns import (
15 FROMDIR, TODIR,
16 assert_same, make_tree, rmtree, run_rsync, test_fail, walk_files,
17 )
18
19 src = FROMDIR
20 vv = json.loads(run_rsync('-VV', check=True, capture_output=True).stdout)
21 compressors = [a for a in vv.get('compress_list', []) if a != 'none']
22 checksums = [a for a in vv.get('checksum_list', []) if a != 'none']
23
24
25 def fresh():
26 rmtree(src)
27 rmtree(TODIR)
28 make_tree(src, depth=3, data=True, data_size=4096)
29 return [p.relative_to(src) for p in walk_files(src)]
30
31
32 def verify(rels, label):
33 for rel in rels:
34 assert_same(TODIR / rel, src / rel, label=f'{label} {rel}')
35
36
37 # --- --compress-choice for every advertised compressor ----------------------
38 # Byte-identical output alone proves only that the option didn't corrupt data;
39 # assert via --debug=NSTR (compat.c) that the requested compressor was actually
40 # selected for the transfer. The trailing " (level" anchors so zlib != zlibx.
41 for algo in compressors:
42 rels = fresh()
43 proc = run_rsync('-az', f'--compress-choice={algo}', '--debug=NSTR',
44 f'{src}/', f'{TODIR}/', capture_output=True)
45 if not re.search(rf'compress: {re.escape(algo)} \(level', proc.stdout):
46 test_fail(f"--compress-choice={algo} was not the selected compressor; "
47 f"--debug=NSTR output:\n{proc.stdout}")
48 verify(rels, f'--compress-choice={algo}')
49
50 # --- --compress-level (the requested level reaches the compressor) ----------
51 rels = fresh()
52 # The default compressor can be lz4, which has no tunable levels and reports
53 # level 0; pick a level-aware compressor so this verifies --compress-level reaches
54 # a compressor that supports it.
55 level_algo = next((a for a in ('zlibx', 'zlib') if a in compressors), None)
56 level_args = [f'--compress-choice={level_algo}'] if level_algo else []
57 proc = run_rsync('-az', *level_args, '--compress-level=9', '--debug=NSTR',
58 f'{src}/', f'{TODIR}/', capture_output=True)
59 if not re.search(r'compress: \S+ \(level 9\)', proc.stdout):
60 test_fail("--compress-level=9 was not applied; "
61 f"--debug=NSTR output:\n{proc.stdout}")
62 verify(rels, '--compress-level=9')
63
64 # --- --skip-compress (the file must still arrive intact) --------------------
65 rels = fresh()
66 (src / 'd1' / 'd2' / 'x.gz').write_bytes(b'\x1f\x8b' + b'pseudo gzip body ' * 64)
67 run_rsync('-az', '--skip-compress=gz', f'{src}/', f'{TODIR}/')
68 assert_same(TODIR / 'd1' / 'd2' / 'x.gz', src / 'd1' / 'd2' / 'x.gz',
69 label='--skip-compress gz')
70
71 # --- --checksum-choice for every advertised checksum ------------------------
72 # As above: assert via --debug=NSTR (checksum.c) that the requested checksum was
73 # the one negotiated, not merely that the transfer succeeded.
74 for algo in checksums:
75 rels = fresh()
76 proc = run_rsync('-a', '-c', f'--checksum-choice={algo}', '--debug=NSTR',
77 f'{src}/', f'{TODIR}/', capture_output=True)
78 if not re.search(rf'checksum: {re.escape(algo)}\b', proc.stdout):
79 test_fail(f"--checksum-choice={algo} was not the selected checksum; "
80 f"--debug=NSTR output:\n{proc.stdout}")
81 verify(rels, f'--checksum-choice={algo}')
82
83 # --- --checksum-seed --------------------------------------------------------
84 rels = fresh()
85 run_rsync('-a', '-c', '--checksum-seed=12345', f'{src}/', f'{TODIR}/')
86 verify(rels, '--checksum-seed')
87
88 print("compress-options: compress/checksum algorithm selection verified at depth")