MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before.

Slides:



Advertisements
Similar presentations
1 Reasoning with Promela Safety properties bad things do not happen can check by inspecting finite behaviours Liveness properties good things do eventually.
Advertisements

Automatic Verification Book: Chapter 6. How can we check the model? The model is a graph. The specification should refer the the graph representation.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
Formalization of Health Information Portability and Accountability Act (HIPAA) Simon Berring, Navya Rehani, Dina Thomas.
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
CS 290C: Formal Models for Web Software Lecture 3: Verification of Navigation Models with the Spin Model Checker Instructor: Tevfik Bultan.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
UPPAAL Introduction Chien-Liang Chen.
Timed Automata.
Formal verification in SPIN Karthikeyan Bhargavan, Davor Obradovic CIS573, Fall 1999.
/ PSWLAB P ROMELA Semantics from “THE SPIN MODEL CHECKER” by G. J. Holzmann Presented by Hong,Shin 5 th Oct :021PROMELA Semantics.
תרגול 9 META LABELS. Basic types of claims State properties.
Frederico Araujo CS6362 – Fall 2010 The SPIN Model Checker.
Wishnu Prasetya Model Checking with SPIN Modeling and Verification with SPIN.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
PSWLAB S PIN Search Algorithm from “THE SPIN MODEL CHECKER” by G Holzmann Presented by Hong,Shin 9 th Nov SPIN Search Algorithm.
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
The Spin Model Checker Promela Introduction Nguyen Tuan Duc Shogo Sawai.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
1 Spin Model Checker Samaneh Navabpour Electrical and Computer Engineering Department University of Waterloo SE-464 Summer 2011.
Spin Tutorial (some verification options). Assertion is always executable and has no other effect on the state of the system than to change the local.
© 2011 Carnegie Mellon University SPIN: Part Bug Catching: Automated Program Verification and Testing Sagar Chaki November 2, 2011.
© 2011 Carnegie Mellon University SPIN: Part Bug Catching: Automated Program Verification and Testing Sagar Chaki October 31, 2011.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture # 11.
Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti Part 4: Specifications.
Model Checking. Used in studying behaviors of reactive systems Typically involves three steps: Create a finite state model (FSM) of the system design.
1 Carnegie Mellon UniversitySPINFlavio Lerda SPIN An explicit state model checker.
1 Formal Engineering of Reliable Software LASER 2004 school Tutorial, Lecture1 Natasha Sharygina Carnegie Mellon University.
CS 290C: Formal Models for Web Software Lecture 4: Model Checking Navigation Models with Spin Instructor: Tevfik Bultan.
The Model Checker SPIN Written by Gerard J. Holzmann Presented by Chris Jensen.
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN.
1 VeriSoft A Tool for the Automatic Analysis of Concurrent Reactive Software Represents By Miller Ofer.
Correctness requirements. Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions.
Scientific Computing By: Fatima Hallak To: Dr. Guy Tel-Zur.
Korea Advanced Institute of Science and Technology The Spin Model Checker - Advanced Features Moonzoo Kim CS Dept. KAIST.
CS6133 Software Specification and Verification
Sept COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 15 More Advanced Program Properties: Temporal logic and jSpin John Gurd,
Concurrency. A process is a program executing on a virtual computer Processor speed and multiplexing of shared resources are ignored Order of thread execution.
2/19/20031 Introduction to SMV. 2/19/20032 Useful Links CMU Model checking homepage SMV windows version
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
1 CSEP590 – Model Checking and Automated Verification Lecture outline for August 6, 2003.
Temporal Logic Model-checking with SPIN
The Spin Model Checker : Part I Moonzoo Kim KAIST.
/ PSWLAB S PIN Search Optimization from “THE SPIN MODEL CHECKER” by G. Holzmann Presented by Hong,Shin 23 th Nov SPIN Search.
Lecture 4 Introduction to Promela. Promela and Spin Promela - process meta language G. Holzmann, Bell Labs (Lucent) C-like language + concurrency dyamic.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)
Today’s Agenda  Quiz 5 (end of the class)  Quick Review  Finish Search Algorithms Formal Methods in Software Engineering1.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Wishnu Prasetya Model Checking with SPIN Modeling and Verification with Promela.
Agenda  Quick Review  Finish Introduction  Java Threads.
Symbolic Model Checking of Software Nishant Sinha with Edmund Clarke, Flavio Lerda, Michael Theobald Carnegie Mellon University.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CSE 555 Protocol Engineering Dr. Mohammed H. Sqalli Computer Engineering Department King Fahd University of Petroleum & Minerals Credits: Dr. Abdul Waheed.
Formal verification in SPIN
CSE 503 – Software Engineering
Automatic Verification
Specifying Multithreaded Java semantics for Program Verification
An explicit state model checker
CSE 555 Protocol Engineering
CSE 503 – Software Engineering
Presentation transcript:

MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A A A

Overview  Model Checking  PROMELA Model and Language  SPIN Model Checker  Example(s) and Demo

Common Design Flaws  Deadlock  Livelock, starvation  Underspecification  Unexpected reception of messages  Overspecification  Dead code  Violations of Constraints  Buffer overruns  Array bounds violations 3 In designing distributed systems: network applications, data communication protocols, multithreaded code, client-server applications. Designing concurrent (software) systems is so hard that these flaws are mostly overlooked Fortunately, most of these design errors can be detected using model checking techniques

What is model checking?  [Clarke & Emerson 1981]: “Model checking is an automated technique that, given a finite-state model of a system and a logical property, systematically checks whether this property holds for (a given initial state in) that model.”  Model checking tools automatically verify whether holds, where M is a (finite-state) model of a system and property F is stated in some formal notation.  Problem: state space explosion!  SPIN [Holzmann 1991] is one of the most powerful model checkers. (based on [Vardi & Wolper 1986] 4 Clarke, Emerson, and Sifakis Receive 2007 ACM Turing Award

Classic Model Checking 5

“Modern” Model Checking  Abstraction is the key activity in both approaches  Here, we deal with pure SPIN, i.e. the classic model checking approach 6

Verification vs Debugging  Two (extreme) approaches with respect to the application of model checkers.  verification approach: tries to assure the correctness of a detailed model M of the system under validation.  debugging approach: tries to find errors in a model M.  Model checking is most effective in combination with the debugging approach.  Automatic verification is not about proving correctness, but about finding bugs much earlier in the development of a system. (there are exceptions: BIP approach [Henzinger and Sifakis]) 7

Spin and Promela  SPIN = Simple Promela Interpreter  Promela = Process Meta Language The modeling language of SPIN  So it is not a language to build an application!  Strong features :  Powerful constructs to synchronize concurrent processes  Cutting edge model checking technology  Simulation to support analysis (of the models)

9 System, process, and action.  A system in SPIN consists of a set of interacting and concurrent processes.  Each process is sequential, but possibly non-deterministic.  Each process is built from atomic actions (transition).  Concurrent execution is modeled by interleaving.  Fairness can be impossed.

Recall: interleaving model of concurrency 10 P : x++ print x Q : P || Q :

Promela model  Promela model consists of:  Type declarations  Channel declarations  Variable declarations  Process declarations  [init process]  A Promela model corresponds with a (usually very large, but) finite transition system, so  No unbounded data  No unbounded channels  No unbounded processes  No unbounded process creation

Processes  A process type ( proctype ) consist of  A name  A list of formal parameters  Local variable declarations  body 12

Processes  A process  Is defined by a proctype definition  Executes concurrently with all other processes, independent of speed behavior  Communicate with other processes Using global (shared) variables Using channels  There may be several processes of the same type  Each process has its own local state:  Process counter (process identifier)  Contents of the local variables 13

Processes  Processes are created using the run statement  Processes can be created at any point in the execution  Processes start executing after the run statement  Processes can also be created by adding active in front of the proctype declaration 14

Statements  The body of a process consists of a sequence of statements. A statement is either:  executable: the statement can be executed immediately  blocked: the statement cannot be executed  An assignment is always executable  An expression is also a statement; it is executable if it evaluates to non-zero. 15

Statements  The skip statement is always executable.  “does nothing”, only changes process’ process counter  A run statement is only executable if a new process can be created (remember: the number of processes is bounded).  A printf statement is always executable 16

Statements  Assert expression;  The assert-statement is always executable.  If evaluates to zero, SPIN will exit with an error, as the “has been violated”.  The assert-statement is often used within Promela models, to check whether certain properties are valid in a state. 17

(Enabledness) Expression  Example :  This process has 3 atomic actions.  The action “y==0” only enabled in a state where the expression is true it can only be executed when it is enabled; the effect is skip so, as long as it is disabled, the process will block if it is not enabled in the current state, due to the interleaving semantics it may become enabled in the next state (by a transition caused by another process) even if it is enabled in the current state, there is no guarantee the action will be selected for execution; but there is a way in SPIN to impose fairness. active proctype P { x++ ; (y==0) ; x-- }

Example  Use it to synchronize between processes :  // both will terminate, but forcing Q to finish last byte x=0, y=0 active proctype P { x++ ; (y>0) ; x-- } active proctype Q { (x>0) ; y++ ; (x==0) ; y-- }

Multiprogramming is tricky….  E.g. one or more processes can become stuck (deadlocked) : (hence the need for verification!) byte x=0, y=0 active proctype P { x++ ; (y>0) ; (y==0) } active proctype Q { y++ ; (x>0) ; (x==0) ; y-- }

Non-determinism  Non-determinism can be used to abstractly model alternate behavior: active proctype client1() { do :: r ! REQ1// spamming requests :: g1 ? GRANTED ;... ; rstatus = 0 :: g1 ? GRANTED ; rstatus= err // sometimes error :: break// sometimes customer is impatient od...

Scope  There are only 2 levels of scope:  global var (visible in the entire sys)  local var (visible only to the process that contains the declaration)

Channels  for exchanging messages between processes  finite sized and asynchronously, unless you set it to size 0  synchronous channel  Syntax : c ! 0 sending over channel c; blocking if c is full c ? x receives from c, transfer it to x; blocking if c is empty  There are some more exotic channel operations : checking empty/full, testing head-value, copying instead of receiving, sorted send, random receive...  check out the Manual chan c = [0] of {bit}; chan d = [2] of {mtype, bit, byte}; chan e[2] = [1] of {mtype, record};

Assertion  Thanks to built-in non-determinism in the interleaving semantics, we can also use assertion to specify a global invariant ! // implying that at any time during the run x is either 0 or 1 byte x=0, y=0 active proctype P { x++ ; (y>0) ; x-- } active proctype Q { (x>0) ; y++ ; (x==0) ; y--} active proctype Monitor { assert ((x==0 || x==1)) }

End state  When a process P fails to reach its terminal (end) state:  Then it was locked  error.  Maybe this P is not supposed to reach end-state  suppress end-state checking with SPIN option.  The terminal state is by default just the textual end of of P’s code.  You can specify additional terminal states by using end- label:  Of the form “end*” 25

State  Each (global) state of a system is a “product” of the states of its processes.  E.g. Suppose we have:  One global var byte x  Process P with byte y  Process Q with byte z  Each system state should describe:  all these variables  Program counter of each process  Other SPIN predefined vars  Represent each global state as a tuple … this tuple can be quite big. 26

Watch out for state explosion!  Size of each state: > 96 bits  Number of possible states  (2 32 ) 3 = 2 96  Far too huge  Focus on the critical aspect of your model; abstract from data when possible. 27 int x,y,z ; P { do :: x++ od } Q { do :: y++ od } R { do :: x/=y  z++ od }

(X)SPIN Architecture LTL Translater Spin Simulator Verifier Generator spin random guided interactive Xspin ϕ deadlocks safety properties liveness properties Promela model M editing window simulation options verification options MSC simulation window C program checker pan.* pan.exe counter example false

The stack  To save space SPIN does not keep a stack of states (large!), but rather a stack of action-IDs (small!)  Though this requires computing action-undo when backtracking 29

Verifier’s output assertion violated !((crit[0]&&crit[1])) (at depth 5) // computation depth... Warning: Search not completed Full statespace search for:... never-claim - (not selected) assertion violations + invalid endstates + State-vector 20 byte, depth reached 7, errors: 1 // max. stack depth 24 states, stored // states stored in hash table 17 states, matched // states found re-revisited 41 transitions (= stored+matched) 0 atomic steps hash conflicts: 0 (resolved) (max size 2^19 states) memory usage (Mbyte)

Specifying LTL properties  In Xspin via the LTL manager; available operators ; somewhat silly interface  SPIN then generates the Buchi automaton for this LTL formula; called “Never Claim” in SPIN. [](ok1 && !ok2) #define ok1 crit[1] #define ok2 crit[2]

Example of a Never Claim  Here is the never-claim of []<>p (the Buchi of  []<>p = <>[]  p)  This is automatically generated by SPIN never { do :: p ; break :: skip od ; accept : do :: !p ; skip od } Error if accept is reachable in the lock-step execution, and from there a cyclic run can be found.

Demo Time  Just to have a rough idea of how SPIN works!!! 33