© 2011 Carnegie Mellon University Introduction to SMV Part 2 Arie Gurfinkel (SEI/CMU) based on material by Prof. Clarke and others.

Slides:



Advertisements
Similar presentations
Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
Advertisements

SMV Example: Bus Protocol Ed Clarke Daniel Kroening Carnegie Mellon University.
Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Introduction to SMV Part 2
Metodi formali dello sviluppo software a.a.2013/2014 Prof.Anna Labella.
Algorithmic Software Verification VII. Computation tree logic and bisimulations.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Introduction to Formal Methods for SW and HW Development 09: SAT Based Abstraction/Refinement in Model-Checking Roberto Sebastiani Based on work and slides.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
An Introduction to the Model Verifier verds Wenhui Zhang September 15 th, 2010.
CS5270 Lecture 31 Uppaal, and Scheduling, and Resource Access Protocols CS 5270 Lecture 3.
ECE Synthesis & Verification - L271 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Model Checking basics.
1 MODULE name (parameters) “Ontology” “Program” “Properties” The NuSMV language A module can contain modules Top level: parameters less module Lower level.
Temporal Logic and the NuSMV Model Checker CS 680 Formal Methods Jeremy Johnson.
Model Checking I What are LTL and CTL?. and or dreq q0 dack q0bar.
CS6133 Software Specification and Verification
UPPAAL Introduction Chien-Liang Chen.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Model Checking Inputs: A design (in some HDL) and a property (in some temporal logic) Outputs: Decision about whether or not the property always holds.
CS 267: Automated Verification Lecture 7: SMV Symbolic Model Checker, Partitioned Transition Systems, Counter-example Generation in Symbolic Model Checking.
Model Checking I What are LTL and CTL?. and or dreq q0 dack q0bar D D.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
© 2011 Carnegie Mellon University Introduction to SMV Arie Gurfinkel (SEI/CMU) based on material by Prof. Clarke and others.
FMuOS: Formal verification of critical program parts NuSMV system Prepared by: Alan Jović, Ph.D. Acad. year: 2014/2015.
Shared Memory Coordination We will be looking at process coordination using shared memory and busy waiting. –So we don't send messages but read and write.
SMV Examples Bug Catching in 2006 Fall Oct. 24, 2006.
Lecture 4&5: Model Checking: A quick introduction Professor Aditya Ghose Director, Decision Systems Lab School of IT and Computer Science University of.
1 Using Cadence SMV to verify temporal properties of finite-state machines : Intro to Model Checking October 9, 2008.
Review of the automata-theoretic approach to model-checking.
2/18/20051 Introduction to SMV. 2/18/20052 Symbolic Model Verifier Ken McMillan, Symbolic Model Checking: An Approach to the State Explosion Problem,
System Design Research Laboratory Specification-based Testing with Linear Temporal Logic Li Tan Oleg Sokolsky Insup Lee University of Pennsylvania.
Flavio Lerda 1 LTL Model Checking Flavio Lerda. 2 LTL Model Checking LTL –Subset of CTL* of the form: A f where f is a path formula LTL model checking.
Traffic Light Controller Examples in SMV Himanshu Jain Bug catching (Fall 2007)
Introduction to Software Testing Chapter 9.4 Model-Based Grammars Paul Ammann & Jeff Offutt
1 Introduction to SMV and Model Checking Mostly by: Ken McMillan Cadence Berkeley Labs Small parts by: Brandon Eames ISIS/Vanderbilt.
Institute for Applied Information Processing and Communications 1 Karin Greimel Semmering, Open Implication.
1 Automatic Refinement and Vacuity Detection for Symbolic Trajectory Evaluation Orna Grumberg Technion Haifa, Israel Joint work with Rachel Tzoref.
SMV TUTORIAL – Part I Eriko Nurvitadhi Note: content of these slides are from “Getting started with SMV” by K. L. McMillan, Refer to this document.
10/19/2015COSC , Lecture 171 Real-Time Systems, COSC , Lecture 17 Stefan Andrei.
CS6133 Software Specification and Verification
Automatic Verification of Finite-State Concurrent Systems Using Temporal Logic Specifications 1.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Introduction to Formal Verification using Rulebase April 18, 2001 Rebecca Gott eServer I/O Development Hardware Verification
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
2/19/20031 Introduction to SMV. 2/19/20032 Useful Links CMU Model checking homepage SMV windows version
1 Example: traffic light controller Guarantee no collisions Guarantee eventual service E S N.
Lecture 81 Optimizing CTL Model checking + Model checking TCTL CS 5270 Lecture 9.
CIS 842: Specification and Verification of Reactive Systems Lecture INTRO-Examples: Simple BIR-Lite Examples Copyright 2004, Matt Dwyer, John Hatcliff,
VIS Technology Transfer Course Session 7 Fairness Constraints and Monitors Serdar Tasiran.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
1 CSEP590 – Model Checking and Automated Verification Lecture outline for July 9, 2003.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Writing, Verifying and Exploiting Formal Specifications for Hardware Designs Chapter 3: Verifying a Specification Presenter: Scott Crosby.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Basic concepts of Model Checking
CS 352 Introduction to Logic Design
Learning to Program in Python
Automatic Verification of Industrial Designs
CSCI1600: Embedded and Real Time Software
Introduction to SMV 2/19/2003.
Lecture 9: SMV: An Introduction
Presentation transcript:

© 2011 Carnegie Mellon University Introduction to SMV Part 2 Arie Gurfinkel (SEI/CMU) based on material by Prof. Clarke and others

© 2011 Carnegie Mellon University Brief Review

3 © 2011 Carnegie Mellon University 2/18/ Symbolic Model Verifier (SMV) Ken McMillan, Symbolic Model Checking: An Approach to the State Explosion Problem, Finite-state Systems described in a specialized language Specifications given as CTL formulas Internal representation using ROBDDs Automatically verifies specification or produces a counterexample

4 © 2011 Carnegie Mellon University 2/18/ A Sample SMV Program (short.smv) MODULE main VAR request: boolean; state: {ready, busy}; ASSIGN init(state) := ready; next(state) := case state=ready & request: busy; TRUE: {ready, busy}; esac; SPEC AG(request -> AF (state = busy)) MODULE main VAR request: boolean; state: {ready, busy}; ASSIGN init(state) := ready; next(state) := case state=ready & request: busy; TRUE: {ready, busy}; esac; SPEC AG(request -> AF (state = busy))

5 © 2011 Carnegie Mellon University A Three-Bit Counter MODULE main VAR bit0 : counter_cell(TRUE); bit1 : counter_cell(bit0.carry_out); bit2 : counter_cell(bit1.carry_out); SPEC AG AF bit2.carry_out MODULE counter_cell(carry_in) VAR value : boolean; ASSIGN init(value) := FALSE; next(value) := value xor carry_in; DEFINE carry_out := value & carry_in; MODULE main VAR bit0 : counter_cell(TRUE); bit1 : counter_cell(bit0.carry_out); bit2 : counter_cell(bit1.carry_out); SPEC AG AF bit2.carry_out MODULE counter_cell(carry_in) VAR value : boolean; ASSIGN init(value) := FALSE; next(value) := value xor carry_in; DEFINE carry_out := value & carry_in; value + carry_in mod 2

6 © 2011 Carnegie Mellon University inout val inout inout inout val module instantiations bit0 bit1 bit2 module declaration

7 © 2011 Carnegie Mellon University Inverter Ring MODULE main VAR gate1 : process inverter(gate3.output); gate2 : process inverter(gate1.output); gate3 : process inverter(gate2.output); SPEC (AG AF gate1.output) & (AG AF !gate1.output) MODULE inverter(input) VAR output : boolean; ASSIGN init(output) := FALSE; next(output) := !input; FAIRNESS running MODULE main VAR gate1 : process inverter(gate3.output); gate2 : process inverter(gate1.output); gate3 : process inverter(gate2.output); SPEC (AG AF gate1.output) & (AG AF !gate1.output) MODULE inverter(input) VAR output : boolean; ASSIGN init(output) := FALSE; next(output) := !input; FAIRNESS running

8 © 2011 Carnegie Mellon University Fairness Assumed to be true infinitely often Model checker only explores paths satisfying fairness constraint Each fairness constraint must be true infinitely often If there are no fair paths All existential formulas are false All universal formulas are true FAIRNESS Ctlform FAIRNESS running

9 © 2011 Carnegie Mellon University Can A TRUE Result of Model Checker be Trusted Antecedent Failure [Beatty & Bryant 1994] A temporal formula AG (p ⇒ q) suffers an antecedent failure in model M iff M ⊧ AG (p ⇒ q) AND M ⊧ AG (  p) Vacuity [Beer et al. 1997] A temporal formula  is satisfied vacuously by M iff there exists a sub-formula p of  such that M ⊧  [p←q] for every other formula q e.g., M ⊧ AG (r ⇒ AF a) and M ⊧ AG (r ⇒ AF  a) and AG (r ⇒ AF  r) and AG (r ⇒ AF FALSE ), …

10 © 2011 Carnegie Mellon University Vacuity Detection: Single Occurrence  is vacuous in M iff there exists an occurrence of a subformula p such that M ⊧  [p ← TRUE] and M ⊧  [p ← FALSE] M ⊧ AG (req ⇒ AF TRUE) M ⊧ AG TRUE M ⊧ AG (req ⇒ AF FALSE) M ⊧ AG  req M ⊧ AG (TRUE ⇒ AF ack) M ⊧ AG AF ack M ⊧ AG (FALSE ⇒ AF ack) M ⊧ AG TRUE

11 © 2011 Carnegie Mellon University Detecting Vacuity in Multiple Occurrences: ACTL An ACTL  is vacuous in M iff there exists an a subformula p such that M ⊧  [p ← x], where x is a non-deterministic variable Is AG (req ⇒ AF req) vacuous? Should it be? Is AG (req ⇒ AX req) vacuous? Should it be? Always vacuous!!! M ⊧ AG (x ⇒ AF x) M ⊧ AG TRUE Can be vacuous!!! M ⊧ AG (x ⇒ AX x) can’t reduce

12 © 2011 Carnegie Mellon University Run NuSMV NuSMV [options] inputfile -int interactive mode -lplist all properties -n X check property number X -cttcheck totality of transition relation -oldcompatibility mode -ofm file output flattened model

13 © 2011 Carnegie Mellon University Using NuSMV in Interactive Mode Basic Usage go – prepare model for verification check_ctlspec – verify properties Simulation pick_state [-i] [-r] – pick initial state for simulation [interactively] or [randomly] simulate [-i] [r] s – simulate the model for ‘s’ steps [interactively] or [randomly] show_traces – show active traces

14 © 2011 Carnegie Mellon University Useful Links NuSMV home page NuSMV tutorial NuSMV user manual NuSMV FAQ NuSMV on Andrew /afs/andrew.cmu.edu/usr6/soonhok/public/NuSMV-zchaff x86_64-redhat- linux-gnu/ NuSMV examples /share/nusmv/examples Ken McMillan, Symbolic Model Checking: An Approach to the State Explosion Problem,

15 © 2011 Carnegie Mellon University Today: 3 Examples Mutual Exclusion Bus Protocol Traffic Light Controller

16 © 2011 Carnegie Mellon University Example 1: Mutual Exclusion Two processes want access to a shared resource they go through idle, trying, critical states Safety (Mutual Exclusion) Only one process can be in the critical section at any given time – AG ( !(p0 = critical & p1 = critical) ) Liveness (No Starvation) If a process is trying to enter critical section, it eventually enters it – AG (p0 = trying -> AF p0 = critical)

Ed Clarke Daniel Kroening Carnegie Mellon University SMV Example: Bus Protocol

Overview Node 1 Design goals: Collision free operation Priorities for the nodes Design goals: Collision free operation Priorities for the nodes Preliminaries: Single, shared bus Every node can broadcast on this bus Preliminaries: Single, shared bus Every node can broadcast on this bus Node 2 Node 3 Node 4 Similar busses are used in the automotive industry CAN Byteflight Similar busses are used in the automotive industry CAN Byteflight

Basic Idea Achieve design goals by: Assign unique time to each node Guarantees Collision free operation The node with the lower time gets priority Achieve design goals by: Assign unique time to each node Guarantees Collision free operation The node with the lower time gets priority Operation Principle Round based algorithm First person to start sending gets the bus Operation Principle Round based algorithm First person to start sending gets the bus 

Example Node 1 Node 2 Node 3 Node 4   Bus time 

Example Node 1 Node 2 Node 3 Node 4   Bus time  Hm, I won’t send

Example Node 1 Node 2 Node 3 Node 4   Bus time  I will send!

Example Node 1 Node 2 Node 3 Node 4   Bus time 

Example Node 1 Node 2 Node 3 Node 4   Bus time 

Example Node 1 Node 2 Node 3 Node 4   Bus time 

Example Node 1 Node 2 Node 3 Node 4   Bus time  RESET CLOCK! Start of new Cycle

Example Node 1 Node 2 Node 3 Node 4   Bus time  Hm, I won’t send

SMV Model Design: A state machine controls each node Counter keeps track of clock Design: A state machine controls each node Counter keeps track of clock Counter: Reset if someone sends Increment otherwise Counter: Reset if someone sends Increment otherwise MODULE node(bus_active) VAR counter: ; ASSIGN next(counter):= case bus_active : 0; counter < 99: counter + 1; TRUE: 99; esac; MODULE node(bus_active) VAR counter: ; ASSIGN next(counter):= case bus_active : 0; counter < 99: counter + 1; TRUE: 99; esac;

SMV Model Design: A state machine controls each node Counter keeps track of the clock Design: A state machine controls each node Counter keeps track of the clock Bus busy Skip Wait Sending bus_active beginning counter=priority

SMV Model MODULE node(priority, bus_active) VAR counter: ; state: { busy, skip, waiting, sending }; ASSIGN init(state):=busy; next(state):= case state=busy & beginning : { skip, waiting }; state=busy : busy; state=skip & bus_active : busy; state=skip : skip; state=waiting & bus_active : waiting; state=waiting & counter=priority: sending; state=waiting: waiting; state=sending: { busy, sending }; esac; MODULE node(priority, bus_active) VAR counter: ; state: { busy, skip, waiting, sending }; ASSIGN init(state):=busy; next(state):= case state=busy & beginning : { skip, waiting }; state=busy : busy; state=skip & bus_active : busy; state=skip : skip; state=waiting & bus_active : waiting; state=waiting & counter=priority: sending; state=waiting: waiting; state=sending: { busy, sending }; esac;

SMV Model MODULE main VAR node1: node(1, bus_active); node2: node(2, bus_active); node3: node(3, bus_active); node4: node(4, bus_active); DEFINE bus_active:=node1.is_sending | node2.is_sending | node3.is_sending | node4.is_sending; MODULE main VAR node1: node(1, bus_active); node2: node(2, bus_active); node3: node(3, bus_active); node4: node(4, bus_active); DEFINE bus_active:=node1.is_sending | node2.is_sending | node3.is_sending | node4.is_sending;

Properties Desired Properties Safety: Only one node uses the bus at a given time Desired Properties Safety: Only one node uses the bus at a given time SPEC AG (node1.is_sending -> (!node2.is_sending & !node3.is_sending & !node4.is_sending)) SPEC AG (node2.is_sending -> (!node1.is_sending & !node3.is_sending & !node4.is_sending)) SPEC AG (node3.is_sending -> (!node1.is_sending & !node2.is_sending & !node4.is_sending)) SPEC AG (node4.is_sending -> (!node1.is_sending & !node2.is_sending & !node3.is_sending)) SPEC AG (node1.is_sending -> (!node2.is_sending & !node3.is_sending & !node4.is_sending)) SPEC AG (node2.is_sending -> (!node1.is_sending & !node3.is_sending & !node4.is_sending)) SPEC AG (node3.is_sending -> (!node1.is_sending & !node2.is_sending & !node4.is_sending)) SPEC AG (node4.is_sending -> (!node1.is_sending & !node2.is_sending & !node3.is_sending))

Properties Desired Properties Liveness: a node that is waiting for the bus will eventually get it, given that the nodes with higher priority are fair Desired Properties Liveness: a node that is waiting for the bus will eventually get it, given that the nodes with higher priority are fair FAIRNESS node1.is_skipping FAIRNESS node1.is_skipping & node2.is_skipping FAIRNESS node1.is_skipping & node2.is_skipping & node3.is_skipping SPEC AG AF bus_active SPEC AG(node1.is_waiting -> AF node1.is_sending) SPEC AG(node2.is_waiting -> AF node2.is_sending) SPEC AG(node3.is_waiting -> AF node3.is_sending) SPEC AG(node4.is_waiting -> AF node4.is_sending) FAIRNESS node1.is_skipping FAIRNESS node1.is_skipping & node2.is_skipping FAIRNESS node1.is_skipping & node2.is_skipping & node3.is_skipping SPEC AG AF bus_active SPEC AG(node1.is_waiting -> AF node1.is_sending) SPEC AG(node2.is_waiting -> AF node2.is_sending) SPEC AG(node3.is_waiting -> AF node3.is_sending) SPEC AG(node4.is_waiting -> AF node4.is_sending)

based on slides by Himanshu Jain Traffic Light Controller

Outline  Modeling Traffic Light Controller in SMV  Properties to Check  Four different SMV models for traffic light controller

N S W Scenario

N S W   No turning

N S W Binary traffic lights

N S W Safety Property This should not happen

N S W Safety Property This should not happen

N S W Liveness Property When will the stupid light become green again

N S W Liveness Property Thank God! Traffic in each direction must be served

43 Let’s Model all of this in NuSMV

44 N S W SMV variables North.Go=F South.Go=F West.Go=T Three Boolean variables track the status of the lights

45 N S W SMV variables Three Boolean variables sense the traffic in each direction North.Sense =T South.Sense =T West.Sense =F

Properties 1/2  Mutual exclusion  AG !(West.Go & (North.Go | South.Go))  Liveness (e.g., in North direction)  AG (North.Sense & !North.Go -> AF North.Go)  Similarly for South and West directions 46

Properties 2/2  No strict sequencing  We don’t want the traffic lights to give turns to each other (if there is no need for it)  For example, if there is no traffic on west lane, we do not want West.Go becoming TRUE periodically  We can specify such properties partially  AG (West.Go -> A[West.Go U !West.Go & A[!West.Go U South.Go | North.Go]])  See code for other such properties  We want these properties to FAIL 47

48 N S W SMV modules North module will control South module will control West module will control Main module Initialize variables Start s all modules

N S W What if north light is always green and there is always traffic in north direction???

Fairness Constraints  What if a light is always green and there is always traffic in its direction  We will avoid such scenarios by means of fairness constraints  FAIRNESS !(Sense & Go)  FAIRNESS running  In any infinite execution, there are infinite number of states where either the light is red or there is no traffic in its direction

Implementations…

Some more variables  To ensure mutual exclusion  We will have two Boolean variables  NS_lock : denotes locking of north/south lane  EW_lock : denotes locking of west lane  To remember that there is traffic on a lane  Boolean variable: North.Req  If North.Sense becomes TRUE, then North.Req is set to TRUE  Similarly, for South.Req and West.Req

traffic1.smv: main module MODULE main VAR -- lock for North-South direction NS_lock : boolean; -- lock for East-West direction EW_lock : boolean; North : process North (NS_lock, EW_lock, South.Go); South : process South (NS_lock, EW_lock, North.Go); West : process West (EW_lock, NS_lock); ASSIGN init (NS_lock) := FALSE; init (EW_lock) := FALSE; … MODULE main VAR -- lock for North-South direction NS_lock : boolean; -- lock for East-West direction EW_lock : boolean; North : process North (NS_lock, EW_lock, South.Go); South : process South (NS_lock, EW_lock, North.Go); West : process West (EW_lock, NS_lock); ASSIGN init (NS_lock) := FALSE; init (EW_lock) := FALSE; …

traffic1.smv: North module1/2 MODULE North (NS_lock, EW_lock, FriendGo) VAR Go : boolean; Sense : boolean; Req : boolean; State : {idle, entering, critical, exiting}; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; State = entering & !EW_lock : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac; MODULE North (NS_lock, EW_lock, FriendGo) VAR Go : boolean; Sense : boolean; Req : boolean; State : {idle, entering, critical, exiting}; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; State = entering & !EW_lock : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac;

traffic1.smv: North module2/2 next (NS_lock) := case State = entering & !EW_lock : TRUE; State = exiting & !FriendGo : FALSE; TRUE: NS_lock; esac; init (Req) := FALSE; next (Req) := case State = exiting : FALSE; Sense: TRUE; TRUE: Req; esac; next (NS_lock) := case State = entering & !EW_lock : TRUE; State = exiting & !FriendGo : FALSE; TRUE: NS_lock; esac; init (Req) := FALSE; next (Req) := case State = exiting : FALSE; Sense: TRUE; TRUE: Req; esac; init (Go) := FALSE; next (Go) := case State = critical : TRUE; State = exiting : FALSE; TRUE : Go; esac; init (Go) := FALSE; next (Go) := case State = critical : TRUE; State = exiting : FALSE; TRUE : Go; esac;

56 South is symmetric West is a bit simpler (no East) Let’s run NuSMV!!!

Mutual Exclusion CEX 1. All variables FALSE 2. North.Sense = T (North Run) 3. North.Sense=F, North.Req = T 4. North.State = entering 5. NS_lock=T, North.Sense=T,North.State=critical 6. South.Sense=T (South Run) 7. South.Sense=F, South.Req=T 8. South.State = entering 9. South.State = critical 10. South.Go = T, South.State = exiting 11. West.Sense=T (West Run) 12. West.Sense=F, West.Req=T 13. West.State=entering 14. NS_lock=F, South.Go=F,South.Req=F, South.State=idle (South Run) 15. EW_lock=T, West.State=critical,West.Sense=T (West Run) 16. North.Go=T, North.Sense=F(North Run) 17. West.Go=T, West.Sense=F(West Run)

traffic1.smv: North module1/2 MODULE North (NS_lock, EW_lock, FriendGo) VAR Go : boolean; Sense : boolean; Req : boolean; State : {idle, entering, critical, exiting}; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; State = entering & !EW_lock : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac; MODULE North (NS_lock, EW_lock, FriendGo) VAR Go : boolean; Sense : boolean; Req : boolean; State : {idle, entering, critical, exiting}; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; State = entering & !EW_lock : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac; init (Go) := FALSE; next (Go) := case State = critical : TRUE; State = exiting : FALSE; TRUE : Go; esac; init (Go) := FALSE; next (Go) := case State = critical : TRUE; State = exiting : FALSE; TRUE : Go; esac;

traffic2.smv: fix DEFINE EnterCritical := State = entering & !EW_lock; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; EnterCritical : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac; DEFINE EnterCritical := State = entering & !EW_lock; ASSIGN init (State) := idle; next (State) := case State = idle & Req : entering; EnterCritical : critical; State = critical & !Sense : exiting; State = exiting : idle; TRUE : State; esac; init (Go) := FALSE; next (Go) := case EnterCritical : TRUE; State = exiting : FALSE; TRUE : Go; esac; init (Go) := FALSE; next (Go) := case EnterCritical : TRUE; State = exiting : FALSE; TRUE : Go; esac;

Model checking traffic2.smv  Mutual exclusion property is satisfied  Liveness property for North direction fails  AG ( (Sense & !Go) -> AF Go) IN North

CEX for Liveness is a Fair Cycle 1.6 North.State = entering North.EnterCritical = T all others are idle 1.6 North.State = entering North.EnterCritical = T all others are idle 1.10 South is given a turn, but does nothing 1.10 South is given a turn, but does nothing 1.15 West.State = critical 1.15 West.State = critical 1.16 North is given a turn, but can’t get a lock 1.16 North is given a turn, but can’t get a lock 1.19 West.State = idle 1.19 West.State = idle

Add ‘Turn’ to Ensure Liveness  This is in traffic3.smv  Use Peterson’s mutual exclusion algorithm  Introduce a variable Turn  Turn : {nst, wt}  If I have just exited the critical section, offer Turn to others

traffic3.smv: Adding Turn DEFINE EnterCritical := State = entering & !EW_lock & (Turn = nst | !OtherReq); next (Turn) := case State = exiting & Turn = nst & !FriendReq : wt; TRUE : Turn; esac; DEFINE EnterCritical := State = entering & !EW_lock & (Turn = nst | !OtherReq); next (Turn) := case State = exiting & Turn = nst & !FriendReq : wt; TRUE : Turn; esac; Similar change in West module

Model check again…  Mutual still exclusion holds!  What about liveness properties  In north direction? HOLDS  In south direction? HOLDS  In west direction? FAILS 

traffic4.smv  Two extra variables to distinguish between North and South completion  North.Done, South.Done  When North exits critical section  North.Done is set to TRUE  Similarly for South.Done  When West exits  both South.Done and North.Done are set to FALSE

traffic4.smv: North Module init (Done) := FALSE; next (Done) := case State = exiting : TRUE; TRUE : Done; esac; next (Turn) := case State = exiting & Turn = nst & !FriendReq : wt; State = exiting & Turn = nst & FriendDone & OtherReq : wt; TRUE : Turn; esac; init (Done) := FALSE; next (Done) := case State = exiting : TRUE; TRUE : Done; esac; next (Turn) := case State = exiting & Turn = nst & !FriendReq : wt; State = exiting & Turn = nst & FriendDone & OtherReq : wt; TRUE : Turn; esac;

Hurray!  Mutual exclusion holds  Liveness for all three directions holds  No Strict sequencing

Possible extensions  Allow for north, south, east, and west traffic  Allow for cars to turns  Replace specific modules by a single generic one  Instantiate it four times  Once for each direction  Ensure properties without using fairness constraints