Files
lilygo-t-deck/emulator/tests/sim_helpers.h
T
Dejvino a1d0730124 NetDeck: headless test runner — unit + integration suites, E2E as separate build
- emulator/tests/: harness.h (TEST/EXPECT framework, input + serial +
  framebuffer helpers), shim_globals.cpp (shim externs for test binaries,
  replacing main.cpp ownership)
- unit_tests.h (14): map/door/LOS/BFS/cover/link state machine/trace/
  spike/reinforcement/win/loss/reset — deterministic fixed-seed, sim
  stepped tick by tick
- integration_tests.h (7): keyboard->pollKeyboard->handleKey pipeline,
  beacon clicks -> squad movement, full network journey via clicks,
  hover-sever (incl. safe sever during trace), daemon gating
- e2e_tests.cpp (separate NetDeck-e2e build): real setup()/loop() journeys
  with device-pipeline input injection (boot grace, 0x55 keyboard, GT911
  tap, trackball ISRs), transcript + pixel assertions (HUD, freeze tint)
- shim SerialSim: opt-in transcript ring for test assertions (off by
  default, interactive emulator unchanged)
- make netdeck-test / -unit / -e2e (root) and make test / test-unit /
  test-e2e (emulator/); tests/README.md documents the structure
- STATUS.md: test-structure note

Verified: make netdeck-test -> 14 unit + 7 integration + 3 E2E, 0 failures
2026-11-14 13:02:41 +01:00

43 lines
1.2 KiB
C++

/**
* @file sim_helpers.h
* @brief Test helpers that touch sketch internals — include AFTER the
* sketch (single-TU inclusion gives the tests access to the
* sketch's statics, exactly like main.cpp gets them).
*/
#pragma once
#include "harness.h"
// advance the deterministic 20 Hz simulation by n ticks (no wall time)
inline void stepTicks(int n)
{
for (int i = 0; i < n; i++) stepSim();
}
// click exactly on a network node (Network view) — cursor + primary action
inline void clickNode(int node)
{
curX = nodePx(node);
curY = nodePy(node);
registerClick();
}
// click the center of a map tile (Cameras view) — places the beacon
inline void clickTile(int tx, int ty)
{
curX = tx * nd::TILE + nd::TILE / 2;
curY = ty * nd::TILE + nd::TILE / 2;
registerClick();
}
// find the active link on an edge, or -1
inline int linkIdx(int edge) { return linkOnEdge(edge); }
// fresh deterministic scenario state for a test
inline void freshScenario(unsigned seed = 0xC0FFEE)
{
std::srand((unsigned)seed);
resetScenario();
viewMode = VM_CAMERAS; // resetScenario deliberately keeps the view
test::serialClear();
}