INF5140: Specification and Verification of Parallel Systems



Similar documents
Introduction to Promela and SPIN. LACL, Université Paris 12

Introduction to SPIN. Acknowledgments. Parts of the slides are based on an earlier lecture by Radu Iosif, Verimag. Ralf Huuck. Features PROMELA/SPIN

Software Engineering using Formal Methods

Fundamentals of Software Engineering

Formal Verification by Model Checking

Today s Agenda. Automata and Logic. Quiz 4 Temporal Logic. Introduction Buchi Automata Linear Time Logic Summary

The Model Checker SPIN

Lecture 9 verifying temporal logic

Testing LTL Formula Translation into Büchi Automata

Stylianos Basagiannis

Journal of Mathematics Volume 1, Number 1, Summer 2006 pp

MODEL CHECKING OF SERVICES WORKFLOW RECONFIGURATION: A PERSPECTIVE ON DEPENDABILITY

Model Checking LTL Properties over C Programs with Bounded Traces

Specification and Analysis of Contracts Lecture 1 Introduction

Model Checking: An Introduction

Software Model Checking: Theory and Practice

Rigorous Software Development CSCI-GA

Verification of Agent Behavioral Models

Model Checking II Temporal Logic Model Checking

Formal verification of contracts for synchronous software components using NuSMV

Combining Software and Hardware Verification Techniques

logic language, static/dynamic models SAT solvers Verified Software Systems 1 How can we model check of a program or system?

CISC422/853: Formal Methods

Informatica e Sistemi in Tempo Reale

Formal Verification of Software

Real Time Programming: Concepts

T Reactive Systems: Introduction and Finite State Automata

VeriTech - A Framework for Translating among Model Description Notations

Formal Verification and Linear-time Model Checking

Algorithmic Software Verification

tutorial: hardware and software model checking

Temporal Logics. Computation Tree Logic

Software Modeling and Verification

C++ Programming Language

Overview Motivating Examples Interleaving Model Semantics of Correctness Testing, Debugging, and Verification

6.080/6.089 GITCS Feb 12, Lecture 3

Automata-Based Verification of Temporal Properties on Running Programs Dimitra Giannakopoulou Klaus Havelund

Software Quality Exercise 1

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Validated Templates for Specification of Complex LTL Formulas

Fabio Patrizi DIS Sapienza - University of Rome

Simulation-Based Security with Inexhaustible Interactive Turing Machines

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

LTL Model Checking with Logic Based Petri Nets

Sources: On the Web: Slides will be available on:

A Propositional Dynamic Logic for CCS Programs

Feature Specification and Automated Conflict Detection

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Regular Expressions and Automata using Haskell

Predicate Logic Review

A Classification of Model Checking-based Verification Approaches for Software Models

[Refer Slide Time: 05:10]

Lecture 10: Multiple Clock Domains

Software Engineering

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

Concurrent Programming

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Semantics and Verification of Software

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Tutorial on C Language Programming

The C Programming Language course syllabus associate level

Static Program Transformations for Efficient Software Model Checking

The Course.

CHAPTER 7 GENERAL PROOF SYSTEMS

System modeling. Budapest University of Technology and Economics Department of Measurement and Information Systems

Rigorous Software Development CSCI-GA

Using Patterns and Composite Propositions to Automate the Generation of Complex LTL

The Basics of Graphical Models

Moving from CS 61A Scheme to CS 61B Java

Runtime Verification - Monitor-oriented Programming - Monitor-based Runtime Reflection

Concepts and terminology in the Simula Programming Language

Business Process Verification: The Application of Model Checking and Timed Automata

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Notes on Complexity Theory Last updated: August, Lecture 1

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Model Checking based Software Verification

Java (12 Weeks) Introduction to Java Programming Language

Enforcing Security Policies. Rahul Gera

Development of dynamically evolving and self-adaptive software. 1. Background

Faculty of Engineering Student Number:

AKD EtherNet/IP Communication

Glossary of Object Oriented Terms

Model checking test models. Author: Kevin de Berk Supervisors: Prof. dr. Wan Fokkink, dr. ir. Machiel van der Bijl

SPIN Beginners Tutorial

Transcription:

INF5140: Specification and Verification of Parallel Systems Lecture 7 LTL into Automata and Introduction to Promela Gerardo Schneider Department of Informatics University of Oslo INF5140, Spring 2007 Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 1 / 41

Credits Credits: Many slides (all the figures with blue background and few others) were taken from Holzmann s slides on Logical Model Checking, course given at Caltech (http://spinroot.com/spin/doc/course/index.html) Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 2 / 41

Outline 1 Translating LTL into Automata 2 Spin and Promela Spin and Promela A First Example 3 Overview of Promela General Concepts Processes Data Objects Message Channels Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 3 / 41

Translating LTL into Automata Preliminaries Rewrite the eventually and always operators ψ U ψ ψ R ψ Write the formulas in negation normal form ψ ψ De Morgan laws for and (φ U ψ) ( φ) R ( ψ) 1 (φ R ψ) ( φ) U ( ψ) Make use of the following recurrence equations φ U ψ ψ (φ (φ U ψ)) φ R ψ ψ (φ (φ R ψ)) 1 The release operator R is sometimes denoted as V Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 4 / 41

Translating LTL into Automata Algorithm: Chapter 6, section 6.8 of Peled s book Software Reliability Methods We will show (no slides though) how the algorithm works by translating the LTL formula p into a Bï 1 2chi automaton Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 5 / 41

Translating LTL into Automata Example: p Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 6 / 41

Translating LTL into Automata Example: p The core algorithm gives as a result Nodes_Set: Name: 1 Incoming: {init, 1} Old: {, U p} New: Next: { U p} Name: 5 Incoming: {init, 1} Old: {p, U p} New: Next: Name: 6 Incoming: {5, 6} Old: New: Next: Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 7 / 41

Translating LTL into Automata Example: p We build the automaton as follows: The set of labels L are conjunctions of propositions appearing in ψ The set of states S consists of nodes in Nodes_Set There is a transition from s to s if s Incoming(s ) If p is in Old(s), then p will be a label of every transition into s The set of initial states s 0 are the nodes containing the incoming init edge The generalized Bï 1 2chi acceptance condition contains a separate set of states f F for each subformula of the form φ U ψ f contains all the states s such that either p Old(s) or U p Old(s) s 0 p p s 1 T s 2 Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 8 / 41

Spin and Promela PROMELA is an acronym for PROcess MEta LAnguage It s a system description language (not a programming lang.) Its emphasis is on modeling of process synchronization and coordination, not computation Targeted to the description of software systems, rather than hardware circuits SPIN is an acronym for Simple Promela INterpreter It can be used as a simulator and as a verifier Its basic building blocks are Asynchronous processes Buffered and unbuffered message channels Synchronizing statements Structured data There are no floating points, no notion of time nor of a clock Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 10 / 41

The Tool Promela behavior model correctness property e.g., in LTL -v SPIN -i -a pan.c model checking code C compiler executable model checker random and interactive model simulation guided simulation -t error-trails counter-examples to correctness properties Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 11 / 41

Producer and Consumers 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 } Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 13 / 41

Producers and Consumers P and C are two symbolic variables (enumerated type) mtype turn = P declares a global variable turn producer and consumer don t identify a process but a process type (proctype) active means one process will be instantiated from each proctype declaration do is the Promela loop. Each option sequence is preceded by :: (here there is only one, with guard (turn==p)) The execution of a loop may be stopped with a goto or a break (not present in the example) If all guard conditions evaluate to false the process blocks until at least one guard becomes true Good for modeling interprocess synchronization If more than one condition evaluate to true one is chosen non-deterministically Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 14 / 41

Producer and Consumers We can simulate an execution of the above program (limited to 14 steps) $ spin -u14 3-prodcons.pml Produce Consume Produce Consume ------------- depth-limit (-u14 steps) reached... Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 15 / 41

Extending Producers and Consumers We extend the previous model to have 2 producers and 2 consumers To force a strict alternation of producers and consumers we need more structure turn must be neither P nor C: we add N We associate an identity for the process: who of type pid We add, then: mtype = { P, C, N }; mtype turn = P; pid who; Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 16 / 41

Extending Producers and Consumers The producer becomes: active [2] proctype producer() { do :: request(turn, P, N) -> printf("p%d\n", _pid); assert(who == _pid); release(turn, C) od } request(turn, P, N) is not a function, it s an inline definition Also release(turn, C) is an inline definition Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 17 / 41

Extending Producers and Consumers request(_,_,_) may be written as follows: inline request(x, y, z) { atomic { x == y -> x = z; who = _pid } } Formal parameters have no type designation; they are only place holders If the inline is invoked as request(turn, P, N) then the following code is inserted into the model at the invocation point: atomic { (turn == P) -> turn = N; who = _pid } The scope of local variables of an inline definition depends on the invocation point of the inline and it s not restricted to its body atomic means all steps in the sequence will complete before another process may execute (like Manna&Pnueli s < > constructor) - It will execute only if (turn==p) _pid is a predefined, read-only local variable Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 18 / 41

Extending Producers and Consumers After the printing there is an assertion assert(who==_pid) The assertion verifies that the value of who matches the last assigned process The Spin verifier will be able to prove whether the assertion may be satisfied at this point or not Following the assertion, there is another inline, defined as follows: inline release(x, y) { atomic { x = y; who = 0 } } The call release(turn,c) will produce the following inlined code: atomic { turn = C; who = 0 } Executing this will pass the control to a consumer process... Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 19 / 41

The Extended Producer and Consumers Model 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 } Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 20 / 41

Simulating Producers and Consumers We can simulate the model with Spin: $ spin prodcons2.pml more P1 C3 P1 C3 P1 C3 P1 C2... The simulation seems to confirm the alternation of producer and consumers It seems no violation of the assertion has been found Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 21 / 41

Verifying Producers and Consumers We can invoke the Spin verifier: $ spin -a prodcons2.pml # generate a verifier $ cc -o pan pan.c # compile the verifier $./pan # perform the verification (Spin Version 4.2.6 -- 27 October 2005) + Partial Order Reduction Full statespace search for: never claim - (none specified) assertion violations + acceptance cycles - (not selected) invalid end states + State-vector 28 byte, depth reached 5, errors: 0 10 states, stored 3 states, matched 13 transitions (= stored+matched) 0 atomic steps... Only 10 states have been search in order to verify the model There are no errors No assertion violations Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 22 / 41

Central Concepts Finite-state models only: Promela models are always bounded Boundedness guarantees decidability Finite state models can still permit infinite executions Asynchronous behavior No hidden global system clock No implied synchronization between processes Non-deterministic control structures To support abstraction from implementation level detail Executability as a core part of the semantics Every basic and compound statement is defined by a precondition and an effect A statement can be executed, producing the effect, only when its precondition is satisfied; otherwise, the statement is blocked Example: q?m when channel q is non-empty, retrieve message m Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 24 / 41

Central Concepts A Promela model consists of three basic types of objects: Processes Global and local data objects Message channels global data process0 process1 local data message channels local data Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 25 / 41

Central Concepts Interaction and States Processes can synchronize their behavior in 2 ways Through the use of global (shared) variables Via message passing through channels Buffered channels or rendezvous channels There is no global clock that could be used for synchronization Each process has its own local state Process program-counter (i.e., control-flow point) Values of all locally declared variables The model as a whole has a global state The value of all globally declared variables The contents of all message channels The set of all currently active processes Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 26 / 41

Processes Processes are instances of proctypes They can be instantiated in different ways By prefixing a proctypes with the keyword active: active proctype my_process() {...} By using run, from any running process (see next slide) Multiple instances of process is possible: active [4] proctype my_process() {...} Process types are always declared globally The predefined variable _pid denotes the process id The number of active processes is bound to 255 Process termination is different from process death A process terminates when it reaches the end of its code A process can die and be removed only if all processes that were instantiated from it (directly or indirectly) have died Processes can terminate in any order, but they die in the reverse order of their creation Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 28 / 41

Creating Processes with run no active prefix used in this case init is a predefined initial process (optional) two assignments with run expressions on the right print statement init plus two copies of irun run proctype irun(byte x) { printf( it is me %d, %d\n, x, _pid) } init { pid a, b; a = run irun(1); b = run irun(2); printf( I created %d and %d\n, a, b) } $ spin irun.pml it is me 1, 1 I created 1 and 2 it is me 2, 2 3 processes created $ default indentation of output (output of process i gets i+1 tab-stops) suppressed with spin T option two local variables, invisible outside init x is a local variable inside irun, initialized at process initialization pid and byte are data-types _pid is a predefined local variable parameter passing interleaving of statement executions 3 asynchronous processes running. 1 of 6 possible interleavings... assignments and print statements are unconditionally executable expressions are only executable when they evaluate to true Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 29 / 41

Processes Few Remarks Parameter passing is by value Parameter values cannot be passed to the init process nor to processes created as active If a process created with active has parameters, they are treated as local variables and instantiated to zero A newly created process may, but need not, to start executing immediately after it is instantiated Each process defines an asynchronous thread of execution It can interleave its statement executions in arbitrary way with other processes run it s an operator, hence run irun(1) is an expression The run expression is the only one which can have a side effect when it evaluates to non-zero (when it instantiates a process) -but not when it evaluates to zero (when it fails to instantiate a process) Evaluating a run expression produces a value of type pid Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 30 / 41

Scope There are only two levels of scope in Promela Global Global to all processes Not possible to define global variables to a subset of processes Process local Local variables can be referenced from its point of declaration onwards inside the proctype body Not possible to define local variables restricted to specific blocks of statements Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 32 / 41

Basic Data Types Type Typical Range Sample Declaration bit 0..1 bit turn = 1; bool false..true bool flag = true; byte 0..255 byte cnt; chan 1..255 chan q; mtype 1..255 mtype msg; pid 0..255 pid p; short -2 15..2 15-1 short s = 100; int -2 31..2 31-1 int x = 1; unsigned 0..2 n -1 unsigned u : 3; 3 bits of storage range 0..7 the default initial value of all data objects (global and local) is zero all variables (local and global) must be declared before they are used a variable declaration can appear anywhere note: there are no reals, floats, or pointers deliberately: verification models are meant to model coordination not computation Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 33 / 41

Data Structures In Promela is possible to define record structures Example 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) } Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 34 / 41

Few Remarks User-defined variables are defined with the mtype declaration They hold symbolic values which cannot match Promela reserved words Only one-dimensional arrays are possible It is possible, however, to declare multidimensional arrays indirectly A user-defined type variable may be passed as argument in run statements, provided it does not have arrays run me(goo) would trigger an error message Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 35 / 41

Message Channels Processes may exchange data through message channels Asynchronously (buffered channels) Synchronously rendez-vous handshake (unbuffered channels) Declaration: chan qname = [8] of {short, chan, record} The channel named qname can contain at most 8 messages, each message consist of three fields: a short, a chan (channel) and a record (user-defined type) The name of a channel can be local or global, but the channel itself is always global chan x = [3] of { chan }; /* global handle, visible to both A and B */ active proctype A() { chan a; /* uninitialized local channel */ } x?a; /* get channel id, provided by process B */ a!x /* and start using b s channel! */ active proctype B() { chan b = [2] of { chan }; /* initialized local channel */ } x!b; /* make channel b available to A */ b?x; /* value of x doesn t really change */ 0 /* avoid death of B, or else b dissappears */ Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 37 / 41

Sending and Receiving Sending a message: qname!expr1,expr2,expr3 Only executable if the channel is not full Retrieving/receiving a message: qname?var1,var2,var3 Only executable if the channel is not empty If some of the parameters (e.g., var2) is a constant, the receiving operation is executable only if the constant parameters match the value of the corresponding fields in the message to be received We can use eval for imposing constraints on incoming messages: qname?eval(var1),var2,var3 var1 is evaluated and the receive operation is executed only if the first field of the incoming messages matches the current value of var1 Send and receive operations are not expressions; they are i/o statements (a>b && qname?msg0) not valid! (a>b && qname?[msg0]) valid! Expression qname?[msg0] is true when qname?msg0 would be executed at this point (but the actual receive is not executed) Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 38 / 41

Send and Receive Variants Sorted send: q!!n,m,p Like q!n,m,p but adds the message n,m,p to q in numerical order (rather than in FIFO order) Random receive: q??n,m,p Like q?n,m,p but can match any message in q (it need not be the first message) Brackets : q?[n,m,p] It is a side-effect free Boolean expression It evaluates to true precisely when q?n,m,p is executable, but has no effect on n,m,p and does not change the contents of q Braces : q?n(m,p) Alternative notation for standard receive; same as q?n,m,p Sometimes useful for separating type from arguments Channel polls: q?<n,m,p> It is executable iff q?n,m,p is executable; has the same effect on n,m,p as q?n,m,p, but does not change the contents of q Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 39 / 41

Asynchronous vs. synchronous q!m1 q!m1 q?m1 q!m2 m3 m2 m1 q!m2 q?m2 q!m3 q?m1 q!m3 q?m3 asynchronous messages can be buffered for later retrieval up to the capacity of the channel sender blocks when channel is full receiver blocks when channel is empty q?m2 q?m3 synchronous channel capacity is 0 can only perform an rv handshake not store messages sender blocks until matching receiver is available and vice versa Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 40 / 41

Further Reading and Final Remarks The LTL to Automata was taken from Chap. 6 of Peled s book The rest was based on Chapters 2 and 3 of Holzmann s book The Spin Model Checker For more details on where to find more on Promela syntax and Spin see Pensum/laringskrav at the course homepage Next lecture we ll continue with Chap. 3 of Holzmann s book and Chap. 7 Gerardo Schneider (Ifi, UiO) INF5140 - Lecture 7: Introduction to Promela 07.03.2007 41 / 41