Skip to content

Wire the HMTL cross-ABI layout sweep into make test, and bump the pointer - #33

Merged
aphelps-claude-bot merged 3 commits into
mainfrom
pack-programs-timesync-wire-structs
Aug 14, 2026
Merged

aphelps-claude-bot merged 3 commits into
mainfrom
pack-programs-timesync-wire-structs

Conversation

@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator

Super-repo half of aphelps/HMTL#7, which packs the PROGRAM payload structs and msg_time_sync_t so an ATMega328 and an ESP32 stop disagreeing about their layout. See that PR for the measurements and the reasoning; this one is about making sure the new guard actually runs.

Why a target here is load-bearing

This repo has never invoked HMTL's own make test. ci.yml runs make test STRICT=1 plus a WLED pio run, and neither compiles any TU that includes HMTLPrograms.h or TimeSync.h. Landing a layout guard where CI never evaluates it is the exact failure mode the guard exists to prevent — the fifth instance of one root cause in this workstream, and the third time the fix has been "make the check runnable by the thing that already runs".

make test-hmtl delegates to HMTL/tests/layout/, which compiles the real wire headers with host, host -fpack-struct=1, avr-g++ and xtensa-esp32-elf-g++, then to its negative control, which perturbs all 46 asserted numbers under all four ABIs and requires every one of the 184 compiles to fail.

Coverage is reported, not assumed

A missing cross-toolchain is skipped rather than fatal, so this stays runnable on a machine that has neither — but never silently: the sweep ends with a COVERAGE: line naming what ran and what did not, plus an explicit (partial …) note. REQUIRE_TOOLCHAINS=1 turns a skip into an error; that is the switch to add to CI once a runner has both toolchains installed. This deliberately mirrors the STRICT convention already in this Makefile, which exists because a skipped suite and a passing one used to look identical.

I did not set REQUIRE_TOOLCHAINS=1 in ci.yml in this PR: it would turn CI red until avr-gcc is installed on the runner, which is your call on cost. As it stands CI gets the host pair, and after the unsigned long → uint32_t change in HMTL#7 the -fpack-struct=1 proxy is a valid AVR stand-in for these structs — that is precisely what the type change bought.

Verified end to end

Breaking one assert in HMTL/Libraries/TimeSync/TimeSync.h turns make test-hmtl red here, not just inside the submodule:

super-repo make test-hmtl with a broken assert: exit=2
TimeSync.h:72:15: error: static assertion failed …: msg_time_sync_t.timestamp moved

Testing

  • make test STRICT=1 — all suites pass, including the new == HMTL cross-ABI wire layout sweep == at full coverage (host host-avr-proxy avr xtensa) and 184/184 perturbations breaking the build.
  • cd WLED && rm -rf .pio/libdeps/ampworks/RS485Utils && pio run -e ampworks — SUCCESS. The bridge imports only HMTLWireFormat.h, never HMTLPrograms.h, so it should be unaffected; running it after clearing the stale libdeps copy proves that rather than assuming it.

Merge order

Merge aphelps/HMTL#7 first, then re-point the submodule here if the merge commit differs from the branch tip.

🤖 Generated with Claude Code

https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ

…nter

aphelps/HMTL#7 packs the PROGRAM payloads and msg_time_sync_t so an ATMega328
and an ESP32 stop disagreeing about them, and adds HMTL/tests/layout/ — the
thing that actually compiles those headers with avr-g++ and
xtensa-esp32-elf-g++, because nothing did before.

This repo has never invoked HMTL's own `make test`, so without a target here the
new guard would not run in CI: exactly the failure mode the guard exists to
prevent. test-hmtl delegates to HMTL/tests/layout/ and then to its negative
control, which perturbs all 46 asserted numbers across all four ABIs and
requires every one of the 184 compiles to fail.

Coverage is reported rather than assumed. The sweep prints a COVERAGE line
naming any toolchain it skipped, so a host-only run cannot read as a full one,
and REQUIRE_TOOLCHAINS=1 turns a skip into an error — pass it once a runner has
avr-g++ and xtensa-esp32-elf-g++ installed.

Verified end to end: breaking one assert in HMTL/Libraries/TimeSync/TimeSync.h
turns `make test-hmtl` red here, not just inside the submodule.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator Author

CI is green, and the coverage reporting earned its keep on the first run — worth recording because it partly answers the cost question in the description:

== HMTL cross-ABI wire layout sweep ==
--- avr-g++ SKIPPED: not found at /home/runner/.platformio/packages/toolchain-atmelavr/bin/avr-g++ ---
=== layout sweep COVERAGE: host host-avr-proxy xtensa ===
    (partial — a real toolchain was missing; set REQUIRE_TOOLCHAINS=1 to make that an error)
138 perturbations across 3 toolchains: 138 broke the build as required, 0 did not

So the runner already has xtensa — the espressif32 platform install brings it, at no extra CI time — and the sweep is checking the real 32-bit toolchain today. That is the half that was actually broken; the AVR layout is the one already on the wire.

Only avr-g++ is missing, so REQUIRE_TOOLCHAINS=1 is a smaller ask than I priced it at: one toolchain install rather than two. Filed as a follow-up rather than done here, since it still turns CI red the moment it lands and before the install.

Note the run reports 138 rather than 184 perturbations — 46 asserts × 3 ABIs instead of × 4. That number moving with coverage is the intended behaviour, not a partial run being hidden.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the super-repo make test-hmtl wiring together with the submodule PR aphelps/HMTL#7 that it points at. The packing itself is right and the measurements reproduce; my findings are all about whether the new guard can actually fail, which is the stated point of the PR.

1. The hmtl_program_color_t packing guard cannot fail as the sweep is configured — verified, not argued.

tests/layout/Makefile sets CXXFLAGS once and never compiles with -DBIG_PIXELS. But BIG_PIXELS is the only configuration in which hmtl_program_color_t had the interior-padding bug: with the default PIXEL_ADDR_TYPE = uint8_t, CRGB(3B, align 1) + two uint8_t is 5 bytes with range at 3 on every ABI, packed or not. I deleted __attribute__((__packed__)) from hmtl_program_color_t in a scratch copy and re-ran the sweep's exact command line:

flags=none          g++                     rc=0   0 assert failures
flags=none          xtensa-esp32-elf-g++    rc=0   0 assert failures
flags=-DBIG_PIXELS  g++                     rc=1   2 assert failures
flags=-DBIG_PIXELS  xtensa-esp32-elf-g++    rc=1   2 assert failures

So the struct this PR spends its longest comment block on is the one struct whose packing nothing checks. The negative control does not catch it either: it perturbs assert numbers, not the attribute. -DBIG_PIXELS compiles clean today (I checked), so adding a second pass over each toolchain with that flag is a few lines and no expected churn.

The same reasoning applies more weakly to hmtl_program_sequence_t (8x u8 + 8x u16 + 8x u8 = 32 B, naturally aligned) and hmtl_program_brightness_t: removing packed from either is invisible to every ABI. Those are correctly described in the header as "never diverged", so they are regression guards against field reordering rather than against unpacking — worth a one-line note next to them so the distinction survives.

2. negative_control.py's GUARDED list includes a header with zero asserts in it.

grep -n static_assert HMTL/Libraries/HMTLprotocol/HMTLWireFormat.h returns nothing. All the HMTL#6 per-struct asserts (msg_hdr_t, msg_value_t, msg_program_t, ...) live in platformio/HMTL_Test/test/test_wire_format/test_wire_format.cpp, which is not in GUARDED and is not compiled by layout_check.cpp. The entry is a no-op that reads as coverage.

The consequence matters for this PR's framing: the new make test-hmtl cross-ABI-checks the HMTLPrograms and TimeSync asserts plus the six frame-length totals restated in layout_check.cpp, but it does not cross-ABI-check the HMTL#6 struct offsets. Those are still reachable only through HMTL's pio test -e native, which super-repo CI still does not call — the exact gap the PR description says it closes. Either drop HMTLWireFormat.h from GUARDED and say plainly what covers it, or move those asserts into the header the way msg_time_sync_t was moved (which would be consistent with the rule the plan's Notes section proposes).

Related: the six static_asserts in tests/layout/layout_check.cpp itself are never perturbed, since GUARDED only walks Libraries/. The harness does not negative-control the one file it owns.

3. make -j silently degrades the COVERAGE line, which is the mechanism protecting against a partial sweep being read as a full one.

In tests/layout/Makefile, host does rm -f .coverage-note, the four compile targets append to it, and summary reads it — with no ordering dependencies between them. all: host host-avr-proxy avr xtensa summary under -j will run summary concurrently with (or before) the appends, so tr '\n' ' ' < .coverage-note prints an empty or stale list and the recipe still exits 0. A .NOTPARALLEL: in that Makefile, or making summary depend on the others, costs one line. Same class of problem for anyone running make -C tests/layout avr on its own: it appends to whatever .coverage-note was left behind.

4. Suggested test: nothing compiles a TU that actually dereferences a now-packed member.

The plan's Test Plan item "compile every TU that includes the changed headers with -Waddress-of-packed-member -Werror" is checked off, but I do not see it in the diff: tests/layout/CXXFLAGS has -Wall and no -Werror, and layout_check.cpp includes headers only. TimeSync.cpp:85 casts into the receive buffer and reads msg_time->timestamp at offset 1 — now correct precisely because packing forces byte-wise access on xtensa — and HMTLPrograms.cpp does the same for the PROGRAM payloads, but neither file is compiled by any toolchain in the sweep. Adding a -fsyntax-only pass over TimeSync.cpp (and HMTLPrograms.cpp if the stub set stretches that far) with -Werror=address-of-packed-member would make the claim true; if it does not stretch that far, the honest move is to say so rather than leave the box ticked.

5. Low: bump_last_code_int masks // comments and string literals but not /* ... */.

The function's docstring explains exactly why comment digits must not be bumped — that bug already bit once — and the fix covers two of the three ways to write a comment. Nothing in the tree triggers it today, and the failure mode is a loud false alarm rather than a silent pass (a comment-only mutation compiles, so it is reported as "no failure when breaking"), but it re-arms the moment someone writes HMTL_LAYOUT_SIZE(x, 10); /* was 12 */.

Things I checked that are fine, recorded so they are not re-litigated: TimeSync.h does reach msg_time_sync_t after the move (it includes HMTLMessaging.h, so it is not relying on layout_check.cpp's include order); unsigned long -> uint32_t is genuinely a no-op for every consumer in TimeSync.cpp (all by value, no &, no printf formats, and the delta = (timestamp + latency) - now arithmetic stays 32-bit unsigned on both real targets); the negative control passes 184/184 across all four toolchains here in 21 s, matching the ~25 s the Makefile comment budgets for it.

Comment thread Makefile Resolved
Comment thread Makefile Resolved
Self-review caught that `make test STRICT=1` on a runner with neither cross
toolchain would compile the host pair, report success, and have cross-checked no
embedded ABI at all - the same "a skipped suite reports green" failure the STRICT
machinery in this Makefile already exists to prevent, reintroduced by the target
I added to enforce it.

STRICT now passes REQUIRE_ANY_REAL to the sweep. That is deliberately weaker than
REQUIRE_TOOLCHAINS: it demands not a particular compiler but that at least one of
avr-g++ / xtensa ran, so it holds today (the espressif32 platform install brings
xtensa to the runner) while still failing loudly if the real coverage ever drops
to zero. Verified both directions: passes as-is, exits 2 with PIO_PKG pointed at
nothing.

Also runs the sweep's new packed-access check, and bumps the pointer for
aphelps/HMTL@e39a652, which fixes a colour-struct guard that could not fail.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
@aphelps-claude-bot

Copy link
Copy Markdown
Collaborator Author

All five self-review findings addressed in aphelps/HMTL@e39a652 + e9358dc here. Finding 1 was right and is the important one — I reproduced it before fixing it.

1. hmtl_program_color_t's packing guard could not fail. Confirmed independently: unpacking that struct alone in a scratch copy of Libraries/ gave 0 assert failures under default flags and 2 under -DBIG_PIXELS. The sweep only ever compiled default flags, so the one struct whose bug this PR describes as interior padding had a guard that could not observe it.

Fixed by adding a second axis: every toolchain now compiles both default and -DBIG_PIXELS. The same unpack-and-sweep now exits 2 with those two failures. The sequence/brightness version of the point stands and is unchanged — they never diverged, and the header says so.

2. HMTLWireFormat.h had no asserts to guard. Correct, and worse than a cosmetic list error: GUARDED naming a file with zero asserts is a control that controls nothing, and the HMTL#6 numbers stayed host-only. The compile-time block moves to tests/layout/wire_layout_asserts.h, included by both layout_check.cpp and test_wire_format.cpp — one copy of the numbers, now swept by all four ABIs and reachable by the negative control. test_wire_format.cpp keeps its runtime byte-order cases, which a static_assert cannot express.

3. make -j breaking the COVERAGE line. Real; the directory is now .NOTPARALLEL: with the reasoning in a comment.

4. No TU dereferencing a packed member. Also correct — the plan item was ticked without being done. New packed-access target compiles hmtl_sources.cpp (which pulls HMTLPrograms.cpp) with -Werror=address-of-packed-member, under both pixel variants, and it is in make test. Verified by injecting return &b->off_period; into HMTLPrograms.cpp and watching it go red. Scope is stated in the Makefile rather than overclaimed: TimeSync.cpp is not in that TU, so its four uses were checked by hand instead — all by value, none taking an address.

5. /* */ masking. Fixed; it re-armed the exact bug the docstring documents.

Inline Makefile:124 — STRICT=1 not implying real-ABI coverage. The sharpest one, since it reintroduced into my own target the failure the STRICT machinery exists to prevent. STRICT now passes REQUIRE_ANY_REAL, deliberately weaker than REQUIRE_TOOLCHAINS: not "this compiler must exist" but "at least one of avr/xtensa must have run". That holds on today's runner — as the CI log above shows, xtensa comes free with the espressif32 platform — while failing loudly if real coverage ever drops to zero. Verified both ways: passes as-is, exits 2 with PIO_PKG pointed at nothing.

Inline Makefile:109 — overstated comment. Rewritten alongside finding 2, which is now actually true rather than merely claimed.

Coverage went from 184 perturbations to 460 (115 asserts × 4 toolchains, each counted caught only if some pixel variant goes red), and the negative control from ~25 s to ~60 s. make test STRICT=1 and make test-native are green.

@aphelps-claude-bot aphelps-claude-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All five review findings and both inline comments are addressed. Because the fixes landed across two repos, here is where each one went — and, since this review was about whether the guard can fail, what I re-ran to confirm it now does.

Where the fixes are. Findings 1–5 are all in the HMTL submodule, fixed in aphelps/HMTL@e39a652 ("close the review's five gaps in the layout guard, one of which could not fail"), which this PR's submodule pointer already references. The inline comment on the STRICT/REQUIRE_TOOLCHAINS split is fixed here, in e9358dc.

Finding Disposition
1 — hmtl_program_color_t's guard cannot fail Fixed. PIXEL_VARIANTS := default BIG_PIXELS; every toolchain now compiles both.
2 — GUARDED lists a header with zero asserts Fixed. HMTLWireFormat.h dropped; wire_layout_asserts.h added, so the harness now negative-controls the one file it owns.
3 — make -j degrades the COVERAGE line Fixed. .NOTPARALLEL: with a comment explaining what it protects.
4 — nothing compiles a TU that dereferences a packed member Fixed. New packed-access target, -Werror=address-of-packed-member over hmtl_sources.cpp, both pixel widths. Scope stated honestly in the comment: TimeSync.cpp is not in that TU and was checked by hand instead — the box is no longer ticked on a claim the harness doesn't make.
5 — bump_last_code_int misses /* … */ Fixed. Block comments masked alongside // and string literals.
inline, Makefile:124 — STRICT vs REQUIRE_TOOLCHAINS Fixed, taking the second option you offered: STRICT now implies REQUIRE_ANY_REAL (at least one real embedded ABI ran) rather than REQUIRE_TOOLCHAINS (all of them), so it stays green on a runner without avr-g++ while still refusing to call a host-only sweep a pass. The reasoning is in the comment block above the target.
inline, Makefile:115 — "nothing else reaches those asserts" overstated Fixed. The comment now names what actually reaches CI and why HMTL's own make test doesn't.

Re-verified at the current pointer (e39a652), not just re-read:

=== layout sweep COVERAGE: host host-avr-proxy avr xtensa x [default BIG_PIXELS] ===
make packed-access   → clean, both widths
make negative        → 460 perturbations across 4 toolchains x 2 pixel-width variants:
                       460 broke the build as required, 0 did not

And the specific claim finding 1 rested on — I removed __attribute__((__packed__)) from hmtl_program_color_t and re-ran the sweep:

--- host [default] ---        (clean)
--- host [BIG_PIXELS] ---     error: static assertion failed: hmtl_program_color_t changed size
                              error: static assertion failed: hmtl_program_color_t.range moved

Green at the default width, red under -DBIG_PIXELS with exactly the two failures predicted. The guard that could not fail now fails.

One thing worth recording rather than leaving for a future reader to rediscover: the sweep emits warning: ignoring packed attribute because of unpacked non-POD field 'CRGB …' on every struct with a CRGB member. The attribute really is being ignored there — the layout is correct anyway because CRGB is 3 bytes at alignment 1, and it is the static_asserts, not the attribute, that hold those structs in place. -Wall is deliberately left on so those warnings stay visible.

@aphelps-reviewer-bot aphelps-reviewer-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of the incremental diff aa08f72..e9358dc — one commit, "make STRICT imply 'at least one real embedded ABI ran'", which addresses the inline comment on Makefile:124.

The change does what it says and I verified the submodule side independently at the pinned pointer e39a652: sweep green across host host-avr-proxy avr xtensa x [default BIG_PIXELS], packed-access clean at both widths, negative control 460/460. I also removed __attribute__((__packed__)) from hmtl_program_color_t and confirmed the sweep now goes red under -DBIG_PIXELS with exactly the two predicted assert failures — the "guard that cannot fail" from the previous round genuinely can now.

Two findings on this commit.

1. STRICT=1 now depends on a GitHub Actions cache hit, and fails closed when it misses.

REQUIRE_ANY_REAL makes the sweep fail unless avr-g++ or xtensa ran. The sub-Makefile finds xtensa only at $(HOME)/.platformio/packages/toolchain-xtensa-esp32/.... In .github/workflows/ci.yml the step order is:

  1. ./setup.sh --no-verify
  2. make test STRICT=1 <- REQUIRE_ANY_REAL is enforced here
  3. pio run -e ampworks …

setup.sh:113 is explicit that the smoke build is what fetches the ESP32 toolchain ("first build also fetches the ESP32 toolchain"), and --no-verify skips it (setup.sh:117). So step 2 runs before anything in this workflow installs the espressif32 platform. The only reason xtensa is present at that point is the actions/cache restore of ~/.platformio from a previous run.

That makes CI green-or-red on cache warmth rather than on the code. The restore-keys: pio-toolchain-${{ runner.os }}- fallback means it will usually hit, which is worse, not better — the failure is rare and looks like a test failure rather than a missing toolchain. It will bite on a cold cache: first run after the 10 GB LRU eviction the cache comment itself warns about, a fork PR with no access to the base repo's cache, or a cache-key change from touching platformio.ini/requirements.txt.

The Makefile comment states this as settled — "Today's CI runner has xtensa (the espressif32 platform install brings it), so this passes" — but the platform install it credits happens in a later step. Worth either moving the toolchain install ahead of the host-test step, or setting REQUIRE_ANY_REAL explicitly in ci.yml where the dependency is visible, rather than deriving it from STRICT and inheriting an ordering assumption. The pending "install avr-gcc on CI" task would also resolve it, by giving the step a toolchain that does not depend on the cache.

2. Low: the off-value list is now duplicated, and the two knobs can silently desynchronise.

The new ifeq block repeats filter-out 0 no No NO false False FALSE off Off OFF verbatim from the missing_tests block three lines below it. They are two independent conditionals over the same predicate. Adding n/N/disabled to one list and not the other yields a state where STRICT=n skips suites leniently but still demands a real toolchain — a combination nobody intends and nothing catches. Computing the predicate once (strict_on := $(filter-out …,$(strip $(STRICT)))) and branching on it twice keeps them locked together.

Checked and fine: passing REQUIRE_ANY_REAL= (empty) on the sub-make command line correctly overrides the sub-Makefile's ?= and reads as unset at the [ -n ] test, so STRICT=0 really does opt out. Chaining packed-access and negative with && preserves fail-fast. .NOTPARALLEL: in the sub-Makefile means the parent's sequential && chain cannot race the COVERAGE file.

HMTL#7 landed on main as 64cc71d. The pointer this branch carried (e39a652)
was the pre-squash branch head, which no ref reaches now that the branch is
deleted — a fresh `git submodule update --init` would fail to fetch it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants