Test And Debug¶
Small examples for scan-cycle behavior, memory markers, deterministic checks, debugging, and test output.
Read Scan Cycle first if %M behavior is new.
Memory Marker Counter¶
Docs category: docs/public/examples/test-and-debug.md
This tutorial teaches the scan-cycle memory model and shows how to inspect it in Live Values and the debugger.
Learning Goal¶
Understand exactly when %M values are read and written in one cycle:
- cycle start:
%M-> bound ST variable - logic execution: program updates values
- cycle end: updated ST variable ->
%M
Project Files¶
src/Main.stsrc/Configuration.sttrust-lsp.toml.vscode/launch.json
Step 1: Open and Build¶
From repository root:
code examples/memory_marker_counter
trust-runtime build --project examples/memory_marker_counter --sources src
trust-runtime validate --project examples/memory_marker_counter
Step 2: Start the Simulator and open Live Values¶
- In the truST view, press Start: the Simulator runs the program and Live Values opens. To use a runtime instead, select it in the truST view and press Connect; truST: Open Live Values opens Live Values at any time.
- In Live Values:
- Memory holds
%MW0: write%Mvalues there - Outputs holds
%QW0: read%Qvalues there - the values change while the scans run
Step 3: Core Experiment (Annotated)¶
Bindings (src/Configuration.st):
%MW0<->Counter%QW0<->CounterLatched
Procedure:
- Queue the write:
trust-runtime ctl --project examples/memory_marker_counter io-write %MW0 41. - Wait one cycle.
Expected after first cycle:
%QW0 = Int(41)(latched cycle-start value)%MW0 = Int(42)(incremented writeback at cycle end)
Expected after more cycles:
%MW0increments by 1 per cycle.
Step 4: Debugger Integration¶
- Open
src/Main.st. - Set breakpoint on
Counter := Counter + 1;. - Press
F5using.vscode/launch.json. - In Variables panel, inspect
CounterandCounterLatched. - Step over and observe value transitions.
- Confirm inline values in editor match debugger state.
Step 5: Modify and Re-Test¶
Change:
Counter := Counter + 1;->Counter := Counter + 5;
Repeat Step 3 and confirm %MW0 jumps by 5 each cycle.
Automated Check¶
./scripts/test_memory_marker_sync.sh
Pitfalls and Fixes¶
- Writing
%Qand expecting it to behave like input memory: - fix: write
%MW0, observe%QW0as output evidence. - Live Values shows no live data:
- fix: press Start in the truST view, or connect to the runtime there.
- Values not updating:
- fix: confirm cycle is running and writes are applied (not staged only).
Screen¶
hmi/pages/overview.toml shows this example's values. It opens in the HMI Builder in VS Code; press Live while the simulator runs to see the values move. To open it in a browser, enable [runtime.web] in runtime.toml; the runtime then serves it at /hmi.