Applications of Formal Verification

Similar documents
Applications of Formal Verification

Applications of Formal Verification

Formal Specification and Verification

Software Engineering using Formal Methods

Software Engineering using Formal Methods

Tool demonstration: Spin

Computer Aided Verification 2015 The SPIN model checker

Spin: Overview of PROMELA

Network Protocol Design and Evaluation

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Formal Specification and Verification

CS477 Formal Software Development Methods / 39

Design and Analysis of Distributed Interacting Systems

Lecture 3 SPIN and Promela

Distributed Systems Programming F29NM1 2. Promela I. Andrew Ireland. School of Mathematical and Computer Sciences Heriot-Watt University Edinburgh

The SPIN Model Checker

Computer Lab 1: Model Checking and Logic Synthesis using Spin (lab)

Spin: Overview of PROMELA

SPIN: Introduction and Examples

Formal Methods for Software Development

Patrick Trentin Formal Methods Lab Class, March 03, 2017

Patrick Trentin Formal Methods Lab Class, Feb 26, 2016

The Spin Model Checker : Part I/II

Formal Methods for Software Development

Computer Lab 1: Model Checking and Logic Synthesis using Spin (lab)

Promela and SPIN. Mads Dam Dept. Microelectronics and Information Technology Royal Institute of Technology, KTH. Promela and SPIN

4/6/2011. Model Checking. Encoding test specifications. Model Checking. Encoding test specifications. Model Checking CS 4271

A Tutorial on Model Checker SPIN

Design of Internet Protocols:

SPIN: Part /614 Bug Catching: Automated Program Verification. Sagar Chaki November 12, Carnegie Mellon University

The SPIN Model Checker

Distributed Systems Programming (F21DS1) SPIN: Simple Promela INterpreter

What is SPIN(Simple Promela Interpreter) Elements of Promela. Material About SPIN. Basic Variables and Types. Typical Structure of Promela Model

SPIN part 2. Verification with LTL. Jaime Ramos. Departamento de Matemática, Técnico, ULisboa

T Parallel and Distributed Systems (4 ECTS)

What is SPIN(Simple Promela Interpreter) Material About SPIN. Elements of Promela. Basic Variables and Types. Typical Structure of Promela Model

Logic Model Checking

The Spin Model Checker : Part I. Moonzoo Kim KAIST

Introduction to Model Checking

Iterative Statements. Iterative Statements: Examples. Counter-Controlled Loops. ICOM 4036 Programming Languages Statement-Level Control Structure

LECTURE 18. Control Flow

Program Syntax; Operational Semantics

Automated Reasoning. Model Checking with SPIN (II)

Model checking Timber program. Paweł Pietrzak

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

THE MODEL CHECKER SPIN

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Motivation was to facilitate development of systems software, especially OS development.

Chapter 8. Statement-Level Control Structures

Programming Language Concepts: Lecture 2

Multi-Threaded System int x, y, r; int *p, *q, *z; int **a; EEC 421/521: Software Engineering. Thread Interleaving SPIN. Model Checking using SPIN

Distributed Systems Programming (F21DS1) SPIN: Formal Analysis I

CS111: PROGRAMMING LANGUAGE II

SWEN-220 Mathematical Models of Software. Concurrency in SPIN Interleaving

CGS 3066: Spring 2015 JavaScript Reference

INF672 Protocol Safety and Verification. Karthik Bhargavan Xavier Rival Thomas Clausen

SPIN, PETERSON AND BAKERY LOCKS

Mapping of UML Diagrams to Extended Petri Nets for Formal Verification

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

15-819M: Data, Code, Decisions

Hello World. Slides mostly a reproduction of Theo C. Ruys SPIN Beginners Tutorial April 23, Hello() print "Hello"

Chapter 8. Statement-Level Control Structures ISBN

Using Model Checking with Symbolic Execution for the Verification of Data-Dependent Properties of MPI-Based Parallel Scientific Software

PLD Semester Exam Study Guide Dec. 2018

Distributed Systems Programming (F21DS1) SPIN: Formal Analysis II

Formal Systems II: Applications

BLM2031 Structured Programming. Zeyneb KURT

Chapter 8. Statement-Level Control Structures

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

G52CON: Concepts of Concurrency

Formal Verification by Model Checking

G52CON: Concepts of Concurrency

Programming Language Concepts: Lecture 2

Programming, numerics and optimization

TOWARDS AUTOMATED VERIFICATION OF WEB SERVICES

Distributed Systems Programming (F21DS1) Formal Verification

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Sri Vidya College of Engineering & Technology

A Fast Review of C Essentials Part I

Generating Code from Event-B Using an Intermediate Specification Notation

A Tutorial Introduction to Shared Memory Concurrency

Programming for Engineers Iteration

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

C - Basics, Bitwise Operator. Zhaoguo Wang

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

Motivation was to facilitate development of systems software, especially OS development.

C++ Programming: From Problem Analysis to Program Design, Third Edition

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Programming in C. What is C?... What is C?

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

Ch. 7: Control Structures

Flow Control. CSC215 Lecture

Iteration. Side effects

Models of concurrency & synchronization algorithms

COP4020 Programming Assignment 1 - Spring 2011

1007 Imperative Programming Part II

Transcription:

Applications of Formal Verification Model Checking: Introduction to PROMELA Bernhard Beckert Mattias Ulbrich SS 2017 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State of Baden-Württemberg and National Large-scale Research Center of the Helmholtz Association

Literature THE COURSE BOOK: Ben-Ari Mordechai Ben-Ari: Principles of the Spin Model Checker, Springer, 2008(!). Authored by receiver of ACM award for outstanding Contributions to CS Education. Recommended by G. Holzmann. Excellent student text book. further reading: Holzmann Gerard J. Holzmann: The Spin Model Checker, Addison Wesley, 2004. Beckert, Ulbrich Applications of Formal Verification SS 2017 2/37

A Major Case Study with SPIN Checking feature interaction for telephone call processing software Software for PathStar TM server from Lucent Technologies Automated abstraction of unchanged C code into PROMELA Web interface, with SPIN as back-end, to: track properties (ca. 20 temporal formulas) invoke verification runs report error traces Finds shortest possible error trace, reported as C execution trace Work farmed out to 16 computers, daily, overnight runs 18 months, 300 versions of system model, 75 bugs found strength: detection of undesired feature interactions (difficult with traditional testing) Main challenge: defining meaningful properties Beckert, Ulbrich Applications of Formal Verification SS 2017 3/37

Towards Model Checking System Model Promela Program byte n = 0; active proctype P() { n = 1; active proctype Q() { n = 2; System Property [ ]! (criticalsectp && criticalsectq) Model Checker criticalsectp = 0 1 1 criticalsectq = 1 0 1 Beckert, Ulbrich Applications of Formal Verification SS 2017 4/37

What is PROMELA? PROMELA is an acronym Process meta-language Beckert, Ulbrich Applications of Formal Verification SS 2017 5/37

What is PROMELA? PROMELA is an acronym Process meta-language PROMELA is a language for modeling concurrent systems multi-threaded Beckert, Ulbrich Applications of Formal Verification SS 2017 5/37

What is PROMELA? PROMELA is an acronym Process meta-language PROMELA is a language for modeling concurrent systems multi-threaded synchronisation and message passing Beckert, Ulbrich Applications of Formal Verification SS 2017 5/37

What is PROMELA? PROMELA is an acronym Process meta-language PROMELA is a language for modeling concurrent systems multi-threaded synchronisation and message passing few control structures, pure (no side-effects) expressions Beckert, Ulbrich Applications of Formal Verification SS 2017 5/37

What is PROMELA? PROMELA is an acronym Process meta-language PROMELA is a language for modeling concurrent systems multi-threaded synchronisation and message passing few control structures, pure (no side-effects) expressions data structures with finite and fixed bound Beckert, Ulbrich Applications of Formal Verification SS 2017 5/37

What is PROMELA Not? PROMELA is not a programming language Very small language, not intended to program real systems (we will master most of it in today s lecture!) No pointers No methods/procedures No libraries No GUI, no standard input No floating point types Fair scheduling policy (during verification) No data encapsulation Non-deterministic Beckert, Ulbrich Applications of Formal Verification SS 2017 6/37

A First PROMELA Program active proctype P() { printf("hello world\n") Command Line Execution Simulating (i.e., interpreting) a PROMELA program > spin hello.pml Hello world Beckert, Ulbrich Applications of Formal Verification SS 2017 7/37

A First PROMELA Program active proctype P() { printf("hello world\n") Command Line Execution Simulating (i.e., interpreting) a PROMELA program > spin hello.pml Hello world First observations keyword proctype declares process named P C-like command and expression syntax C-like (simplified) formatted print Beckert, Ulbrich Applications of Formal Verification SS 2017 7/37

Arithmetic Data Types active proctype P() { int val = 123; int rev; rev = (val % 10) * 100 + /* % is modulo */ ((val / 10) % 10) * 10 + (val / 100); printf("val = %d, rev = %d\n", val, rev) Beckert, Ulbrich Applications of Formal Verification SS 2017 8/37

Arithmetic Data Types active proctype P() { int val = 123; int rev; rev = (val % 10) * 100 + /* % is modulo */ ((val / 10) % 10) * 10 + (val / 100); printf("val = %d, rev = %d\n", val, rev) Observations Data types byte, short, int, unsigned with operations +,-,*,/,% All declarations implicitly at beginning of process (avoid to have them anywhere else!) Expressions computed as int, then converted to container type Arithmetic variables implicitly initialized to 0 No floats, no side effects, C/Java-style comments No string variables (only in print statements) Beckert, Ulbrich Applications of Formal Verification SS 2017 8/37

Booleans and Enumerations bit b1 = 0; bool b2 = true; Observations bit is actually small numeric type containing 0,1 (unlike C, JAVA) bool, true, false syntactic sugar for bit, 0, 1 Beckert, Ulbrich Applications of Formal Verification SS 2017 9/37

Booleans and Enumerations bit b1 = 0; bool b2 = true; Observations bit is actually small numeric type containing 0,1 (unlike C, JAVA) bool, true, false syntactic sugar for bit, 0, 1 mtype = { red, yellow, green ; mtype light = green; printf("the light is %e\n", light) Observations literals represented as non-0 byte: at most 255 mtype stands for message type (first used for message names) There is at most one mtype per program Beckert, Ulbrich Applications of Formal Verification SS 2017 9/37

Control Statements Sequence using ; as separator; C/JAVA-like rules Guarded Command Selection non-deterministic choice of an alternative Repetition loop until break (or forever) Goto jump to a label Beckert, Ulbrich Applications of Formal Verification SS 2017 10/37

Guarded Statement Syntax :: guard-statement -> command; Observations symbol -> is overloaded in PROMELA semicolon optional first statement after :: used as guard :: guard is admissible (empty command) Can use ; instead of -> (avoid!) Beckert, Ulbrich Applications of Formal Verification SS 2017 11/37

Guarded Commands: Selection active proctype P() { byte a = 5, b = 5; byte max, branch; if :: a >= b -> max = a; branch = 1 :: a <= b -> max = b; branch = 2 fi Beckert, Ulbrich Applications of Formal Verification SS 2017 12/37

Guarded Commands: Selection active proctype P() { byte a = 5, b = 5; byte max, branch; if :: a >= b -> max = a; branch = 1 :: a <= b -> max = b; branch = 2 fi Command Line Execution Trace of random simulation of multiple runs > spin -v max.pml > spin -v max.pml >... Beckert, Ulbrich Applications of Formal Verification SS 2017 12/37

Guarded Commands: Selection active proctype P() { byte a = 5, b = 5; byte max, branch; if :: a >= b -> max = a; branch = 1 :: a <= b -> max = b; branch = 2 fi Observations Guards may overlap (more than one can be true at the same time) Any alternative whose guard is true is randomly selected When no guard true: process blocks until one becomes true Beckert, Ulbrich Applications of Formal Verification SS 2017 12/37

Guarded Commands: Selection Cont d active proctype P() { bool p =...; if :: p ->... :: true ->... fi; active proctype P() { bool p =...; if :: p ->... :: else ->... fi; Beckert, Ulbrich Applications of Formal Verification SS 2017 13/37

Guarded Commands: Selection Cont d active proctype P() { bool p =...; if :: p ->... :: true ->... fi; Second alternative can be selected anytime, regardless of whether p is true active proctype P() { bool p =...; if :: p ->... :: else ->... fi; Beckert, Ulbrich Applications of Formal Verification SS 2017 13/37

Guarded Commands: Selection Cont d active proctype P() { bool p =...; if :: p ->... :: true ->... fi; Second alternative can be selected anytime, regardless of whether p is true active proctype P() { bool p =...; if :: p ->... :: else ->... fi; Second alternative can be selected only if p is false Beckert, Ulbrich Applications of Formal Verification SS 2017 13/37

Guarded Commands: Selection Cont d active proctype P() { bool p =...; if :: p ->... :: true ->... fi; Second alternative can be selected anytime, regardless of whether p is true So far, all our programs terminate: we need loops active proctype P() { bool p =...; if :: p ->... :: else ->... fi; Second alternative can be selected only if p is false Beckert, Ulbrich Applications of Formal Verification SS 2017 13/37

Guarded Commands: Repetition active proctype P() { /* computes gcd */ int a = 15, b = 20; do :: a > b -> a = a - b :: b > a -> b = b - a :: a == b -> break od Beckert, Ulbrich Applications of Formal Verification SS 2017 14/37

Guarded Commands: Repetition active proctype P() { /* computes gcd */ int a = 15, b = 20; do :: a > b -> a = a - b :: b > a -> b = b - a :: a == b -> break od Command Line Execution Trace with values of local variables > spin -p -l gcd.pml > spin --help Beckert, Ulbrich Applications of Formal Verification SS 2017 14/37

Guarded Commands: Repetition active proctype P() { /* computes gcd */ int a = 15, b = 20; do :: a > b -> a = a - b :: b > a -> b = b - a :: a == b -> break od Observations Any alternative whose guard is true is randomly selected Only way to exit loop is via break or goto When no guard true: loop blocks until one becomes true Beckert, Ulbrich Applications of Formal Verification SS 2017 14/37

Counting Loops Counting loops such as for-loops as usual in imperative programming languages are realized with break after the termination condition: #define N 10 /* C-style preprocessing */ active proctype P() { int sum = 0; byte i = 1; do :: i > N -> break /* test */ :: else -> sum = sum + i; i++ /* body, increment */ od Beckert, Ulbrich Applications of Formal Verification SS 2017 15/37

Counting Loops Counting loops such as for-loops as usual in imperative programming languages are realized with break after the termination condition: #define N 10 /* C-style preprocessing */ active proctype P() { int sum = 0; byte i = 1; do :: i > N -> break /* test */ :: else -> sum = sum + i; i++ /* body, increment */ od Observations Don t forget else, otherwise strange behaviour Can define for(var,start,end) macro, but we advise against: not a structured command (scope), can cause hard-to-find bugs Beckert, Ulbrich Applications of Formal Verification SS 2017 15/37

Arrays #define N 5 active proctype P() { byte a[n]; a[0] = 0;a[1] = 10;a[2] = 20;a[3] = 30;a[4] = 40; byte sum = 0, i = 0; do :: i > N-1 -> break; :: else -> sum = sum + a[i]; i++ od; Beckert, Ulbrich Applications of Formal Verification SS 2017 16/37

Arrays #define N 5 active proctype P() { byte a[n]; a[0] = 0;a[1] = 10;a[2] = 20;a[3] = 30;a[4] = 40; byte sum = 0, i = 0; do :: i > N-1 -> break; :: else -> sum = sum + a[i]; i++ od; Observations Arrays start with 0 as in Java and C Arrays are scalar types: a b always different arrays Array bounds are constant and cannot be changed Only one-dimensional arrays (there is an (ugly) workaround) Beckert, Ulbrich Applications of Formal Verification SS 2017 16/37

Record Types typedef DATE { byte day, month, year; active proctype P() { DATE D; D.day = 1; D.month = 7; D.year = 62 Beckert, Ulbrich Applications of Formal Verification SS 2017 17/37

Record Types typedef DATE { byte day, month, year; active proctype P() { DATE D; D.day = 1; D.month = 7; D.year = 62 Observations C-style syntax Can be used to realize multi-dimensional arrays: typedef VECTOR { int vector[10] ; VECTOR matrix[5]; /* base type array in record */ matrix[3].vector[6] = 17; Beckert, Ulbrich Applications of Formal Verification SS 2017 17/37

Jumps #define N 10 active proctype P() { int sum = 0; byte i = 1; do :: i > N -> goto exitloop; :: else -> sum = sum + i; i++ od; exitloop: printf("end of loop") Beckert, Ulbrich Applications of Formal Verification SS 2017 18/37

Jumps #define N 10 active proctype P() { int sum = 0; byte i = 1; do :: i > N -> goto exitloop; :: else -> sum = sum + i; i++ od; exitloop: printf("end of loop") Observations Jumps allowed only within a process Labels must be unique for a process Can t place labels in front of guards (inside alternative ok) Easy to write messy code with goto Beckert, Ulbrich Applications of Formal Verification SS 2017 18/37

Inlining Code PROMELA has no method or procedure calls Beckert, Ulbrich Applications of Formal Verification SS 2017 19/37

Inlining Code PROMELA has no method or procedure calls typedef DATE { byte day, month, year; inline setdate(d, DD, MM, YY) { D.day = DD; D.month = MM; D.year = YY active proctype P() { DATE d; setdate(d,1,7,62); Beckert, Ulbrich Applications of Formal Verification SS 2017 19/37

Inlining Code PROMELA has no method or procedure calls typedef DATE { byte day, month, year; inline setdate(d, DD, MM, YY) { D.day = DD; D.month = MM; D.year = YY active proctype P() { DATE d; setdate(d,1,7,62); The inline construct macro-like abbreviation mechanism for code that occurs multiply creates new local variables for parameters, but no new scope avoid to declare variables in inline they are visible Beckert, Ulbrich Applications of Formal Verification SS 2017 19/37

Non-Deterministic Programs Deterministic PROMELA programs are trivial Assume PROMELA program with one process and no overlapping guards All variables are (implicitly or explictly) initialized No user input possible Each state is either blocking or has exactly one successor state Such a program has exactly one possible computation! Beckert, Ulbrich Applications of Formal Verification SS 2017 20/37

Non-Deterministic Programs Deterministic PROMELA programs are trivial Assume PROMELA program with one process and no overlapping guards All variables are (implicitly or explictly) initialized No user input possible Each state is either blocking or has exactly one successor state Such a program has exactly one possible computation! Non-trivial PROMELA programs are non-deterministic! Possible sources of non-determinism 1 Non-deterministic choice of alternatives with overlapping guards 2 Scheduling of concurrent processes Beckert, Ulbrich Applications of Formal Verification SS 2017 20/37

Non-Deterministic Generation of Values byte range; if :: range = 1 :: range = 2 :: range = 3 :: range = 4 fi Observations assignment statement used as guard assignment statement always succeeds (guard is true) side effect of guard is desired effect of this alternative could also write :: true -> range = 1, etc. selects non-deterministically a value in {1, 2, 3, 4 for range Beckert, Ulbrich Applications of Formal Verification SS 2017 21/37

Non-Deterministic Generation of Values Cont d Generation of values from explicit list impractical for large range Beckert, Ulbrich Applications of Formal Verification SS 2017 22/37

Non-Deterministic Generation of Values Cont d Generation of values from explicit list impractical for large range #define LOW 0 #define HIGH 9 byte range = LOW; do :: range < HIGH -> range++ :: break od Observations Increase of range and loop exit selected with equal chance Chance of generating n in random simulation is 2 (n+1) Obtain no representative test cases from random simulation! Ok for verification, because all computations are generated Beckert, Ulbrich Applications of Formal Verification SS 2017 22/37

Sources of Non-Determinism 1 Non-deterministic choice of alternatives with overlapping guards 2 Scheduling of concurrent processes Beckert, Ulbrich Applications of Formal Verification SS 2017 23/37

Concurrent Processes active proctype P() { printf("process P, statement 1\n"); printf("process P, statement 2\n") active proctype Q() { printf("process Q, statement 1\n"); printf("process Q, statement 2\n") Observations Can declare more than one process (need unique identifier) At most 255 processes Beckert, Ulbrich Applications of Formal Verification SS 2017 24/37

Execution of Concurrent Processes Command Line Execution Random simulation of two processes > spin interleave.pml Beckert, Ulbrich Applications of Formal Verification SS 2017 25/37

Execution of Concurrent Processes Command Line Execution Random simulation of two processes > spin interleave.pml Observations Scheduling of concurrent processes on one processor Scheduler selects process randomly where next statement executed Many different computations are possible: non-determinism Use -p and -g options to see more execution details Beckert, Ulbrich Applications of Formal Verification SS 2017 25/37

Sets of Processes active [2] proctype P() { printf("process %d, statement 1\n", _pid); printf("process %d, statement 2\n", _pid) Observations Can declare set of identical processes Current process identified with reserved variable _pid Each process can have its own local variables Beckert, Ulbrich Applications of Formal Verification SS 2017 26/37

Sets of Processes active [2] proctype P() { printf("process %d, statement 1\n", _pid); printf("process %d, statement 2\n", _pid) Observations Can declare set of identical processes Current process identified with reserved variable _pid Each process can have its own local variables Command Line Execution Random simulation of set of two processes > spin interleave_set.pml Beckert, Ulbrich Applications of Formal Verification SS 2017 26/37

PROMELA Computations 1 active [2] proctype P() { 2 byte n; 3 n = 1; 4 n = 2; 5 Beckert, Ulbrich Applications of Formal Verification SS 2017 27/37

PROMELA Computations 1 active [2] proctype P() { 2 byte n; 3 n = 1; 4 n = 2; 5 One possible computation of this program 2, 2 3, 2 3, 3 3, 4 4, 4 0, 0 1, 0 1, 1 1, 2 2, 2 Notation Program pointer (line #) for each process in upper compartment Value of all variables in lower compartment Beckert, Ulbrich Applications of Formal Verification SS 2017 27/37

PROMELA Computations 1 active [2] proctype P() { 2 byte n; 3 n = 1; 4 n = 2; 5 One possible computation of this program 2, 2 3, 2 3, 3 3, 4 4, 4 0, 0 1, 0 1, 1 1, 2 2, 2 Notation Program pointer (line #) for each process in upper compartment Value of all variables in lower compartment Computations are either infinite or terminating or blocking Beckert, Ulbrich Applications of Formal Verification SS 2017 27/37

PROMELA Computations Note Semantics of concurrent PROMELA program are all its interleavings Called interleaving semantics of concurrent programs Not universal: in Java certain reorderings allowed Beckert, Ulbrich Applications of Formal Verification SS 2017 28/37

Interleaving Cont d Can represent possible interleavings in a DAG 1 active [2] proctype P() { 2 byte n; 3 n = 1; 4 n = 2; 5 4, 2 2, 0 3, 2 2, 2 0, 0 1, 0 2, 3 0, 1 3, 3 1, 1 2, 4 0, 2 4, 3 2, 1 3, 4 1, 2 4, 4 2, 2 Beckert, Ulbrich Applications of Formal Verification SS 2017 29/37

Atomicity At which granularity of execution can interleaving occur? Definition (Atomicity) An expression or statement of a process that is executed entirely without the possibility of interleaving is called atomic. Beckert, Ulbrich Applications of Formal Verification SS 2017 30/37

Atomicity At which granularity of execution can interleaving occur? Definition (Atomicity) An expression or statement of a process that is executed entirely without the possibility of interleaving is called atomic. Atomicity in PROMELA Assignments, jumps, skip, and expressions are atomic In particular, conditional expressions are atomic: (p -> q : r), C-style syntax, brackets required Guarded commands are not atomic Beckert, Ulbrich Applications of Formal Verification SS 2017 30/37

Atomicity Cont d int a,b,c; active proctype P() { a = 1; b = 1; c = 1; if :: a!= 0 -> c = b / a :: else -> c = b fi active proctype Q() { a = 0 Beckert, Ulbrich Applications of Formal Verification SS 2017 31/37

Atomicity Cont d int a,b,c; active proctype P() { a = 1; b = 1; c = 1; if :: a!= 0 -> c = b / a :: else -> c = b fi active proctype Q() { a = 0 Command Line Execution Interleaving into selection statement forced by interactive simulation > spin -p -g -i zero.pml Beckert, Ulbrich Applications of Formal Verification SS 2017 31/37

Atomicity Cont d How to prevent interleaving? 1 Consider to use expression instead of selection statement: c = (a!= 0 -> (b / a) : b) Beckert, Ulbrich Applications of Formal Verification SS 2017 32/37

Atomicity Cont d How to prevent interleaving? 1 Consider to use expression instead of selection statement: c = (a!= 0 -> (b / a) : b) 2 Put code inside scope of atomic: active proctype P() { a = 1; b = 1; c = 1; atomic { if :: a!= 0 -> c = b / a :: else -> c = b fi Beckert, Ulbrich Applications of Formal Verification SS 2017 32/37

Usage Scenario of PROMELA 1 Model the essential features of a system in PROMELA abstract away from complex (numerical) computations make usage of non-deterministic choice of outcome replace unbounded data structures with finite approximations assume fair process scheduler 2 Select properties that the PROMELA model must satisfy Generic Properties (discussed in later lectures) Mutal exclusion for access to critical resources Absence of deadlock Absence of starvation System-specific properties Event sequences (e.g., system responsiveness) Beckert, Ulbrich Applications of Formal Verification SS 2017 33/37

Formalisation with PROMELA Formal Execution Model System Requirements Formal Requirements Specification Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA PROMELA Model System Requirements Formal Properties Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA C Code System Requirements Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA Abstraction C Code PROMELA Model System Requirements Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA Abstraction C Code PROMELA Model System Requirements Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA C Code PROMELA Model System Requirements Generic Properties Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Formalisation with PROMELA C Code PROMELA Model System Requirements Generic Properties System Properties Beckert, Ulbrich Applications of Formal Verification SS 2017 34/37

Usage Scenario of PROMELA Cont d 1 Model the essential features of a system in PROMELA abstract away from complex (numerical) computations make usage of non-deterministic choice of outcome replace unbounded datastructures with finite approximations assume fair process scheduler 2 Select properties that the PROMELA model must satisfy Mutal exclusion for access to critical resources Absence of deadlock Absence of starvation Event sequences (e.g., system responsiveness) 3 Verify that all possible runs of PROMELA model satisfy properties Typically, need many iterations to get model and properties right Failed verification attempts provide feedback via counter examples Beckert, Ulbrich Applications of Formal Verification SS 2017 35/37

Verification: Work Flow (Simplified) PROMELA Program Properties [ ](!csp!csq) byte n = 0; active proctype P() { n = 1; active proctype Q() { n = 2; Spin csp = 0 1 1 csq = 1 0 1 Beckert, Ulbrich Applications of Formal Verification SS 2017 36/37

Literature for this Lecture Ben-Ari Chapter 1, Sections 3.1 3.3, 3.5, 4.6, Chapter 6 Spin Reference card (linked from jspin website) jspin User manual, file doc/jspin-user.pdf in distribution Beckert, Ulbrich Applications of Formal Verification SS 2017 37/37