30
Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti [email protected] Part 2: The PROMELA Language

Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti [email protected] Part 2: The PROMELA Language

Embed Size (px)

Citation preview

Page 1: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Temporal Logic Model-checking with SPIN

COMP6004

Stéphane Lo [email protected]

Part 2: The PROMELA Language

Page 2: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Last LectureXspin

PROMELA parserLTL parser

and translator

Simulation Verifier (analyzer) generator

C Pre-processor/Compilation

ExecutionCounter-example

Page 3: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Introduction

PROMELA is the input language of SPIN

Inspired by: C, Guarded Command/CSP

Describes the model and part of the specification (other part: correctness claim as LTL formula)

Page 4: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

What is a model?

FOLDOC (Free Online Directory of Computing, wombat.doc.ic.ac.uk/foldoc):

A description of observed behaviour, simplified by ignoring certain details. Models allow complex systems to be understood and their behaviour predicted within the scope of the model, but may give incorrect descriptions and predictions for situations outside the realm of their intended use.

Page 5: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

PROMELA Basic Elements

Process Types and instances Local scope

Variables Data types Arrays

Statements/Conditions Channels

FIFO queue (array)

Page 6: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Macro definitions

#define name value

ex: #define red 2 x = x+red

Page 7: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Processes (1)

Process typeproctype myprocess(parameters)

{ ... }

Process instantiationrun myprocess(param_values)

Page 8: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Processes (2)

Data arrays or process types are the only types that cannot be passed as parameters

Process state defined by the values of its variables

Special process: init

Page 9: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Data types

Name Range Typically

bit / bool

0 .. 1 false .. true

byte 0 .. CHAR_BIT 0 .. 255

short SHRT_MIN .. SHRT_MAX -215-1 .. 215-1

int INT_MIN .. INT_MAX -232-1 .. -215-1

Page 10: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Symbolic values

Message typesmtype = {value_names}

ex: mtype = {red, green, blue}

Special

0 is false

Any non-0 value is true

Page 11: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Records

C structTypedef name

{ fieldtype1 fieldname1;

fieldtype2 fieldname2;}

Ex: Typedef picture{

int numcolors;

int vert_resolution;

int horz_resolution:}

Page 12: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Variables

Declarationdatatype variable_nameex: int counter

Assignmentvariable_name = valueex: counter = 1

Testvariable_name == valueex: counter == 0

Page 13: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Arrays

Declarationelem_type array_name[size]

ex: int vector[10]

Element valuearray_name[index]

ex: vector[0]

Page 14: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Statements (1)

Statements and conditions are not differentiated: both are either executable or blocked

Conditions areexecutable when trueblocked when false

Statements areexecutable when eligible for executionblocked when waiting for synchronization

Page 15: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Statements (2)

Always executable Variable declarations, Assignments, printf Assertions true / non-0 values skip, goto, break

Always blocked false and 0 (a.k.a. block, hang) values

Page 16: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Statements (3)

Special caserun is executable if a process of the specified type can be instantiated (memory limit, too many processes)

Statement separators (where interleaving may occur)

; or ->

Page 17: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Atomic sequences

Indivisible unit (no interleaving)atomic { statements }

Page 18: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

First example

byte state = 1;

proctype A(){byte tmp;(state==1) -> tmp=state; tmp=tmp+1; state=tmp}

proctype B(){byte tmp;(state==1)->tmp=state; tmp=tmp-1; state=tmp}

init { run A(); run B() }

Page 19: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Process communication (1)

Via (buffered) channels

Declaration

chan channame = [size] of {msgtype}

ex: chan com1 = [16] of {byte,int}

Global or local

Page 20: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Process communication (2)

Sending a value on a channelchanname!value

Receiving a value on a channelchanname?varname

Page 21: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Process communication (3)

More than one value

channame?value1,value2,...

Convention: first value is message type (mtype)

channame!mtype(value2,...)

Test a receive statement

channame?[values]

Page 22: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Process communication (4)

Size of the channel buffer

len(channame)

Rendez-vous communication (synchronous): channel of buffer size 0

Page 23: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Second example

proctype A(chan q1){ chan q2; q1?q2; q2!123 }

proctype B(chan qforb){ int x; qforb?x; printf(“x= %d\n”,x) }

init {chan qname = [1] of {chan};chan qforb = [1] of {int};run A(qname);run B(qforb);qname!qforb}

Page 24: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Control flow (1)

Case selectionif:: statement1:: statement2fi

ex: if:: (a==b) -> option1:: (a!=b) -> option2fi

Page 25: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Control flow (2)

Repetitiondo

:: statement1

:: statement2

od

Terminating the repetition: break

Page 26: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Control flow (3)

Unconditional jump Declare a label

mylabel: ... Jump to that label

goto mylabel

Three special kinds of labelsend, progress, accept

Page 27: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Control flow (4)

Unless{statement1} unless

{statement2;statement3}

Page 28: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Pseudo-statements

Timeoutdo:: statement1:: timeout -> statement2Od

Elseif:: statement1:: else -> statement2fi

Page 29: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Assertions

assert(condition)

Combined with labels to express the specification

Page 30: Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti splp@ecs.soton.ac.uk Part 2: The PROMELA Language

Semantics of PROMELA

http://www.spinroot.com/spin/Man/Intro.html

Operational model based on: Processes (Labelled transition Systems) Variables Channels Semantics engine