12 verify with spin
TRANSCRIPT
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 1/95
Formal Specication and VericationIntroduction to Spin
Bernhard Beckert
Based on a lecture by Wolfgang Ahrendt and Reiner Hahnle atChalmers University, Goteborg
Formal Specication and Verication: Spin B. Beckert 1 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 2/95
Spin : Previous Lecture vs. This Lecture
Previous lectureSpin
appeared as aPromela
simulatorThis lecture
Intro to Spin as a model checker
Formal Specication and Verication: Spin B. Beckert 2 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 3/95
What Does A Model Checker Do?
A Model Checker (MC) is designed to prove the user wrong.
MC tries its best to nd a counter example to the correctness properties.It is tuned for that.
MC does not try to prove correctness properties.It tries the opposite.
Formal Specication and Verication: Spin B. Beckert 3 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 4/95
What Does A Model Checker Do?
A Model Checker (MC) is designed to prove the user wrong.
MC tries its best to nd a counter example to the correctness properties.It is tuned for that.
MC does not try to prove correctness properties.It tries the opposite.
But why then can a MC also prove correctness properties?
Formal Specication and Verication: Spin B. Beckert 3 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 5/95
What Does A Model Checker Do?
A Model Checker (MC) is designed to prove the user wrong.
MC tries its best to nd a counter example to the correctness properties.It is tuned for that.
MC does not try to prove correctness properties.It tries the opposite.
But why then can a MC also prove correctness properties?
MC’s search for counter examples is exhaustive.
Formal Specication and Verication: Spin B. Beckert 3 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 7/95
What does ‘exhaustive search’ mean here?
exhaustive search=
resolving non-determinism in all possible ways
Formal Specication and Verication: Spin B. Beckert 4 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 8/95
What does ‘exhaustive search’ mean here?
exhaustive search=
resolving non-determinism in all possible ways
For model checking Promela code,two kinds of non-determinism to be resolved:
explicit, local:if / do statements
:: guardX -> ....
:: guardY -> ....implicit, global:scheduling of concurrent processes(see next lecture)
Formal Specication and Verication: Spin B. Beckert 4 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 9/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 10/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 11/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively)generating a verier
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 12/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively)generating a verier
verier generated by Spin is a C program performing
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 13/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively)generating a verier
verier generated by Spin is a C program performing
model checking:
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 14/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively)generating a verier
verier generated by Spin is a C program performing
model checking:exhaustively checks Promela model against correctness properties
Formal Specication and Verication: Spin B. Beckert 5 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 15/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively)generating a verier
verier generated by Spin is a C program performing
model checking:exhaustively checks Promela model against correctness propertiesin case the check is negative:generates a failing run of the model
Formal Specication and Verication: Spin B. Beckert 5 / 47
d l h k f h
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 16/95
Model Checker for This Course: Spin
Spin : “Simple Promela Interpreter”
If this was all, you would have seen most of it already.The name is a serious understatement!
Main functionality of Spin :
simulating a model (randomly/interactively/ guided)generating a verier
verier generated by Spin is a C program performing
model checking:exhaustively checks Promela model against correctness propertiesin case the check is negative:generates a failing run of the model, to be simulated by Spin
Formal Specication and Verication: Spin B. Beckert 5 / 47
S i W k O i
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 17/95
Spin Workow: Overview
SPIN
modelname.pml
correctnesspropertiescorrectness
ro erties
verierpan.c Ccompiler
executableverier
pan
“errors: 0 ”failing
runname.pml.trail
interactive /random/ guidedsimulation
-a
o r
e i t
h e r
-i-t
Formal Specication and Verication: Spin B. Beckert 6 / 47
Pl i Si l i i h S i
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 18/95
Plain Simulation with Spin
SPIN
modelname.pml
correctnesspropertiescorrectness
ro erties
verierpan.c
Ccompiler
executableverier
pan
“errors: 0 ”failing
runmodel.trail
interactive /random/ guidedsimulation
-i
Formal Specication and Verication: Spin B. Beckert 7 / 47
R h l Si l ti D
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 19/95
Rehearsal: Simulation Demo
run example, random and interactiveinterleave.pml , zero.pml
Formal Specication and Verication: Spin B. Beckert 8 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 20/95
Meaning of Correctness wrt Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 21/95
Meaning of Correctness wrt. Properties
GivenPromela
model M , and correctness properties C 1, . . . , C n .Be R M the set of all possible runs of M .For each correctness property C i ,R M
,C i is the set of all runs of M satisfying C i .
(R M ,C i ⊆ R M )
M is correct wrt. C 1, . . . , C n iff (R M ,C 1 ∩ . . . ∩ R M
,C n ) = R M .
If M is not correct, theneach r ∈(R M \ (R M
,C 1 ∩ . . . ∩ R M
,C n )) is a counter example.
Formal Specication and Verication: Spin B. Beckert 10 / 47
Meaning of Correctness wrt Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 22/95
Meaning of Correctness wrt. Properties
GivenPromela
model M , and correctness properties C 1, . . . , C n .Be R M the set of all possible runs of M .For each correctness property C i ,R M
,C i is the set of all runs of M satisfying C i .
(R M ,C i ⊆ R M )
M is correct wrt. C 1, . . . , C n iff (R M ,C 1 ∩ . . . ∩ R M
,C n ) = R M .
If M is not correct, theneach r ∈(R M \ (R M
,C 1 ∩ . . . ∩ R M
,C n )) is a counter example.
We know how to write models M .
Formal Specication and Verication: Spin B. Beckert 10 / 47
Meaning of Correctness wrt Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 23/95
Meaning of Correctness wrt. Properties
GivenPromela
model M , and correctness properties C 1, . . . , C n .Be R M the set of all possible runs of M .For each correctness property C i ,R M
,C i is the set of all runs of M satisfying C i .
(R M ,C i ⊆ R M )
M is correct wrt. C 1, . . . , C n iff (R M ,C 1 ∩ . . . ∩ R M
,C n ) = R M .
If M is not correct, theneach r ∈(R M \ (R M
,C 1 ∩ . . . ∩ R M
,C n )) is a counter example.
We know how to write models M .But how to write Correctness Properties?
Formal Specication and Verication: Spin B. Beckert 10 / 47
Stating Correctness Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 24/95
Stating Correctness Properties
modelname.pml
correctnesspropertiescorrectness
ro erties
Formal Specication and Verication: Spin B. Beckert 11 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 25/95
Stating Correctness Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 26/95
Stating Correctness Properties
modelname.pml
correctnesspropertiescorrectness
ro erties
Correctness properties can be stated within, or outside, the model.
stating properties within model , usingassertion statements
Formal Specication and Verication: Spin B. Beckert 11 / 47
Stating Correctness Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 27/95
Stating Correctness Properties
modelname.pml
correctnesspropertiescorrectness
ro erties
Correctness properties can be stated within, or outside, the model.
stating properties within model , usingassertion statementsmeta labels
end labels
accept labelsprogress labels
Formal Specication and Verication: Spin B. Beckert 11 / 47
Stating Correctness Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 28/95
Stating Correctness Properties
modelname.pml
correctnesspropertiescorrectness
ro erties
Correctness properties can be stated within, or outside, the model.
stating properties within model , usingassertion statementsmeta labels
end labels
accept labelsprogress labels
stating properties outside model , usingnever claimstemporal logic formulas
Formal Specication and Verication: Spin B. Beckert 11 / 47
Stating Correctness Properties
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 29/95
Stating Correctness Properties
modelname.pml
correctnesspropertiescorrectness
ro erties
Correctness properties can be stated within, or outside, the model.
stating properties within model , usingassertion statements (today)meta labels
end labels (today)
accept labelsprogress labels
stating properties outside model , usingnever claimstemporal logic formulas
Formal Specication and Verication: Spin B. Beckert 11 / 47
Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 30/95
Assertion Statements
Denition (Assertion Statements)
Assertion statements in Promela are statements of the formassert ( expr )
were expr is any Promela expression.
Formal Specication and Verication: Spin B. Beckert 13 / 47
Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 31/95
Denition (Assertion Statements)
Assertion statements in Promela are statements of the formassert ( expr )
were expr is any Promela expression.
Typically, expr is of type bool .
Formal Specication and Verication: Spin B. Beckert 13 / 47
Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 32/95
Denition (Assertion Statements)
Assertion statements in Promela are statements of the formassert ( expr )
were expr is any Promela expression.
Typically, expr is of type bool .
Assertion statements can appear anywhere where a Promela statementis expected.
Formal Specication and Verication: Spin B. Beckert 13 / 47
Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 33/95
Denition (Assertion Statements)
Assertion statements in Promela are statements of the formassert ( expr )
were expr is any Promela expression.
Typically, expr is of type bool .
Assertion statements can appear anywhere where a Promela statementis expected.
. . .s tmt1;a s s e r t ( max == a );s tmt2;. ..
Formal Specication and Verication: Spin B. Beckert 13 / 47
Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 34/95
Denition (Assertion Statements)
Assertion statements in Promela are statements of the formassert ( expr )
were expr is any Promela expression.
Typically, expr is of type bool .
Assertion statements can appear anywhere where a Promela statementis expected.
. . .s tmt1;a s s e r t ( max == a );s tmt2;. ..
. . .
i f :: b1 -> stmt3 ;a s s e r t (x < y)
:: b2 -> stmt4.. .
Formal Specication and Verication: Spin B. Beckert 13 / 47
Meaning of Boolean Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 35/95
g
assert ( expr )has no effect if expr evaluates to truetriggers an error message if expr evaluates to false
This holds in both, simulation and model checking mode.
Formal Specication and Verication: Spin B. Beckert 14 / 47
Meaning of General Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 36/95
assert ( expr )has no effect if expr evaluates to non-zero valuetriggers an error message if expr evaluates to 0
This holds in both, simulation and model checking mode.
Formal Specication and Verication: Spin B. Beckert 14 / 47
Meaning of General Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 37/95
assert ( expr )has no effect if expr evaluates to non-zero valuetriggers an error message if expr evaluates to 0
This holds in both, simulation and model checking mode.
Recall:
bool true false is syntactic sugar for
Formal Specication and Verication: Spin B. Beckert 14 / 47
Meaning of General Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 38/95
assert ( expr )has no effect if expr evaluates to non-zero valuetriggers an error message if expr evaluates to 0
This holds in both, simulation and model checking mode.
Recall:
bool true false is syntactic sugar forbit 1 0
Formal Specication and Verication: Spin B. Beckert 14 / 47
Meaning of General Assertion Statements
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 39/95
assert ( expr )has no effect if expr evaluates to non-zero valuetriggers an error message if expr evaluates to 0
This holds in both, simulation and model checking mode.
Recall:
bool true false is syntactic sugar forbit 1 0
⇒ general case covers Boolean case
Formal Specication and Verication: Spin B. Beckert 14 / 47
Instead of using ‘printf’s for Debugging ...
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 40/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f :: a >= b -> max = a ;:: a <= b -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
Formal Specication and Verication: Spin B. Beckert 16 / 47
Instead of using ‘printf’s for Debugging ...
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 41/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f :: a >= b -> max = a ;:: a <= b -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
Command Line Execution
(simulate, inject faults, add assertion, simulate again)> spi n max . p ml
Formal Specication and Verication: Spin B. Beckert 16 / 47
... we can employ Assertions
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 42/95
quoting from le max.pml :/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: a <= b -> max = b ;
f i ;a s s e r t ( a > b -> max == a : max == b )
Formal Specication and Verication: Spin B. Beckert 18 / 47
... we can employ Assertions
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 43/95
quoting from le max.pml :/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: a <= b -> max = b ;
f i ;a s s e r t ( a > b -> max == a : max == b )
Now, we have a rst example with a formulated correctness property .
Formal Specication and Verication: Spin B. Beckert 18 / 47
... we can employ Assertions
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 44/95
quoting from le max.pml :/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: a <= b -> max = b ;
f i ;a s s e r t ( a > b -> max == a : max == b )
Now, we have a rst example with a formulated correctness property .
We can do model checking, for the rst time!
Formal Specication and Verication: Spin B. Beckert 18 / 47
Generate Verier in C
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 45/95
SPIN
modelmax.pml
correctnesspropertiescorrectness
ro erties
verierpan.c
-a
Command Line ExecutionGenerate Verier in C
> spin -a max . pml
Spin generates Verier in C , called pan.c(plus helper les)
Formal Specication and Verication: Spin B. Beckert 20 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 46/95
Compile To Executable Verier
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 47/95
verierpan.c
Ccompiler
executableverierpan
Command Line Executioncompile to executable verier
> gcc -o pan pan .c
C compiler generates executable verier pan
Formal Specication and Verication: Spin B. Beckert 22 / 47
Compile To Executable Verier
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 48/95
verierpan.c
Ccompiler
executableverierpan
Command Line Executioncompile to executable verier
> gcc -o pan pan .c
C compiler generates executable verier pan
pan : historically “protocol analyzer”, now “process analyzer”
Formal Specication and Verication: Spin B. Beckert 22 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 49/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
Formal Specication and Verication: Spin B. Beckert 24 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 50/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
prints “errors: 0 ”
Formal Specication and Verication: Spin B. Beckert 24 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 51/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
prints “errors: 0 ” ⇒ Correctness Property veried!
Formal Specication and Verication: Spin B. Beckert 24 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 52/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
prints “errors: 0 ”, orprints “errors: n” (n > 0)
Formal Specication and Verication: Spin B. Beckert 24 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 53/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
prints “errors: 0 ”, orprints “errors: n” (n > 0) ⇒ counter example found!
Formal Specication and Verication: Spin B. Beckert 24 / 47
Run Verier (= Model Check)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 54/95
executable
verierpan
“errors: 0 ”failing
runmax.pml.trail
either or
Command Line Executionrun verier pan
> ./ p an
prints “errors: 0 ”, orprints “errors: n” (n > 0) ⇒ counter example found!
records failing run inmax.pml.trailFormal Specication and Verication: Spin B. Beckert 24 / 47
Guided Simulation
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 55/95
To examine failing run: employ simulation mode, “guided” by trail le.
SPIN
failingrun
max.pml.trailguided
simulation
-t
Command Line Executioninject a fault, re-run verication, and then:
> spin - t -p - l max . pml
Formal Specication and Verication: Spin B. Beckert 26 / 47
Output of Guided Simulation
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 56/95
can look like:
St ar tin g P with pid 01: proc 0 (P) l ine 8 " max .pml " ( state 1) [ a = 1 ]
P(0) : a = 12: proc 0 ( P) l ine 14 " max . pml " ( state 7) [ b = 2]
P(0) : b = 2
3: p ro c 0 ( P ) l in e 23 " m ax . p ml " ( s ta te 1 3) [((a<=b))]3: proc 0 ( P) l ine 23 " max . pml " ( state 14) [ max = a]P(0) : max = 1
spi n : l in e 25 " max . pml " , E rr or : a ss er ti on v io la te ds pi n : t ex t of f ai le d a ss er ti on :
a s s e r t (( (( a> b) ) -> (( max == a) ) : (( max == b) ) ) )
Formal Specication and Verication: Spin B. Beckert 28 / 47
Output of Guided Simulation
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 57/95
can look like:
St ar tin g P with pid 01: proc 0 (P) l ine 8 " max .pml " ( state 1) [ a = 1 ]
P(0) : a = 12: proc 0 ( P) l ine 14 " max . pml " ( state 7) [ b = 2]
P(0) : b = 2
3: p ro c 0 ( P ) l in e 23 " m ax . p ml " ( s ta te 1 3) [((a<=b))]3: proc 0 ( P) l ine 23 " max . pml " ( state 14) [ max = a]P(0) : max = 1
spi n : l in e 25 " max . pml " , E rr or : a ss er ti on v io la te ds pi n : t ex t of f ai le d a ss er ti on :
a s s e r t (( (( a> b) ) -> (( max == a) ) : (( max == b) ) ) )
assignments in the run
Formal Specication and Verication: Spin B. Beckert 28 / 47
Output of Guided Simulation
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 58/95
can look like:
St ar tin g P with pid 01: proc 0 (P) l ine 8 " max .pml " ( state 1) [ a = 1 ]
P(0) : a = 12: proc 0 ( P) l ine 14 " max . pml " ( state 7) [ b = 2]
P(0) : b = 2
3: p ro c 0 ( P ) l in e 23 " m ax . p ml " ( s ta te 1 3) [((a<=b))]3: proc 0 ( P) l ine 23 " max . pml " ( state 14) [ max = a]P(0) : max = 1
spi n : l in e 25 " max . pml " , E rr or : a ss er ti on v io la te ds pi n : t ex t of f ai le d a ss er ti on :
a s s e r t (( (( a> b) ) -> (( max == a) ) : (( max == b) ) ) )
assignments in the runvalues of variables whenever updated
Formal Specication and Verication: Spin B. Beckert 28 / 47
What did we do so far?following whole cycle (most primitive example assertions only)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 59/95
following whole cycle (most primitive example, assertions only)
SPIN
modelname.pml
correctnesspropertiescorrectness
ro erties
verierpan.c Ccompiler
executableverier
pan
“errors: 0 ”failing
runname.pml.trail
interactive /random/ guidedsimulation
-a
o r
e i t
h e r
-i-t
Formal Specication and Verication: Spin B. Beckert 29 / 47
What did we do so far?following whole cycle (most primitive example assertions only)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 60/95
following whole cycle (most primitive example, assertions only)
SPIN
modelname.pml
correctnesspropertiescorrectness
ro erties
verierpan.c Ccompiler
executableverier
pan
“errors: 0 ”failing
runname.pml.trail
interactive /random/ guidedsimulation
-p -l -g ...
-a
o r
e i t
h e r
-i-t
Formal Specication and Verication: Spin B. Beckert 29 / 47
Further Examples: Integer Division
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 61/95
i n t d iv id en d = 15;i n t divisor = 4;i n t quotient , remainder ;
q uo ti en t = 0;r em ai nd er = d iv id en d ;do
:: r em ai nd er > d iv is or ->quot ient++;r em ai nd er = r em ai nd er - d iv is or
:: e l s e ->break
od ;p r i n t f ( "%d div ided by %d = %d, remainder = %d\n" ,
dividend , d ivisor , quotient , remainder) ;
Formal Specication and Verication: Spin B. Beckert 31 / 47
Further Examples: Integer Division
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 62/95
i n t d iv id en d = 15;i n t divisor = 4;i n t quotient , remainder ;
q uo ti en t = 0;r em ai nd er = d iv id en d ;do
:: r em ai nd er > d iv is or ->quot ient++;r em ai nd er = r em ai nd er - d iv is or
:: e l s e ->break
od ;p r i n t f ( "%d div ided by %d = %d, remainder = %d\n" ,dividend , d ivisor , quotient , remainder) ;
simulate, put assertions, verify, change values, ...
Formal Specication and Verication: Spin B. Beckert 31 / 47
Further Examples: Greatest Common Divisor
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 63/95
i n t x = 15 , y = 20;i n t a , b ;a = x ; b = y ;do
:: a > b -> a = a - b:: b > a -> b = b - a
:: a == b -> breakod ;p r i n t f ( " Th e GC D of % d a nd % d = %d \ n" , x , y, a )
Formal Specication and Verication: Spin B. Beckert 33 / 47
Further Examples: Greatest Common Divisor
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 64/95
i n t x = 15 , y = 20;i n t a , b ;a = x ; b = y ;do
:: a > b -> a = a - b:: b > a -> b = b - a
:: a == b -> breakod ;p r i n t f ( " Th e GC D of % d a nd % d = %d \ n" , x , y, a )
full functional verication not possible here (why?)
Formal Specication and Verication: Spin B. Beckert 33 / 47
Further Examples: Greatest Common Divisor
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 65/95
i n t x = 15 , y = 20;i n t a , b ;a = x ; b = y ;do
:: a > b -> a = a - b:: b > a -> b = b - a
:: a == b -> breakod ;p r i n t f ( " Th e GC D of % d a nd % d = %d \ n" , x , y, a )
full functional verication not possible here (why?)
still, assertions can perform sanity check
Formal Specication and Verication: Spin B. Beckert 33 / 47
Further Examples: Greatest Common Divisor
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 66/95
i n t x = 15 , y = 20;i n t a , b ;a = x ; b = y ;do
:: a > b -> a = a - b:: b > a -> b = b - a
:: a == b -> breakod ;p r i n t f ( " Th e GC D of % d a nd % d = %d \ n" , x , y, a )
full functional verication not possible here (why?)
still, assertions can perform sanity check
⇒ typical for model checking
Formal Specication and Verication: Spin B. Beckert 33 / 47
Typical Command Lines
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 67/95
typical command line sequences:
random simulationspin name.pml
Formal Specication and Verication: Spin B. Beckert 34 / 47
Typical Command Lines
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 68/95
typical command line sequences:
random simulationspin name.pml
interactive simulationspin -i name.pml
Formal Specication and Verication: Spin B. Beckert 34 / 47
Typical Command Lines
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 69/95
typical command line sequences:
random simulationspin name.pml
interactive simulationspin -i name.pml
model checkingspin -a name.pmlgcc -o pan pan.c./pan
Formal Specication and Verication: Spin B. Beckert 34 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 70/95
Spin Reference Card
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 71/95
Ben-Ari produced Spin Reference Card, summarizing
typical command line sequencesoptions forSpin
gccpan
Promeladatatypesoperatorsstatementsguarded commands
processeschannels
temproal logic syntax
Formal Specication and Verication: Spin B. Beckert 35 / 47
Why Spin ?
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 72/95
Spin targets software, instead of hardware vericationbased on standard theory of ω -automata and linear temporal logic2001 ACM Software Systems Award (other winning software systemsinclude: Unix, TCP/IP, WWW, Tcl/Tk, Java)used for safety critical applicationsdistributed freely as research tool, well-documented, activelymaintained, large user-base in academia and in industryannual Spin user workshops series held since 1995
Formal Specication and Verication: Spin B. Beckert 36 / 47
Why Spin ? (Cont’d)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 73/95
Promela and Spin are rather simple to usegood to understand a few system really well, rather than many
systems poorlyavailability of good course book (Ben-Ari)availability of front end jSpin (also Ben-Ari)
Formal Specication and Verication: Spin B. Beckert 37 / 47
What is jSpin ?
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 74/95
graphical user interface for Spin
developed for pedagogical purposeswritten in Java
simple user interfaceSpin options automatically suppliedfully congurablesupports graphics output of transition system
Formal Specication and Verication: Spin B. Beckert 38 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 76/95
Command Line Executioncalling jSpin
> java - jar / usr / l o c a l / jSp in / jSp in . ja r
(with path adjusted to to your setting)
or use shell script:
> j sp in
Formal Specication and Verication: Spin B. Beckert 40 / 47
jSpin Demo
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 77/95
Command Line Executioncalling jSpin
> java - jar / usr / l o c a l / jSp in / jSp in . ja r
(with path adjusted to to your setting)
or use shell script:
> j sp in
play around with similar examples ...
Formal Specication and Verication: Spin B. Beckert 40 / 47
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 78/95
q g p/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
Formal Specication and Verication: Spin B. Beckert 42 / 47
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 79/95
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 80/95
q g p/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
simulate a few times⇒ crazy “timeout ” message sometimes
Formal Specication and Verication: Spin B. Beckert 42 / 47
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 81/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
simulate a few times⇒ crazy “timeout ” message sometimes
generate and execute pan
Formal Specication and Verication: Spin B Beckert 42 / 47
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 82/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
simulate a few times⇒ crazy “timeout ” message sometimes
generate and execute pan⇒ reports “errors: 1 ”
Formal Specication and Verication: Spin B Beckert 42 / 47
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 83/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */i f
:: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
simulate a few times⇒ crazy “timeout ” message sometimes
generate and execute pan⇒ reports “errors: 1 ”
????
Formal Specication and Verication: Spin B Beckert 42 / 47
Catching A Different Type of Error
quoting from le max2.pml :
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 84/95
/* a ft er c ho os in g a , b fr om {1 , 2 ,3} */
i f :: a >= b -> max = a ;:: b <= a -> max = b ;
f i ;p r i n t f ( " the maximum of %d and %d is %d\n" ,
a , b , max );
simulate a few times⇒ crazy “timeout ” message sometimes
generate and execute pan⇒ reports “errors: 1 ”
Note: no assert in max2.pml .
Formal Specication and Verication: Spin B Beckert 42 / 47
Catching A Different Type of Error
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 85/95
Further inspection of pan output:
. . .pan: i n v a l i d e n d s t a t e ( at depth 1)pan : wro te max2 .pml . t r a il. . .
Formal Specication and Verication: Spin B Beckert 44 / 47
Legal and Illegal Blocking
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 86/95
A process may legally block,as long as some other process can proceed.
Formal Specication and Verication: Spin B Beckert 45 / 47
Legal and Illegal Blocking
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 87/95
A process may legally block,as long as some other process can proceed.
Blocking for letting others proceed is useful, and typical,for concurrent and distributed models (i.p. protocols).
Formal Specication and Verication: Spin B Beckert 45 / 47
Legal and Illegal Blocking
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 88/95
A process may legally block,as long as some other process can proceed.
Blocking for letting others proceed is useful, and typical,for concurrent and distributed models (i.p. protocols).
Butit’s an error if a process blocks while no other process can proceed
Formal Specication and Verication: Spin B Beckert 45 / 47
Legal and Illegal Blocking
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 89/95
A process may legally block,as long as some other process can proceed.
Blocking for letting others proceed is useful, and typical,for concurrent and distributed models (i.p. protocols).
Butit’s an error if a process blocks while no other process can proceed
⇒ “Deadlock”
Formal Specication and Verication: Spin B Beckert 45 / 47
Legal and Illegal Blocking
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 90/95
A process may legally block,as long as some other process can proceed.
Blocking for letting others proceed is useful, and typical,for concurrent and distributed models (i.p. protocols).
Butit’s an error if a process blocks while no other process can proceed
⇒ “Deadlock”
in max1.pml , no process can take over.
Formal Specication and Verication: Spin B Beckert 45 / 47
Valid End States
D iti (V lid E d St t )
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 91/95
Denition (Valid End State)
An end state of a run is valid iff the location counter of each processes isat an end location.
Formal Specication and Verication: Spin B Beckert 46 / 47
Valid End States
Denition (Valid End State)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 92/95
Denition (Valid End State)
An end state of a run is valid iff the location counter of each processes isat an end location.
Denition (End Location)End locations of a process P are:
P’s textual end
Formal Specication and Verication:Spin
B Beckert 46 / 47
Valid End States
Denition (Valid End State)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 93/95
Denition (Valid End State)
An end state of a run is valid iff the location counter of each processes isat an end location.
Denition (End Location)End locations of a process P are:
P’s textual endeach location marked with an end label: “end xxx : ”
Formal Specication and Verication:Spin
B Beckert 46 / 47
Valid End States
Denition (Valid End State)
8/8/2019 12 Verify With Spin
http://slidepdf.com/reader/full/12-verify-with-spin 94/95
Denition (Valid End State)
An end state of a run is valid iff the location counter of each processes isat an end location.
Denition (End Location)End locations of a process P are:
P’s textual endeach location marked with an end label: “end xxx : ”
End labels are not useful inmax1.pml , but elsewhere, they are.Example: end.pml
Formal Specication and Verication:Spin
B Beckert 46 / 47
Literature for this Lecture