lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008...

67
introduction to runtime verification CS 119 beyond assert and print

Transcript of lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008...

Page 1: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

introduction toruntime verification

CS 119

beyond assert and print

Page 2: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

standing order: sell whenprice drops more than 2%within 1 day.

action

property

events from Wall Street

Page 3: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

definition

runtime verification is the study of how to design artifacts for monitoring and analyzing system executions. Such artifacts can be used for a variety ofpurposes, including testing/program understanding and fault protection.

Page 4: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

the informal version

runtime verification is the study of how to get as much out of your runs possible.

Page 5: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

purposes

• correctness checking• debugging and testing• dynamic documentation/understanding• performance evaluation• fault protection/dependability• security/intrusion detection• functionality modification• aspect oriented programming

Page 6: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

field still has many names• runtime verification• runtime monitoring• runtime checking• runtime result checking• runtime reflection• monitoring oriented programming• design by contract• runtime analysis• dynamic analysis• trace analysis• fault protection

Page 7: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

http://www.runtime-verification.org

Page 8: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM
Page 9: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

program

specification

input output

specification and programming

Page 10: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

specification and programming

program

specification

static analysis

input output

Page 11: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

program

specification

dynamic analysis

input output

specification and programming

Page 12: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

program

specification

input output

specification and programming

test input/schedule generation

Page 13: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

program

specification

runtime verification

input output

specification and programming

Page 14: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

program

specification

specification learning

input output

specification and programmingvisualization

Page 15: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

comparison of techniques

s

p

c

we are giving up on coverageto write better specificationsand scale

Page 16: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

monitor the proof obligations

static analyzer

combiningstatic and dynamic analysis

program + spec

proof obligations

Page 17: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

components• instrumentation language (I)• property specification language (P)• reaction language (R)

monitorappl.

reaction

PI

R

Page 18: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

a trace view of execution• a formal view of an execution is to

consider it as a sequence ¾ of programstates: ¾ = s1 s2 s3 … sn

• during program execution we are at anypoint in time in the present moment nowwhere the past is known and the futureis unknown.

nowpast future

Page 19: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

instrumentation

monitorappl.

reaction

PI

R

• instrumentation language (I)• property specification language (P)• reaction language (R)

Page 20: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

while(true){ if(x>0)lock(L); x = shared; shared = f(x); unlock(L);}

trace generation

Page 21: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

while(true){ if(x>10){ lock(L); logLock(t,L); } x = shared; shared = f(x); release(L); logRelease(t,L);}

Trace:lock(t2,L)release(t2,L)lock(t2,L)release(t2,L)release(t2,L)lock(t2,L)release(t2,L)lock(t2,L)

execute monitor

Instrument program.For example usingAspect Oriented Programming

trace generation

Page 22: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

instrumentation• manual

– assertions– pre/post conditions in design by contract solutions

• automated– instrumentation of source code:

• CIL ( C ) http://manju.cs.berkeley.edu/cil/– instrumentation of byte/object code

• BCEL (Java) http://jakarta.apache.org/bcel/• Valgrind ( C ) http://valgrind.org

– High level bytecode APIs• Sofya http://sofya.unl.edu

– aspect orinted programming:• AspectJ (Java) http://www.eclipse.org/aspectj• AspectC ( C ) http://research.msrg.utoronto.ca/ACC• AspectC++ (C++) http://www.aspectc.org

this course

Page 23: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

monitor

monitorappl.

reaction

PI

R

• instrumentation language (I)• property specification language (P)• reaction language (R)

Page 24: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

property language• programming language• program (built-in algo. focused on specific problem)

– data race detection– atomicity violation– deadlock detection

• logic (formal system)– design by contract (pre/post conditions), JML for example– state machines– regular expressions– grammars (context free languages)– temporal logic (past time, future time)– csp/ccs (process algebra)– “super languages” combining several of these– full fledged formal specification languages (Z, VDM, …)– graphical languages (UML, …)

Page 25: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

//@ public invariant 0 <= size;/*@ requires size < elems.length-1; @ assignable elems[size], size; @ ensures size == \old(size+1); @ ensures elems[size-1] == x; @ ensures_redundantly @ (\forall int i; 0 <= i && i < size-1; @ elems[i] == \old(elems[i])); @*/

public void push(Object x) { elems[size] = x; size++;}

design by contract (JML)

nowpast future

old

Page 26: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

what about therest of the trace?

• pre/post conditions are not designed fortotal trace view, only “now” and“previous” (old) state.

• one can of course encode a total traceview using history variables.

• but that can be rather inconvenient.

nowpast future

Page 27: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

future time properties

nowpast future

A B

• If A happens now B must happen

¤(A ! § B)

Page 28: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

logicA ∨ B ?

p ∧ q “p and q”

p ∨ q “p or q”

p → q “p implies q”

¬p “not p”

Boolean logic allows us toformulate statements abouta single world/situation : now

Page 29: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

future time temporal logic(A → ◊B) ?

p “always p”

◊p “eventually p”

p U q “p until q”

(A → ◊B) (A → ◊B)∧ ◊B

p ∧ q “p and q”

p ∨ q “p or q”

p → q “p implies q”

¬p “not p”

(A → ◊B)

A B

(A → ◊B)∧ ◊B

Page 30: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

past time properties

nowpast future

AB

• If A happens now B must have happened

¤(A ! ¨B)

Page 31: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

past time temporal logic (A → B) ? B

p “sofar p”

p “previously p”

p S q “p since q”

p ∧ q “p and q”

p ∨ q “p or q”

p → q “p implies q”

¬p “not p”

(A → B){B}

B A

(A → B){B}

…(A → B) true ∧ (A → B){B}

Page 32: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

state machines• A and B should alternate

nowpast future

A B A BA B

1 2

A

B

Page 33: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

regular expressions

(A B)*

• A and B should alternate

A B A BA B

nowpast future

Page 34: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

context free grammars• An Bn

S ! A S B | ²

A B B BA A

nowpast future

Page 35: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

process algebra• AB randomly interleaved with CD

B D C AA C

nowpast future

p = q k rq = A ! B ! qr = C ! D ! r

Page 36: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

this course

regularexpressions

context free grammars

temporal logic-past time-future time

“super” logics

AspectJ + Java

Page 37: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

expressiveness

regularexpressions

context free grammars

temporal logic-past time-future time

“super” logicsJava

Page 38: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

monitor integration

• offline– analyzing log file / trace dump

• online– outline

• monitor runs in parallel with application.• communication for ex. over socket.

– synchronous (appl. waits for response)– asynchronous (buffered communication)

– inline• monitoring code is embedded into the application

p m

p m

p m

Page 39: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

violation versus validation• violation : the normal case, checking that the

system conforms to a property. A violation isreported when the property is violated.

• validation :– it can sometimes be easier to state property in

negative form: what we do not want to happen.Hence we want reported when the bad propertygets “validated”.

– or: it is a good property and we just want to logwhenever something good happens

most systems can only do one of the two forms

Page 40: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

violation example

(green yellow red)*

nowpast future

redgreen

violation

Page 41: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

validation example

green red

nowpast future

redgreen

validation

Page 42: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

violation Á ≠ validation ¬ Á

• some systems support both concepts• one cannot achieve validation semantics just

be negating a violation formula. example:– suppose our system can only check validation– violate ab ≠ validate ~(ab).– reason: observe the first ‘a’ in the trace ‘ab’.

• it validates ~(ab)• it does not violate ab yet (and will not in this case).

• some logics do not have negation (contextfree grammars for example)

Page 43: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

total trace versustrace suffix semantics

• total trace semantics: property must beviolated/validated on the whole trace

• suffix trace semantics:– validation : there exists a rightmost suffix

for which it holds– violation : hard to make sense of

nowpast future

Page 44: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

predictive analysis

good run

hmm … looks pretty good

to me!

bad run

Page 45: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

predictive analysis

good run

shoot … some foot printsof a bug!

bad run

turn a hard to test

property into an easy to test

property

Page 46: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

factual versus predictive

• factual– the standard case: violation/validation is what it is: violation/validation(¾) ) error (¾)

• predictive– violation/validation is only suggestive, indicating

the potential for an error in some other trace ofthe monitored system:

violation/validation(¾) ! 9 ¾’ : Traces • error(¾’)

Page 47: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

reaction

monitorappl.

reaction

PI

R

• instrumentation language (I)• property specification language (P)• reaction language (R)

Page 48: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

interaction degree1. error message2. separate code execution (not interacting with monitored

program, not same memory space)3. exception in monitored program, and monitored program then

deals with it4. integrated code execution (access to memory). Here the

monitor defines how to change the behavior of the monitoredprogram

p merror message

code execution

exception

code execution

1

2

3

4

Page 49: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

• Java’s assert statements, Java expressions:– http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html

• JML, pre/post conditions:– http://www.eecs.ucf.edu/~leavens/JML/index.shtml

• jContractor, pre/post conditions:– http://jcontractor.sourceforge.net/

• Temporal Rover (commercial), metric future time temporal logic/UML:– http://www.dbrover.com/

• Java MaC, past time temporal logic:– http://rtg.cis.upenn.edu/mac/index.php3

• JLO, future time temporal logic:– http://www.sable.mcgill.ca/~ebodde/rv//JLO

• Tracematches, regular expression suffix-validation:– http://abc.comlab.ox.ac.uk/papers

• PQL, context free grammars, suffix-validation:– http://pql.sourceforge.net/

• PTQL, SQL, suffix-validation:– http://techreports.lib.berkeley.edu/accessPages/CSD-04-

1315

systems for Java

Page 50: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

• LOLA:– http://www-step.stanford.edu/papers/time05.html

• T-UPPAAL, timed automata:– http://www.cs.aau.dk/~marius/tuppaal

• Jass, CSP (process algebra, pre/post conditions):– http://csd.informatik.uni-oldenburg.de/~jass

• Eagle/Hawk, recursion-based “super logic”:– http://yangtze.cs.uiuc.edu/~ksen/eagle

• Java MOP, plugin for different logics:– http://fsl.cs.uiuc.edu/index.php/JavaMOP

• RuleR, rule-based “super logic” (second attempt after Eagle):– http://www.cs.man.ac.uk/~howard/Logics%20for%20Program%20A

nalysis.html

systems for Java

this course

Page 51: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

systems for C• AspectC:

– http://research.msrg.utoronto.ca/ACC• Arachne, simple subset of regular expressions:

– http://www.emn.fr/x-info/arachne/index.html

Page 52: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

predictive systems• Visual threads (Eraser)

– http://h21007.www2.hp.com/portal/site/dspp/PAGE.template/page.document?ciid=e608bce06ee02110bce06ee02110275d6e10RCRD

• jPredictor– http://fsl.cs.uiuc.edu/index.php/JPredictor

• Atomicity

Page 53: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

learning specs from runs

• DAIKON, learning JML:– http://groups.csail.mit.edu/pag/daikon/

• Perecotta, learning temporal formulas:– http://www.cs.virginia.edu/perracotta

• Redux : learning call graphs etc.– Allan Mycroft et. al.

Page 54: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

Thread main (polygon) executes method main in the Server Object (rectangle). Method main creates a Worker object and calls start on it.

After the call of start on the Worker object the Worker thread can runand eventually it does. The run can happen anytime after start.

Server Worker

main

create

start

Worker

main

run

thread

thread

object object

timeline timeline

program visualization

Page 55: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

formalizing concept of monitorAlphabet: Given an alphabet (set) A of symbols

Language:A language L µ A* over A is a subset of A*.

Property:A property P over A is a language:

P µ A*

Page 56: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

examples

{²,ab,aabb,aaabbb,…}S ! a S b | ²

{²,ab,abab,ababab, …}(ab)*

{²,c,ba,baa,baba,…}¤(a ! ¨b)

{²,cc,b,ab,aab,…}¤(a ! §b)

language L(ϕ) formula ϕ

liveness

safety

a formula in a logic compacts an infinite language

Page 57: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

safety propertiesSafety property:A property P µ A* is a safety property if and only if P is prefix closed:

prefix(P) = P

where prefix(L) = {¾ | 9 ¾’ • ¾ a ¾’ 2 L}

intuitively: if a trace is safe then all prefixes of the trace are safe. This is for example not true for‘aab’ in the language P of ¤(a ! § b).Here ‘aa’ is for example not in P.

Page 58: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

monitoring a languageA monitor:A monitor M for a language L µ A* is a “box” which as input takes a listof symbols ® 2 A, one by one, and emits a value for the next symbol ®n as follows:

M! = ®1,®2,®3,…,®n

iff. ! 2 L

iff. @!’• ! a !’2 L

otherwise

Y

N

?

Page 59: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

the monitoring problemfor a logic L

The monitoring problem:

Given a logic L.Given a formula ϕ 2 Formulas(L).

Construct a monitor for the language of ϕ:

ML(ϕ)

For L 2 {RE,CFG,PTTL,FTTL,…}

Page 60: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

challenges• specification-based monitoring

– definition of specification languages• succinct• easy to adopt• expressive

– creation of efficient monitors from specs– minimize impact on monitored system– integrate static and dynamic analysis– how to control application in case of violation/validation (fault

protection)• predictive analysis/learning: what can one conclude from good

runs• how to instrument code (languages for specifying relevant

events, reactions)

Page 61: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

overview of course

1. introduction2. the AspectJ language (AspectJ)3. using AspectJ for monitoring (AspectJ)4. propositional regular expressions5. parameterized regular expressions (JavaMOP)6. context free grammars (JavaMOP)7. temporal logic (JavaMOP)8. rule-based systems (RuleR)9. predictive analysis

Page 62: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

properties of Java library APIs

R1: There should be no two calls to next() without a call to hasNext() in between, on the same iterator.

Page 63: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

http://www.eclipse.org/aspectj

Page 64: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

public class Resource { void authenticate() {…} void access() {…}}

aspect MonitorAspect { boolean authenticated = false; before() : call(void Resource.authenticate()) { authenticated = true; }

before() : call(void Resource.access()) { if (!authenticated) error("access without authentication"); }}

application

aspect

monitoring with AspectJ

“an access should be preceded byan authentication”

Page 65: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

http://fsl.cs.uiuc.edu/index.php/JavaMOP

Page 66: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

http://fsl.cs.uiuc.edu/index.php/JavaMOP

Page 67: lecture1 - Runtime Verification · Title: lecture1.ppt Author: khavelun Created Date: 4/29/2008 7:28:19 AM

end