Académique Documents
Professionnel Documents
Culture Documents
Chenyi Zhang
March 28, 2007 For a comprehensive tutorial, please visit the site http://nusmv.irst.itc.it/
NuSMV-tutorial
Introduction History
SMV is the rst BDD-based symbolic model checker NuSMV is a re-implementation and extension of SMV by ITC-IRST, UniTN, CMU and UniGE, now its on version 2.4.1 Extensions: LTL, Simulation, SAT etc. OpenSource Licensing In CSE available @ czhang/nusmv, you may create a link to this le by resetting your $PATH and then export
NuSMV-tutorial
NuSMV-tutorial
!b0 0
b0 1
NuSMV-tutorial
NuSMV-tutorial
Another Example
MODULE main VAR b0 : boolean; b1 : boolean;
!b0 /!b1
b0 /!b1
!b0 /b1
b0 /b1
NuSMV-tutorial
Expressions
Arithmetic operators: +, , , /, mod, (unary) Comparison operators: =, ! =, >, <, <=, >= Logic operators: &, |, xor, !, >, < > Set operators: {v1 , v2 , . . . vn }, in, union Conditional Expression: variable := case c1 : e1 ; c2 : e2 ; . . . 1: en ; esac
NuSMV-tutorial
NuSMV-tutorial
NuSMV-tutorial
10
Arrays
The SMV language provides also the possibility to dene arrays. VAR x : array 0..10 of boolean; y : array 2..4 of 0..10; ASSIGN init(x[5]) := 1; init(y[2]) := {0,2,4,6,8,10}; Array indexes in SMV must be constants.
NuSMV-tutorial
11
NuSMV-tutorial
12
NuSMV-tutorial
13
Examples Cont.
init(status) := ready; (double assignments) init(status) := busy; init(status) := {ready, busy}; (ok) x := (y + 1) mod 2; (circular dependencies) y := (x + 1) mod 2; next(x) := x & next(y); (circular dependencies) next(y) := y & next(x); next(x) := x & next(y); (ok, no circles)
NuSMV-tutorial
14
Modules
An SMV program can consist of one or more module declarations. MODULE mod VAR out: 0..9; ASSIGN next(out) := (out+1) mod 10 main m1 m2 MODULE main VAR m1 : mod; m2 : mod; sum: 0..18; ASSIGN sum := m1.out + m2.out;
NuSMV-tutorial
15
More Modules
Modules are instantiated in other modules. The instantiation is performed inside the VAR declaration of the parent module. In each SMV specication there must be a module main. It is the top-most module. All the variables declared in a module instance are visible in the module in which it has been instantiated via the dot notation (eg., m1.out, m2.out). MODULE mod(in) VAR out: 0..9; ... MODULE main VAR m1 : mod(m2.out); m2 : mod(m1.out); ...
NuSMV-tutorial
16
Specications
Specications can be added in any module of the program Each property is verifed separately Dierent kinds of properties are allowed: On reachable states: INVARSPEC On the computation paths (LTL): LTLSPEC Qualitative characteristic of models: COMPUTE Branching time (CTL): SPEC Bounded CTL: SPEC
NuSMV-tutorial
17
U A[ U ]
Bounded CTL: SPEC ABF 0..2 out = 3 which says out = 3 is reachable in 2 steps
NuSMV-tutorial
18
Fairness Constraints
NuSMV allows to specify fairness cosntraints Fairness constraints are formulas which are assumed to be true innitely often in all the execution paths of interest During the verication of properties, NuSMV considers path quantiers to apply only to fair paths Syntax: FAIRNESS simple expression Example: FAIRNESS out = 3
NuSMV-tutorial
19
NuSMV-tutorial
20
Assignments vs Constraints
Any ASSIGN-based specication can be easily rewritten as an equivalent constraint-based specication, but the converse might be hard In assignment style, there is always at least one initial state, and all states have at least one next state by construction In constraint style, INIT constraints can be inconsistent (eg. INIT p& !p), then any specication is vacuously true TRANS constraints can be inconsistent in the sense that the transition relation is not total (there are deadlock states), and NuSMV detects and reports this case. In assignment style, nondeterminism is apparent (unassigned variables, set assignments . . . ), but in constraint style nondeterminism is hidden in the constraints.
NuSMV-tutorial
21
ready/!req
busy/!req
ready/req
busy/req
NuSMV-tutorial
22
Synchronous Composition
MODULE cell(input) VAR val: {red, green}; ASSIGN next(val):={val, input}; MODULE main VAR c1: cell(c2.val); c2: cell(c1.val);
By default, composition of modules is synchronous. step c1.val c2.val 0 Here is a possible execution: 1 2 3 ... red green green green ... green red green green ...
NuSMV-tutorial
23
Asynchronous Composition
Asynchronous composition can be obtained by using keyword process. In asynchronous composition one process moves at each step. Boolean variable running is dened in each process: it is true when that process is selected it can be used to guarantee a fair scheduling of processes. MODULE cell(input) VAR val: {red, green, blue}; ASSIGN next(val):={val, input}; FAIRNESS running MODULE main VAR c1: process cell(c2.val); c2: process cell(c3.val); c3: process cell(c1.val);
NuSMV-tutorial
24
NuSMV-tutorial
25
Questions
NuSMV-tutorial
26
Other Issues
1. Consultation: when (?) and where (CSE level 2) 2. Ask questions on the course forum