Skip to content

test(gfx): assert hue ramps are continuous instead of printing them (#668) - #3809

Merged
zackees merged 1 commit into
masterfrom
test/rainbow-ramp-continuity-668
Aug 1, 2026
Merged

zackees merged 1 commit into
masterfrom
test/rainbow-ramp-continuity-668

Conversation

@zackees

@zackees zackees commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Closes #668.

The finding

tests/fl/hsv2rgb_accuracy.cpp had a test case named "HSV to RGB Conversion - Hue Sweep Test". It contained no assertion — 22 lines of FL_WARN printing 64 sampled rows, then nothing. It could not have failed for any input, on any platform, ever.

It also stepped the hue by 4:

// Increased step from 1 to 4 for performance (256 -> 64 iterations = 75% reduction)
// Still provides excellent hue sweep coverage with 64 samples
for (int hue = 0; hue < 256; hue += 4) {

A single bad hue is the entire failure mode here, and sampling steps right over it. So the test was doubly unable to catch what it nominally covered.

Why that matters for #668

#668 (2018) reported one unexpected red pixel partway through the yellow region of a 114-LED strip filled with fill_rainbow(leds, 114, hue, 1), reproduced across three Nanos and two strips.

hsv2rgb_rainbow is a hand-written piecewise function: eight 32-hue sections selected by bit tests on the hue, joined by magic constants (K85/K170/K171) and compile-time switches (Y1/Y2/G2/Gscale). Nothing structurally forces one section to end on the value the next one starts from — a wrong constant surfaces as exactly one off-colour pixel mid-ramp.

The change

Walk every adjacent hue pair, including the 255→0 wrap, and bound the per-channel step, for all three converters. Plus a case reproducing #668's exact call.

Measured maxima at full saturation/value:

converter max per-channel step
rainbow 6
spectrum 4
fullspectrum 6

Bound set at 8 — room to nudge a constant without hiding a real break, which is tens.

Verified the test can fail

The point of this PR is a test that fails on the bug it targets, so I injected one. Changing K171 → 151 in the O→Y section:

WARN: rainbow: discontinuity of 21 between hue 31 and 32 (allowed 8)
FAIL: HSV to RGB Conversion - hue ramps have no discontinuity
FAIL: fill_rainbow has no isolated off-colour pixel (issue #668)

It pinpoints the exact section boundary and the magnitude, and both cases fire. Reverted before commit.

Status of #668 itself

It does not reproduce. The current ramps are continuous everywhere — sections join within 6/255 at every boundary. The colour math is sound today; this pins it so it stays that way.

Validation

check result
bash test --cpp 275/275 unit, 83/83 examples pass
bash lint clean
mutation test fails as shown above

Tests-only change; no src/ diff.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded color accuracy testing across all HSV-to-RGB conversion methods.
    • Added exhaustive checks for smooth color transitions between adjacent hues.
    • Added rainbow animation continuity coverage across a 114-LED sequence.
    • Tests now identify excessive per-channel color changes and fail when configured limits are exceeded, helping prevent visible color flicker or discontinuities.

…668)

The "HSV to RGB Conversion - Hue Sweep Test" contained no assertion. It
printed 64 sampled rows through FL_WARN and always passed, so it could
not have failed for any input. It also stepped the hue by 4, meaning a
single bad hue -- the entire failure mode it nominally covered -- fell
between samples.

That is precisely the defect #668 reported in 2018: one unexpected red
pixel partway through the yellow region of a 114-LED fill_rainbow strip.

Replace it with a check that walks every adjacent hue pair, including
the 255->0 wrap, and bounds the per-channel step. Measured maxima at
full saturation/value are rainbow=6, spectrum=4, fullspectrum=6; the
bound is 8, leaving room to nudge a constant without hiding a break.

The ramps are hand-written piecewise functions -- eight 32-hue sections
chosen by bit tests, joined by magic constants (K85/K170/K171) and
compile-time switches (Y1/Y2/G2/Gscale). Nothing structurally forces a
section to end on the value the next one begins from, so a wrong
constant surfaces as exactly one off-colour pixel.

Verified the new test fails on the bug it targets: changing K171 to 151
in the O->Y section reports "rainbow: discontinuity of 21 between hue 31
and 32" and fails both cases. The current ramps are continuous, so #668
no longer reproduces -- this pins that.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f428f6e2-61bc-42e0-88ce-6739acc891af

📥 Commits

Reviewing files that changed from the base of the PR and between 26df858 and 5b86661.

📒 Files selected for processing (1)
  • tests/fl/hsv2rgb_accuracy.cpp

📝 Walkthrough

Walkthrough

The HSV-to-RGB accuracy tests now replace sampled hue diagnostics with exhaustive adjacent-hue continuity checks. They also validate continuity across 114 pixels generated by fill_rainbow.

Changes

HSV/RGB continuity validation

Layer / File(s) Summary
Exhaustive hue continuity checks
tests/fl/hsv2rgb_accuracy.cpp
The tests measure adjacent hue transitions, including the 255-to-0 wrap, across all HSV-to-RGB converters. They report the worst channel transition and fail when it exceeds 8. The tests also check 114-pixel fill_rainbow output for isolated color jumps.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/rainbow-ramp-continuity-668

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit a0a078d into master Aug 1, 2026
4 checks passed
@zackees
zackees deleted the test/rainbow-ramp-continuity-668 branch August 1, 2026 17:12
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Aug 1, 2026
@zackees

zackees commented Aug 1, 2026

Copy link
Copy Markdown
Member Author

Correcting a claim in the description above, since leaving it would be worse than the gap it papers over.

I wrote that #668 "does not reproduce" and that "the colour math is sound." That is wrong about the cause. #668 did reproduce, and #3808 — merged shortly before this — is its actual fix: hsv2rgb_rainbow has three paths that call scale8_video_LEAVING_R1_DIRTY and then return without cleanup_R1(), leaving AVR's __zero_reg__ non-zero in violation of the ABI. That explains every reported symptom, including why the bad pixel moved under recompilation and why it showed on three different Nanos.

What I actually measured was that the ramps are continuous in the native build. That is a different property, and it could never have caught #668: the R1 hazard is AVR-only inline-asm ABI damage, invisible to a host-compiled test.

So, to be precise about what this PR does and does not do:

  • Does: replace an assertion-free FL_WARN loop with a real check, and pin section-boundary continuity of the three hue ramps.
  • Does not: cover the AVR LEAVING_R1_DIRTY / cleanup_R1() contract. Nothing here would fail if a fourth such path were introduced tomorrow.

That second gap is the more valuable target and wants a different mechanism — a lint or AST check pairing every *_LEAVING_R1_DIRTY call against a cleanup_R1() on all reachable exits, rather than a runtime test. Filing that separately.

The continuity guard still stands on its own merits (verified failing via the injected-constant mutation above); it just should not be read as coverage of #668's root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fill_rainbow() - Unexpected red pixel

1 participant