Methods of Assessing Model Behavior Testing “spot checks” aspects of real system Simulation “spot checks” aspects of abstract (model) system Deductive.

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

1 Data Link Protocols By Erik Reeber. 2 Goals Use SPIN to model-check successively more complex protocols Using the protocols in Tannenbaums 3 rd Edition.
Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Models of Concurrency Manna, Pnueli.
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
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:
White Box and Black Box Testing Tor Stålhane. What is White Box testing White box testing is testing where we use the info available from the code of.
Situation Calculus for Action Descriptions We talked about STRIPS representations for actions. Another common representation is called the Situation Calculus.
Model Checking I What are LTL and CTL?. and or dreq q0 dack q0bar.
UPPAAL Introduction Chien-Liang Chen.
Timed Automata.
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.
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.
Shin Hong, KAIST17 th April,2007 1/33 Provable Software Laboratory, CS KAIST.
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.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
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.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
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.
Formal Verification of SpecC Programs using Predicate Abstraction Himanshu Jain Daniel Kroening Edmund Clarke Carnegie Mellon University.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN.
Correctness requirements. Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions.
Korea Advanced Institute of Science and Technology The Spin Model Checker - Advanced Features Moonzoo Kim CS Dept. KAIST.
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.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Radu Iosif Introduction to SPIN Radu Iosif
Temporal Logic Model-checking with SPIN
May University of Glasgow Generalising Feature Interactions in Muffy Calder, Alice Miller Dept. of Computing Science University of Glasgow.
CIS 842: Specification and Verification of Reactive Systems Lecture INTRO-Examples: Simple BIR-Lite Examples Copyright 2004, Matt Dwyer, John Hatcliff,
Verification & Validation By: Amir Masoud Gharehbaghi
Hwajung Lee. Well, you need to capture the notions of atomicity, non-determinism, fairness etc. These concepts are not built into languages like JAVA,
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,
CSCI1600: Embedded and Real Time Software Lecture 28: Verification I Steven Reiss, Fall 2015.
Lecture 4 Introduction to Promela. Promela and Spin Promela - process meta language G. Holzmann, Bell Labs (Lucent) C-like language + concurrency dyamic.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
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.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Lecture #12 Page 1 ECE 4110– Digital Logic Design Lecture #12 Agenda 1.VHDL : Behavioral Design (Processes) Announcements 1.n/a.
Formal verification in SPIN
CSE 503 – Software Engineering
Automatic Verification
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
The Spin Model Checker - Advanced Features
CSC215 Lecture Control Flow.
An explicit state model checker
A Refinement Calculus for Promela
Abstraction.
CSE 555 Protocol Engineering
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
CSC215 Lecture Control Flow.
The Spin Model Checker - Advanced Features
CSE 503 – Software Engineering
Presentation transcript:

Methods of Assessing Model Behavior Testing “spot checks” aspects of real system Simulation “spot checks” aspects of abstract (model) system Deductive verification Uses axioms and proofs on a mathematical model of system Model checking Exhaustively checks states of a finite state model

Testing Requires the real system Remember the “cost to repair” during testing? Can’t test all possibilities Primarily an experimental approach For embedded systems, the same test may yield varying results depending on timing.

Simulation Tests a model of the real system Cheaper than testing Many details can be abstracted away Lets us concentrate of the important aspects Can simulate long before we can test with code Works fairly well, cost is medium For embedded systems, often the only way for “real” execution prior to having the hardware

Deductive Verification Extremely powerful Extremely hard One proof can cover very large range of behaviors Usually requires automated theorem prover These are hard to use Require lots of experience Remember loop check? That was easy. May Not produce an answer (undecidable)

Model Checking Exhaustively checks all states of a finite state machine. Can be automated Always terminates with a yes/no answer Often provides counter-example of bad behavior Requires a model. Doesn’t work well on real code.

Unfolding a State Machine A do/x:=1 B do/x++ C E1 E2 E3[x==1] E4 A B C A B C C A B C A B C C C C C C C C C C C C C C C C C C C C C... This is an infinite tree E5 Example path: A,B,A,B,C,C,C,….. This is what we can do with a state machine

What is Model Checking? Formal model of System Formal model of System “Unwind” model to searchable representation “Unwind” model to searchable representation Search tree for properties Search tree for properties Properties to test Properties to test Passes, or we get counter-example Really, a Kripke Structure is used for model checking. A Kripke Structure is a graph of states with transitions where each state is labeled with properties true in that state.

What Can Model Checking Do? Determine if something always happens Or, eventually fails to happen Determine if something eventually happens Or, it never happens Determine if a state can be reached at all Determine if a series of states form an infinite loop Sometimes, run the model in simulation

How Can These Be Used? Safety properties: Nothing “bad” ever happens Formalized using state invariants  execution never reaches a “bad” state Liveness properties: Something “good” eventually happens Formalized using temporal logic  special logic for describing sequences Specifying Important Properties

The Model Checker “SPIN” Code the model in the language Promela Run model through SPIN and produce C code Produces “model” to execute Specify properties “never cases” reachability presence of loops Execute Model Steps to follow to perform Model Check

Promela - Procedure active proctype foo() { int x,y,z; x = 1; y = 2; z = x+y; printf(“the value of z is %d\n”, z); } Declares a procedure Declares variables More or less standard “C” syntax Variable assignment

Promela - Guards (state == idle) ; state = go; (state == idle) -> state = go; These are equivalent Guard blocks until it can execute. Any statement can be a guard This is syntactic “sugar” for reading convenience Guards are used extensively in Promela. By convention, the first statement is called a “guard”, but a sequence can be a guard too... state == idle -> ready -> count > 16 -> state = go; tests conditions sequentially

Promela - IF vs DO do :: cond1 -> stmt1; :: cond2 -> stmt2; :: cond3 -> stmt3; od if :: cond1 -> stmt1; :: cond2 -> stmt2; :: cond3 -> stmt3; fi Waits until one of the guards is true, then executes the statement and continues. If none true, if-fi hangs. Continually loops executing the statement with true guard. If none true, waits until one is true.

Breaking loops and non-determinisim init { int x = 0; do :: printf("value of x is %d\n", x) -> x++; :: printf("value of x is %d\n", x) -> x--; :: x == 0 -> break; od; printf("done\n"); } c:\spin>SPIN349 test.pr value of x is 0 value of x is 1 value of x is 2 value of x is 3 value of x is 4 value of x is 5 value of x is 4 value of x is 5 value of x is 4 value of x is 5 value of x is 4 value of x is 3 value of x is 2 value of x is 1 value of x is 2 value of x is 1 done 1 processes created c:\spin> break gets out of loop. Notice non-deterministic execution

Sending Messages chan = [ ] of {message type}; chan!value; chan?value; Send a message Receive a message Declare a channel is length of queue. 0 means no queue; processes must “sync up” on the send/receive pair.

Message Example mtype {hello, goodbye}; chan event = [0] of {mtype}; active proctype one() { printf("proc one waiting for hello\n"); event?hello -> event!goodbye; printf("proc one got hello and sent goodbye\n"); } active proctype two() { printf("proc two sending hello\n"); event!hello; printf("proc two now looking for goodbye\n"); event?goodbye -> printf("proc two got goodbye\n"); } c:\spin>SPIN349 test.pr proc one waiting for hello proc two sending hello proc two now looking for goodbye proc one got hello and sent goodbye proc two got goodbye 2 processes created c:\spin> onetwo hello goodbye X X Produces

Hangar Door Model (1st 1/2) active proctype main() { state = sidle; do :: (state == sidle) -> printf("in state idle\n"); if :: button?down-> !vdownlimit -> printf("selecting down\n"); state = sstart; :: button?up -> !vuplimit -> printf("selecting up\n"); state = sstart; fi; :: (state == sstart) -> printf("in state start\n"); printf("start coil on\n"); if :: button?stop -> printf("start coil off; run coil off\n"); state = sidle; :: event?vuplimit -> state = shold :: event?downlimit -> state = shold; :: event?speed -> state = srun; :: event?motortimeout -> state = sfail; fi; do to keep the machine running notice choice statement here

Hangar Door Model (2nd 1/2) :: (state == srun) -> printf("in state run\n"); if :: button?stop -> printf("start coil off; run coil off\n"); state = sidle; :: event?uplimit -> state = shold :: event?downlimit -> state = shold; fi; :: (state == sfail) -> printf("in state sfail\n"); if :: event?ten_sec_timeout -> state = shold; fi; :: (state == shold) -> printf("in state hold\n"); button?stop -> state = sidle; od; }

Timeout Scenario /* States */ mtype {sidle, sstart, srun, sfail, shold}; /* events */ mtype {uplimit, downlimit, motortimeout, ten_sec_timeout, speed}; /* button events */ mtype {up,down,stop}; mtype state; chan event = [0] of {mtype}; chan button = [0] of {mtype}; bit vuplimit = 0; bit vdownlimit = 0; init { button!up; printf("sent up button\n"); event!motortimeout; printf("sent motor timeout\n"); event!ten_sec_timeout; printf("sent ten sec timeout\n"); button!stop; printf("sent button stop\n"); } Simulates the environment

Output From Model (1) c:\spin>SPIN349.EXE door.pr in state idle selecting up sent up button in state start start coil on sent event speed in state run sent uplimit in state hold timeout #processes: 2 state = shold vuplimit = 1 vdownlimit = 0 29: proc 1 (main) line 81 "door.pr" (state 49) 29: proc 0 (:init:) line 25 "door.pr" (state 8) 2 processes created c:\spin> active proctype main() { state = sidle; do :: (state == sidle) -> printf("in state idle\n"); if :: button?down-> !vdownlimit -> printf("selecting down\n"); state = sstart; :: button?up -> !vuplimit -> printf("selecting up\n"); state = sstart; fi; :: (state == sstart) -> printf("in state start\n"); printf("start coil on\n"); if :: button?stop -> printf("start coil off; run coil off\n"); state = sidle; :: event?vuplimit -> state = shold :: event?downlimit -> state = shold; :: event?speed -> state = srun; :: event?motortimeout -> state = sfail; fi;

Output From Model (2) :: (state == srun) -> printf("in state run\n"); if :: button?stop -> printf("start coil off; run coil off\n"); state = sidle; :: event?uplimit -> state = shold :: event?downlimit -> state = shold; fi; :: (state == sfail) -> printf("in state sfail\n"); if :: event?ten_sec_timeout -> state = shold; fi; :: (state == shold) -> printf("in state hold\n"); button?stop -> state = sidle; od; } c:\spin>SPIN349.EXE door.pr in state idle selecting up sent up button in state start start coil on sent event speed in state run sent uplimit in state hold timeout #processes: 2 state = shold vuplimit = 1 vdownlimit = 0 29: proc 1 (main) line 81 "door.pr" (state 49) 29: proc 0 (:init:) line 25 "door.pr" (state 8) 2 processes created c:\spin> Line 81 init { button!up; printf("sent up button\n"); event!motortimeout; printf("sent motor timeout\n"); event!ten_sec_timeout; printf("sent ten sec timeout\n"); button!stop; printf("sent button stop\n"); } Line 25

How to Make a Model From a State Machine Choice 1: Use DO and state variable do :: (state == idle) -> … ::... od; Choice 2: Use goto, labels state1: event?foo -> goto state2; state2: event?bar-> goto state1 performs transition

Transitions Within a state, channels are not quite right, but can be useful. But, we need “choice” construct for multiple transitions: state: if :: event?one -> … :: event?two ->... :: (foo == bar) -> … fi state: event?one -> … event?two -> … (foo == bar) -> … Picks up choices, and waits until one is ready This is wrong! Sequentially waits for each condition

Example State Machine mtype = {pwr_on, pwr_off, fan_on, fan_off}; chan event = [0] of {mtype}; init { event!pwr_on; event!fan_on; event!pwr_off; } active proctype fan_controller() { off: printf("in state off\n"); event?pwr_on -> goto power; power: printf("in state power\n"); if :: event?fan_on -> goto fanon; :: event?pwr_off -> goto off; fi; fanon: printf("in state fanon\n"); if :: event?fan_off -> goto power; :: event?pwr_off -> goto off; fi; } off power fanon pwr_on fan_onfan_off pwr_off c:\spin>SPIN349.EXE fan.pr in state off in state power in state fanon in state off timeout #processes: 2 7: proc 1 (fan_controller) line 15 "fan.pr" (state 2) 7: proc 0 (:init:) line 9 "fan.pr" (state 4) 2 processes created c:\spin>

How to Make a Composite State Could “flatten” state machine But this is not aesthetically pleasing Would like encapsulation proctypes are only construct available proctypes are concurrent. How to sync? Need to handle transitions to more complex than simple return Composite states can transition anywhere

Simulating a “call” chan wait = [5] of {int,mtype}; chan event = [5] of {mtype}; mtype = {ok, state2}; active proctype one() { int pid; mtype ns; pid = run two(); wait??eval(pid),ns; printf("two has returned\n"); event?ok -> printf("got queued event 1\n"); event?ok -> printf("got queued event 2\n"); if :: ns == state2 -> printf("next state is state2\n") fi; } proctype two() { int i; printf("now in proc two\n"); event!ok; printf("two sent two events\n"); wait!_pid,state2; } one calls and waits for two Here is the wait, and return of next state. eval turns variable into constant. Here is “return”, or state exit. Passes “next state” notice compound message

Example Execution chan wait = [5] of {int,mtype}; chan event = [5] of {mtype}; mtype = {ok, state2}; active proctype one() { int pid; mtype ns; pid = run two(); wait??eval(pid),ns; printf("two has returned\n"); event?ok -> printf("got queued event 1\n"); event?ok -> printf("got queued event 2\n"); if :: ns == state2 -> printf("next state is state2\n") fi; } proctype two() { int i; printf("now in proc two\n"); event!ok; printf("two sent two events\n"); wait!_pid,state2; } c:\spin>SPIN349 composite.pr now in proc two two sent two events two has returned got queued event 1 got queued event 2 next state is state2 2 processes created c:\spin> c:\spin>SPIN349 composite.pr now in proc two two sent two events two has returned got queued event 1 got queued event 2 next state is state2 2 processes created c:\spin>

How to Make a Class Same problems as composite state Must have encapsulation  Implies proctype again Need concurrency between classes proctype works for this All instance variables visible to this state machine If composite states in class, need to share between proctypes Can use a structure for instance variables

Representing Class Structure Use a proctype for the class. The Promela code will represent the top level behavior. proctype Foo() { (code for top level) } Put instance variables in a global typedef so they can be accessed by each composite state.

Class Instance Variables Foo x int y int sw bool typedef Foo_T { int x; int y; bool sw; } Foo_T Foo_V ; Foo_V.sw->Foo_V.x = Foo_V.y + 1; For this class, instance variables are declared like this -- and made public Instantiated like this Used like this Instance variables have to be accessible across proctype boundaries (composite states) because each composite state can access each instance variable. Declare the instance variables at the top of the Promela source file. Instance variables have to be accessible across proctype boundaries (composite states) because each composite state can access each instance variable. Declare the instance variables at the top of the Promela source file.