Model checking

Protocols and verdicts

Model checking proves that the global protocols in your Flex model can’t go wrong. A global protocol describes a whole conversation between components, such as AcceptedThermalBand, in which CommandPost asks Radar for a temperature and Radar replies with one. Each component in it has its own part to play, and the model checker works out whether components that each follow their part will always exchange messages without a mismatch or a deadlock, and always reach the end.

The checker gives each global protocol one of four verdicts. Proven means the protocol is safe, and Ill-formed means it’s definitely wrong. Indeterminate means the checker could neither prove it safe nor find an error, and it names what to look at; Unsupported means the protocol uses something the checker can’t analyze yet. Neither of those two says your design is wrong, but neither is a proof.

RejectedThermalBand shows a protocol that’s Indeterminate. Radar decides whether a reading is in band, but sends CommandPost a Temperature either way, so CommandPost can’t tell which branch Radar took, or whether to reply with Accept or Retry. The checker reports this as knowledge-of-choice. Sending a different message in each branch, OutOfBand for a reading out of band, tells CommandPost which branch it’s in, and the protocol is Proven.

The checker looks at the protocol’s structure, not the values the messages carry, and assumes unbounded message queues. Component tests check the values, against your built component. Writing protocols is covered in the Flex documentation, at flexlang.org.

Indeterminate: the branches look alike
global protocol RejectedThermalBand {
  exch any ReadTemperature from CommandPost to Radar;
  choice in Radar
  | true =>
    exch any Temperature from Radar to CommandPost;
    exch any Accept from CommandPost to Radar;
  | else =>
    exch any Temperature from Radar to CommandPost;
    exch any Retry from CommandPost to Radar;
  end
}
Proven: each branch sends its own message
global protocol RejectedThermalBand {
  exch any ReadTemperature from CommandPost to Radar;
  choice in Radar
  | true =>
    exch any Temperature from Radar to CommandPost;
    exch any Accept from CommandPost to Radar;
  | else =>
    exch any OutOfBand from Radar to CommandPost;
    exch any Retry from CommandPost to Radar;
  end
}

Model-check protocols

tenon verify model model-checks the global protocols in your Flex sources and prints each one’s verdict, with the reason code behind it and the line it’s about. It checks every global protocol in the model unless you name some with --protocol. A verdict other than Proven also comes with an explanation and a suggested fix, which you see with --verbose.

By default Tenon prints a table with one row per protocol, and --format chooses another layout. --out saves the results to a file whose extension sets the format: .json for a machine-readable report, which tracing requirements reads; .txt or .md for text; or .html for a page you can browse. --html opens that page in your browser straight away, and --watch checks again each time you save a .flex file, which suits working on a protocol until it’s Proven.

tenon verify model exits 2 when a protocol is Indeterminate or Unsupported, so a script can tell an unproven protocol from a wrong one. --require-proven makes those count as failures, for a CI job that accepts only a proof. A workflow can model-check your protocols on every run.

Command: tenon verify model [options] [<dir>...]

Arguments

<dir>...
The folders of .flex files to check, as one model. You can also give a single file. Optional when you give --file.

Options

--file <file>
Show results for this file only. With a folder, Tenon still reads the whole model, so imports resolve.
--protocol <name>
Check only these global protocols, separated by commas. A bare name works when it’s unique; a name two files share, or one that matches nothing, is an error. Without it, Tenon checks every global protocol.
--require-proven
Count Indeterminate and Unsupported as failures, so only Proven passes: exit code 2 becomes 1.
--format <summary|detailed|oneline|json>
How to print the results: summary, a table with one row per protocol; detailed, the full explanation of each verdict, with its source and a suggested fix, then the table; oneline, one line per protocol, for logs and scripts; or json. Defaults to summary.
--verbose
The same as --format detailed.
--out <file>
Save the results to <file> instead of printing them. The extension sets the format: .json, .txt, .md, or .html (or .htm).
--html
Open the results as a page in your browser. Add --out <file>.html to keep the page. Can’t be combined with --format.
--watch
Check again each time a .flex file changes, until you press Ctrl-C.

Exit codes

Code Meaning
0 Every protocol is Proven
1 A protocol is Ill-formed, or the check couldn’t run
2 A protocol is Indeterminate or Unsupported (1 with --require-proven)
Model-check protocols
tenon verify model spectenon verify model spec --protocol RejectedThermalBand --verbosetenon verify model spec --watch --html
Model-check in CI
tenon verify model spec --require-proven \    --out reports/modelcheck.json

Explain a verdict

tenon verify model docs opens the model checker’s documentation: what model checking is, what each of the four verdicts means, and every reason code behind one, with its advice. On a terminal it opens a browser you move around with the arrow keys and leave with Esc. --category prints one part as plain text instead, for a pager, a CI log or a screen reader.

Command: tenon verify model docs [--category <category>]

Options

--category <model-checking|verdicts|diagnostic-keys>
Print one category as plain text: model-checking, what model checking is and what the checker does; verdicts, the four verdicts and the reason codes under each; or diagnostic-keys, every reason code, what it means, and what to do about it.
Explain a verdict
tenon verify model docstenon verify model docs --category diagnostic-keys | less

See each component’s part

tenon verify model project prints each component’s own part of your global protocols, as Flex local protocols. That’s what the model checker works from, so it shows you what a protocol asks of each component: in RejectedThermalBand, CommandPost sends ReadTemperature, then listens for either Temperature or OutOfBand and replies to each. A protocol that can’t be split this way is reported, rather than guessed at.

It projects every global protocol in the model unless you name some with --protocol, and every component unless you name one with --role. --write saves the result as a .flex file instead, with the imports it needs, which gives you a starting point for a component’s own local protocol.

Command: tenon verify model project [options] [<dir>...]

Arguments

<dir>...
The folders of .flex files to read, as one model. You can also give a single file. Optional when you give --file.

Options

--file <file>
Show results for this file only. With a folder, Tenon still reads the whole model, so imports resolve.
--json
Print the result as JSON.
--protocol <name>
Project only these global protocols, separated by commas. Names work as they do for tenon verify model.
--role <component>
Print only this component’s part of each protocol.
--write <package,file>
Write the result to <file> instead of printing it. Tenon names the module after the package and the file’s path, so thermal,local/radar.flex declares module thermal.local.radar, and adds the imports the protocols need.
--watch
Project again each time a .flex file changes, until you press Ctrl-C.
See each component's part
tenon verify model project spec --protocol RejectedThermalBandtenon verify model project spec --role Radar