Skip to content

test(channels): cover the dither phase, which nothing observed (#4347) - #4348

Merged
zackees merged 1 commit into
masterfrom
test/4347-dither-cadence
Sep 11, 2026
Merged

zackees merged 1 commit into
masterfrom
test/4347-dither-cadence

Conversation

@zackees

@zackees zackees commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Addresses the tractable half of #4347. The architecture change there stays open.

Why

docs/color-pipeline-contracts.md asks for this in as many words:

State advances on presentation according to the documented driver contract, with explicit tests for dropped submissions and irregular dwell.

There were none. tests/pixel_controller.cpp drives advanceDitherFrame() to walk a cycle, but nothing observed who advances the phase, or what happens to a frame that never reaches a driver.

Three cases

case pins
onBeginFrame advances once, whatever the channel count the "not once per controller" half of the contract
showLeds() is its own logical frame and advances the difference between the two entry points
a dropped submission still consumes a phase #4347's behaviour, characterised

The middle case exists because I got it wrong

I wrote it expecting three showLeds() calls on three channels to share one phase — "once per logical frame, not once per controller" — and measured four advances against an expected one.

The expectation was wrong, not the code:

  • CFastLED::show() calls onBeginFrame() once, then drives each controller through showLedsInternal(), which does not advance
  • CLEDController::showLeds() — the 3.8.x compatibility path a Channel inherits — calls onBeginFrame() itself

So N such calls are N logical frames, not one frame over N controllers. Both are defensible; the difference is easy to read as a bug, which is why it now has a test rather than being a surprise for the next reader.

The third characterises, it does not endorse

The advance happens at the frame boundary, before encode and before enqueue, so a frame that is never presented spends a phase anyway — contrary to "state advances on presentation". Pinned so that implementing the requirement is a visible change to this file, and so the current behaviour has a name.

Not fixed here for the reason on #4347: advancing on presentation means the counter cannot live at the frame boundary at all, which needs per-channel state or a presentation callback, and P8's dithering deliverable will move this ground anyway.

Removing detail::advanceDitherFrame() fails all three.

bash test --cpp: 304/304 unit, 84/84 examples. bash lint clean. New test file only; no source changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Tests
    • Added test coverage for temporal-dither phase advancement across frame rendering and LED display operations.
    • Verified consistent phase behavior across multiple channels, driver submissions, and disabled channels.

The contracts addendum asks for this directly -- "state advances on
presentation ... with explicit tests for dropped submissions and irregular
dwell" -- and there were none. tests/pixel_controller.cpp drives
advanceDitherFrame() to walk a cycle, but nothing observed who advances the
phase or what happens to a frame that never reaches a driver.

Three cases: onBeginFrame advances once whatever the channel count;
showLeds() is its own logical frame and advances; and a dropped submission
still consumes a phase.

The middle one exists because I got it wrong. I expected three showLeds()
calls on three channels to share one phase -- "once per logical frame, not
once per controller" -- and measured four advances. CFastLED::show() calls
onBeginFrame() once and drives controllers through showLedsInternal(), which
does not advance; CLEDController::showLeds(), the 3.8.x compatibility path a
Channel inherits, calls onBeginFrame() itself. So N such calls are N logical
frames. The expectation was wrong, not the code, and the difference between
the two entry points is worth a test rather than a surprise.

The third characterises rather than endorses: the advance happens at the
frame boundary, before encode and before enqueue, so a frame that is never
presented spends a phase anyway. Pinned so implementing #4347 is a visible
change here rather than a silent one.

Removing the advance fails all three.

bash test --cpp: 304/304 unit, 84/84 examples. bash lint clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8fbc1337-4c85-4fd7-86a6-7eb3deb28c9f

📥 Commits

Reviewing files that changed from the base of the PR and between 574ef41 and 3fe7687.

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

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change adds temporal-dither tests. The tests verify phase advancement for onBeginFrame() and showLeds(), driver submissions, and disabled channels.

Changes

Temporal dither test coverage

Layer / File(s) Summary
Phase advancement coverage
tests/fl/channels/dither_frame.cpp
Adds a counting driver and WS2812 configuration helper. Tests verify one phase advancement per frame callback, one advancement and driver submission per showLeds() call, and phase consumption without submission for disabled channels.

Priority: ⬇️ Low

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

Merge Risk: ⚪ Minimal · up to 3fe76

The added temporal-dither tests cover the intended frame and disabled-channel behavior without changing production code. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies that the pull request adds channel tests for dither phase behavior. The wording is awkward, but the title remains specific and related to the main change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/4347-dither-cadence

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 e02058f into master Sep 11, 2026
6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 11, 2026
zackees added a commit that referenced this pull request Sep 11, 2026
…her (#4347) (#4361)

* test(color): measure what a phase-correlated frame drop costs the dither (#4347)

#4347 records that the dither phase advances on frame attempt, so a frame that
is never presented still consumes one, and then says of the consequence: "The
exposure is entirely about whether drops correlate with phase, and nothing
currently observes that."

Nothing did. This file already measures the dither carefully -- the black
floor, sub-code recovery, the low-code brightening, full-scale exactness -- but
every one of those sums a complete eight-frame cycle, which is exactly the
condition a correlated drop breaks. #4348 pinned who advances the phase and
that a dropped submission consumes one; it did not measure the cost.

At 1/4 brightness with source code 9, where the exact product is 2.26 codes:
the undropped cycle renders 2.38, presenting only even phases renders 2.00,
only odd phases 2.75. So a parity-correlated drop swings the rendered value by
0.75 codes -- inside the one-LSB bound #4347 predicts, and about a third of the
value being rendered. Uncorrelated drops over 4096 frames land back on 2.38,
which is the other half of the issue's claim and is now checked rather than
assumed.

Two corrections along the way, both recorded in the file.

The baseline is the undropped cycle, not the exact product. Those differ by
0.12 here -- the low-code brightening two cases above -- and charging it to the
drop pattern would overstate the effect by a third. Against the right baseline
the subsets straddle it near-symmetrically, -0.38 and +0.37, and that symmetry
is the signature of a correlated drop rather than of lost light, so it is
asserted too.

And "contiguous" is not "uncorrelated": presenting the first four phases of
each cycle still renders 2.25, because bit-reversal maps phases 0-3 to offsets
averaging 112 rather than 128. The control is a fixed-seed LCG instead. Worth
recording, since dropping a contiguous window is the intuitive wrong answer.

Both cases mutation-tested by swapping their drop patterns: making the
uncorrelated one phase-derived moves the mean 0.38 and fails its 0.05 bound;
making the parity one depend on loop index fails all three correlation checks.

This is the measurement half only. Advancing the phase on presentation remains
the architecture decision #4347 defers, and that issue stays open.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

* test(color): pin the presented-frame count so the drop control cannot go vacuous

Review finding, and a real one. `FL_CHECK_GT(presented, kFrames / 4)` was a
lower bound only, so a drop rule that stopped dropping would present all 4096
frames and then trivially render the undropped mean this case compares against
-- passing while measuring nothing. That is the one way this test could go
vacuous, and it was open.

The LCG is fixed-seed u32 arithmetic, so the count is deterministic: pinned at
2058 rather than bounded. Confirmed by replacing the drop condition with one
that never drops, which now fails at 4096 against 2058 and previously passed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Sep 12, 2026
…4393)

The contract sentence R8 is about asks for two tests: "with explicit tests for
dropped submissions and irregular dwell." #4348 and #4361 did drops. This is
dwell, and it is a separate defect on a separate axis -- dither correctness is
a time-weighted mean, so a phase held twice as long counts twice, whether or
not anything was dropped.

Measured at 1/4 brightness, source code 9. Holding the phases that carry the
low half of the bit-reversed offsets three times as long renders 2.19 against
2.57 for the opposite weighting, either side of the 2.38 that even dwell
gives. Nothing is dropped; every phase still reaches the wire.

0.38 codes of swing against the drop case's 0.75, and that ratio is not
coincidence: dropping a parity gives the survivors 100% of the weight while
holding 3:1 gives them 75%, so the displacement is half as far. Dwell reaches
the same place as dropping, by degrees.

Which is why it wants its own test. An implementation that advanced the phase
on presentation -- the fix R8 defers -- would close the drop half of that
sentence and leave this half exactly as it is, because dwell is about how long
a presented frame stays up, not whether it was presented.

The control is dwell that is irregular against the frame clock but uniform
against the phase: every frame twice as long, mean unmoved. Correlation is the
fault, not jitter.

The helper weights by the phase's own parity rather than by position in the
loop. Indexing by position is what I wrote first, and it silently reversed the
sign -- the cycle starts wherever the global counter is, so a fixed array
lands on whichever parity it lands on. Recorded in the helper so the next
reader does not repeat it.

Verified by making the weighting uniform, which fails three assertions.


Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees deleted the test/4347-dither-cadence branch November 5, 2026 05:53
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.

1 participant