Skip to content

Testing

codingncaffeine edited this page Sep 2, 2026 · 15 revisions

Testing

Everything is measured; nothing is promised. ctest --test-dir build --output-on-failure runs all of it.

Unit tests

One test program per subsystem under tests/ (test_layout, test_flex, test_floats, test_forms, test_style_resolver, test_css_parser, test_http, test_connections, test_cache, test_cookies, test_png, test_jpeg, test_gif, test_truetype, test_rasterizer, test_font_manager, and the rest), written with a small CHECK/CHECK_EQ harness. Network tests serve loopback HTTP from a thread and never touch the network. Codec tests build their inputs by hand — the JPEG test carries its own baseline and progressive encoders — and the PNG test re-decodes the encoder's output through an independent inflate.

Conformance suites

Suite Score How it is held
html5lib tokenizer 7032 / 7032 A baseline that only ratchets upward
html5lib tree construction 1784 / 1784 The same
WPT urltestdata 893 / 893 The same
WPT CSS reference tests see Measurements tests/wpt/passing.txt names every passing test; a listed test that fails is a regression and fails CI

Reference tests

tests/pages/*.html render to PNGs compared byte for byte against tests/goldens/*.png, on Linux, Windows and macOS, with gcc and with clang. They use the built-in face only, so a golden is one file for every platform. Re-bless with build/tests/reftest tests/pages tests/goldens --update after reading the new picture.

Shell scripts

tests/shell/*.script drive the headless shell (see Scripting the shell); their chrome screenshots are goldens too, compared the same way. live.script needs the network and is run by hand.

The WPT CSS reference tests

bash tools/wpt-fetch.sh                      # a shallow, sparse checkout at tests/wpt/REVISION
build/tests/wpt_reftest wpt tests/wpt/directories.txt tests/wpt/passing.txt --revision tests/wpt/REVISION

The runner reads the suite's own manifest rules (reference names, -manual/-visual/-crash/-print flags), serves the pages as if from http://web-platform.test:8000/ so shared references and the Ahem font resolve with no network, follows <link rel="match"> and <link rel="mismatch"> chains the way wptrunner does, honors the fuzzy-meta allowances, and renders everything at 800×600 with the built-in face plus the page's own fonts. The whole suite — over 13,000 tests, 20,000 renders — takes about 25 seconds.

Flag Does
--only <substring> Run the matching tests only (the baseline is not enforced)
--dump <dir> Write the test and reference PNGs of every failure — the instrument
--print N Print up to N failures
--update Re-bless the baseline
--json <file>, --html <file> Write the per-directory table (docs/wpt.json, docs/wpt.html)
SASHFOLD_WPT_TRACE=1 Print each render as it starts, to find a hang

A pixel comparison between two renders of the same engine passes when both are equally wrong, so passes are spot-checked with --dump too, and every test that flips is explained before the baseline moves.

Fuzzing

libFuzzer harnesses under fuzz/ for the HTML tokenizer and tree builder, the CSS tokenizer and parser, the URL parser, inflate, the HTTP response parser, and the PNG, GIF, JPEG and TrueType readers, with seed corpora. CI runs them as a smoke pass on every push; the sanitizer lane runs the whole test suite under AddressSanitizer and UndefinedBehaviorSanitizer.

The two checks

tools/pledge-check.sh (the binary's imports against the per-OS allowlist) and tools/egress-check.sh (network primitives behind the one choke point) run in CI and in bash tools/buildall.sh. See The Pledge.

Instruments

  • --dump-layout on --render prints the fragment tree; --report writes a JSON account of a load; --bench times the phases. See Running Sashfold.
  • --dump-dom prints the parsed tree; --font-info, --font-list and --font-sampler show what the font code sees.

Clone this wiki locally