Add visual regression harness for all 547 widgets (tools/visreg)

One command rebuilds every examples Widget.cpp, re-renders it under
Xvfb, and diffs the screenshot against its golden with ImageMagick
RMSE (0.5 pct threshold):

  tools/visreg/run.sh     (also: make visreg)

Reuses the cdoc docs sweep render path (same g++ flags, same
Widget - XFrame demo window capture with the root-capture fallback).
Goldens vendored from /opt/lightgui-docs/shots (Dec 2, 2026). Report goes
to tools/visreg/report/report.txt (plus report.tsv and shots/); exit code
is 0 only when every gated widget passes.

Two deliberate behaviours, both documented in tools/visreg/README.md:
- failed shots are retried 3x (transient XOpenDisplay flakes; the docs
  sweep needed a retry pass for the same four widgets)
- TTimeEdit, TDateEdit and TCalendar render the wall clock, so they are
  reported SKIP (RMSE recorded, not gated) instead of FAIL

Baseline full run (Dec 2, 2026, HEAD beec92b): 544 PASS, 3 SKIP, 0 FAIL;
max RMSE among PASS 0.0000 pct (every passing widget pixel-identical).
This commit is contained in:
cnmcdee committed 2026-12-02 09:38:06 +00:00
1 parent beec92b3ce
commit 7d7fa6cfbc
552 files changed
+467

No files matched your search

+7
View File
@@ -115,3 +115,10 @@ test:
clean: clean:
rm -f lightgui $(OBJS) rm -f lightgui $(OBJS)
rm -rf widgets/build rm -rf widgets/build
# Visual regression: re-render all 547 widget examples under Xvfb, diff
# each screenshot against tools/visreg/golden/ (ImageMagick RMSE, 0.5%
# threshold), write tools/visreg/report/report.txt. Exit code 0 only
# when every widget PASSes. See tools/visreg/README.md.
visreg:
tools/visreg/run.sh
+3
View File
@@ -0,0 +1,3 @@
build/
report/
__pycache__/
+87
View File
@@ -0,0 +1,87 @@
# Visual regression harness (C widgets)
One command, from the repo root:
```sh
tools/visreg/run.sh # full run: build + shoot + diff + report
make visreg # same thing via the Makefile
```
## What it does
1. **Build** — compiles every `examples/<Widget>.cpp` (547) with the same
flags the cdoc docs sweep used (`g++ -std=c++17 -O2 -I widgets/components
-I widgets <src> -lX11`), 8 parallel workers, into `tools/visreg/build/`.
2. **Shoot** — runs each binary under Xvfb `:97`, waits for the
`<Widget> - XFrame demo` window, screenshots it with ImageMagick
`import` (with the docs sweep's root-capture fallback when a
per-window capture comes back black), into `tools/visreg/report/shots/`.
3. **Diff** — compares each new screenshot against its golden in
`tools/visreg/golden/` with `compare -metric RMSE` and reports the
normalised RMSE as a diff percentage.
4. **Report** — writes `tools/visreg/report/report.txt` (per-widget
PASS/FAIL + summary counts) and `report.tsv` (machine-readable).
Exit code is 0 only when every widget PASSes.
## Retries and time-dependent widgets
Shooting is flaky at the edges: a binary occasionally exits before its
window appears (`XOpenDisplay` failing transiently — the docs sweep hit
the same flakes and needed a retry pass). A failed shot is retried up to
3 times before it counts as a failure.
Three widgets render the wall clock, so no golden can match them except
when run in the same minute/day the golden was shot: **TTimeEdit**
(defaults to the current time — two shots 65 s apart differ by 1.23%
RMSE), **TDateEdit** and **TCalendar** (both default to today's date).
They are still shot and diffed and their RMSE is recorded, but the result
is **SKIP** (not gated) rather than FAIL, so a clean tree exits 0. A gross
regression in one still shows up as a large RMSE in its SKIP row.
## Threshold
A widget PASSes when its RMSE is at most **0.5%**. Screenshots differ by
a few pixels run to run from font rendering / anti-aliasing, so exact
matching would false-positive on a clean tree; 0.5% was tuned so a clean
tree passes with headroom — the Dec 2, 2026 baseline run's worst PASS
was 0.0000% (every passing widget pixel-identical to its golden; see the
max-PASS line in `report.txt`) — while any visible draw change scores far
above it. Override per run:
```sh
tools/visreg/run.sh --threshold 0.2
```
## Goldens
`golden/` holds the 547 golden screenshots produced by the docs sweep
(`/opt/lightgui-docs/shots/`, Dec 2, 2026, repo HEAD `93d0fe9`). They are
vendored here so the harness is self-contained. To diff against a
different golden set instead (e.g. a fresh baseline after an intentional
visual change), pass `--golden DIR` or set `VISREG_GOLDEN_DIR`.
To re-baseline after an intentional visual change, copy the new shots
over the goldens and commit them together with the change:
```sh
cp tools/visreg/report/shots/*.png tools/visreg/golden/
```
## Partial runs (no re-render needed to re-tune the threshold)
```sh
python3 tools/visreg/visreg.py --only diff --threshold 0.2 # re-diff saved shots
python3 tools/visreg/visreg.py --only build # rebuild only
python3 tools/visreg/visreg.py --only shoot # re-shoot only
```
`VISREG_DISPLAY` overrides the X display (default `:97`).
## Notes
- `build/` and `report/` are generated and git-ignored; only the harness
code, this README, and `golden/` are committed.
- Shooting is sequential (one X server, one window at a time); a full run
takes roughly 10 minutes, most of it the 0.5 s settle per widget.
- A size mismatch between a new shot and its golden is a FAIL (the RMSE
is still reported, computed after resizing, so the number stays useful).
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 914 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 652 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 990 B

Loaded 100 of 552 files, more files were not shown because too many files have changed in this diff. Show more