Repository navigation
Check test images against stored fuzzy fingerprints - #26
Conversation
fpm test now checks every PNG and every GIF frame the tests write against a fingerprint stored in tests/fingerprints.txt, so the test suite catches changed pictures without Python, matplotlib or reference images. Each image becomes 64 words of 64 bits, one word per tile, computed with integer arithmetic only: ink splatted onto a 160x128 cell grid, a discrete Laplacian, then sparse random projections quantized with a period so that a bit flips in proportion to how much its projection changed. A case fails when any word differs in more than 10 bits. Compiler rounding noise (one intensity level on thousands of antialiased pixels) moves a word by at most 6 bits; a tick moved by 1 px, a missing label or a typo in a title move it by 18 to 40. Regenerate the fingerprints after an intended change with fpm test -- --update.
|
@jalvesz let me know what you think. I fixed LFortran, but must make a new release and get it into conda, so that we can use it here. |
|
Hi @certik I think this looks pretty good. I wonder if instead of a single file containing all the fingerprints, there should be one per image ? That could facilitate running the tests in parallel |
|
The finger print file is only read, right? So it can run in parallel? But we could save the fingerprint into the test file itself, that's another option. And automatically update with a script. |
LFortran 0.66.0 fixes lfortran/lfortran#12788, which made legend_labels fail its fingerprint, so the LFortran test step runs again. conda-forge builds LFortran 0.66.0 against clang 21 and flang 22 against clang 22, and the two cannot be installed together. LFortran therefore gets its own pixi environment; its tasks are defined only there, so `pixi run test-lfortran` and `pixi run fpm-lfortran` select it without naming it. The default environment keeps flang and loses nothing else.
|
I tested this by hand locally and it seems to work. Omitting a label or changing a label from |
fpm test(andpixi run test-flang/test-lfortran) now checks every PNG and GIF frame written bytests/test_plots.f90against a 4096-bit fingerprint stored intests/fingerprints.txt(150 kB). No Python, matplotlib or reference images are needed.How it works (
tests/test_fingerprint.f90, integer arithmetic only): ink is spread onto a 160×128 cell grid, a discrete Laplacian is taken, and each of the 64 tiles gets a 64-bit word. Each bit is the parity of a sparse random projection divided by a fixed period. A case fails when any word differs in more than 10 bits, and the report names the image region.tests/test_image_io.f90decodes the PNG and GIF files, so the encoders are covered too.Measured locally (macOS):
fpm test) and flang: all 144 images identical to the stored fingerprints.bar3d), limit 10.-O3vs-O0: 105 images differ by one intensity level on up to 21,000 pixels, which moves no word by more than 6 bits.Known failures this exposes:
legend_labels(a constant substring of a character component with a default initializer was read from the initializer, so a line labelled_hiddenappeared in the legend), reported as Wrong value for constant substring of character component with default initialization lfortran/lfortran#12788. Fixed in LFortran 0.66.0, which this PR now uses; theTest with LFortranCI step runs and passes (largest difference 5 bits).fpm test --profile release(gfortran-O3) fails 6 cases (clabel,quiver3d,trisurf,mosaic,subplots_2x2,subplots_shared). These are numerical-robustness bugs in fplot (tick labels0.0vs0, contour label placement) and will be fixed separately.After an intended change of the pictures:
fpm test -- --update.LFortran 0.66.0 and pixi environments: conda-forge builds LFortran 0.66.0 against clang 21 and flang 22 against clang 22, which cannot be installed together. LFortran now has its own pixi environment (
lfortran), and its tasks are defined only there, sopixi run test-lfortranandpixi run fpm-lfortranselect it by themselves. The default environment keeps flang; the only packages it loses are LFortran and its runtime dependencies. CI installs both environments.