Correctness requirements. Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions.

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.
Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Models of Concurrency Manna, Pnueli.
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:
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
Program correctness The State-transition model A global state S  s 0 x s 1 x … x s m {s k = local state of process k} S0  S1  S2  … Each state transition.
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
UPPAAL Introduction Chien-Liang Chen.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
© 2011 Carnegie Mellon University SPIN: Part /614 Bug Catching: Automated Program Verification Sagar Chaki April 21, 2014.
/ 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.
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.
Critical Section chapter3.
Sept COMP60611 Fundamentals of Parallel and Distributed Systems Lecture 12 The Critical Section problem John Gurd, Graham Riley Centre for Novel.
Chapter 3 The Critical Section Problem
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.
Tele Design of Reactive Systems Summer 2001 Prof. Dr. Stefan Leue Institute for Computer Science Albert-Ludwigs-Universität Freiburg
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.
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.
Fundamentals of Python: From First Programs Through Data Structures
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Fundamentals of Python: First Programs
Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN.
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,
CIS 842: Specification and Verification of Reactive Systems Lecture Specifications: Sequencing Properties Copyright , Matt Dwyer, John Hatcliff,
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.
MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Program correctness The State-transition model The set of global states = so x s1 x … x sm {sk is the set of local states of process k} S0 ---> S1 --->
Temporal Logic Model-checking with SPIN
CSE 555 Protocol Engineering Dr. Mohammed H. Sqalli Computer Engineering Department King Fahd University of Petroleum & Minerals Credits: Dr. Abdul Waheed.
Program correctness The State-transition model A global states S  s 0 x s 1 x … x s m {s k = set of local states of process k} S0  S1  S2  Each state.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Defining Liveness by Bowen Alpern and Fred B. Schneider Presented by Joe Melnyk.
May University of Glasgow Generalising Feature Interactions in Muffy Calder, Alice Miller Dept. of Computing Science University of Glasgow.
Hwajung Lee. The State-transition model The set of global states = s 0 x s 1 x … x s m {s k is the set of local states of process k} S0  S1  S2  Each.
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
/ 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.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
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.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Agenda  Quick Review  Finish Introduction  Java Threads.
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
ITEC452 Distributed Computing Lecture 5 Program Correctness
An explicit state model checker
Linear Time Properties
HW6: Due Dec 14 23:59 To specify a corresponding Promela specification
COMP60621 Designing for Parallelism
HW6: Due Nov 26 23:59 To specify a corresponding Promela specification
CSE 503 – Software Engineering
HW6: Due Dec 20 23:59 To specify a corresponding Promela specification
Presentation transcript:

Correctness requirements

Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions

Basic Assertions assert(expression) Always executable, has no effect if expression==true For init{ assert (false) } spin false.pml spin: line 1 “false.pml“, Error: assertion violated #processes 1 1:proc 0 (:init:) line 1 “ false.pml“ (state 1) 1 process created

A good design is provable free of deadlocks –Verifying even the simplest of protocol properties, e.g., absence of deadlock, is PSPACE hard even for a finite state model –The complexity can be attacked from two directions: A formalism for specifying correctness requirements that is relatively simple A method for reducing the complexity of models PROMELA is the formalism used.

Several levels of complexity are formalized: Simple level - most frequently used requirements, e.g., absence of deadlock, are expresses straightforwardly and checked independently. They can be analyzed mechanically with fast algorithms even for very large systems. More complicated requirements - e.g., absence of livelocks, are expressed independently. Have an independent computational expense when validated mechanically. Very sophisticated requirements - the most expensive to check

Reasoning about Behavior Two types of claims are given behavior: Inevitable Impossible The number of possible behaviors of a PROMELA model is finite, a claim of either implies a complementary and equivalent claim of the other type. All correctness criteria that can be expressed in PROMELA define behaviors that are claims to be impossible.

To state that a given behavior is inevitable, we state that all deviant behaviors are impossible The behavior of a validation model is defined completely by the set of all the execution sequences it can perform An execution sequence is a finite ordered set of states A state in defined by the specification of all values, all control flow points of running processes, and the contents of message channels

Valid States A finite ordered set of states is said to be valid for a given PROMELA model M if it satisfies the following two criteria: The first state of the sequence is the initial state of M with all variables initialized to zero, all message channels empty, with only the init process active and set in its initial state If M is placed in the state with ordinal i, there is at least one executable statement that can bring it to the state with ordinal i+1

Two special types of sequences We consider: –An execution sequence is said to be terminating if no state occurs more than once in the sequence, and the model M contains no executable statements when placed in the last state of the sequence. –An execution sequence is said to cyclic if all states except the last one are distinct, and the last state of the sequence is equal to one of the earlier states. The union of all states included in the system behavior is called the set of reachable states of the model.

Properties of states Correctness claims for PROMELA models can be built up from simple propositions, where a proposition is a Boolean condition on the state of the system. Temporal Claims –We specify ordering of propositions. –Ordering of propositions is different from ordering of statements. Within a proctype a sequential ordering of two statements implies that the second statement is to be executed after the first one terminates.

Temporal claims We are not allowed to make any assumptions about the relative speeds of concurrently executing processes, the only valid interpretation of the word after above is eventually after. –In a temporal claim a sequential ordering of two propositions defines an immediate consequence. –An important requirement that applies to terminating sequences is absence of deadlock Assertions –Correctness criteria can be expressed as Boolean conditions that can be satisfied when a process reaches a given state:

ASSERT in PROMELA –assert(condition) –Always executable, if the condition is true the statement has no effect –The validity of the statement is violated if there is at least one execution sequence in which the condition is false when the assert statement becomes executable. byte state = 1; proctype A(){(state==1)->state=state + 1 } proctype B(){(state==1)->state=state - 1 } init { run A(); run B() }

–We try to claim that when process A() completes the value of state must be 2 and when process B() completes it must be 0 byte state = 1; proctype A() { (state == 1) -> state = state + 1; assert(state == 2) } proctype B() { (state == 1) -> state = state - 1; assert(state == 2) } init { run A(); run B() } –This claims are false.

System Invariants Boolean conditions that if true in the initial system state remain true in all reachable states, independently of the execution sequence that leads to each specific state. proctype monitor () { assert(invariant) } Once an instance of monitor has been started, it executes independently of the rest of the system; its assert statement is executable precisely once for every state of the system.

Dijkstra semaphore validation model #define p 0 #define v 1 chan sema[0] of { bit }; proctype dijkstra(){ do :: sema!p -> sema?v Od } proctype user(){ sema?p; /* critical section */ sema!v } init{ atomic{run dijkstra();run user();run user()})

semaphore –The semaphore guarantees mutually exclusive access of users processes to their critical sections. –We modify the user process: byte count; proctype user(){ sema?p; count = count + 1; skip; /* critical section */ count = count - 1; sema!v skip; } proctype monitor(){assert(count==0||count==1) }

–An instantiation of monitor must be included in init, to allow it to perform the correctness check init {atomic { run dijkstra(); run monitor(); run user(); run user(); run() }

Deadlocks In a finite state system, all execution sequences either terminate or they cycle back to a previously visited state. Terminating sequences are not necessarily deadlocks. Distinguish between expected, proper, end-states and unexpected ones. Deadlock states are unexpected end- states.

Other unexpected end-states include cases of incomplete protocol specification. For example: the unspecified reception. The final state in a terminating execution sequence must minimally satisfy the following: –Every process that was instantiated has terminated. –All message channels are empty.

End-State Not all processes necessarily terminate. We must be able to identify individual process states as proper end-states. This is done with end-state labels: proctype dijkstra() { end: do :: sema!p -> sema?v od }

Bad Cycles A state labeled end is a proper end-state. This brings about a revision of the first statement of a proper state: –Every process that was instantiated has either terminated or has reached a state marked as a proper end-state. Bad Cycles Two properties of cyclic sequences can be expressed in PROMELA:

Progress-States –Based on the explicit marking of states: –There are no infinite behaviors of only unmarked states. –There are no infinite behaviors that include marked states. –Marked states are called progress-states –Execution sequences that violate the above correctness claim are called non-progress cycles –Execution sequences that violate the latter claim are called livelocks.

Non-Progress Cycles A progress-state label marks a state that must be executed for the protocol to make progress. Semaphore example: we can label the successful passing of a semaphore test as “progress” proctype dijkstra() { end: do :: sema!p -> progress: sema?v od }

Livelocks By marking the progress state we express the correctness criteria that passing the semaphore guard cannot be postponed infinitely long. Livelocks –We define acceptance states. –An acceptance-state label is any label starting with the letter sequence “accept”

proctype dijkstra() { end: do :: sema!p -> accept: sema?v od } We claim that we cannot cycle through a series of p and v operations. This claim is false. We can either prove that it is false manually, or we can use an automated validator to provide a counter-example.

Temporal Claim Supposed we want to express the temporal claim: “every state in which property P is true is followed by a state in which property Q is true.” Two different interpretations of “follows” are possible: –immediately follows –eventually follows No assumption can be made in PROMELA about the relative timing of process execution. Temporal claims define temporal ordering of properties of states.

For every state in which property P is true is followed by a state in which property Q is true: we could write –P->Q There are two snags with that approach: –Since all our correctness criteria are based on properties that are claimed to be impossible, the temporal claims we use must also express ordering of properties that are impossible. –The temporal claims are defined on complete execution sequences. Even if a prefix of the sequence is irrelevant, it must still be represented as a trivially-true sequence of propositions.

Thus P->Q can be expressed as: –never { do :: skip od P->!Q } This is the format of a temporal claim in PROMELA. In other words, independent of the initial sequence of events, it is impossible for a state in which property P is true to be followed by a state in which property Q is true. Suppose we want to express the temporal property that condition1 can never remain true infinitely long:

–For that we must find where condition1 may be: false initially becomes true eventually remains true never { do :: skip :: condition1 -> break od; accept:do :: condition1 od }

condition1 skip is always true. when :: condition1 -> break executes, it means that condition1 turns true. condition1 in the second do stays true never { do :: skip :: condition1 -> break od; accept: condition1 }

The claim contains just one more state transition after condition1 becomes true. The claim is matched if there is at least one execution sequence in which condition1 holds in two subsequent states. A claim can be seen as a finite state machine. The finite state machine above contains three states: –the initial state –the state labeled accept –normal end state

The correct version of the claim states that it would be an error (a livelock) if the machine can stay in the second state infinitely long. The second version is that it would be an error if the third state is reachable.

Never claims Never claims in combination with acceptance-state labels can express also the absence of non-progress cycles. The complexity of finding non-progress cycles directly with progress-state labels is smaller than the expense of the validation of a claim that specifies the same property.

#define MAX 3 mtype = { msg0, msg1, ack0, ack1 }; chan sender = [1] of { byte }; chan receiver = [1] of { byte }; proctype Sender() {byte any; again: do :: receiver!msg1; if :: sender?ack1 -> break :: sender?any /* lost */ :: timeout /* retransmit */ fi od;

do :: receiver!msg0; if :: sender?ack0 -> break :: sender?any /* lost */ :: timeout /* retransmit */ fi od; goto again }

proctype Receiver() {byte any; again:do :: receiver?msg1-> sender!ack1; break :: receiver?msg0-> sender!ack0 :: receiver?any /* lost */ od; p0: do :: receiver?msg0 -> sender!ack0; break :: receiver?msg1 -> sender!ack1 :: receiver?any /* lost */ :: timeout /* retransmit */ od; p1: goto again

init { atomic { run Sender(); run Receiver() } }

Message loss Message loss is modeled explicitly with clauses that can steal an incoming message before it is processed. Claim: “it is always true that when the sender transmits a message, the receiver will eventually accept it.” The claim is a four-state machine: –the initial state –the two states that were labeled –the normal end state

never { do :: len(receiver) == 0 :: receiver?[msg0] -> goto accept0 :: receiver?[msg1] -> goto accept1 od; accept0: do :: !Receiver[2]:P0 od; accept1: do :: !Receiver[2]:P1 od; }

Claims At least one of the three conditions must be true in the initial system state. The claim remains in this state as long as receiver is empty. If receiver contains msg0 or msg1, it will change state to either accept0 or accept1. Once a transition is made, the claim can only remain in that state if the receiver process will never accept a message with the same sequence number.

I.e., the receiver never passes the state labeled P0. The pid of init is 0, Sender is 1, and Receiver is 2. Receiver[2] refers to the receiver process. Receiver[2]:P0 refers to that Receiver is currently in state labels P0. Receiver[2]:P0 is a special case of a more general construct: –A reference to variable any, Receiver[2].any can be –assert(Receiver[2].any<0) –A period refers to local variables.