test(comdelay): host unit tests for ComDelay divider/latch tick state machine - #479
Open
Mikefly123 wants to merge 3 commits into
Open
test(comdelay): host unit tests for ComDelay divider/latch tick state machine#479Mikefly123 wants to merge 3 commits into
Mikefly123 wants to merge 3 commits into
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
ComDelay had no unit test coverage (CMakeLists UT block was a commented template). Extract the tick/divider/latch state machine into a host-testable ComDelayLogic class -- following this repo's established pattern for passive-component logic extraction (RtcHelper, BDot, Magnetorquer, StrategySelector, Bypasser, Parser/Validator/Authenticator) -- and add it to the gtest suite driven by `make test-unit`. ComDelay.cpp/.hpp now delegate to ComDelayLogic; behavior is unchanged (verified against the pre-existing atomic compare_exchange consume-once semantics and against the U8 tick-counter width). Covers: tick-paced release, divider math (small N and the default divider), exactly-once consumption, no-emit when nothing is latched, runtime divider changes mid-cycle (shrink and grow), and param-invalid fallback to the default divider. Finding: DEFAULT_DIVIDER=299 does not actually yield a ~30s/300-tick period as commented in ComDelay.fpp -- the production tick counter is a U8 (max 255), so it wraps via 8-bit overflow at 256 ticks before ever reaching the 299 comparison threshold. Tests pin the real (256-tick) behavior rather than the aspirational one; no behavior change made here.
Adds the passthrough test cases that belong with perf/comdelay-divider0-passthrough (#475), mirroring the coverage intended by closed PR #478: - divider-0 forwards immediately (both SUCCESS and FAILURE values) without ever setting the latch, so run ticks cannot double-emit - divider 0 -> N runtime transition latches/tick-paces again - N -> 0 transition with a status already latched neither loses the latched status nor double-emits it (exactly one tick emission) - invalid DIVIDER parameter falls back to the nonzero default and therefore latches, never passthroughs Kept as a separate commit so the extraction/refactor layer diff of this branch stays reviewable on its own. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Mikefly123
force-pushed
the
test/comdelay-ut
branch
from
July 31, 2026 03:07
a91b95e to
4a2bfcd
Compare
Mikefly123
changed the base branch from
feat/usp-radio
to
perf/comdelay-divider0-passthrough
July 31, 2026 03:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ComDelay (
PROVESFlightControllerReference/Components/ComDelay/) gates radio comStatus by aDIVIDERparam, but had zero unit test coverage — the component'sCMakeLists.txtUT block was a commented-out template only.This PR extracts the tick/divider/latch state machine into a header-only, host-testable
ComDelayLogicclass and adds it to this repo's existing host-side gtest suite (make test-unit), following the same extraction pattern already used for other passive F´ components with ports/params in this repo:RtcHelper(RtcManager),BDot/Magnetorquer/StrategySelector(DetumbleManager),Bypasser(ProvesRouter), andParser/Validator/Authenticator(TcSecurityDeframer).ComDelay.cpp/.hppnow delegate toComDelayLogic; no behavior change — verified the extraction preserves the pre-existing atomic compare-exchange consume-once semantics and the 8-bit tick-counter width.Coverage
DIVIDER=Nreleases everyN+1ticks for small N.DIVIDER=0valid is not mistaken for invalid).Finding (documented in tests, not fixed here)
DEFAULT_DIVIDER = 299is commented inComDelay.fppas "on a 1Hz tick, transmit every 30S" (i.e. a 300-tick period). In production, however, the tick counter is aU8(max 255), so it wraps via 8-bit integer overflow at 256 ticks — it never reaches the 299 comparison threshold. The actual default release period is ~256 ticks (~25.6s @ 1Hz), not 300/30s.test_ComDelay_ComDelayLogic.cpp::DefaultDividerActuallyWrapsAt256TicksNot300pins the real behavior. Flagging this as a pre-existing latent discrepancy worth a follow-up, out of scope for this test-only PR.Why this matters
perf/comdelay-divider0-passthrough, open) adds a DIVIDER=0 immediate-passthrough path to this same component and has shipped hardware-validated only, with no automated regression coverage. This PR does not stack on perf(comdelay): DIVIDER=0 passes comStatus straight through (TX-done-paced downlink) #475 directly (see note below) but gives the shared divider/latch core a regression baseline that perf(comdelay): DIVIDER=0 passes comStatus straight through (TX-done-paced downlink) #475's passthrough branch can build on / rebase onto.test_LinkProfiles,test_DetumbleManager,test_RtcManager, etc.) is that passive-component core logic gets extracted and host-tested rather than shipped untested — ComDelay was the one component in the radio-adjacent path that hadn't received that treatment yet.Base branch / stacking note
This PR is based directly on
feat/usp-radiopost-#477 (patch-collapse merged), not stacked onperf/comdelay-divider0-passthrough(#475). #475's branch predates #477 and has drifted (it still carries the pre-collapse individualpatches/*.patchfiles and oldwest.yml/submodule pins); rebasing it was out of scope for this PR to avoid rewriting another open PR's branch history without explicit sign-off. If #475 is rebased onto currentfeat/usp-radiofirst, its DIVIDER=0 passthrough tests (immediate forward without waiting for a tick, no latch set, DIVIDER>0 unchanged) can be layered on top ofComDelayLogiccleanly — the extraction here is what makes that follow-up small.Test plan
make test-unitpasses locally: 12/12 tests green, including the 9 newComDelayLogicTestcases, with no regressions totest_LinkProfiles,test_DetumbleManager_*,test_RtcManager_RtcHelper,test_TcSecurityDeframer_*,test_ProvesRouter_Bypasser.🤖 Generated with Claude Code
Stack note (2026-07-30): rebased and stacked on #475 (
perf/comdelay-divider0-passthrough); base changed accordingly (stack:feat/usp-radio<- #475 <- #479). The rebase ported #475's divider-0 passthrough into the extractedComDelayLogic(newacceptStatus()— divider 0 forwards immediately without latching; divider > 0 latches as before), and a separate commit adds passthrough test cases (immediate forward w/o latch, 0->N re-latch, N->0 latched-status no-loss/no-double-emit, invalid-param fallback latches) — the coverage closed PR #478 intended. ComDelay suite is now 13 tests; fullmake test-unit13/13 suites green.