Repository navigation
test(channels): cover the dither phase, which nothing observed (#4347) - #4348
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds temporal-dither tests. The tests verify phase advancement for ChangesTemporal dither test coverage
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
…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]>
…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]>
Addresses the tractable half of #4347. The architecture change there stays open.
Why
docs/color-pipeline-contracts.mdasks for this in as many words:There were none.
tests/pixel_controller.cppdrivesadvanceDitherFrame()to walk a cycle, but nothing observed who advances the phase, or what happens to a frame that never reaches a driver.Three cases
onBeginFrameadvances once, whatever the channel countshowLeds()is its own logical frame and advancesThe 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()callsonBeginFrame()once, then drives each controller throughshowLedsInternal(), which does not advanceCLEDController::showLeds()— the 3.8.x compatibility path aChannelinherits — callsonBeginFrame()itselfSo 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 lintclean. New test file only; no source changes.🤖 Generated with Claude Code
https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
Summary by CodeRabbit