Debian Codegraph @

testsuite/README.md

raw symbols SCIP
1 # rsync testsuite
2
3 This directory holds rsync's automated regression tests. Ideally every code
4 change or bug fix comes with a test that would have caught the problem.
5
6 The tests are Python scripts named `testsuite/*_test.py`, driven by the
7 `runtests.py` harness at the top of the tree (the old shell-based `runtests.sh`
8 is gone). Shared helpers live in `testsuite/rsyncfns.py`. A handful of C helper
9 programs (`tls`, `getgroups`, `trimslash`, …) are built alongside `rsync` and
10 used by some tests. Coverage notes are in [COVERAGE.md](COVERAGE.md).
11
12 ## Writing tests
13
14 Favour readability — a test is also documentation of the behaviour it pins, so
15 prefer clarity over cleverness:
16
17 * When a test writes an `rsyncd.conf`, write it as a triple-quoted f-string so
18 the actual config is readable top-to-bottom, with module parameters indented
19 with plain spaces. Don't build it from adjacent string literals full of `\n`
20 (and `\t`) escapes. The daemon's parser accepts space-indented parameters.
21 * Better still, use the structured helpers in `rsyncfns.py` when a stock config
22 will do: `write_daemon_conf(modules, globals)` (per-test modules/params) or
23 `build_rsyncd_conf()` (the four standard modules). They also handle the
24 root-only `uid`/`gid` lines for you (needed so a `use chroot = no` daemon run
25 as root can read a root-owned module).
26 * For config that varies (e.g. those root-only `uid`/`gid` lines), interpolate a
27 single optional block that expands when needed and is an empty string
28 otherwise, rather than splicing pieces together:
29
30 ```python
31 root = get_testuid() == get_rootuid()
32 ids = f"uid = {get_rootuid()}\ngid = {get_rootgid()}" if root else ""
33 conf.write_text(f"""\
34 pid file = {base}/rsyncd.pid
35 use chroot = no
36 {ids}
37 log file = {base}/rsyncd.log
38
39 [m]
40 path = {mod}
41 read only = yes
42 """)
43 ```
44
45 ## Running the tests
46
47 ### Via make
48
49 Run from the build directory:
50
51 - **`make check`** — build the helper programs and run the whole suite in
52 parallel (`CHECK_J`, default 8) against the just-built `./rsync`. You do **not**
53 need `make install` first; indeed you generally should not install before
54 testing. Use `make check CHECK_J=1` to run serially.
55 - **`make check29`** / **`make check30`** — the same, forcing protocol version 29
56 or 30.
57 - **`make installcheck`** — run the suite against the *installed* binary (e.g.
58 `/usr/local/bin/rsync`). Per the GNU standards this does not search `$PATH`.
59 Handy for testing a distribution build.
60 - **`make check-progs`** — (re)build just the C helper programs the tests need,
61 without running anything.
62 - **`make coverage`** / **`coverage-tcp`** / **`coverage-all`** — generate an HTML
63 coverage report (needs `./configure --enable-coverage` and `gcovr`);
64 `coverage-all` merges runs across protocol versions and the tcp transport.
65
66 ### Via runtests.py directly
67
68 `make check` just drives `runtests.py`; run it directly for finer control. It
69 defaults `--rsync-bin` to `./rsync`, so run it from the build directory (or pass
70 `--rsync-bin` / `--tooldir`):
71
72 ```sh
73 ./runtests.py # all tests
74 ./runtests.py chmod-temp-dir # a single test by name
75 ./runtests.py 'xattr*' # a glob of test names
76 ```
77
78 Useful options:
79
80 - `-j N`, `--parallel N` — run up to N tests at once
81 - `--use-tcp` — run daemon tests against a real `rsyncd` on `127.0.0.1` (the
82 default runs them over a stdio pipe). **Read the security warning below before
83 using this on a shared machine.**
84 - `--protocol VER` — force a protocol version
85 - `--preserve-scratch` — keep each test's scratch dir afterwards
86 - `--log-level N`, `--always-log` — more verbose output / show logs for passing tests too
87 - `--stop-on-fail` — stop after the first failure
88 - `--timeout SECS` — per-test timeout (default 300)
89 - `--timing` — after the run, list the tests by wall-clock, slowest first, with
90 the serial sum and the floor set by the single longest test
91 - `--race-timeout SECS` — budget a TOCTOU race test may spend trying to win its
92 race. These are the suite's slowest tests: a race test is a negative oracle,
93 so it passes by spending its *whole* budget (5–15s each by default). Lowering
94 this speeds the suite up and weakens the oracle in equal measure.
95 - `--valgrind`, `--valgrind-opts OPTS` — run rsync under valgrind
96 - `--rsync-bin PATH`, `--tooldir DIR`, `--srcdir DIR` — locate the binary / build / source dirs
97 - `--expect-skipped LIST` — see skip enforcement below
98
99 ### Security warning: `--use-tcp`
100
101 > **⚠️ Do not use `--use-tcp` on a machine with untrusted local users.**
102 >
103 > `--use-tcp` starts a real `rsync` daemon listening on a loopback TCP port
104 > (`127.0.0.1` / `::1`) and **deliberately configures insecure test scenarios**
105 > (daemon modules without authentication, unsafe options enabled, etc.). Loopback
106 > addresses are reachable by *every* local user, so for as long as the tests run,
107 > any other user on the machine can connect to that daemon and exploit those
108 > deliberately-insecure modules — potentially reading or writing files with the
109 > privileges of the user running the tests (which is **root** if you run the suite
110 > as root).
111 >
112 > Only run `--use-tcp` where there are **no possible local users who might try to
113 > exploit it** — a single-user workstation or a dedicated, isolated CI machine.
114 > The default stdio-pipe transport carries no such risk: it talks to the daemon
115 > over a private pipe with nothing listening on the network, so prefer it on any
116 > shared or multi-user host.
117
118 ### Results and exit codes
119
120 Each test prints one result line — `PASS`, `FAIL`, `ERROR`, `SKIP` (with a
121 reason), or `XFAIL` (an expected failure) — and the run ends with a
122 `passed / failed / skipped` summary. Per-test exit-code convention:
123
124 | code | meaning |
125 |------|---------|
126 | 0 | pass |
127 | 1 | fail |
128 | 2 | error |
129 | 77 | skip |
130 | 78 | xfail |
131
132 `runtests.py` exits non-zero if any test fails. Some tests need root or another
133 precondition and otherwise `SKIP` — read the individual test scripts for details.
134
135 **Skip enforcement:** on a full run, set `RSYNC_EXPECT_SKIPPED=a,b,c` (or
136 `--expect-skipped a,b,c`) and the run fails if the set of skipped tests does not
137 match. This is how the CI workflows pin each platform's expected skip set. An
138 `@FILE` entry reads a skip list (one test per line) instead, and several may be
139 composed: the workflows use
140 `@testsuite/skiplist/common.txt,@testsuite/skiplist/linux.txt`. Keeping the
141 lists one-name-per-line is what stops two branches that each add a skipping test
142 from conflicting -- see `testsuite/skiplist/README.md`.
143
144 ### Scratch dirs and debugging
145
146 Each test runs in `testtmp/<name>/`. On failure the scratch directory is left in
147 place (also `--preserve-scratch`); including its logs in a bug report is helpful.
148
149 ### Preconditions
150
151 You need `python3`, `/bin/sh`, and the normal build toolchain. The ACL/xattr
152 tests need the `acl` and `attr` tools (`getfacl`/`setfacl`,
153 `getfattr`/`setfattr`) and skip if they are absent. Some tests need root.
154
155 These tests also run in CI via GitHub Actions (see `.github/workflows/`).
156
157 ## Fleet testing (fleettest.py)
158
159 `testsuite/fleettest.py` builds the committed HEAD of an rsync checkout on a
160 fleet of remote machines over ssh and runs the suite under both transports
161 (stdio-pipe and `--use-tcp`) in parallel, reporting only the *unexpected*
162 results. It is a fast local pre-flight for the GitHub CI matrix: each target
163 mirrors a `.github/workflows/*.yml` job — its configure flags, and the
164 `RSYNC_EXPECT_SKIPPED` list parsed straight from the workflow.
165
166 Because every run includes a `--use-tcp` pass, the fleet stands up the insecure
167 loopback test daemon on each target — so only point it at machines with **no
168 untrusted local users** (see the [security warning](#security-warning---use-tcp)
169 above).
170
171 The fleet — which machines, and how to reach and build on each — is described in
172 a JSON file. Copy the bundled example (it is git-ignored) and edit it for your
173 hosts:
174
175 ```sh
176 cp testsuite/fleettest.json.example testsuite/fleettest.json # then edit
177 # (or symlink it, or point elsewhere with --fleet PATH)
178 ```
179
180 The config is looked up in order: `~/.fleettest.json` first, then
181 `testsuite/fleettest.json`, unless overridden with `--fleet PATH`.
182
183 Each entry names an ssh host (`null` to run locally), the workflow it mirrors,
184 and its configure flags, plus optional per-target settings (`make`, `privilege`,
185 `env_prefix`, …). See the comments in `fleettest.json.example`.
186
187 A target with `"nonroot": true` does an extra pass, after the main (root) run,
188 that reruns the privilege-sensitive tests as the unprivileged ssh user. Which
189 tests those are is **not** listed in the fleet config — a test opts in by
190 setting a module-level `fleet_nonroot = True`, so the set is maintained in the
191 test files and new privilege-sensitive tests join automatically with no
192 fleet-config change.
193
194 A target with `"protocols": [30, 29]` runs one extra stdio-pipe pass per listed
195 version, each forcing that older wire version with `runtests --protocol=N` — the
196 fleet analogue of a workflow's `check30`/`check29` steps. Each pass takes the
197 `RSYNC_EXPECT_SKIPPED` spec from the workflow's own `check30`/`check29` step, so
198 a lane with extra protocol-gated skips (`check29` adds
199 `@testsuite/skiplist/proto29.txt`) is enforced correctly. They show up as
200 `protoNN` columns in the report (and `--timing` breakdown); targets that don't
201 set `protocols` show `-` there.
202
203 Run it from inside a checkout (it builds the current directory's HEAD; use
204 `--repo PATH` for another tree):
205
206 ```sh
207 python3 testsuite/fleettest.py # whole fleet, both transports
208 python3 testsuite/fleettest.py --list # list configured targets
209 python3 testsuite/fleettest.py --targets NAME[,NAME]
210 python3 testsuite/fleettest.py --fleet other.json --transport pipe
211 python3 testsuite/fleettest.py --timing # per-target wall-clock breakdown
212 python3 testsuite/fleettest.py --keep-on-fail # keep logs + tree where it broke
213 python3 testsuite/fleettest.py --full-tcp # whole suite in the tcp pass too
214 ```
215
216 `--timing` adds a per-target breakdown after the report — total wall-clock plus
217 the push / build / pipe / tcp / protoNN / nonroot phases, sorted slowest-first. Targets
218 run in parallel, so the whole run is gated by the slowest one; the phase columns
219 show whether that target's hold-up is the push, the build, or a test pass. It
220 also passes `--timing` down to each target's `runtests.py`, so the captured
221 output attributes a slow pass to individual tests.
222
223 The `tcp` pass runs **only the tests that can reach the daemon transport**, since
224 it follows a full pipe pass over the very same build. `--use-tcp` is observable
225 through exactly one path — `RSYNC_TEST_USE_TCP` is read once in `rsyncfns`
226 (`USE_TCP`) and acted on once, in `start_test_daemon()` — so a test that never
227 gets there produces an identical result twice. That drops 186 of the 340 tests
228 and roughly a third of the pass's work; the count skipped is always printed.
229 Pass `--full-tcp` to sweep the whole suite there anyway. The narrowing applies
230 only when both transports run: under `--transport tcp` that pass is the only
231 one, so it runs the whole suite regardless.
232
233 `--keep-on-fail [DIR]` makes a failure inspectable without repeating the run.
234 For every target that came back with anything unexpected it writes the full
235 build and per-transport output to `DIR/<run_id>/<target>/` (default
236 `./fleettest-logs`) and keeps that target's remote run dir, with the scratch
237 trees its failing tests left behind. Targets that came back clean are swept as
238 usual. This matters most for the race tests, which may not fail the same way
239 twice — and because a re-run costs a full configure + build on every machine.
240
241 Each run gets its own randomly-named build dir on every target
242 (`<builddir>-<run_id>`), so two or three runs can share the same fleet without
243 interfering. The dir is removed when the run ends — on success or failure, and
244 best-effort on Ctrl-C/kill; pass `--keep` to retain it for inspection. A hard
245 kill (`SIGKILL`), or a signal arriving mid-push, can leave a stray
246 `<builddir>-<id>` behind; sweep leftovers with
247 `python3 testsuite/fleettest.py --cleanup` (scope it with `--targets`, and only
248 run it when no other fleet runs are active, since it removes *all* matching run
249 dirs on the selected targets).
250
251 Each target must be provisioned with the build toolchain its workflow installs
252 (autoconf, automake, a C compiler, perl, a python3 markdown module such as
253 cmarkgfm or commonmark unless the flags pass `--disable-md2man`, and the dev
254 libraries its configure flags enable). A missing piece shows up as `BUILD-FAIL`.
255
256 ## Differential regression hunting (abdiff.py)
257
258 `testsuite/abdiff.py` is a developer tool — **not** a `*_test.py`, so `runtests.py`
259 ignores it. It hunts *regressions* by running the **same benign transfer** with
260 two rsync binaries (`A` = the build under test, `B` = a baseline) and comparing
261 the OUTCOME. The oracle is: for a benign input, a correctness/behaviour change
262 between the builds must be **invisible**, so A and B must produce an identical
263 result. Any divergence is a regression candidate to investigate and, if real,
264 minimize into a `*_test.py`.
265
266 It compares exit code, stderr (error markers + normalised text), `--stats`
267 "Literal data", the destination tree (content + full metadata: mode/uid/gid/
268 mtime/size/symlink target/xattrs/ACLs/hardlink grouping), the `--itemize` list,
269 and — with `--cost` — peak process-group RSS (a resource-regression oracle that
270 functional comparison misses). A **stability gate** runs each binary several
271 times and escalates on a candidate diff; nondeterministic scenarios are
272 quarantined `FLAKY`, never reported as regressions.
273
274 Run it from the build directory (so `./rsync` and `old_versions/` resolve):
275
276 ```sh
277 testsuite/abdiff.py # default: ./rsync vs old_versions/rsync_3.4.1
278 testsuite/abdiff.py --sweep all -j5 # broad single pass, 5-way parallel
279 testsuite/abdiff.py --loop --timelimit 3600 --cost # hunt for an hour, resource oracle on
280 testsuite/abdiff.py --list --sweep all # list scenarios without running
281 ```
282
283 Each finding is classed `DIFF` (regression candidate), `ALLOW` (an intentional,
284 documented behaviour change listed in the tool's allowlist), `BETTER` (A succeeds
285 where B fails), `FLAKY`, or `TIMEOUT`. Findings are printed and appended to a
286 per-run `abdiff-log_<TIME>.txt` (and the curated `--findings` log).
287
288 Key options: `-j N` parallelism; `--sweep NAME|all`; `--loop` (endless
289 random + systematic-combo stream) bounded by `--timelimit SECS`; `--cost`
290 (+`--scale N` for the large-tree fixtures); `--repeat N` (stability samples);
291 `--rsync-a`/`--rsync-b` the two binaries. Run **as root** to fold in the
292 owner/device/specials/fake-super and chroot-daemon sweeps automatically.
293
294 Transport lanes (a feature broken only over the wire is invisible to a local
295 copy): local, an ssh split (`support/lsh.sh`), a stdio-pipe daemon, a **real TCP
296 daemon** (bound port + greeting/handshake, and an auth challenge-response
297 variant), and the restricted **rrsync** wrapper (`support/rrsh.sh`). rrsync's
298 behaviour ships in the *script*, so pair each binary with its own version's
299 rrsync via `--rrsync-a`/`--rrsync-b` (give B's rrsync, e.g. one extracted from
300 that release's `support/rrsync`).
301
302 Cross-version baselines are the static binaries already in `old_versions/`;
303 `old_versions/build_static.sh` builds more from a git tag (and you can grab a
304 matching `support/rrsync` from the same tag for the rrsync lane).