Added FSM state transition visualization#296
Conversation
|
@claude_doc |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
@claude_doc |
|
Claude finished @devYaoYH's task —— View job Documentation AnalysisThis PR extends the FSM visualization system from individual state tests to full state machine transitions across all build profiles (flight, bringup, debug). Summary of ChangesThe PR adds comprehensive FSM state transition visualization that extends the existing running state test approach to visualize complete state machine flows for different build profiles. Key additions include:
--- a/web/visualizer/README.md
+++ b/web/visualizer/README.md
@@ -30,6 +30,26 @@ npm run dev
## Generating Log Data
+### FSM integration tests (recommended)
+
+The FSM tests exercise the full state machine for each build profile. They are tagged
+`manual` so they don't run with `bazel test //...` (which is reserved for unit tests).
+Run them individually with their dedicated `.bazelrc` configs:
+
+```bash
+# Debug profile: init -> running (no extra config needed)
+bazel test //src/scheduler:fsm_test_debug
+
+# Flight profile: init -> burn_wire -> running
+bazel test //src/scheduler:fsm_test_flight --config=fsm-flight
+
+# Bringup profile: init -> bringup
+bazel test //src/scheduler:fsm_test_bringup --config=fsm-bringup
+```
+
+Output JSON files are saved to:
+```
+bazel-testlogs/src/scheduler/fsm_test_debug/test.outputs/fsm_viz_picubed_debug.json
+bazel-testlogs/src/scheduler/fsm_test_flight/test.outputs/fsm_viz_picubed_flight.json
+bazel-testlogs/src/scheduler/fsm_test_bringup/test.outputs/fsm_viz_picubed_bringup.json
+```
+
### Single-state running test
```bash
@@ -64,6 +84,26 @@ Upload the generated JSON file to the visualizer using the "Load Log File" butt
## Features
+### State Machine Diagram
+- Rounded-rectangle state nodes arranged in transition order
+- Arrows showing observed transitions between states
+- Final (stable) state highlighted with a dashed border
+- Task count displayed per state
+
+### State Timeline
+- Horizontal bar showing which state was active at each point in time
+- Color-coded per state
+
+### Task Timeline
+- Shows when each task is initialized and dispatched
+- Color-coded tasks for easy identification
+- State background bands showing which state was active behind the task rows
+- Dashed vertical lines at state transition boundaries
+- Time markers in milliseconds
+
+### Task List
+- Displays all discovered tasks
+- Shows dispatch period for each task
+- Click to filter the timeline and event log
+
### Event Log
- Scrollable list of all events
- Color-coded by event type
--- a/src/scheduler/BUILD.bazel
+++ b/src/scheduler/BUILD.bazel
@@ -107,0 +107,42 @@ cc_library(
+
+# ============================================================================
+# FSM Integration Tests
+# ============================================================================
+
+load("//bzl:defs.bzl", "samwise_test")
+
+# Common deps for all FSM tests
+_FSM_TEST_DEPS = [
+ "//src/states/init:init_state",
+ "//src/states/running:running_state",
+ "//src/states/bringup:bringup_state",
+ "//src/states/burn_wire:burn_wire_state",
+ "//src/states/burn_wire_reset:burn_wire_reset_state",
+]
+
+samwise_test(
+ name = "fsm_test_debug",
+ srcs = ["test/test_fsm.c"],
+ deps = _FSM_TEST_DEPS,
+)
+
+# FLIGHT and BRINGUP tests require global --copt defines to propagate to
+# state source files. They are tagged "manual" so they don't break
+# `bazel test //...`. Run them with their dedicated configs:
+# bazel test //src/scheduler:fsm_test_flight --config=fsm-flight
+# bazel test //src/scheduler:fsm_test_bringup --config=fsm-bringup
+samwise_test(
+ name = "fsm_test_flight",
+ srcs = ["test/test_fsm.c"],
+ defines = ["FLIGHT"],
+ tags = ["manual"],
+ deps = _FSM_TEST_DEPS,
+)
+
+samwise_test(
+ name = "fsm_test_bringup",
+ srcs = ["test/test_fsm.c"],
+ defines = ["BRINGUP"],
+ tags = ["manual"],
+ deps = _FSM_TEST_DEPS,
+)
--- a/.bazelrc
+++ b/.bazelrc
@@ -146,0 +146,16 @@ test:tests --define=profile=picubed-debug
+
+# ============================================================================
+# FSM Test Configurations
+# ============================================================================
+
+# FSM test for flight profile (includes burn wire sequence)
+test:fsm-flight --define=profile=picubed-flight
+test:fsm-flight --copt=-DFLIGHT
+test:fsm-flight --test_output=all
+
+# FSM test for bringup profile (stops at bringup state)
+test:fsm-bringup --define=profile=picubed-bringup
+test:fsm-bringup --copt=-DBRINGUP
+test:fsm-bringup --test_output=all
--- /dev/null
+++ b/src/scheduler/test/test_fsm.c
@@ -0,0 +1,268 @@
+/**
+ * @file test_fsm.c
+ * @brief FSM integration test - exercises full state machine transitions
+ *
+ * Tests the complete state machine for a given build profile, starting from
+ * STATE_INIT and running until the FSM reaches a stable state (same state
+ * returned for 5 consecutive dispatch cycles).
+ *
+ * Build profiles tested via separate Bazel targets:
+ * - fsm_test_flight (FLIGHT defined) : init -> burn_wire -> running
+ * - fsm_test_bringup (BRINGUP defined) : init -> bringup
+ * - fsm_test_debug (no special defs) : init -> running
+ */
--- /dev/null
+++ b/web/visualizer/src/components/StateMachine.tsx
@@ -0,0 +1,311 @@
+import React from 'react';
+import { StateSpan, StateTransition } from '../types';
+
+interface StateMachineProps {
+ stateSpans: StateSpan[];
+ transitions: StateTransition[];
+ maxTime: number;
+}
+
+export const StateMachine: React.FC<StateMachineProps> = ({
+ stateSpans,
+ transitions,
+ maxTime,
+}) => {
+ // FSM Diagram with state nodes, transition arrows, and state timeline bar
+ // Shows visual representation of state machine flow and timing
+```
#### Changelog Entry
```markdown
## [Unreleased]
### Added
- FSM integration tests for full state machine visualization across build profiles (#296) @devYaoYH
- Interactive state machine diagram component with transition arrows and state timelines
- Support for flight, bringup, and debug profile FSM testing with dedicated Bazel configs
- Enhanced test infrastructure for FSM simulation and visualization data export
- GitHub Actions integration for FSM test execution and output preservation
### Changed
- Extended web visualizer to support complete FSM flows in addition to single-state tests (#296)
- Updated README with comprehensive FSM testing instructions and feature documentation |
|
This change adds a second set of tests alongside state tests (events executed within a state) -- fsm test (which tests states executed within a build type) This allows us to verify transitions between different states in our configured builds |
Extended the current style of running_state_test to the overall FSM transitions to be made for each build profile (flight, bringup, debug).