Files
hsmc/verification/tests/correspondence_event_queue.rs
swaits e183cdd95e feat(verify): discharge Creusot VCs end-to-end
Make `just verify` actually invoke Why3 + alt-ergo + z3 against every
Pearlite VC, and fix the mutant + miri pipelines along the way.

Verification crate
  - Drop the const-generic CAP types for EventQueue / TimerTable.
    Mirror with std::vec::Vec, whose creusot-std specs carry the
    proof burden. Capacity behavior is exercised by the runtime's
    own unit tests + correspondence tests.
  - View impls are #[logic(open)] over a pub field so contracts on
    push/pop/etc. can see the link to the inner Vec's @ view.
  - 14/14 VCs discharge: EventQueue {new, push, pop, is_empty, len,
    clear, Default}; TimerTable {new, len, is_empty, Default};
    Entry derives.
  - `cargo creusot prove --no-cache` always runs the SMT solvers;
    `time` shows ~7s CPU on ~1.2s wall-clock = real parallel work.

Tooling
  - verification/mise.toml pins nightly-2025-11-13 + rust-src,
    rustc-dev, llvm-tools-preview, rustfmt; declares opam, python,
    uv, and the project-local .venv. Inherits root mise.toml's just
    + cargo-* tools.
  - just verify clones creusot v0.9.0 to ~/.local/share/hsmc-verify/
    and runs the canonical ./INSTALL — that's the only way the
    bundled prelude-generator + creusot-rustc actually build.
  - just verify --no-cache forces SMT re-runs every time.
  - Drop bespoke pin/install of cargo-creusot from mise.toml; the
    cargo backend goes through cargo-binstall which can't pin a
    multi-bin git workspace at a tag.

Mutants — was missing every JournalSink mutant
  - Recipe runs with --features tokio,journal so journal_* and det_*
    tests (gated on both) actually execute.
  - Add clear_journal_empties_the_journal test in journal_smoke.rs
    to kill the JournalSink::clear with-() mutant.
  - Remove dead JournalSink::len + is_empty (called nowhere; only
    existed as mutation-bait).
  Result: 0 missed, 42 caught, 211 unviable (proc-macro emitted
  code that mutants can't standalone-compile).

Miri — was hitting the trybuild glob isolation issue
  - --exclude hsmc-macros (trybuild ui test isn't UB-relevant)
  - --exclude hsmc-verification (different pinned toolchain)
  - 66 tests pass under Miri, 0 UB.

Gitignore
  - /verif/, /why3find.json, /.why3find/, **/.venv/ — all
    regenerated by `just verify`. Repo stays clean of per-machine
    prover timings + venv artifacts.

Misc
  - Fix root-state targetability: `on(Trig) => <ChartName>;` resolves
    to root id 0 in both ir.rs::resolve_transitions and
    validate.rs's separate name_map.
  - `set shell` and `set script-interpreter` route every justfile
    recipe through `mise exec`, so all subshells see the right
    Rust + opam + cargo-* tools regardless of how `just` was
    invoked. No shebangs anywhere.
2026-04-27 21:22:44 -06:00

123 lines
3.3 KiB
Rust

//! Correspondence test: the verified [`EventQueue`] mirror behaves
//! identically to the real runtime [`hsmc::__private::EventQueue`]
//! for the operations we've verified.
//!
//! The mirror is unbounded (uses `Vec<E>`) where the runtime is
//! capacity-bounded (uses `heapless::Deque<E, N>`). This test ignores
//! capacity exhaustion — that path is exercised by the runtime's own
//! unit tests in `hsmc/src/lib.rs::private_internals`. What this test
//! pins down is the FIFO discipline + length tracking + clear, which
//! ARE proven by Creusot for the mirror.
use hsmc::__private::EventQueue as RealQueue;
use hsmc_verification::event_queue::EventQueue as MirrorQueue;
#[derive(Debug, Clone, Copy)]
enum Op {
Push(u32),
Pop,
Clear,
IsEmpty,
Len,
}
/// Drive both queues with the same op sequence and assert observable
/// behavior matches at every step.
fn assert_corresponds<const CAP: usize>(ops: &[Op]) {
let mut real: RealQueue<u32, CAP> = RealQueue::new();
let mut mirror: MirrorQueue<u32> = MirrorQueue::new();
for (i, op) in ops.iter().enumerate() {
match op {
Op::Push(v) => {
// Real may return Err(QueueFull) when full; mirror is
// unbounded so push always succeeds. Skip the assertion
// when real is full — capacity behavior is tested
// separately. Otherwise both succeed; lengths track.
let r = real.push(*v);
if r.is_ok() {
mirror.push(*v);
}
}
Op::Pop => {
let r = real.pop();
let m = mirror.pop();
assert_eq!(r, m, "step {i} Pop: real {r:?} vs mirror {m:?}");
}
Op::Clear => {
real.clear();
mirror.clear();
}
Op::IsEmpty => {
assert_eq!(
real.is_empty(),
mirror.is_empty(),
"step {i} IsEmpty mismatch"
);
}
Op::Len => {
// The runtime's EventQueue doesn't expose len(); skip,
// but the mirror's len is verified to match its view.
let _ = mirror.len();
}
}
}
}
#[test]
fn corr_basic_push_pop() {
assert_corresponds::<8>(&[
Op::IsEmpty,
Op::Push(1),
Op::Push(2),
Op::Push(3),
Op::Len,
Op::IsEmpty,
Op::Pop,
Op::Pop,
Op::Pop,
Op::IsEmpty,
Op::Pop,
]);
}
#[test]
fn corr_clear_empties() {
assert_corresponds::<8>(&[
Op::Push(1),
Op::Push(2),
Op::Push(3),
Op::Clear,
Op::IsEmpty,
Op::Pop,
Op::Push(99),
Op::Pop,
]);
}
#[test]
fn corr_alternating() {
let mut ops = Vec::new();
for i in 0..50u32 {
ops.push(Op::Push(i));
ops.push(Op::Push(i + 100));
ops.push(Op::Pop);
}
assert_corresponds::<8>(&ops);
}
#[test]
fn corr_fill_drain_repeat() {
let mut ops = Vec::new();
for round in 0..5 {
for i in 0..8u32 {
ops.push(Op::Push(round * 100 + i));
}
for _ in 0..8 {
ops.push(Op::Pop);
}
}
ops.push(Op::IsEmpty);
assert_corresponds::<8>(&ops);
}