Skip to content

Add simavr-based functional test for UnitTest sketch (make sim-test)#139

Merged
laurb9 merged 1 commit into
masterfrom
feature/simavr-test
Jul 7, 2026
Merged

Add simavr-based functional test for UnitTest sketch (make sim-test)#139
laurb9 merged 1 commit into
masterfrom
feature/simavr-test

Conversation

@laurb9

@laurb9 laurb9 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Retains and automates the simavr test procedure used to verify #137 and #138, so CI (and anyone locally) gets a functional test of real step timing on an emulated ATmega328P — not just compile checks. A verdict flip like #93 (LINEAR_SPEED running 4× fast at low rpm) would fail this test.

What's included

  • test/simavr-run.sh — runs the UnitTest firmware under simavr -m atmega328p -f 16000000, waits for a new TESTS COMPLETE marker (the sketch's loop() never exits, so the script kills the simulator on completion or timeout), strips ANSI codes and simulator noise, then compares OK/FAIL verdict lines against the golden baseline with digits stripped — so µs timings that drift with toolchain versions don't cause false failures, while any OK↔FAIL flip does. --update regenerates the baseline.
  • make sim-test / make sim-test-update — build (pio run -e uno) + run/regenerate.
  • CI: new SimTest job in the PlatformIO workflow (installs simavr via apt, runs make sim-test).
  • Devcontainer: simavr added to the Dockerfile package list.
  • examples/UnitTest/uno-simavr.txt — golden baseline (57 lines, 14 verdicts), joining the existing per-board reference outputs. Note: some FAILs at high rpm are the 16 MHz hardware speed limit, not bugs, and are part of the baseline.
  • examples/UnitTest/UnitTest.ino — prints TESTS COMPLETE at the end of setup() (completion/crash detection; harmless on real hardware).
  • Docs synced: AGENTS.md (structure diagram + simavr Testing section), test/README.

Test results

  • make sim-test in the devcontainer: PASS, 14 verdict lines match, run twice — output is byte-identical between runs (simavr is deterministic); full sketch run completes in ~8.4 s wall clock.
  • Negative test 1: flipping a single OK→FAIL in the golden makes the run exit 1 with a clear diff.
  • Negative test 2: TIMEOUT=2 correctly exits 1 with "completion marker never appeared" (hang/crash detection).
  • All 5 PlatformIO envs (uno, adafruit_feather_m0, nodemcuv2, esp32dev, teensylc) still build with the sketch change.

Performance impact

None on the library itself (no src/ changes). CI gains one ~2-minute job.


Agent: claude-fable-5 (Claude Code 2.1.153) — implementation by claude-opus-4-8 subagent, test runs by claude-sonnet-5 subagent, verified by claude-fable-5; max context and thinking level not exposed to the agents

🤖 Generated with Claude Code

Run the UnitTest sketch on a simulated ATmega328P (simavr) and compare
its OK/FAIL verdicts against a committed golden baseline. This gives CI
a functional test of actual step timing on emulated 8-bit hardware, not
just compile checks - a verdict flip like issue #93 (LINEAR_SPEED
running 4x fast at low rpm) would be caught.

- test/simavr-run.sh: runs firmware under simavr, waits for the new
  "TESTS COMPLETE" marker (kills the sim on completion, since loop()
  never exits), strips ANSI/simulator noise, and diffs OK/FAIL verdict
  lines against examples/UnitTest/uno-simavr.txt with digits stripped,
  so toolchain-version timing drift does not cause false failures while
  any verdict flip does. --update regenerates the baseline.
- Makefile: sim-test and sim-test-update targets (pio build + script).
- .github/workflows/platformio.yml: SimTest job (apt install simavr,
  make sim-test).
- .devcontainer/Dockerfile: install simavr.
- examples/UnitTest/uno-simavr.txt: golden baseline; FAILs at high rpm
  are the 16 MHz hardware speed limit and are part of the baseline.
- examples/UnitTest/UnitTest.ino: print TESTS COMPLETE at end of setup.
- AGENTS.md, test/README: document the procedure.

Validation: make sim-test passes twice (deterministic, 14 verdict
lines, ~8.4s sim run); flipping one verdict in the golden makes it fail
with a diff; TIMEOUT=2 correctly reports the missing completion marker;
all 5 pio envs still build with the sketch change.

Agent: claude-fable-5 (Claude Code 2.1.153); implementation by
claude-opus-4-8 subagent, test runs by claude-sonnet-5 subagent,
verified by claude-fable-5; max context and thinking level not exposed

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@laurb9 laurb9 merged commit b232909 into master Jul 7, 2026
11 checks passed
@laurb9 laurb9 deleted the feature/simavr-test branch July 7, 2026 04:04
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.

1 participant