Escolar Documentos
Profissional Documentos
Cultura Documentos
Willem Visser
wvisser@email.arc.nasa.gov
Overview
2002
• Introduction to Model Checking
– Hardware and Software Model Checking
• Program Model Checking
– Major Trends
• Abstraction
• Improved model checking technology
– A Brief History
• SPIN
• Hand-translations
• State-less model checking
• Semi-automated translations
• Fully automated translations
– Current Trends
• Custom-made model checkers for programs
• SLAM
• JPF
• Summary
• NASA Case Studies - Remote Agent, DEOS and Mars Rover
• Future of Software Model Checking
k p
Each transition
y ~p
represents an execution
step in the system ~p The labels represent
hh
predicates in each state
e.g. (x = 5)
z ~p
K = ({p,~p},{x,y,z,k,h},R,{x},L)
N1 T1 N2 T2
T1 S0 C1 S1 || T2 S0 C2 S1
C2 N2 S0
C1
24 September 2002 N1 S0 © Willem Visser 2002 7
Mutual Exclusion Example
2002
N1N2S0
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
No matter where you are there is
always a way to get to the initial state
24 September 2002 © Willem Visser 2002 8
Mutual Exclusion Example
2002
N1N2S0
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0)
{ s S | M,s ╞ f }
• Characteristics • Characteristics
– Memory intensive – Can handle very large state spaces
– Good for finding concurrency errors – Not as good for asynchronous systems
– Short execution paths are better, but – Cannot deal well with long execution
long execution paths can also be traces
handled
– Can handle dynamic creation of – Works best with a static transition
objects/threads relation, hence doesn’t deal well with
dynamic creation of objects/threads
– Mostly used in software – Mostly used in hardware
Abstraction
Program Model Checker
void add(Object o) {
Input
buffer[head] = o;
head = (head+1)%size;
}
Object take() {
…
tail=(tail+1)%size;
return buffer[tail];
}
Verification model
translation
Program
10 01 10 01 10
y := 1 x := 1 y := 1 y := 1
11 11 11
T2 T4
T3 T1
T3 T2 T4 T1
T4 T2
T1 ; T2 || T3 ; T4
T2 T4
T3 T1
T3 T2 T4 T1
T4 T2
T1 ; T2 || T3 ; T4
T2 T4
T3 T1
T3 T2 T4 T1
T4 T2
T1 ; T2 || T3 ; T4
Program
void add(Object o) {
Abstract Program Correct
buffer[head] = o;
head = (head+1)%size; T1 > T2
T3 > T4
Custom
}
T5 > T6 Model Checker
Object take() {
…
Abstraction …
tail=(tail+1)%size;
return buffer[tail]; Error-trace
}
Abstraction refinement
Abstraction
T F
Abstract EQ = T EQ := F EQ = F
In
fe
as
bli
[1]: [1]:
e
co
un
te
r-
ex
am
X
p
[2]:
le
[2]: [3]:
Predicate
C Program Abstraction
annotated with C2BP
API usage rules
void add(Object o) {
buffer[head] = o;
head = (head+1)%size; Custom
}
Predicates Model Checker Correct
Object take() {
… BEBOP
tail=(tail+1)%size;
return buffer[tail];
}
Symbolic Error-trace
Execution
NEWTON
False
Error-trace is Feasible
24 September 2002 © Willem Visser 2002 56
SLAM
2002
• Check API usage rules for sequential C programs
– Mostly applied to device driver code
• C2BP
– Inputs: C program and predicates
– Output: boolean program over the predicates
• BEBOP
– Symbolic interprocedural data flow analysis
– Concrete CFG and BDD encoding of states
• NEWTON
– Symbolic execution of C programs
– Using Simplify theorem prover for checking feasibility
of conditionals
24 September 2002 © Willem Visser 2002 57
Abstraction Refinement Example
Adapted from Ball & Rajamani POPL02
2002
nPacketsOld = nPackets;
request = devExt->WLHeadVa;
if (request){
KeReleaseSpinLock(&devExt->writeListLock);
...
nPackets++;
}
} while (nPackets != nPacketsOld);
KeReleaseSpinLock(&devExt->writeListLock);
Error-trace : 1,2,3,5,1,2
[1] do {
[2] KeAcquireSpinLock(&devExt->writeListLock);
nPacketsOld = nPackets;
request = devExt->WLHeadVa;
[3] if (request){
[4] KeReleaseSpinLock(&devExt->writeListLock);
...
nPackets++;
}
[5] } while (nPackets != nPacketsOld);
[6] KeReleaseSpinLock(&devExt->writeListLock);
[1] do
[2] AcquireLock();
[3] b = true; // nPacketsOld = nPackets
[4] if (*) then
[5] ReleaseLock();
[6] b = b ? False : *; // nPackets++
fi
[7] while (!b); //(nPacketsOld != nPackets)
[8] ReleaseLock();
Model
Checker
Special
JVM
dSPIN
Java
Jimple (BC)
Parser
SMV
Slicer Simulator
Error Trace Display Decompile ; javac
JPF
24 September 2002 © Willem Visser 2002 65
Key Points
2002
• Models can be infinite state
– Unbounded objects, threads,…
– Depth-first state generation (explicit-state)
– Verification requires abstraction
• Handle full Java language
– but only for closed systems
– Cannot handle native code
• no Input/output through GUIs, files, Networks, …
• Must be modeled by java code instead
• Allows Nondeterministic Environments
– JPF traps special nondeterministic methods
• Checks for User-defined assertions, deadlock and LTL properties
Slice
mentioned
in property Source program Resulting
slice
• slicing criterion generated automatically from
observables mentioned in the property
• backwards slicing automatically finds all components that
might influence the observables.
24 September 2002 © Willem Visser 2002 76
Property-directed Slicing
2002
/**
* @observable EXP Full: (head == tail) Slicing Criterion
*/ All statements
that assign to
class BoundedBuffer { head, tail.
Object [] buffer_;
int bound; removed by
int head, tail; slicing
buffer_[head] = o;
Included in
head = (head+1) % bound;
slicing notifyAll();
criterion } indirectly
...
relevant
}
24 September 2002 © Willem Visser 2002 77
Slicing in JPF
2002
• JPF uses Bandera’s slicer
• Bandera slices w.r.t.
– Deadlock - i.e. communication statements
– Variables occurring in temporal properties
– Variables participating in race-violations
• Used with JPF’s runtime analysis
• More examples of slicing for model checking
– Slicing for Promela (Millet and Teitelbaum)
• http://netlib.bell-labs.com/netlib/spin/ws98/program.html
– Slicing for Hardware Description Languages (Shankar et al.)
• http://www.cs.wisc.edu/~reps/
• Theorem [Saidi:SAS’00]
Every path in the abstracted program where all assignments
are deterministic is a path in the concrete program.
• Bias the model checker
– to look only at paths that do not
include instructions that introduce
non-determinism
• JPF model checker modified
– to detect non-deterministic choice and backtrack from those
points
Sta
for states with least number of non-
te
deterministic choices enabled
s pa
ce s
• If no “deterministic” error exists it
ear
also searches rest of the state space
c he
d fi
rst
X X
• Reality check:
– Model Checkers run out of memory OFTEN!
• If no error was found, how confident can we be that
none exists?
– Require coverage measure
• JPF extended with Branch coverage calculations
• Can the coverage measure guide the model checker
– Yes, as a heuristic
– Better heuristic values are given for least explored branches
1200.00
1000.00 Autopilot
JPF
1000.00
DEOS
800.00 Java-translation
JPF
Mars Rover
600.00 Remote Agent 550.00 JPF
Hand-translation
400.00 SPIN 330.00 DEOS
Systematic
200.00 Hand-translation
50.00 SPIN
30.00
0.00
1997 1998 2000 2001 2002
24 September 2002
LOC analyzed per Person day
© Willem Visser 2002 84
JPF
2002 Most Recent Extensions
• Symbolic execution based model checking
– Sarfraz Khurshid (MIT), Corina Pasareanu and
Doron Peled (Warwick)
– Traverses all paths and collects and solves constraints on-the-fly
during model checking
– Using the Omega libraries for constraint solving
– Main application is test-case generation
• Error Explanations
– Alex Groce (CMU)
– Find an error, then try and find “similar” paths that lead to errors
(negatives) and that don’t lead to an error (positives).
– Analyze the positives and negatives
• Find smallest change to make a positive a negative
• Find invariants on positives and negatives (using Diakon)
• Find statements that are on all and only positives (negatives)
Mars Rover
Tasks Sensors
Achieve
Property
Subscribe
Property Data
Locks base
Lock
Event
Change
Interrupt
Event
Properties Monitor
Unexpected timing
DB change? of change event
Monitor Logic
yes no
check wait
• Five difficult to find concurrency errors detected
• “[Model Checking] has had a substantial impact, helping the RA team improve the
quality of the Executive well beyond what would otherwise have been produced.” -
RA team
• During flight RA deadlocked (in code we didn’t analyze)
– Found this deadlock with JPF
24 September 2002 © Willem Visser 2002 92
DEOS Operating System
2002
• Integrated Modular Avionics (IMA)
– DEOS Guarantee Space and Time partitioning