Using Cadence SMV to verify temporal properties of

  • Slides: 14
Download presentation
Using Cadence SMV to verify temporal properties of finite-state machines 15 -817: Intro to

Using Cadence SMV to verify temporal properties of finite-state machines 15 -817: Intro to Model Checking October 9, 2008 1

Review of Temporal Logic a Xa Fa Ga a. Ub “a is true now”

Review of Temporal Logic a Xa Fa Ga a. Ub “a is true now” “a is true in the ne. Xt state” “a will be true sometime in the Future” “a will be Globally true in the future” “a will hold true Until b becomes true” • Potential source of confusion: “in the future” ≠ “in a future state”. I. e. , the remaining time of the current state is part of the future. • So, “F a” is satisified if a is true in the current state. • And, “G a” is falsified if a is false in the current state. Path Quantifiers: • “E a”: There exists a path (from the current state) on which a is true. • “A a”: Along all paths (from the current state), a is true. 2

EF g : “it is possible that g will be true” 3

EF g : “it is possible that g will be true” 3

AF g : “g will necessarily be true sometime in the future” 4

AF g : “g will necessarily be true sometime in the future” 4

AG g : “g is an invariant” 5

AG g : “g is an invariant” 5

EG g : “on some path, g is always true” 6

EG g : “on some path, g is always true” 6

Microwave Oven Example • Suppose we are designing a controller for a microwave oven.

Microwave Oven Example • Suppose we are designing a controller for a microwave oven. • The heating element should be off if the door is open. • If the user presses the Start button when the door is open, then enter an error mode. Leave the error mode when the user presses the Reset button. ~ Closed ~ Heat Error Start (with door open) ~ Closed ~ Heat ~ Error Open door Close door Closed ~ Heat Error Closed ~ Heat ~ Error Start oven Done Closed Heat ~ Error Reset 7

Microwave Oven Example MODULE main VAR start, reset, closed : boolean; error, heat :

Microwave Oven Example MODULE main VAR start, reset, closed : boolean; error, heat : boolean; ASSIGN init(error) : = 0; init(heat) : = 0; next(error) : = case start & ~closed : 1; closed & reset : 0; 1 : error; esac; next(heat) : = case start & closed ~closed 1 esac; : 1; : 0; : heat; SPEC AG (!closed -> AX (!heat)) SPEC EF (heat) 8

Microwave Example in Cadence SMV • Cadence SMV and Nu. SMV and two model

Microwave Example in Cadence SMV • Cadence SMV and Nu. SMV and two model checkers. • Both support an older-style syntax that is used in this presentation. • Cadence also supports a newstyle syntax that is more expressive. • Cadence can run on both Windows and Linux. 9

simple 01. smv MODULE main VAR request : boolean; state : {ready, busy}; ASSIGN

simple 01. smv MODULE main VAR request : boolean; state : {ready, busy}; ASSIGN init(state) : = ready; next(state) : = case state = ready & request : busy; 1 : {ready, busy}; esac; SPEC AG(request -> AF state = busy) 10

Three-Bit Counter; Modules MODULE counter_cell(carry_in) VAR value : boolean; ASSIGN init(value) : = 0;

Three-Bit Counter; Modules MODULE counter_cell(carry_in) VAR value : boolean; ASSIGN init(value) : = 0; next(value) : = value + carry_in mod 2; DEFINE carry_out : = value & carry_in; MODULE VAR bit 0 bit 1 bit 2 SPEC main : counter_cell(1); : counter_cell(bit 0. carry_out); : counter_cell(bit 1. carry_out); AG AF bit 2. carry_out 11

Peterson’s Mutual-Exclusion Algorithm (broken version) MODULE agent(req_self, req_other, turn, num) VAR pc : {L

Peterson’s Mutual-Exclusion Algorithm (broken version) MODULE agent(req_self, req_other, turn, num) VAR pc : {L 0, L 1, L 3, L 4 }; ASSIGN init(req_self): = 0; init(pc): = L 0; next(pc): = case pc = L 0 : { L 0, pc = L 1 pc = L 3 & ( req_other ) pc = L 3 pc = L 4 esac; next(req_self): = case pc = L 1 : 1; pc = L 4 : 0; 1 : req_self; esac; DEFINE request: = pc = L 1; critical: = pc = L 4; FAIRNESS running L 1 }; : L 3; : L 4; : L 0; agent 0: L 1: L 3: L 4: Idle; req 0 = 1; //request to enter critical section while (req 1 == 1); req 0 = 0; //clear the request agent 1: L 0: L 1: L 3: L 4: Idle; req 1 = 1; //request to enter critical section while (req 0 == 1); req 1 = 0; //clear the request MODULE main VAR turn : boolean; req 0 : boolean; req 1 : boolean; agent 0 : process agent(req 0, req 1, turn, 0); agent 1 : process agent(req 1, req 0, turn, 1); safe: SPEC AG( !agent 0. critical | !agent 1. critical ); fairness 0: SPEC AG( agent 0. request -> EF agent 0. critical ); fairness 0: SPEC AG( agent 1. request -> EF agent 1. critical ); 12

MODULE agent(req_self, req_other, turn, num) VAR pc : {L 0, L 1, L 2,

MODULE agent(req_self, req_other, turn, num) VAR pc : {L 0, L 1, L 2, L 3, L 4 }; ASSIGN init(req_self): = 0; init(pc): = L 0; next(pc): = case pc = L 0 : { L 0, L 1 }; pc = L 1 : L 2; pc = L 2 : L 3; pc = L 3 & (turn = !num) & req_other: L 3; pc = L 3 : L 4; pc = L 4 : L 0; esac; next(req_self): = case pc = L 1 : 1; pc = L 4 : 0; 1 : req_self; esac; next(turn): = case pc = L 2 : !num; 1 : turn; esac; DEFINE request: = pc = L 1; critical: = pc = L 4; FAIRNESS running Peterson’s Mutex (Fixed) agent 0: L 1: L 2: L 3: L 4: Idle; req 0 = 1; //request to enter critical section turn = 1; //give priority to the other procress while (turn == 1 && req 1 == 1); req 0 = 0; //clear the request agent 1: L 0: L 1: L 2: L 3: L 4: Idle; req 1 = 1; //request to enter critical section turn = 0; //give priority to the other procress while (turn == 0 && req 0 == 1); req 1 = 0; //clear the request MODULE main VAR turn : boolean; req 0 : boolean; req 1 : boolean; agent 0 : process agent(req 0, req 1, turn, 0); agent 1 : process agent(req 1, req 0, turn, 1); safe: SPEC AG( !agent 0. critical | !agent 1. critical ); fairness 0: SPEC AG( agent 0. request -> EF agent 0. critical ); fairness 0: SPEC AG( agent 1. request -> EF agent 1. critical ); 13

14

14