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
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* @file integration_tests.h
|
||||
* @brief Integration tests: several sketch subsystems cooperating —
|
||||
* keyboard device -> pollKeyboard -> handleKey, cursor clicks ->
|
||||
* registerClick -> beacon/node routing, sim ticks -> combat/objective
|
||||
* flow. Still deterministic (fixed seed, direct tick stepping, no
|
||||
* wall time, no rendering — pixels are the E2E layer's job).
|
||||
*
|
||||
* Included by test_main.cpp AFTER the sketch and unit_tests.h.
|
||||
*/
|
||||
#include "sim_helpers.h"
|
||||
|
||||
TEST(integration/keyboard_device_pipeline)
|
||||
{
|
||||
freshScenario();
|
||||
test::resetInput();
|
||||
test::typeKey('p'); // keyboard device @0x55
|
||||
pollKeyboard(); // -> handleKey
|
||||
EXPECT_EQ(viewMode, VM_NETWORK);
|
||||
test::typeKey(' ');
|
||||
pollKeyboard();
|
||||
EXPECT(!paused); // freeze OFF
|
||||
test::typeKey('p');
|
||||
pollKeyboard();
|
||||
EXPECT_EQ(viewMode, VM_CAMERAS);
|
||||
test::typeKey('r');
|
||||
pollKeyboard();
|
||||
EXPECT(test::serialHas("[key] RESET"));
|
||||
EXPECT(paused); // reset re-arms paused
|
||||
}
|
||||
|
||||
TEST(integration/beacon_click_paths_the_squad)
|
||||
{
|
||||
freshScenario();
|
||||
clickTile(20, 12); // corridor floor
|
||||
EXPECT_EQ(beaconTX, 20);
|
||||
EXPECT_EQ(beaconTY, 12);
|
||||
EXPECT(test::serialHas("[click] beacon -> tile 20,12"));
|
||||
stepTicks(200); // marines march + engage
|
||||
bool progressed = units[0].tx >= 6 || !units[2].alive;
|
||||
EXPECT(progressed); // moving and/or fighting
|
||||
EXPECT(test::serialHas("[combat]")); // contact was made
|
||||
for (const auto &t : tracers) EXPECT(t.ttl >= 0 && t.ttl <= 2);
|
||||
}
|
||||
|
||||
TEST(integration/click_blocked_tile_keeps_beacon)
|
||||
{
|
||||
freshScenario();
|
||||
clickTile(20, 12); // valid first
|
||||
int bx = beaconTX, by = beaconTY;
|
||||
clickTile(5, 0); // wall tile
|
||||
EXPECT(test::serialHas("beacon ignored"));
|
||||
EXPECT_EQ(beaconTX, bx); // unchanged
|
||||
EXPECT_EQ(beaconTY, by);
|
||||
}
|
||||
|
||||
TEST(integration/full_network_journey)
|
||||
{
|
||||
freshScenario();
|
||||
handleKey('p'); // Network view
|
||||
clickNode(N_JUNC); // route AIRLK-JUNC
|
||||
stepTicks(LINK_TICKS);
|
||||
EXPECT(nodeOnline[N_JUNC]);
|
||||
clickNode(N_DOOR); // route JUNC-DOOR
|
||||
stepTicks(LINK_TICKS);
|
||||
EXPECT(nodeOnline[N_DOOR]);
|
||||
EXPECT(!doorOpen);
|
||||
clickNode(N_DOOR); // online DOOR toggles
|
||||
EXPECT(doorOpen);
|
||||
clickNode(N_HIVE); // 3 s ICE
|
||||
stepTicks(ICE_TICKS);
|
||||
EXPECT(hiveCracked);
|
||||
EXPECT(traceActive);
|
||||
stepTicks(TRACE_TICKS);
|
||||
EXPECT(heatT > 0); // feedback spike cooldown
|
||||
EXPECT(units[6].alive); // reinforcement spawned
|
||||
EXPECT(!nodeOnline[N_JUNC]); // spike dropped the net
|
||||
}
|
||||
|
||||
TEST(integration/sever_via_hovered_link)
|
||||
{
|
||||
freshScenario();
|
||||
handleKey('p');
|
||||
clickNode(N_JUNC);
|
||||
stepTicks(LINK_TICKS);
|
||||
EXPECT(nodeOnline[N_JUNC]);
|
||||
// midpoint of the AIRLK(36,164)-JUNC(148,52) segment
|
||||
curX = (nodePx(N_AIRLK) + nodePx(N_JUNC)) / 2;
|
||||
curY = (nodePy(N_AIRLK) + nodePy(N_JUNC)) / 2;
|
||||
EXPECT_EQ(hoverLink(), linkIdx(0));
|
||||
handleKey('x');
|
||||
EXPECT(test::serialHas("[net] severed AIRLK-JUNC"));
|
||||
EXPECT(!nodeOnline[N_JUNC]);
|
||||
}
|
||||
|
||||
TEST(integration/sever_during_trace_is_safe)
|
||||
{
|
||||
freshScenario();
|
||||
handleKey('p');
|
||||
clickNode(N_JUNC); stepTicks(LINK_TICKS);
|
||||
clickNode(N_HIVE); stepTicks(ICE_TICKS);
|
||||
EXPECT(traceActive); // trace running
|
||||
curX = (nodePx(N_JUNC) + nodePx(N_HIVE)) / 2; // hover the ICE link
|
||||
curY = (nodePy(N_JUNC) + nodePy(N_HIVE)) / 2;
|
||||
handleKey('x'); // sever before arrival
|
||||
EXPECT(!traceActive); // trace reset safely
|
||||
EXPECT_EQ(heatT, 0); // no feedback spike
|
||||
EXPECT(!units[6].alive); // no reinforcement
|
||||
}
|
||||
|
||||
TEST(integration/daemon_gating_messages)
|
||||
{
|
||||
freshScenario();
|
||||
handleKey('1'); // no HIVE link yet
|
||||
EXPECT_EQ(strcmp(msgText, "NO HIVE LINK"), 0);
|
||||
handleKey('p');
|
||||
clickNode(N_JUNC); stepTicks(LINK_TICKS);
|
||||
clickNode(N_HIVE); stepTicks(ICE_TICKS);
|
||||
handleKey('1'); // HIVE online -> armed
|
||||
EXPECT_EQ(strcmp(msgText, "M4 PENDING"), 0); // payload lands in M4
|
||||
EXPECT(test::serialHas("daemon 1 armed"));
|
||||
}
|
||||
Reference in New Issue
Block a user