Lesson: A Level Crossing
This lesson reads the level crossing that Live serves, verifies its two cases, and reads the trace of the one that fails.
The Model
Two tracks cross a road at one barrier. Each track reports its trains to a controller, and the controller tells the barrier to go down and up. The events they exchange are declared by three interfaces:
A track follows a train from Free through Approaching and Near to InCrossing on its sensors' events. It reports trainApproaching when a train approaches and trainLeft when it leaves:
The controller lowers the barrier on the first report of an approach, from either track, and lifts it on the first report that a train left:
The synchronous composite LevelCrossing holds a statechart of each kind, two tracks among them, binds the tracks' sensors to its own ports and connects the reports and the commands by channels:
The model runs in steps. In each step the environment may raise the sensors' events, every statechart runs once, and the events sent over channels arrive in the next step. Semantic Decisions states the full semantics.
Verification Cases
A verification case names its component and holds its property, as Writing a Verification Case says. The first case claims that no train is ever in the crossing while the barrier is up:
The second asks whether trains on both tracks can be in the crossing at once:
Before you run the first, think about whether it holds.
Verifying
Press Verify all in any of the editors above; each verifies the whole model.
To verify it on your machine, save the model as LevelCrossing.gamma and run semantifyr-gamma verify LevelCrossing.gamma.
Reading the Trace
A case has a trace when a single run proves its verdict: a failed AG or a passed EF case. Which run a trace shows depends on the backend that answered. In most steps of the run below the environment raises several sensor events at once, and a track takes the one its state has a transition for. The trace of BarrierDownWhileTrainInCrossing has seven steps:
- Initialization: both tracks are
Free, the controller isIdle, and the barrier isUp. - Trains approach on both tracks, and both tracks report
trainApproaching. - Both trains are
Near. The controller takes track A's report, moves toTrainPresent, and raiseslower. Track B's report is lost, since a statechart's input events are reset after it runs. - Both trains enter the crossing, and the barrier goes
Down. - Track A's train leaves, and track A reports
trainLeft. - The controller takes track A's report, moves to
Idle, and raiseslift. A new train approaches on track A. - The barrier takes the
liftand goesUpwhile track B's train is still in the crossing. The controller takes track A's new report and raiseslower; the trace ends with the barrierUp.
The case fails because the controller follows one train at a time: it loses track B's report and lifts the barrier when track A's train leaves, with track B's train still in the crossing. Whether that is a defect of the design or of the requirement is for the engineer to decide.
The Gamma trace view shows the same run as a Gamma execution trace (Gamma traces); on your machine it is trace.get, next to the case's report.