The Spin Model Checker : Part I Moonzoo Kim KAIST.

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

The SPIN System. What is SPIN? Model-checker. Based on automata theory. Allows LTL or automata specification Efficient (on-the-fly model checking, partial.
The SPIN System. What is SPIN? Model-checker. Based on automata theory. Allows LTL or automata specification Efficient (on-the-fly model checking, partial.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
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:
UPPAAL Introduction Chien-Liang Chen.
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.
An Overview of PROMELA. A protocol Validation Language –A notation for the specification and verification of procedure rules. –A partial description of.
תרגול 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.
CIS 725 Guarded Command Notation. Programming language style notation Guarded actions en(a)  a en(a): guard of the action boolean condition or boolean.
Paul Ammann & Jeff Offutt
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.
Introduction to Software Testing Chapter 2.1, 2.2 Overview Graph Coverage Criteria Paul Ammann & Jeff Offutt
The Spin Model Checker Promela Introduction Nguyen Tuan Duc Shogo Sawai.
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.
Introduction in algorithms and applications Introduction in algorithms and applications Parallel machines and architectures Parallel machines and architectures.
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.
CS 290C: Formal Models for Web Software Lecture 4: Model Checking Navigation Models with Spin Instructor: Tevfik Bultan.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN.
Overview Graph Coverage Criteria ( Introduction to Software Testing Chapter 2.1, 2.2) Paul Ammann & Jeff Offutt.
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.
1 Rendez-Vous Logical extension of chan buffer = [N] of byte is chan port = [0] of byte Channel port is a rendez-vous port (binary handshake). Two processes,
Concurrency. A process is a program executing on a virtual computer Processor speed and multiplexing of shared resources are ignored Order of thread execution.
MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before.
Today’s Agenda  Quiz 4 next Tuesday  Quick Review  Continue on SPIN Overview.
Radu Iosif Introduction to SPIN Radu Iosif
Temporal Logic Model-checking with SPIN
Software Testing and Maintenance Lecture 2.1 Overview Graph Coverage
/ 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.
1 Graph Coverage (3). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section 2.2 ◦ Section
Concurrency Analysis for Correct Concurrent Programs: Fight Complexity Systematically and Efficiently Moonzoo Kim Computer Science, KAIST.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Paul Ammann & Jeff Offutt
Wishnu Prasetya Model Checking with SPIN Modeling and Verification with Promela.
Using SPIN. INTRODUCTION To extend the protocol simulator from Chapter 12 with an validator generator, all we have to do is to activate two command line.
Data Flow Testing. Introduction to Software Testing (Ch 2) © Ammann & Offutt 2 Definition of a Graph A set N of nodes, N is not empty A set N 0 of initial.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
CSE 555 Protocol Engineering Dr. Mohammed H. Sqalli Computer Engineering Department King Fahd University of Petroleum & Minerals Credits: Dr. Abdul Waheed.
November COMP60621 Designing for Parallelism Lecture 14 Deadlock + Channels in Promela John Gurd, Graham Riley Centre for Novel Computing School.
Paul Ammann & Jeff Offutt
Formal verification in SPIN
CSE 503 – Software Engineering
COMP60611 Fundamentals of Parallel and Distributed Systems
Paul Ammann & Jeff Offutt
The Spin Model Checker - Advanced Features
Paul Ammann & Jeff Offutt
Graph Coverage Criteria
An explicit state model checker
A Refinement Calculus for Promela
Graph Coverage Criteria
Paul Ammann & Jeff Offutt
CSE 555 Protocol Engineering
The Spin Model Checker - Advanced Features
Paul Ammann & Jeff Offutt
CSE 503 – Software Engineering
Presentation transcript:

The Spin Model Checker : Part I Moonzoo Kim KAIST

Hierarchy of SW Coverage Criteria 2/60 Simple Round Trip Coverage SRTC Node Coverage NC Edge Coverage EC Edge-Pair Coverage EPC Prime Path Coverage PPC Complete Path Coverage CPC Complete Round Trip Coverage CRTC All-DU-Paths Coverage ADUP All-uses Coverage AUC All-defs Coverage ADC Complete Value Coverage CVC (SW) Model checking Concolic testing

Model Checker Analyzes All Possible Scheduling active type A() { byte x; again: x++; goto again; } 3 x:0 x:1 x:2 x:255 active type A() { byte x; again: x++; goto again; } active type B() { byte y; again: y++; goto again; } x:0,y:0 x:1,y:0 x:2,y:0 x:255,y:0 x:0,y:1 x:1,y:1 x:0,y:255 x:1,y:255 x:255,y:255 x:2,y:1 x:2,y:255

Overview of the Spin Architecture A few characteristics of Spin Promela allows a finite state model only Asynchronous execution Interleaving semantics for concurrency 2-way process communication Non-determinism Promela provides (comparatively) rich set of constructs such as variables and message passing, dynamic creation of processes, etc 4 System Spec. In Promela Req. Spec. In LTL Spin Model Checker pan.c C compiler a.out OK Counter Example (s)

Tcl GUI of SPIN (ispin.tcl): Edit Window 5

Tcl GUI of SPIN (ispin.tcl): Verification Window 6

Tcl GUI of SPIN (ispin.tcl): Simulation Window 7

Overview of the Promela byte x; chan ch1= [3] of {byte}; active[2] proctype A() { byte z; printf(“x=%d\n”,x); z=x+1; ch1!z } proctype B(byte y) { byte z; ch1?z; } Init { run B(2); } 8 Similar to C syntax but simplified No pointer No real datatype such as float or real No functions Processes are communicating with each other using Global variables Message channels Process can be dynamically created Scheduler executes one process at a time using interleaving semantics Global variables (including channels) Process (thread) definition and creation Another process definition System initialization

Process Creation Example run() operator creates a process and returns a newly created process ID There are 6 possible outcomes due to non- deterministic scheduling A0.A1.B, A0.B.A1 A1.A0.B, A1.B.A0 B.A0.A1, B.A1.A0 In other words, process creation may not immediately start process execution 9 active[2] proctype A() { byte x; printf(“A%d is starting\n”); } proctype B() { printf(“B is starting\n”); } Init { run B(); }

Variables and Types Basic types bit bool Byte (8 bit unsigned integer) short (16 bits signed integer) Int (32 bits signed integer) Arrays bool x[10]; Records typedef R { bit x; byte y;} Default initial value of variables is 0 Most arithmetic (e.g.,+,-), relational (e.g. >,==) and logical operators of C are supported bitshift operators are supported too. 10

Finite State Model Promela spec generates only a finite state model because Max # of active process <= 255 Each process has only finite length of codes Each variable is of finite datatype All message channels have bounded capability <=

Basic Statements Each Promela statement is either executable: Blocked There are six types of statement Assignment: always executable Ex. x=3+x, x=run A() Print: always executable Ex. printf(“Process %d is created.\n”,_pid); Assertion: always executable Ex. assert( x + y == z) Expression: depends on its value Ex. x+3>0, 0, 1, 2 Ex. skip, true Send: depends on buffer status Ex. ch1!m is executable only if ch1 is not full Receive: depends on buffer status Ex. ch1?m is executable only if ch1 is not empty 12

Expression Statements An expression is also a statement It is executable if it evaluates to non-zero 1 : always executable 1<2:always executable x<0: executable only when x < 0 x-1:executable only when x !=0 If an expression statement in blocked, it remains blocked until other process changes the condition an expression e is equivalent to while(!e); in C 13

assert Statement assert(expr ) assert is always executable If expr is 0, SPIN detects this violation assert is most frequently used checking method, especially as a form of invariance ex. active proctype inv() { assert( x> 0);} –Note that inv() is equivalent to [] (x>0) in LTL with thanks to interleaving semantics 14

Generation of all possible interleaving scenarios 15 Original execution tree Thread1 Thread2 After adding Inv() process Thread1 Thread2 Inv() Therefore, just a single assert(x> 0) statement in Inv() can check if x>0 all the time

Program Execution Control Promela provides low-level control mechanism, i.e., goto and label as well as if and do Note that non-deterministic selection is supported else is predefined variable which becomes true if all guards are false; false otherwise 16 proctype A() { byte x; starting: x= x+1; goto starting; } proctype A() { byte x; if ::x x=x+1 ::x==0 -> x=1 fi } proctype A() { byte x; do :: x x=x+1; :: x==0 ->x=1; :: else -> break od } int i; for (i : ) { printf("i =%d\n",i) }

Critical Section Example 17 bool lock; byte cnt; active[2] proctype P() { !lock -> lock=true; cnt=cnt+1; printf("%d is in the crt sec!\n",_pid); cnt=cnt-1; lock=false; } active proctype Invariant() { assert(cnt <= 1); } spin_test]# ls crit.pml spin_test]# spin -a crit.pml spin_test]# ls crit.pml pan.b pan.c pan.h pan.m pan.t spin_test]# gcc pan.c spin_test]# a.out pan: assertion violated (cnt<=1) (at depth 8) pan: wrote crit.pml.trail Full statespace search for: never claim - (none specified) assertion violations + acceptance cycles - (not selected) invalid end states + State-vector 36 byte, depth reached 16, errors: states, stored 47 states, matched 166 transitions (= stored+matched) 0 atomic steps hash conflicts: 0 (resolved) memory usage (Mbyte) spin_test]# ls a.out crit.pml crit.pml.trail pan.b pan.c pan.h pan.m pan.t

Critical Section Example (cont.) 18 spin_test]# spin -t -p crit.pml Starting P with pid 0 Starting P with pid 1 Starting Invariant with pid 2 1: proc 1 (P) line 5 "crit.pml" (state 1) [(!(lock))] 2: proc 0 (P) line 5 "crit.pml" (state 1) [(!(lock))] 3: proc 1 (P) line 5 "crit.pml" (state 2) [lock = 1] 4: proc 1 (P) line 6 "crit.pml" (state 3) [cnt = (cnt+1)] 1 is in the crt sec! 5: proc 1 (P) line 7 "crit.pml" (state 4) [printf('%d is in the crt sec!\\n',_pid)] 6: proc 0 (P) line 5 "crit.pml" (state 2) [lock = 1] 7: proc 0 (P) line 6 "crit.pml" (state 3) [cnt = (cnt+1)] 0 is in the crt sec! 8: proc 0 (P) line 7 "crit.pml" (state 4) [printf('%d is in the crt sec!\\n',_pid)] spin: line 13 "crit.pml", Error: assertion violated spin: text of failed assertion: assert((cnt<=1)) 9: proc 2 (Invariant) line 13 "crit.pml" (state 1) [assert((cnt<=1))] spin: trail ends after 9 steps #processes: 3 lock = 1 cnt = 2 9: proc 2 (Invariant) line 14 "crit.pml" (state 2) 9: proc 1 (P) line 8 "crit.pml" (state 5) 9: proc 0 (P) line 8 "crit.pml" (state 5) 3 processes created

Revised Critical Section Example 19 bool lock; byte cnt; active[2] proctype P() { atomic{ !lock -> lock=true;} cnt=cnt+1; printf("%d is in the crt sec!\n",_pid); cnt=cnt-1; lock=false; } active proctype Invariant() { assert(cnt <= 1); } revised]# a.out Full statespace search for: never claim - (none specified) assertion violations + acceptance cycles - (not selected) invalid end states + State-vector 36 byte, depth reached 14, errors: 0 62 states, stored 17 states, matched 79 transitions (= stored+matched) 0 atomic steps hash conflicts: 0 (resolved) memory usage (Mbyte)

Deadlocked Critical Section Example 20 bool lock; byte cnt; active[2] proctype P() { atomic{ !lock -> lock==true;} cnt=cnt+1; printf("%d is in the crt sec!\n",_pid); cnt=cnt-1; lock=false; } active proctype Invariant() { assert(cnt <= 1); } deadlocked]# a.out pan: invalid end state (at depth 3) (Spin Version June 2006) Warning: Search not completed + Partial Order Reduction Full statespace search for: never claim - (none specified) assertion violations + acceptance cycles - (not selected) invalid end states + State-vector 36 byte, depth reached 4, errors: 1 5 states, stored 0 states, matched 5 transitions (= stored+matched) 2 atomic steps hash conflicts: 0 (resolved) memory usage (Mbyte)

Deadlocked Critical Section Example (cont.) 21 deadlocked]# spin -t -p deadlocked_crit.pml Starting P with pid 0 Starting P with pid 1 Starting Invariant with pid 2 1: proc 2 (Invariant) line 13 "deadlocked_crit.pml" (state 1) [assert((cnt<=1))] 2: proc 2 terminates 3: proc 1 (P) line 5 "deadlocked_crit.pml" (state 1) [(!(lock))] 4: proc 0 (P) line 5 "deadlocked_crit.pml" (state 1) [(!(lock))] spin: trail ends after 4 steps #processes: 2 lock = 0 cnt = 0 4: proc 1 (P) line 5 "deadlocked_crit.pml" (state 2) 4: proc 0 (P) line 5 "deadlocked_crit.pml" (state 2) 3 processes created

Communication Using Message Channels Spin provides communications through various types of message channels Buffered or non-buffered (rendezvous comm.) Various message types Various message handling operators Syntax chan ch1 = [2] of { bit, byte}; ch1!0,10;ch1!1,20 ch1?b,bt;ch1?1,bt chan ch2= [0] of {bit, byte} 22 Sender (1,20) (0,10) Receiver

Operations on Channels Basic channel inquiry len(ch) empty(ch) full(ch) nempty(ch) nfull(ch) Additional message passing operators ch?[x,y]: polling only ch? : copy a message without removing it ch!!x,y: sorted sending (increasing order) ch??5,y: random receiving ch?x(y) == ch?x,y (for user’s understandability) Be careful to use these operators inside of expressions They have side-effects, which spin may not allow 23

Faulty Data Transfer Protocol (pg 27, data switch model proposed at 1981 at Bell labs) 24 mtype={ini,ack, dreq,data, shutup,quiet, dead} chan M = [1] of {mtype}; chan W = [1] of {mtype}; active proctype Mproc() { W!ini;/* connection */ M?ack;/* handshake */ timeout -> /* wait */ if /* two options: */ :: W!shutup; /* start shutdown */ :: W!dreq; /* or request data */ do :: M?data -> W!data :: M?data-> W!shutup; break od fi; M?shutup; W!quiet; M?dead; } active proctype Wproc() { W?ini;/* wait for ini*/ M!ack;/* acknowledge */ do/* 3 options: */ :: W?dreq->/* data requested */ M!data /* send data */ :: W?data->/* receive data */ skip/* no response */ :: W?shutup-> M!shutup; /* start shutdown*/ break od; W?quiet; M!dead; } Mproc Wproc Channel W Channel M

The Sieve of Eratosthenes (pg 326) 25 /* The Sieve of Eratosthenes (c BC) Prints all prime numbers up to MAX */ #define MAX 25 mtype = { number, eof }; chan root = [0] of { mtype, int }; init { int n = 2; run sieve(root, n); do :: (n n++; root!number(n) :: (n >= MAX) -> root!eof(0); break od } proctype sieve(chan c; int prime) { chan child = [0] of { mtype, int }; bool haschild; int n; printf("MSC: %d is prime\n", prime); end: do :: c?number(n) -> if :: (n%prime) == 0 -> printf("MSC: %d = %d*%d\n", n, prime, n/prime) :: else -> if :: !haschild -> /* new prime */ haschild = true; run sieve(child, n); :: else -> child!number(n) fi; fi :: c?eof(0) -> break od; if :: haschild -> child!eof(0) :: else fi }

Simulation Run spin]$ spin sieve-of-eratosthenes.pml MSC: 2 is prime MSC: 3 is prime MSC: 4 = 2*2 MSC: 5 is prime MSC: 6 = 2*3 MSC: 8 = 2*4 MSC: 7 is prime MSC: 9 = 3*3 MSC: 10 = 2*5 MSC: 12 = 2*6 MSC: 14 = 2*7 MSC: 11 is prime MSC: 15 = 3*5 MSC: 13 is prime MSC: 16 = 2*8 MSC: 18 = 2*9 MSC: 20 = 2*