---
id: M07-L01
title: "Test policy independently of hardware"
module: M07
chapters: "15"
checkpoint: "CP07"
---

# M07-L01 — Test policy independently of hardware

Execute the same normal/fault policy source with controlled input. CP07 includes basic native assertions; it does not include thresholds, hysteresis, or the command parser. Read its README and stage requirements before using the final solution as a reference.

The host compiler builds the shared policy and output source with the test harness. The firmware cross-compiler builds those shared files for the documented target. Shared source prevents a test-only reimplementation from drifting away from the firmware, but host execution still does not simulate electronics or MCU timing.

Derive expectations from the contract. Startup is FAULT/missing. One fresh valid sample remains FAULT/recovering; a second recovers to NORMAL. Missing, nonfinite, and stale input fault. Age exactly 3000 milliseconds remains current; age 3001 becomes stale. An invalid sample or stale gap interrupts recovery.

Inspect `tests/test_monitor.cpp` and identify one assertion tied to each condition. The injected clock avoids waiting in real time. It is a test input, not a measured scheduling result. Ordered calls must respect the documented unsigned-timestamp assumptions.

Run from the project root:

```powershell
.\scripts\test.cmd
.\scripts\replay.cmd fixtures/stale-recovery.csv
```

Inspect the actual process result and relevant assertion/output. A passing suite supports behavior for its cases and source. A valid replay can intentionally enter FAULT and still exit zero. Do not label that expected fault as a malformed fixture or a broken test runner.

Write a short requirement-to-check map with input, starting condition, expected outcome, actual result, and evidence pointer. Keep expected output separate from your run. The test's value lies in its ability to distinguish a meaningful error; the next lesson will deliberately challenge the stale boundary.

## Resources and completion

Read Chapter 15 and the matching Sensor Monitor checkpoint README, requirements, and evidence notes. Project paths are relative to its root. Figures: SS15-01, SS15-02, D12. Attempt the [exercise](exercise.md), preserve actual results, then use the separate instructor answer key. 

Source resources: [Chapter 15](../../../../book/chapters/ch15/chapter.md); [checkpoint and recovery map](../../../../examples/sensor-monitor/docs/checkpoints.md). Use the README and requirements inside your named checkpoint; the repository's final CP09 files include features absent from earlier stages. View [D12](../d12.svg) with its [accessible description](../d12.md).
