Today’s Agenda  Quiz 4 next Tuesday  Quick Review  Continue on SPIN Overview.

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.
Partial Order Reduction: Main Idea
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.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
© 2011 Carnegie Mellon University SPIN: Part /614 Bug Catching: Automated Program Verification Sagar Chaki April 21, 2014.
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.
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.
SPIN Verification System The Model Checker SPIN By Gerard J. Holzmann Comp 587 – 12/2/09 Eduardo Borjas – Omer Azmon ☐ ☐
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.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
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.
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.
Lecture 4&5: Model Checking: A quick introduction Professor Aditya Ghose Director, Decision Systems Lab School of IT and Computer Science University of.
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.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
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.
MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before.
Radu Iosif Introduction to SPIN Radu Iosif
1 CSEP590 – Model Checking and Automated Verification Lecture outline for August 6, 2003.
Temporal Logic Model-checking with SPIN
CIS 842: Specification and Verification of Reactive Systems Lecture INTRO-Examples: Simple BIR-Lite Examples Copyright 2004, Matt Dwyer, John Hatcliff,
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.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CS5270 Lecture 41 Timed Automata I CS 5270 Lecture 4.
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
Quick Test What do you mean by pre-test and post-test loops in C?
Control Structures In Text: Chapter 8.
The Spin Model Checker - Advanced Features
An explicit state model checker
A Refinement Calculus for Promela
CSE 555 Protocol Engineering
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
The Spin Model Checker - Advanced Features
CSE 503 – Software Engineering
HW6: Due Dec 20 23:59 To specify a corresponding Promela specification
Presentation transcript:

Today’s Agenda  Quiz 4 next Tuesday  Quick Review  Continue on SPIN Overview

Quick Review  What are the basic building blocks of a PROMELA system model?

Formal Methods in Software Engineering3 SPIN Overview  Introduction  SPIN by Examples  The PROMELA Language  Defining Correctness Claims  Summary

Formal Methods in Software Engineering4 SPIN is a tool that is designed to verify correctness requirements for multi-threaded and distributed software systems. The SPIN project is developed by Gerard Holzmann in Bell Lab. Additional information can be found at Acknowledgement: The lecture notes use some materials from Dr. Holzmann’s lectures at Caltech.

Formal Methods in Software Engineering5 Model Checking (1) The theoretic foundation of SPIN is model checking, i.e., an automatic technique to verify the correctness of finite state systems. It involves checking a desired property over a system (or a model of the system) through exhaustive search of all the reachable states. Important: Deductive verification can be used to verify systems with infinite state space.

Formal Methods in Software Engineering6 Model Checking (2) In model checking, a system is usually modeled as a state transition graph, and a desired property is usually specified in a temporal logic formula. The verification process is to check if the model (i.e. the state transition graph) satisfies the specified temporal logic formula.

Formal Methods in Software Engineering7 Correctness A system is correct if it meets its requirements:  Correctness cannot be proved in any absolute sense. What we can prove is that a system does or does not satisfy certain properties.  It is human judgment to conclude whether satisfying these properties implies ‘correctness’.  Getting the properties right is as important as getting the system right.

Formal Methods in Software Engineering8 Requirements Some requirements are universal, such as freedom from deadlock, livelock, and starvation. There are also many application-dependent requirements, such as proper termination states, reliable data transfer, and so on. The SPIN tool can be used to check both types of requirements.

Formal Methods in Software Engineering9 Model  A model is an abstraction of reality  it should be less detailed than the artifact being modeled  the level of detail is selected based on its relevance to the correctness properties  the objective is to gain analytical power by reducing details  A model is a design aid  it often goes through different versions, describing different aspects of reality, and can slowly become more accurate, without becoming more detailed.

Formal Methods in Software Engineering10 The Philosophy (1) requirements engineering high level design detailed design coding testing operation design decisions are made design errors are found the cost of fixing a bug increases

Formal Methods in Software Engineering11 The Philosophy (2) requirements engineering high level design detailed design coding testing operation build design models analyze them thoroughly only rely on testing to find coding errors finding errors earlier reduces the overall cost

Formal Methods in Software Engineering12 In practice... There are two ways of working with SPIN:  Use SPIN to verify a design model before implementation.  Extract a model from an implementation and then verify it using SPIN.

Formal Methods in Software Engineering13 A bit history LTLCTL C++panSpin SMV Spin 4.0CFortran 1936: first theory on computability, e.g., Turing machines 1960: early work on w-automata theory, e.g., by J.R. Buchi 1975: Edsger Dijkstra’s paper on Guarded Command Language 1978: Tony Hoare’s paper on Communicating Sequential Processes 1977: Amir Pnueli introduces LTL for system verification 1955: early work on tense logics (predecessors of LTL) 1995: Partial order reduction in SPIN, LTL conversion in SPIN (Doron Peled) 1986: Pierre Wolper and Moshe Vardi define the automata theoretic framework for LTL model checking 1986: Mazuklewicz paper on trace theory the two most popular logic model checkers: Spin: an explicit state LTL model checker based on automata theoretic verification targeting software verification (asynchronous systems) SMV: a symbolic CTL model checker targeting hardware circuit verification (synchronous systems) : the first computers are built 1968: two terms introduced: software crisis, software engineering 1989: Spin V0: verification of w-regular properties 1993: SMV Model Checker (Ken McMillan)

Formal Methods in Software Engineering14 What we will learn is mainly centered around the following questions (1) how to build system models; (2) how to specify logic properties; and (3) how to perform the analysis. We will not only learn how to use the SPIN tool, but also the foundation upon which the tool is built.

Formal Methods in Software Engineering15 Overview of SPIN  Introduction  SPIN by Examples  The PROMELA Language  Defining Correctness Claims  Summary

Formal Methods in Software Engineering16 Hello World active proctype main() { printf(“hello world\n”) } these are keywords ‘main’ is not a keyword no semi-colon here… $ spin hello.pml hello world 1 process created $ $ spin hello.pml hello world 1 process created $ a simulation run: this is a bit like C $ spin –a hello.pml $ gcc –o pan pan.c $./pan... depth reached 2, errors: 0 $ $ spin –a hello.pml $ gcc –o pan pan.c $./pan... depth reached 2, errors: 0 $ a verification run: init { printf(“hello world\n”) }

Formal Methods in Software Engineering17 Producer/Consumer mtype = { P, C }; mtype turn = P; active proctype producer () { do :: (turn == P) -> printf (“Produce\n”); turn = C od } active proctype consumer () { do :: (turn == C) -> printf (“Consume\n”); turn = P od }

Formal Methods in Software Engineering18 Loop and Selection active proctype producer () { again: if :: (turn == P) -> printf (“Produce\n”); turn = C fi goto again } active proctype producer () { do :: (turn == P) -> printf (“Produce\n”); turn = C od }

Formal Methods in Software Engineering19 Guard Conditions A guard condition in a loop or selection structure determines whether or not the statement that follows can be selected for execution. If no guard condition is true, then the process blocks. If more than one guard condition is true, then the selection is non- deterministic. The else guard condition is true iff all other guard conditions are false. (turn == P) -> wait: if :: (turn == P) -> :: else -> goto wait fi;

Formal Methods in Software Engineering20 Alternation If there is only one producer and one consumer, then the earlier program guarantees a strict alternation between producer and consumer. Now, what if there are multiple producers and consumers?

Formal Methods in Software Engineering21 A revised version mtype = { P, C, N } mtype turn = P; pid who; inline request (x, y, z) { atomic { x == y -> x = z; who = _pid; } } inline release (x, y) { atomic { x = y; who = 0} } active [2] proctype producer () { do :: request ( turn, P, N ) -> printf (“P%d\n”, _pid); assert (who == _pid); release ( turn, C) od } active [2] proctype consumer () { do :: request ( turn, C, N) -> printf (“C%d\n”, _pid); assert (who == _pid); release (turn, P) od }

Formal Methods in Software Engineering22 Critical Section Recall that there are two requirements for the critical section problem:  Mutual exclusion – At any given time, there is at most one process inside the CS.  Eventual entry – A process that requests to enter the CS will be able to enter eventually.

Formal Methods in Software Engineering23 Peterson’s Algorithm bool turn, flag[2]; byte cnt; active [2] proctype P () { pid i, j; i = _pid; j = 1 - _pid; again: flag[i] = true; turn = i; (flag[j] == false || turn != i) -> /* wait until true */ cnt ++; assert (cnt == 1); cnt --; flag[i] = false; goto again; }

Formal Methods in Software Engineering24 Executability In PROMELA, every type of statement can be used as a guard in any context. A statement is executable if and only if the expression evaluates to true. Otherwise, it blocks the process, until it becomes executable. Important: All statements are side-effect free when they evaluate to false.

Formal Methods in Software Engineering25 A data exchange protocol mtype = { ini, ack, dreq, data, shutup, quiet, dead } chan M = [1] of { mtype }; chan W = [1] of { mtype }; active proctype Mproc () { W!ini; M?ack; if :: W!shutup :: W!dreq; M?data -> do :: W!data :: W!shutup; break od fi M?shutup; W!quiet; M?dead } active proctype Wproc () { W?ini; M!ack; do :: W?dreq -> M!data :: W?data -> skip :: W?shutup -> M!shutup; break od; W?quiet; M!dead } channel declaration send a message receive a message

Formal Methods in Software Engineering26 SPIN Overview  Introduction  SPIN by Examples  The PROMELA Language  Defining Correctness Claims  Summary

Formal Methods in Software Engineering27 A Meta Language PROMELA stands for PROcess MEta LAnguage. It is designed to facilitate the description of design abstractions. In particular, the language is targeted to the description of concurrent software systems. The emphasis is on the synchronization and communication aspects.

Formal Methods in Software Engineering28 Verification Model PROMELA is used to describe a verification model, not an implementation  A verification model is an abstraction of a design, which omits many low level details that would exist in an implementation.  On the other hand, such a model often includes the behavior of the environment and a specification of correctness properties, which are usually not included in an implementation.

Formal Methods in Software Engineering29 Building Blocks A PROMELA model is typically built from asynchronous processes, message channels, synchronization statements, and structured data. Deliberately, a model often has few computations. In addition, it does not have the notion of time or clock. Important: What is the difference between concurrent systems and real-time systems?

Formal Methods in Software Engineering30 Process Instantiation (1) active [2] proctype MyProc () { printf (“my pid is: %d\n”, _pid); } proctype MyProc (byte x) { printf (“x = %d, pid = %d\n”, x, _pid); } init { run MyProc (0); run MyProc (1); }

Formal Methods in Software Engineering31 Process Instantiation (2) Question: What is the difference between the two ways for process instantiation?

Formal Methods in Software Engineering32 Process Instantiation (3) The value of a run expression evaluates to zero if it fails to instantiate a process; otherwise, it evaluates to the pid of the newly created process. init { pid p0, p1; p0 = run MyProcess(0); p1 = run MyProcess(1); printf (“pids: %d and %d\n”, p0, p1); }

Formal Methods in Software Engineering33 Process Termination and Death (1) A process “terminates” when it reaches the end of its code; a process can only “die” if all child processes have died. When a process has terminated, it can no longer execute statements, but is still maintained in the system. It is removed from the system only after it dies.

Formal Methods in Software Engineering34 Process Termination and Death (2) Processes can terminate in any order, but they can only die in the reverse order. active proctype splurge (int n) { pid p; printf (“%d\n”, n); p = run splurge (n + 1); }

Formal Methods in Software Engineering35 Basic Data Types TypeTypical Range bit0, 1 boolfalse, true byte chan mtype pid short int – 1 unsigned0.. 2 n - 1

Formal Methods in Software Engineering36 Example Declarations bit x, y; bool turn = true; byte a[12]; chan m; mtype n; short b[4] = 89; int cnt = 67; unsigned v : 5; unsigned w : 3 = 5;

Formal Methods in Software Engineering37 Enumeration Type mtype = { apple, pear, orange, banana }; mtype = { fruit, vegetables, cardboard }; init { mtype n = pear; printf (“the value of n is ”); printm (n); printf (“\n”); }

Formal Methods in Software Engineering38 User-defined Type typedef Field { short f = 3; byte g }; typedef Record { byte a[3]; int fld1; Field fld2; chan p[3]; bit b }; proctype me (Field z) { z.g = 12 } init { Record goo; Field foo; run me(foo); }

Formal Methods in Software Engineering39 Multidimensional Array PROMELA supports only one-dimensional array as first class objects. Multi-dimensional arrays have to declared indirectly. typedef Array { byte el[4]; } Array a[4];

Formal Methods in Software Engineering40 Variable Scopes There are only two levels of scope in PROMELA: global and process local. init { int x; { int y; printf (“x = %d, y = %d\n”, x, y); x ++; y ++; } printf (“x = %d, y = %d\n”, x, y); }

Formal Methods in Software Engineering41 Message Channel A message channel is used to exchange data between processes. chan ch = [16] of { short, byte, bool } Question: There are two ways to communicate between processes in PROMELA. What is the other one?

Formal Methods in Software Engineering42 Channel Operations (1) By default, a send operation is executable only if the target channel is not full. Moreover, the number of message fields in a send operation must equal the number of message fields declared for the channel. qname ! expr1, expr2, expr3 qname ! expr1 (expr2, expr3)

Formal Methods in Software Engineering43 Channel Operations (2) A receive operation, without any constant parameters, is executable only if the source channel is non-empty. qname ? var1, var2, var3 qname ? var1 (var2, var3)

Formal Methods in Software Engineering44 Channel Operations (3) A receive operation may take some constants as its parameters. If so, the operation is executable only if these constants are matched in the message that is to be received. qname ? cons1, var2, cons2 qname ? eval(var1), var2, cons2

Formal Methods in Software Engineering45 Channel Operations (4) mtype = { msg0, msg1, ack0, ack1 }; chan to_sndr = [2] of { mtype }; chan to_rcvr = [2] of { mtype }; active proctype Sender () { again: to_rcvr ! msg1; to_sndr ? ack1; to_rcvr ! msg0; to_sndr ? ack0; goto again } active proctype Receiver () { again: to_rcvr ? msg1; to_sndr ! ack1; to_rcvr ? msg0; to_sndr ! ack0; goto again }

Formal Methods in Software Engineering46 Channel Operations (5)  Test the executability of a send or receive operation qname ? [ m0 ]  Poll – Read a message but do not remove it qname ?

Formal Methods in Software Engineering47 Channel Operations (6)  len(qname) – returns the number of msgs  empty(qname)/nempty(qname)  full(qname)/nfull(qname)

Formal Methods in Software Engineering48 Rendezvous (1) PROMELA supports both asynchronous and synchronous or rendezvous communication. Question: What is the difference between the two communication models? chan qname = [N] of { byte } chan qname = [0] of { byte }

Formal Methods in Software Engineering49 Rendezvous (2) mtype = { msgtype }; chan name = [0] of { mtype, byte }; active proctype A () { name ! msgtype (124); name ! msgtype (121) } active proctype B () { byte state; name ? msgtype (state); }

Formal Methods in Software Engineering50 Passing Channels mtype = { msgtype }; chan glob = [0] of { chan }; active proctype A () { chan loc = [0] of { mtype, byte }; glob ! loc; loc ? msgtype (121) } active proctype B () { chan who; glob ? who; who ! msgtype (121) }

Formal Methods in Software Engineering51 Executability (1) PROMELA has four types of statements: print statements, assignments, I/O statements, and expression statements. A statement is either executable or blocked. The first two types of statements are always executable. The other two depends on the current system state. Important: An expression can be used as part of another statement. In this case, the expression is “passable” only if it evaluates to true.

Formal Methods in Software Engineering52 Executability (2) The meaning of statement (a == b); can be explained using the following blocks: while (a != b) skip ; L: if :: (a == b) -> skip :: else -> goto L fi do :: (a == b) -> break :: else -> skip od

Formal Methods in Software Engineering53 Side effects Any expression in PROMELA must be side effect free when it evaluates to false. (Why?)

Formal Methods in Software Engineering54 Compound Statements We have seen the basic statements of PROMELA: print, assignment, expression, and send/receive statements. In addition, there are five types of compound statements: (1) atomic sequence; (2) deterministic steps; (3) selection; (4) repetitions; (5) escape sequences.

Formal Methods in Software Engineering55 Atomic Sequence The execution of an atomic sequence cannot be interrupted. init { atomic { run A (1, 2); run B (2, 3); } Important: The atomicity can be broken if one of the statements is found to be unexecutable. nfull (ch) -> ch ! msg nempty (ch) -> ch ? msg

Formal Methods in Software Engineering56 Selection (1) Selection basically represents the branch structure. An option sequence can be selected only if its first statement or its guard is executable. If more than one guard is executable, the choice is non-deterministic. If none of the guards is executable, the process is blocked. There is no restriction on the types of statements that can be used as a guard.

Formal Methods in Software Engineering57 Selection (2) byte count; active proctype counter () { if :: count ++ :: count –- fi }

Formal Methods in Software Engineering58 Repetition (1) Repetition basically represents the loop structure. One of the option sequences is selected in a way that is similar to selection. active proctype counter () { do :: (count != 0) -> if :: count ++ :: count – fi :: (count == 0) -> break od }

Formal Methods in Software Engineering59 Repetition (2) An else option can be selected only if no other options are executable. active proctype counter () { do :: (count != 0) -> if :: count ++ :: count – :: else fi :: else -> break od }

Formal Methods in Software Engineering60 The AB Protocol mtype = { msg, ack }; chan to_sndr = [2] of { mtype, bit }; chan to_rcvr = [2] of { mtype, bit}; active proctype Sender () {bool seq_out, seq_in; do :: to_rcvr ! msg (seq_out) -> to_sndr ? ack (seq_in); if :: seq_in == seq_out -> seq_out = 1 – seq_out; :: else fi od } active proctype Receiver () {bool seq_in; do :: to_rcvr ? msg (seq_in) -> to_sndr ! ack (seq_in) :: timeout -> to_sndr ! ack (seq_in) od }

Formal Methods in Software Engineering61 timeout vs else  Both timeout and else are predefined boolean variables; their values are set by the system.  else is true iff no other statement is executable in the same process; timeout is true iff no other statement is executable in the same system.  In some sense, timeout can be considered as a system-level else.

Formal Methods in Software Engineering62 Inline Definition (1) The invocation of an inline is replaced with the text of the body of its definition. inline example (x, y) { y = a; x = b; assert (x) } init { int a, b; example (a, b); } init { int a, b; b = a; a = b; assert (a); } Important: There is no concept of value passing with inline’s.

Formal Methods in Software Engineering63 Inline Definition (2) inline example (x) { int y; y = x; printf (“%d\n”, y) } init { int a; a = 34; example (a); y = 0; }

Formal Methods in Software Engineering64 Reading Input Usually, a verification model should be closed, i.e., it must contain all the information that is needed to verify its properties. This means that reading inputs is typically not allowed in a PROMELA model. The only exception is that inputs can be read during simulation runs. Reading inputs is accomplished by reading from a built-in channel STDIN, which define a single message field of type int.

Formal Methods in Software Engineering65 Overview of SPIN  Introduction  SPIN by Examples  The PROMELA Language  Defining Correctness Claims  Summary

Formal Methods in Software Engineering66 Correctness claims... are an integral part of a verification model. They specify design requirements that should be satisfied by a system. SPIN is primarily concerned with the possibility, rather than probability, of a requirement could be violated.

Formal Methods in Software Engineering67 Proof of correctness... should be independent of the following assumptions:  the relative speeds of processes  the time it takes to execute specific instructions  the probability of occurrence of certain events

Formal Methods in Software Engineering68 Safety vs Liveness In general, there are two types of correctness properties:  Safety – Bad things should not happen.  Liveness – Good things must eventually happen.

Formal Methods in Software Engineering69 Types of claims PROMELA provides the following constructs to formalize correctness properties:  Basic assertions  End labels  Progress labels  Accept labels  Never claims  Trace assertions

Formal Methods in Software Engineering70 Basic Assertions Basic assertions are always executable. If they evaluate to true, their execution has no effect. Otherwise, an error message is triggered. An assertion statement is the only type of correctness property checked in both simulation and verification modes. assert (expression)

Formal Methods in Software Engineering71 End Labels (1) By default, SPIN checks if every process reaches the end of its code upon termination. If any process does not, a deadlock is reported. End-state labels are used to specify valid end states other than the default one. Any label that starts with the prefix end defines an end-state label.

Formal Methods in Software Engineering72 End Labels (2) mtype { p, v }; chan sema = [0] of { mtype }; active proctype Dijkstra () {byte count = 1; end: do :: (count == 1) -> sema ! p; count = 0 :: (count == 0) -> sema ? v; count = 1 od } active [3] proctype user () {if :: sema ? p; skip; sema ! v; if }

Formal Methods in Software Engineering73 Progress Labels (1) Progress labels are used to mark statements that signify effective progress. Any label that starts with progress is a progress label. SPIN can be enabled to check for the existence of non-progress cycles, i.e., cycles that do not pass through at least one of the progress labels. Important: If non-progress checking is enabled, then the search for invalid end states is automatically disabled.

Formal Methods in Software Engineering74 Progress Labels (2) byte x = 2; active proctype A () {do :: x = 3 – x; progress: skip od } active proctype B () {do :: x = 3 – x od }

Formal Methods in Software Engineering75 Accept Labels Accept labels are used to instruct SPIN to find all cycles that pass through at least one of the marked statements.

Formal Methods in Software Engineering76 Never Claims (1)... are used to specify behaviors that should never occur. A never claim checks system properties just before and just after each statement execution. If a never claim is matched by any system execution, then an error is triggered.

Formal Methods in Software Engineering77 Never Claims (2) A never claim can be used to check a system invariant p: never { do :: ! p -> break :: else od }

Formal Methods in Software Engineering78 Never Claims (3) Consider the following property: Every system state in which p is true eventually leads to a system state n which q is true, and in the interim p remains true. In SPIN, we are interested in system executions that could violate the above property, i.e., executions in which p first becomes true and thereafter q either remains false forever, or p becomes false before q becomes true.

Formal Methods in Software Engineering79 Never Claim (4) never { S0:do :: p && !q -> break :: true od; S1: accept: do :: !q :: !(p || q) -> break od; } S0 S1 true p && !q !q ! (p || q) error

Formal Methods in Software Engineering80 Never Claims (5) What if we change the second alternative true to else in the first repetition? Important: If we change true to else, then the never claim will only check the first time in a system execution that p becomes true should lead to a state where q is also true.

Formal Methods in Software Engineering81 Never Claims (6) As you may have felt, it is difficult to write never claims. SPIN provides a tool that can be used to convert a LTL formula to a never claim. ! [] (p -> (p U q))

Formal Methods in Software Engineering82 Predefined variables (1) There are four predefined variables in PROMELA:  _ : a write-only variable  _pid : the id of the current process  np_ : indicates if a system is current in a progress state  _last : the id of the process that performed the last step

Formal Methods in Software Engineering83 Predefined Variables (2) never { /* non-progress cycle detector */ do :: true :: np_ -> break od; accept: do :: np_ od }

Formal Methods in Software Engineering84 Predefined Functions (1) The following predefined functions are supposed to be used in never claims:  pc_value (pid) – the current control state of process pid  enabled (pid) – true if process pid has at least one transition enabled  – returns a non-zero value if the next statement to be executed in process pid is marked with label.

Formal Methods in Software Engineering85 Predefined Functions (2) active proctype A () { printf (“%d\n”, pc_value(_pid)); } active proctype B () { pc_value (0) > 2 -> printf (“ok\n”) }

Formal Methods in Software Engineering86 Putting together  An assertion is used to specify a safety property that must hold at a particular point.  An end label specifies alternative valid end states.  A progress label marks a statement that signifies progress.  An accept label is used to mark an acceptance state in a never claim.  A never claim specifies properties that must be checked at each step.  A trace assertion specifies valid or invalid sequences of channel operations.

Formal Methods in Software Engineering87 Overview of SPIN  Introduction  SPIN by Examples  The PROMELA Language  Defining Correctness Claims  Summary

Formal Methods in Software Engineering88 Summary  SPIN is designed to verify concurrent software systems.  A PROMELA model consists of four types of basic objects. What are they?  If a statement is blocked, the statement will be evaluated repeatedly until it becomes true.  Correctness properties must be formally specified as part of a verification model.