Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Verifying: fire verify

fire verify checks the UPPAAL model fire build wrote against the project’s queries, with UPPAAL’s verifyta. The model assumes the contracts of the imported code, so it proves those first. It never writes the model: run fire build first, and again after a source changes.

Usage

fire verify [PROJECT_DIR] [-q <QUERY_FILE>] [-o <OUTPUT_FILE>]
Argument / flagDescription
PROJECT_DIRThe directory holding fire.toml. Defaults to the current directory.
-q, --query <QUERY_FILE>One query file, instead of every .q in <src>/spec/.
-o, --output <OUTPUT_FILE>Also save the report as plain text, even when the run fails.

What it does

  1. Reads fire.toml and resolves the source directory.

  2. Proves the imported code’s contracts with the code verifier for each language that has any: Frama-C for annotated C, pancake2viper for Pancake. Files without contracts have nothing to prove. A header’s contracts are proved on the project’s .c file of the same name, which includes it (include/eth.h on src/eth.c); an annotated header with no such source is an error. A C function named in the entry’s assume is not proved: its file gets an ASSUMED row naming it. Rows name a file by its path in the project.

    A contract can also be on a function that none of those files defines, such as a library routine. Frama-C uses such a contract at each call but cannot prove it. fire verify lists these functions in a row for the header that declares them:

    • EXTERNAL for include/gen/mem.h, the memory routines fic links into every PD. fic proves their contracts itself.
    • ASSUMED for any other header. Nobody proved these contracts.

    fic’s proof holds only for the gen/mem.h that fic generates. If the file has been changed, the run fails on a row naming it; fire build writes the file again.

  3. Reads build/<name>.xta. The --pretty XML is for the GUI only.

  4. Runs verifyta ([verify.model_checker] path, then $VERIFYTA, then PATH) on the model and each query file, asking for a trace.

  5. Prints one PASS / FAIL line per contract file and per query, and exits non-zero if any check fails, or if verifyta answered fewer queries than a file holds (a refused licence, a crash).

With -o, each part’s rows are followed by one line with the tools’ own figures. For C contracts:

verify contracts  demo: datadiode  result: PASS  files: 3  functions: 9  goals: 110/110  assumed: 9  external: 6
  • functions: the functions whose contract Frama-C proves on their body. A contract is the annotation on one function.
  • goals: the facts WP proved, of those it had to. One contract takes several goals, and -wp-rte adds one for each operation that could fail at run time.
  • assumed: the functions that are not proved, named in assume or declared by a header no proved file gives a body for.
  • external: the functions of include/gen/mem.h, which fic proves.

assumed and external are left out when they are zero, and functions when the fic-acsl plugin is not installed.

Writing queries

Which properties matter depends on the application, so fic emits only the model and you write the queries: a UPPAAL query file in <src>/spec/, part of the project’s sources.

Queries name the process instances of the model (the PD names) and their locations; a PD’s variables keep their names, and a struct’s field is pd.var.field. Read build/<name>.xta, or open the --pretty XML in the UPPAAL GUI, to find them.

Buffered channels in the model

A buffered channel c is a queue q_c holding its length (in place of the ring’s two indices), signalled (as filib’s signal word: false while the receiver asks to be notified) and capacity, plus pend_c, Microkit’s pending notification. Its values are q_c_val, oldest first. A PD that receives on one has a local awake:

  • a send that fits stores its value at q_c_val[q_c.length], adds one and, if the receiver asked, sets pend_c; on a full queue it is lost;
  • a receive needs awake && q_c.length > 0, takes q_c_val[0] and shifts the rest down;
  • at a resume point the PD parks (awake = false, asking on each buffered arm) when no arm is enabled, and wakes on a pending notification.

So A[] not (!rx.awake && q_c.length > 0 && !pend_c) states that no wake-up is lost.

An IRQ is raised by the Environment template for ever, as a test harness keeps feeding a device, and handled as seL4 handles it: a raise sets irq_N_pend, which the PD’s irq?N takes, and masks the IRQ (irq_N_masked) until the driver acks it with irq!N, so the device raises again only after the ack. What the device delivers comes from the driver’s contracts (see Contracts). The device always has a move unless a driver never takes or never acks its IRQ, so A[] not deadlock states that no driver is stuck on its IRQ. A receiver stuck on a buffered channel while others run is not a deadlock: the lost-wake-up query above catches it. Each queue holds at most 3 in the model (its capacity if smaller). A result that holds there holds of the real capacity once the small-capacity argument is proved (#601, obligation 6).

A struct in the model keeps its fields but its arrays: a .fi program never indexes one, so no guard reads it. A call whose contract fixes a field of its result (ensures \result.origin == origin) sets that field and leaves the others as they were.

That is enough for secrecy, a reachability query. demo/datadiode’s Frame carries origin, the network it came in on, which eth_frame’s contract fixes; A[] not (... dd.f.origin == ORIGIN_INNER ...) states that no frame from the inner network reaches a PD on the outer side, in any variable or queue slot.

Worked example: ping-pong

demo/pingpong/ has two PDs, ping and pong, which bounce a notification ROUNDS times over a cyclic channel (ping <-> pong) and then stop. WF2 would reject the cycle, so the manifest sets allow_wf2_cycles and spec/pingpong.q decides deadlock freedom instead:

$ fire verify demo/pingpong/
fire: verifying pingpong
  ✓ Running frama-c: /usr/local/bin/frama-c

  ACSL: pingpong.c                                         PASS
  ✓ Running verifyta: /opt/uppaal/bin/verifyta
  ✓ Query file: demo/pingpong/spec/pingpong.q

  Q1  A[] (deadlock imply ping.rounds == ROUNDS)           PASS
  Q2  E<> ping.rounds == ROUNDS                            PASS
  Q3  A[] ping.rounds <= ROUNDS                            PASS
  Q4  E<> pong.L2                                          PASS
  Q5  A<> ping.rounds == ROUNDS                            PASS

Q1 is deadlock freedom up to the intended end: the finished rally is a state where both PDs wait, so a plain A[] not deadlock would fail on it. Q5 says the rally finishes on every path.

Reading a failure

A failing query prints FAIL and, when verifyta produces one, the trace:

  Q1  A[] not deadlock                                     FAIL
    Trace (12 steps):
      ...
      ↯ stuck at: ping.L1, pong.L2

The ↯ stuck at line gives each automaton’s location in the deadlocked state, usually enough to spot the circular wait. A reachability query that fails with (property unreachable — no counterexample trace) names a state that can never be entered.