chasing bugs with the beepbeep event stream processor

261
Sylvain Hallé Université du Québec à Chicoutimi Canada C h a s i n g B u g s w i t h t h e B e e p B e e p E v e n t S t r e a m P r o c e s s o r TAROT 2016

Upload: sylvain-halle

Post on 26-Jan-2017

88 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain HalléUniversité du Québec à Chicoutimi

Canada

Chasing Bugswith the BeepBeep

Event Stream Processor

TAROT 2016

Page 2: Chasing Bugs with the BeepBeep Event Stream Processor

System

Page 3: Chasing Bugs with the BeepBeep Event Stream Processor

System

Page 4: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Page 5: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Page 6: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Trace

Page 7: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Trace

Events

Page 8: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Trace

Events

Page 9: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Trace

Events

Tracevalidation

Page 10: Chasing Bugs with the BeepBeep Event Stream Processor

System

Instrumentation

Page 11: Chasing Bugs with the BeepBeep Event Stream Processor

System

Runtime monitoringInstrumentation

Page 12: Chasing Bugs with the BeepBeep Event Stream Processor

System

Runtime monitoringInstrumentation

Page 13: Chasing Bugs with the BeepBeep Event Stream Processor

System

Runtime monitoring

Overhead

Instrumentation

Page 14: Chasing Bugs with the BeepBeep Event Stream Processor

Monitor

Property

Target system

Sensor

Internalstate

Event

VerdictFeedback(optional)

Page 15: Chasing Bugs with the BeepBeep Event Stream Processor

One trace at a time

Don't care aboutinteracting with the SUT

?

Internal state canbe queried

Properties partiallyspecify behaviour

Page 16: Chasing Bugs with the BeepBeep Event Stream Processor

One trace at a time

Don't care aboutinteracting with the SUT

?

Internal state canbe queried

Properties partiallyspecify behaviour

Page 17: Chasing Bugs with the BeepBeep Event Stream Processor

Possibility for the monitor to interact with the SUT(enforcement monitors)

Opportunity to expressmore complex properties

(ab)*Overhead is a

concern

Page 18: Chasing Bugs with the BeepBeep Event Stream Processor

FAST

RICH

Page 19: Chasing Bugs with the BeepBeep Event Stream Processor

Part One

Use cases for monitoring

Page 20: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

Cloud computingAjax web application

Page 21: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

JavaScript

NOINC

Page 22: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

Bee G

Beatles

Camel

Caravan

NOINC

Page 23: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

Bee G

Beatles

Camel

Caravan

<a onclick=>

"javascript: findBand(’ ’)"Beatles

NOINC

Page 24: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

findBand(’Beatles’)

NOINC

Page 25: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

findBand(’Beatles’)

NOINC

Page 26: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

findBand(’Beatles’)

artist beatles=

NOINC

Page 27: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

findBand(’Beatles’)

artist beatles=

NOINC

Page 28: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

document.innerHTML = findBand(’Beatles’)

artist beatles=

NOINC

Page 29: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application

Does not needto be a URL

Does not needto be HTML

<SearchResults>

</SearchResults>

The Beatles Rubber Soul ...

<Item>

</Item>

<Artist>

</Artist><Title>

</Title>

<Search>

</Search>

beatles

<Artist>

</Artist>

NOINC

Page 30: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingAjax web application<Search>

</Search>

beatles

<Artist>

</Artist> XMLThe eXtensible Markup

Language

?Nested collection ofelements

?Input/output data issemi-structured

.

.

<SearchResults>

</SearchResults>

The Beatles Rubber Soul ...

<Item>

</Item>

<Artist>

</Artist><Title>

</Title>

NOINC

Page 31: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

Cloud computingConceptually...

Page 32: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

NOINC

Page 33: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

NOINC

Page 34: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

NOINC

Page 35: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

NOINC

Page 36: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

NOINC

Page 37: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Cloud computingConceptually...

Web serviceWeb client

NOINC

Page 38: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Main issue

SHOW

Possible between messages sent and messages expected

mismatch

Not like traditional programming: all input-output is exchanged unverified!

Page 39: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Defining message formats

SHOW

?

Page 40: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

1.

2.

...

?

Defining message formats

NOINC

Page 41: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

1.

2.

...

<ItemSearch>

</ItemSearch> beatles<Artist> </object>

Defining message formats

NOINC

Page 42: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch> beatles<Artist> </object>

<ItemSearchResponse> <Items>

</Items></ItemSearchResponse>

Help!The Beatles

<Item>

</Item> ...

<Title> </no> <Artist> </Artist>

Defining message formats

NOINC

Page 43: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

<ItemSearch>

</ItemSearch> beatles<Artist> </object>

<ItemSearchResponse> <Items>

</Items></ItemSearchResponse>

Help!The Beatles

<Item>

</Item> ...

<Title> </no> <Artist> </Artist>

XML request

XML response

Defining message formats

Page 44: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch> beatles<Artist> </object>

ItemSearch[ [string]]Artist

<ItemSearchResponse> <Items>

</Items></ItemSearchResponse>

Help!The Beatles

<Item>

</Item> ...

<Title> </no> <Artist> </Artist>

XML request

XML response

Defining message formats

NOINC

Page 45: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch> beatles<Artist> </object>

ItemSearch[ [string]]Artist

ItemSearchResponse[ [ Item[ Title[string], Artist[string] ]{0,¥} ]]

Items<ItemSearchResponse> <Items>

</Items></ItemSearchResponse>

Help!The Beatles

<Item>

</Item> ...

<Title> </no> <Artist> </Artist>

XML request

XML response

Defining message formats

NOINC

Page 46: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

ItemSearch[ [string]]Artist

ItemSearchResponse[ [ Item[ Title[string], Artist[string] ]{0,¥} ]]

Items

?

!

Defining message formats

NOINC

Page 47: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

Defining message formats

WSDL: Web Service Description Language

ItemSearch[ [string]]Artist

CartCreate[ [int], [int], [ Item[ Title[string], Artist[string] ]{0,¥} ]]

ItemsSessionKeyItems

?

?

ItemSearchResponse[ [ Item[ Title[string], Artist[string], ]{0,¥} ]]

Items

CartCreateResponse[ [int], [int], [ Item[ Title[string], Artist[string] ]{0,¥} ]]

SessionKeyCartIdItems

!

!

. . .

Page 48: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

<ItemSearch>

</ItemSearch>

beatles 1234<Artist> </Artist><Bizbiz> </Bizbiz>

Defining message formats

Page 49: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch>

beatles 1234<Artist> </Artist><Bizbiz> </Bizbiz>

Defining message formats

ItemSearch[ [string]]Artist vs.?

NOINC

Page 50: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch>

beatles 1234<Artist> </Artist><Bizbiz> </Bizbiz>

Defining message formats

ItemSearch[ [string]]Artist vs.?

NOINC

Page 51: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<ItemSearch>

</ItemSearch>

beatles 1234<Artist> </Artist><Bizbiz> </Bizbiz>

Defining message formats

ItemSearch[ [string]]Artist vs.?

NOINC

Page 52: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

<CartCreateResponse> <SessionKey> </SessionKey> <CartId> </CartId> <Items>

</Items></ItemSearchResponse>

1234

abc

...

Defining message formats

Page 53: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<CartCreateResponse> <SessionKey> </SessionKey> <CartId> </CartId> <Items>

</Items></ItemSearchResponse>

1234

abc

...

Defining message formats

CartCreateResponse[ [int], [int], [ Item[ Title[string], Artist[string] ]{0,¥} ]]

SessionKeyCartIdItems

vs.

!

NOINC

Page 54: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<CartCreateResponse> <SessionKey> </SessionKey> <CartId> </CartId> <Items>

</Items></ItemSearchResponse>

1234

abc

...

Defining message formats

CartCreateResponse[ [int], [int], [ Item[ Title[string], Artist[string] ]{0,¥} ]]

SessionKeyCartIdItems

vs.

!

NOINC

Page 55: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

<CartCreateResponse> <SessionKey> </SessionKey> <CartId> </CartId> <Items>

</Items></ItemSearchResponse>

1234

abc

...

Defining message formats

CartCreateResponse[ [int], [int], [ Item[ Title[string], Artist[string] ]{0,¥} ]]

SessionKeyCartIdItems

vs.

!

NOINC

Page 56: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

What happened?

Page 57: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

?

What happened?

NOINC

Page 58: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

?

What happened?

NOINC

Page 59: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

1.

2.

...

What happened?

NOINC

Page 60: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

1.

2.

...

What happened?

NOINC

Page 61: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

2What happened?

NOINC

Page 62: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

c

What happened?

NOINC

Page 63: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

2

c

What happened?

NOINC

Page 64: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

What happened?

NOINC

Page 65: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

?2

c

2

c

Interface contracts

All messages comply with the WSDL but...

1.

2.

...

SHOW

Page 66: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

?2

c

2

c

Interface contracts

You cannot add the same itemtwice to the shopping cart

All messages comply with the WSDL but...

1.

2.

...

NOINC

Page 67: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

?2

c

2

c

Interface contracts

???

You cannot add the same itemtwice to the shopping cart

All messages comply with the WSDL but...

1.

2.

...

NOINC

Page 68: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Interface contracts

???

NOINC

Page 69: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

???

Interface contracts

NOINC

Page 70: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

The big question

SHOW

Prevent contract

violations

Page 71: Chasing Bugs with the BeepBeep Event Stream Processor
Page 72: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

Page 73: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...out.print("Lemming into Floater");...

Page 74: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...out.print("Lemming into Floater");...

Game startsLemming into Blocker...Lemming into Floater...

Page 75: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

Game startsLemming into Blocker...Lemming into Floater...

...logger.log("Lemming into Floater", Logging.LEVEL_DEBUG);...

Page 76: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater...

...logger.log("Lemming into Floater, id: " + lem._id, Logging.LEVEL_DEBUG);...

Page 77: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32...

...logger.log("Lemming into Floater, id: " + lem._id, Logging.LEVEL_DEBUG);...

Page 78: Chasing Bugs with the BeepBeep Event Stream Processor

x?y?

??

LOG

CODE

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32...

...logger.log("Lemming into Floater, id: " + lem._id, Logging.LEVEL_DEBUG);...

Page 79: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32...

...String msg = "Lemming into Floater ";msg += "id: " + lem._id + ", ";msg += "x: " + lem._x + ", ";msg += "y: " + lem._y;logger.log(msg, Logging.LEVEL_DEBUG);...

Page 80: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...String msg = "Lemming into Floater ";msg += "id: " + lem._id + ", ";msg += "x: " + lem._x + ", ";msg += "y: " + lem._y;logger.log(msg, Logging.LEVEL_DEBUG);...

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32, x: 320, y: 67...

Page 81: Chasing Bugs with the BeepBeep Event Stream Processor

y?

x? x?

Page 82: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...String msg = "Lemming into Floater ";msg += "id: " + lem._id + ", ";msg += "x: " + lem._x + ", ";msg += "y: " + lem._y;logger.log(msg, Logging.LEVEL_DEBUG);...

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32, x: 320, y: 67...

Page 83: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...String msg = "Lemming into Floater ";for (Lemming lm in lemmings) { msg += "id: " + lm._id + ", "; msg += "x: " + lm._x + ", "; msg += "y: " + lm._y + "; ";}logger.log(msg, Logging.LEVEL_DEBUG);...

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32, x: 320, y: 67...

Page 84: Chasing Bugs with the BeepBeep Event Stream Processor

LOG

CODE

...String msg = "Lemming into Floater ";for (Lemming lm in lemmings) { msg += "id: " + lm._id + ", "; msg += "x: " + lm._x + ", "; msg += "y: " + lm._y + "; ";}logger.log(msg, Logging.LEVEL_DEBUG);...

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[10:25:01] DEBG Lemming into Floater, id: 32, x: 320, y: 67 ; id: 31, x: 450, y: 43 ; id: 23, x: 229, y: 40 ; ......

Page 85: Chasing Bugs with the BeepBeep Event Stream Processor

Game code

XMLtemplate

T

Temporalproperty

φ

{

}

Gameloop

1

3

2

Monitor

P

Named pipe,TCP socket,

HTTP requestVerdict

XML event Buffer

Page 86: Chasing Bugs with the BeepBeep Event Stream Processor

06bb5c mov espj ebp | EBP=001bfbf4 | ESP=001bfbf406bb5d pop ebp | ESP=001bfbf4 [001bfbf4]=001bfc24 | EBP=001bfc24 ESP=001bfbf806bb5e push ecx | ECX=71f1a8b9 ESP=001bfbf8 | ESP=001bfbf4 [001bfbf4]=71f1a8b906bb5f ret | ESP=001bfbf4 [001bfbf4]=71f1a8b9 | ESP=001bfbf806bb60 ret | ESP=001bfbf8 [001bfbf8]=01391036 | ESP=001bfbfc06bb61 add espj 0x20 | ESP=001bfbfc | ESP=001bfc1c EFLAGS=06bb62 cmp [ebpn0x4]j 0x3e8 | [001bfc20]=000003e8 EBP=001bfc24 | EFLAGS=ZP06bb63 jnz 0x1391057 | EFLAGS=ZP |06bb64 push 0x1392144 | ESP=001bfc1c | ESP=001bfc18 [001bfc18]=01392144

Integer overflow detectionCall sequence profilingReturn address protectionPointer subterfuge detectionMalicious pattern detectionEtc.

Page 87: Chasing Bugs with the BeepBeep Event Stream Processor

Part Two

Specifying properties with logic

Page 88: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

SHOW

Interface contracts

All possible sequences of all possibles messages with all possible values

Page 89: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

NOINC

Interface contracts

Constraintson individualmessages

Page 90: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

NOINC

Interface contracts

Constraintson sequencesConstraints

on individualmessages

Page 91: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

NOINC

Interface contracts

Constraintson sequences

Data-awaresequential constraints

Constraintson individualmessages

Page 92: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

NOINC

Interface contracts

Interface contract =valid (error-free) interactions

Constraintson sequences

Data-awaresequential constraints

Constraintson individualmessages

Page 93: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on individual messages

Examples:

Three types of constraints (I)

SHOWSHOW

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Page 94: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on individual messages

Examples:

Three types of constraints (I)

SHOWSHOW

1. The element must be an integer between 1 and 20.Page "/M

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Page 95: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Three types of constraints (I)

SHOWSHOW

1. The element must be an integer between 1 and 20.

2. The element is mandatory only if is present,otherwise it is forbidden.

Page

Page Results

"/M

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Constraints on individual messages

Examples:

Page 96: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

Page 97: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. The request cannot be resent if its response is

successful..

Login "/

"/

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Page 98: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. The request cannot be resent if its response is

successful..

4. must follow a successful LoginResponse.

Login

CartCreate

"/

"/

"/

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Page 99: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

5. There can be at most one active cart ID per session key."/

Three types of constraints (III)

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

Page 100: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

6. You cannot add the same item twice to the shopping cart."/

Three types of constraints (III)

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

X

Page 101: Chasing Bugs with the BeepBeep Event Stream Processor

Mario cannot reach the end of a level without jumpingat least once

Page 102: Chasing Bugs with the BeepBeep Event Stream Processor

Mario can never jump higher than 20 pixels

20

Page 103: Chasing Bugs with the BeepBeep Event Stream Processor

X

If Mario crouches, he cannot jump right after

Page 104: Chasing Bugs with the BeepBeep Event Stream Processor

X

Mario cannot collide with an enemy while he isholding a Koopa shell

Page 105: Chasing Bugs with the BeepBeep Event Stream Processor

% grep "Lemming into Floater" log

Page 106: Chasing Bugs with the BeepBeep Event Stream Processor

% grep -P "Lemming into Floater, .*? x: (\d+?), y: \1" log

Page 107: Chasing Bugs with the BeepBeep Event Stream Processor

% grep -P "Lemming into Floater, .*? x: (\d+?), y: \1" log | sed 's/^.*id: ([0-9]+).*$/\1/'

Page 108: Chasing Bugs with the BeepBeep Event Stream Processor

% grep -Pzo "(?s)Lemming into Basher, id: (\d+).*Lemming into \ Floater, id: \1 [^;]*?x: (\d+?), y: \2" log | sed -r 'N;s/^.*?id: ([0-9]+).x: ([0-9]+), y: ([0-9]+)$ \ /\1, \2, \3/'

Page 109: Chasing Bugs with the BeepBeep Event Stream Processor

#!/usr/bin/pythonimport rewith open('log', 'r') as logfile: log = logfile.read()bm = re.findall(r'Basher, id: (\d+)', log)fm = re.findall(r'Floater, id: (\d+), x: (\d+), y: (\d+)', log) for lem in fm: if lem[0] in bm: print lem[0] + ', ' + lem[1] + ', ' + lem[2]

Page 110: Chasing Bugs with the BeepBeep Event Stream Processor

#!/usr/bin/pythonimport re, sysbashers = {}for line in sys.stdin: res = re.match(r'^Lemming into (.*?), id: (\d+), x: (\d+),\ y: (\d+)', line) if res: if res.group(1) == 'Basher': bashers[res.group(2)] = 1 else: if res.group(1) == 'Floater' and res.group(2) in bashers: print res.group(2) + ', ' + res.group(3) + ', '\ + res.group(4)

Page 111: Chasing Bugs with the BeepBeep Event Stream Processor

* A regexp (matches the unstructured event text, or the "msg" field for CEE/Lumberjack structured events) ceelog '/DHCP/'* A field comparison (matches a CEE/Lumberjack field) ceelog 'uid == "0"' ceelog 'uid != "0"' ceelog 'trusted!uid == "0"' ceelog 'username ~ /^guest-/' ceelog 'username !~ /^guest-/'* A combination of the above ceelog 'trusted!uid == "0" && username ~ /^guest-/'

Page 112: Chasing Bugs with the BeepBeep Event Stream Processor

* A regexp (matches the unstructured event text, or the "msg" field for CEE/Lumberjack structured events) ceelog '/DHCP/'* A field comparison (matches a CEE/Lumberjack field) ceelog 'uid == "0"' ceelog 'uid != "0"' ceelog 'trusted!uid == "0"' ceelog 'username ~ /^guest-/' ceelog 'username !~ /^guest-/'* A combination of the above ceelog 'trusted!uid == "0" && username ~ /^guest-/'

grep{

Page 113: Chasing Bugs with the BeepBeep Event Stream Processor
Page 114: Chasing Bugs with the BeepBeep Event Stream Processor
Page 115: Chasing Bugs with the BeepBeep Event Stream Processor

grep

Page 116: Chasing Bugs with the BeepBeep Event Stream Processor

RSYSLOG

Page 117: Chasing Bugs with the BeepBeep Event Stream Processor

RSYSLOG

grep

Page 118: Chasing Bugs with the BeepBeep Event Stream Processor

print

Page 119: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Expressing data constraints

Simple XPathFetches portions of an XML document according to aquery path = sequence of tags

: set of messages: set of XML query paths: set of atomic values

: ́ ® 2

Examples:(‘‘/a/b/c’’, m) = {1,2,4}(‘‘/a/b/d’’, m) = Æ

M

M

Q

Q

V

Vp

pp

SHOW

m

{

<a> <b> <c>1</c> <c>2</c> </b> <d> <c>9</c> </d> <b> <c>3</c> </b></a>

Page 120: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Expressing data constraints

XPath termExpresses properties over values fetched by XPath expressions

For some message Î , path Î ,

" x : j(x) Û j(v) for every Î ( , )

$ x : j(x) Û j(v) for some Î ( , )

Examples:" x : x < 5/a/b/c

$ x :/a/b

$ x : " y : y £ x/a/b/c /a/b/c

m M

mq

mq

q Q

q

q

v

v

p

p

2

SHOW

<a> <b> <c>1</c> <c>2</c> </b> <d> <c>9</c> </d> <b> <c>3</c> </b></a>

m

{

Page 121: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Expressing data constraints

2

SHOW

1. The element must be an integer between 1 and 20.

2. The element is mandatory only if is present,otherwise it is forbidden.

Page

Page Results

"/M

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Page 122: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Expressing data constraints

2

SHOW

1. " x : x > 0 Ù x < 21/Message/Page

2. The element is mandatory only if is present,otherwise it is forbidden.

Page Results

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Page 123: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Expressing data constraints

2

SHOW

1. " x : x > 0 Ù x < 21/Message/Page

2. $ x : Û $ y : /Message/Page /Message/Results

<Message> <Action>ItemSearch</Action> <Results>5</Results> <Keyword>beatles</Keyword> <Page>1</Page></Message>

Page 124: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Linear Temporal Logic

Alphabet (A)Set of possible messages

Trace (A*)Sequence of messages

Page 125: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

LTL formula = assertion on the of states in a tracesequence

a "always a" a "a in the next" a "eventually a"

a b "a until b"

GXF

W

Linear Temporal Logic

G (a ® b)X (d cÚ e) WØFALSE TRUE

. . .A A EC CDB B

Page 126: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Well-known results:

1. For every LTL formula j, there exists a Büchi automaton Asuch that for every (infinite) trace s:

i.e. LTL describes languages

2. The alphabet symbols can be generalized to finite sets ofBoolean propositions

w-regular

Þ Let’s use XPath terms as our Boolean propositions

Linear Temporal Logic

j

s |= j Û s Î L(A )j

Page 127: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. The request cannot be resent if its response is

successful..

4. must follow a successful LoginResponse.

Login

CartCreate

"/

"/

"/

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Page 128: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. (" a : a = LoginResponse ®/Message/Action

( " a’ : a’ ¹ Login))/Message/Action.

4. must follow a successful LoginResponse.

G

X G

CartCreate "/

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Page 129: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. (" a : a = LoginResponse ®/Message/Action

( " a’ : a’ ¹ Login))/Message/Action.

4. must follow a successful LoginResponse.

G

X G

CartCreate "/

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Xpath terms

Page 130: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Constraints on message sequences

Examples:

2

SHOW

3. (" a : a = LoginResponse ®/Message/Action

( " a’ : a’ ¹ Login))/Message/Action

4. (" a : a ¹ CartCreate)/Message/Action

(" a’ : a’ = LoginResponse)/Message/Action

G

X G

W

.

<Message> <Action> Login </Action> ...</Message>

<Message> <Action> LoginResponse </Action> ...</Message>

<Message> <Action> CartCreate </Action> ...</Message>

Three types of constraints (II)

X

Xpath terms

Page 131: Chasing Bugs with the BeepBeep Event Stream Processor

Mario cannot reach the end of a level without jumpingat least once

F action = jump

Page 132: Chasing Bugs with the BeepBeep Event Stream Processor

Mario can never jump higher than 20 pixels

G (action = jump → height < 20)

20

Page 133: Chasing Bugs with the BeepBeep Event Stream Processor

X

If Mario crouches, he cannot jump right after

G (action = crouch → X action ≠ jump)

Page 134: Chasing Bugs with the BeepBeep Event Stream Processor

X

Mario cannot collide with an enemy while he isholding a Koopa shell

G (action = haveShell → X action ≠ collision)

G (action = haveShell →(action ≠ collision U action = dropShell))

or better

Page 135: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 136: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

j

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 137: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s =

j

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 138: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = a

j

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 139: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = a

ja

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 140: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = ab

ja

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 141: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = ab

ja b

b

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 142: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = aba

ja b

b

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 143: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

s = aba

ja

a

a

b

b

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is readon-the-fly

Page 144: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Gerth, Peled, Vardi, Wolper (PSTV 1995): construction of a Büchi automaton from a given LTL formula j

Benefit:

" ": automaton states are built as thetrace is read

Dead end: formula is false

on-the-fly

Runtime monitoring

s = aba

ja

a

a

b

b

Page 145: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Runtime monitoring

Algorithm overview:

1. An LTL formula is decomposed into nodes of the form

sub-formulas thatmust be true now

sub-formulas that mustbe true in the next state

Page 146: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Algorithm overview:

1. An LTL formula is decomposed into nodes of the form

Example:

sub-formulas thatmust be true now

sub-formulas that mustbe true in the next state

Runtime monitoring

Page 147: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

2. Negations pushed inside (classical identities + dual of U = V)

3. At the leaves, G contains atoms + negations of atoms:we evaluate them

Verdict:

! All leaves contain : formula is false! A leaf is : formula is true! Otherwise:

4. Next event: D copied into G and we continue

FALSEempty

Runtime monitoring

Page 148: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

Runtime monitoring

Page 149: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

G (a ® b)X ?

Runtime monitoring

Page 150: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

G (a ® b)X ?

a ® bX G (a ® b)X?

Runtime monitoring

Page 151: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

G (a ® b)X ?

Øa G (a ® b)X?

a ® bX G (a ® b)X?

Runtime monitoring

Page 152: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

G (a ® b)X ?

a, X b G (a ® b)X?Øa G (a ® b)X?

a ® bX G (a ® b)X?

Runtime monitoring

Page 153: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

G (a ® b)X ?

a, X b G (a ® b)X?

a G (a ® b), bX?

Øa G (a ® b)X?

a ® bX G (a ® b)X?

Runtime monitoring

Page 154: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

a G (a ® b), bX?

Øa G (a ® b)X?

Runtime monitoring

Page 155: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a G (a ® b), bX?

Øa G (a ® b)X?

Runtime monitoring

Page 156: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a G (a ® b), bX?

Øa G (a ® b)X?

Runtime monitoring

Page 157: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a G (a ® b), bX?

Runtime monitoring

Page 158: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

G (a ® b), bX?

Runtime monitoring

Page 159: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

?G (a ® b), bX

G (a ® b), bX?

Runtime monitoring

Page 160: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a, X b, b G (a ® b)X?

a, b G (a ® b), bX?

Øa, b G (a ® b)X?

a ® b, bX G (a ® b)X?

?G (a ® b), bX

Runtime monitoring

Page 161: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a, b G (a ® b), bX?

Øa, b G (a ® b)X?

Runtime monitoring

Page 162: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

a, b G (a ® b), bX?

Øa, b G (a ® b)X?

Runtime monitoring

Page 163: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = a

Øa, b G (a ® b)X?

Runtime monitoring

Page 164: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = ac

Øa, b G (a ® b)X?

Runtime monitoring

Page 165: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = ac

Øa, b G (a ® b)X?

Runtime monitoring

Page 166: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Example: G (a ® b)X

s = ac

No way to extend the trace:formula is false

Runtime monitoring

Page 167: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

The verification can be separated in two steps

Three types of constraints (II)

G

X

Ú

"$

$ G

F

®

1. Temporal stepDetermine termporal relationships to current message

2. Data stepEvaluate relevant XPath terms on message

Page 168: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

5. There can be at most one active cart ID per session key."/

Three types of constraints (III)

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

Page 169: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

5. (" k : " c : /Message/SessionKey /Message/CartId

(" k’ : " c’ : /Message/SessionKey /Message/CartId

k = k’ ® c = c’))

G

G

Three types of constraints (III)

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

Page 170: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

5. (" k : " c : /Message/SessionKey /Message/CartId

(" k’ : " c’ : /Message/SessionKey /Message/CartId

k = k’ ® c = c’))

G

G

Three types of constraints (III)

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

<Message> <SessionKey>123</SessionKey> <CartId>789</CartId> ...</Message>

Page 171: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Three types of constraints (III)

2

SHOW

5. (" k : " c : /Message/SessionKey /Message/CartId

(" k’ : " c’ : /Message/SessionKey /Message/CartId

k = k’ ® c = c’))

G

G

Page 172: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

·XPath terms and temporal operators aremixed

.

·Not just ‘‘LTL with syntactical sugar’’.

·Not just a pathological case

5. (" k : " c : /Message/SessionKey /Message/CartId

(" k’ : " c’ : /Message/SessionKey /Message/CartId

k = k’ ® c = c’))

G

G

Three types of constraints (III)

2

SHOW

G

G

"

"

k

Page 173: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

6. You cannot add the same item twice to the shopping cart."/

Three types of constraints (III)

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

X

Page 174: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Data-aware sequential constraints

Examples:

2

SHOW

6. (" a : a = CartAdd ®/Message/Action

" i : (" a’ :/Message/ItemId /Message/Action

a’ = CartAdd ® " i’ : i ¹ i’ ))/Message/ItemId

G

X G

Three types of constraints (III)

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

<Message> <Action>CartAdd</Action> <Items> <Item> <ItemId>567</ItemId> ...

X

Page 175: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Quantification must be relative to the values in the current message, and not the whole set V of possible values!

Example: ‘‘In every message, the a parameter must equal the b parameter’’. Suppose V = {1,2}, and classical first-order quantification.

Runtime monitoring

" x : " y : x = ya b

(" y : 1 = y) Ù (" y : 1 = y)b b

( 1 = 1) Ù ( 1 = 2) Ù ( 1 = 1) Ù ( 1 = 2)

Contradiction

G

G G

G G G G

Page 176: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

LTL-FO+

current

(Hallé & Villemaire, EDOC 2008)Extension of LTL with (limited) first-order quantification on message elements

·Boolean and LTL operators keep their original meaning·An XPath term is always meant to refer to the

message in the trace

Runtime monitoring

Page 177: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Adaptation of the runtime monitoring algorithm to handle LTL-FO+:

1. Atoms become equality tests

2. Decomposition rules for quantifiers

(and vice versa)

Runtime monitoring

Page 178: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Enforcing interface contracts at runtime

NOINC

XMLHttpRequest

·JavaScript object·Provided by the browser·All communications to monitor

already centralized: ‘‘no’’instrumentation

Page 179: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Enforcing interface contracts at runtime

NOINC

XMLHttpRequestBB

Page 180: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Enforcing interface contracts at runtime

NOINC

XMLHttpRequestBB

XMLHttpRequestLTL-FO+algorithm

·Wrapper around original·Provides same methods·Checks messages before

relaying them

Page 181: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

myapplication.html

<html><head><title></title><script type=" " href=" "/>

</head><body>

</body></html>

My Application

...

text/javascriptmyapplication.js

?

�Include BeepBeep

Copy BeepBeep in the application's directoryhttp://beepbeep.sourceforge.net

Page 182: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

myapplication.html

<html><head><title></title><script type=" " href=" "/>

</head><body>

</body></html>

My Application

...

text/javascriptmyapplication.js

<script type="text/javascript" href="beepbeep.js"/>

?

�Include BeepBeep

Copy BeepBeep in the application's directoryhttp://beepbeep.sourceforge.net

Page 183: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

myapplication.html myapplication.js

<html><head><title></title><script type=" " href=" "/>

</head><body>

</body></html>

My Application

...

text/javascriptmyapplication.js

<script type="text/javascript" href="beepbeep.js"/>

// Initializations

= ();

(){

( );}

...

req XMLHttpRequest

...

abc

... req. some_message

new

function

send

?

�Include BeepBeep

Copy BeepBeep in the application's directoryhttp://beepbeep.sourceforge.net

Page 184: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

beepstore.html beepstore.js

<html><head><title></title><script type=" " href=" "/>

</head><body>

</body></html>

My Application

...

text/javascriptmyapplication.js

<script type="text/javascript" href="beepbeep.js"/>

// Initializations

= ();

(){

( );}

...

req

...

abc

... req. some_message

new

function

send

XMLHttpRequestBB

Include BeepBeep

?

Copy BeepBeep in the application's directoryhttp://beepbeep.sourceforge.net

Page 185: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Create a with LTL-FO+ formulascontract file ?

Add BeepBeep to an application

# -------------------------------------------------------# BeepBeep contract file for the Beep Store# -------------------------------------------------------

% The element Page must be an integer between 1 and 20.

% The element Page is mandatory only if Results is present, otherwise it is forbidden.

% The Login request cannot be resent if its response is successful.

; ( p /Message/Page (((p) > ({0})) ((p) < ({21}))))

; ( a /Message/Action (((a) = ({ItemSearch})) ( (( r /Message/Results ({TRUE}))

( p /Message/Page ({TRUE}))) (( p /Message/Page ({TRUE})) ( r /Message/Results ({TRUE}))))))

; ( a /Message/Action (((a) ({LoginResponse})) ( ( ( b /Message/Action ( ((b) ({Login}))))))))

G

G

GX G

[ ]

[ ]< >< >

< >< >

[ ][ ]

&

->->

&->

= ->! =

Caption: usedwhen violationsare discovered

Plain-textLTL-FO+(automaticallyparsed)

}

Page 186: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

When loading the application, BeepBeep starts as a smallJava applet inside the page

TheBeepStore

GO

Sign in or register

What is this?

Login

Ask for account

Contact us

Fault parameters

Search: Your Cart

Search results for ‘Beatles’

Rubber SoulThe Beatles

Yellow SubmarineThe Beatles

?/?/?/?/?/?:0:0

Page 187: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

Add BeepBeep to an application

When loading the application, BeepBeep starts as a smallJava applet inside the page

TheBeepStore

GO

Sign in or register

What is this?

Login

Ask for account

Contact us

Fault parameters

Search: Your Cart

Search results for ‘Beatles’

Rubber SoulThe Beatles

Yellow SubmarineThe Beatles

?/?/?/?/?/?:0:0

Page 188: Chasing Bugs with the BeepBeep Event Stream Processor

Sylvain Hallé

BeepBeep’s visible interface

?/?/?/?/?/?:0:0

Current state of monitorfor each property

Number ofmessagesprocessed

Cumulativeprocessingtime (in ms)

T: last message made it truet: is trueF: last message made it falsef: is false?: not yet true/false

Page 189: Chasing Bugs with the BeepBeep Event Stream Processor

Chocolate Doom74 KLOC

Angry Bots26 KLOC

Pacman Canvas1 KLOC

Bos Wars113 KLOC

Infinite Mario Bros.6 KLOC

Pingus40 KLOC

Page 190: Chasing Bugs with the BeepBeep Event Stream Processor
Page 191: Chasing Bugs with the BeepBeep Event Stream Processor

We still have to write theproperties, so what's the point?*

We're too busy to learnanother toolA*

Using this requires a higher level ofeducation. We'll have to increase wagesA*

*Really happened

We can already do all thisA*

(The Angry Practicioner)

Page 192: Chasing Bugs with the BeepBeep Event Stream Processor

OF COURSE.

This is a finitely computable problem.

It can be computed in finite time by aTuring machine.

There exists a C/Python/Assembly/Haskell/JavaScript/Scala/Go/BrainFuck//Whatever

program that does that. We just need towrite it down.

So what's the big news???

Page 193: Chasing Bugs with the BeepBeep Event Stream Processor

Data

30,000LINES OF

GLUE CODE

UntestedYou wrote thisHardly reusable

Result

HOW.

Page 194: Chasing Bugs with the BeepBeep Event Stream Processor

DataComponentizedReusableWorth investing time testing

Result

HOW.

Engine

1,000LINES OF

DSL

Page 195: Chasing Bugs with the BeepBeep Event Stream Processor

Alan Perlis(1922-1990)

Beware of of the Turing tar-pit in which everything is possible but nothing of interest is easy. ,,

,,

Page 196: Chasing Bugs with the BeepBeep Event Stream Processor

G (∃ retAddrVal ∈ ./return-address : ((./instruction = call) ∧ (¬ ((F( ((./instruction = mov)

∧ (./output/type = general-register)) →(∃ regA ∈ ./output/name : (F (( ((./instruction = mov)∧ (./output/type = general-register))∧ (./input/type = litteral) ) →

(∃ regB ∈ ./output/name :( ∃ constAddr ∈ ./input/value :(F (((./instruction = cmp ) ∧

(./output/type = regA)) →(∃ loc ∈ ./location : (F((

((./instruction = mov ) ∧(./output/type = general-register)) ∧(./output/name = regA ) ) ∧((./input/name = regB ) ∧ (./input/type = ptr)))))) ))))) )))

U ((./instruction = return)∧ (./fonction-returned = retAddrVal)) )) ))

Page 197: Chasing Bugs with the BeepBeep Event Stream Processor

Part Three

From RV to CEP

Page 198: Chasing Bugs with the BeepBeep Event Stream Processor

CEP

omplex

vent

rocessing

Page 199: Chasing Bugs with the BeepBeep Event Stream Processor

EventsEvents

An event is an element e taken from someset E, called the event type

Booleans

B

Numbers

R

234

π

Strings

S

abc

Functions

X Y→

Sets

X2

Primitivetypes

Compositetypes

Page 200: Chasing Bugs with the BeepBeep Event Stream Processor

A sample logA sample log

A file (or stream) of events

[10:24:31] INFO Game starts[10:24:33] WARN Lemming into Blocker...[[10:25:01] DEBG Lemming into Floater, id: 32, x: 320, y: 67 ; id: 31, x: 450, y: 43 ; id: 23, x: 229, y: 40 ; ... ...

Each event has one or more data elements

Actual (physical) format not relevantfor us

Page 201: Chasing Bugs with the BeepBeep Event Stream Processor

Searching the logSearching the log

Select AVG(closingPrice)From ClosingStockPricesWhere stockSymbol = `MSFT'for (t = ST; t < ST+50, t+= 5) { WindowIs(ClosingStockPrices, t - 4, t);}

Page 202: Chasing Bugs with the BeepBeep Event Stream Processor

ProblemsProblems

Formal languages (e.g. logic, automata)focus on event ordering; not so good atperforming computations over events

Complex Event Processing often reducesto a thin layer over custom proceduralcode

Goal: provide a formal andnon-procedural framework forthe processing of event streams

Page 203: Chasing Bugs with the BeepBeep Event Stream Processor

TracesTraces

An event trace (or event stream) is a potentiallyinfinite sequence of events of a given type:

2 0 6 34 9 . . .

Traces are symbolically denoted by:

e = e0 e1 e2 e3 ...

The set of all traces of type T is denoted as:

T*

Page 204: Chasing Bugs with the BeepBeep Event Stream Processor

ProcessorsProcessors

A processor is a function that takes 0 or moreevent traces as input, and returns 0 or 1event trace as output

1 : 1 processor

2 : 1 processor

. . . . . .

Page 205: Chasing Bugs with the BeepBeep Event Stream Processor

A high-level event trace can be produced bycomposing ("piping") together one or moreprocessors from lower-level traces

CompositionComposition

Page 206: Chasing Bugs with the BeepBeep Event Stream Processor

Processor algebraProcessor algebraGoal: come up with a "toolbox" of basicprocessors sufficient to perform variouscomputations over traces

??

Page 207: Chasing Bugs with the BeepBeep Event Stream Processor

A few useful functionsA few useful functions

Identity function: returns an event if given one,or t if passed the empty event ε

ιt(x) = { t if x = εx otherwise

+ (x) = {x}Wrap function

-({x}) = xPeel function

Path function: returns subtree at endof path π

Page 208: Chasing Bugs with the BeepBeep Event Stream Processor

SemanticsSemanticsProcessors can be defined formally bydescribing how their output trace is createdfrom their input trace(s)

e0, ..., en : φ(x0 , ..., xn)

Input trace(s)

Symbolic variables:xi refers to the i-th trace

on the left

Page 209: Chasing Bugs with the BeepBeep Event Stream Processor

Constants as processorsConstants as processors

Any element t of type T can be lifted as a0 : 1 processor producing the infinite tracet t t t ...

t . . .t t

The constantprocessor t e : t = t t t ...

Page 210: Chasing Bugs with the BeepBeep Event Stream Processor

Input/outputInput/output

0 : 1 processors can be used to produce anevent trace out of an external source (i.e.standard input, a file, etc.)

Ditto for 1 : 0 processors

a . . .b

a . . .b

Page 211: Chasing Bugs with the BeepBeep Event Stream Processor

MutatorMutator

Returns t, but only as many times as the number of events received so far

i.e. "mutates" input events into t

tte

Page 212: Chasing Bugs with the BeepBeep Event Stream Processor

Functions as processorsFunctions as processors

Any n-ary function f defined on individual events can be lifted to an n:1 processor ontraces, by applying it successively to n-uples

2 0 6. . .

3 8 1

+ 7 8 5

. . .

. . .

Page 213: Chasing Bugs with the BeepBeep Event Stream Processor

Functions as processorsFunctions as processors

Any n-ary function f defined on individual events can be lifted to an n:1 processor ontraces, by applying it successively to n-uples

e0, e1 : x0+x1

e00+ e10

e01+ e11

, e02+ e12

, , . . .

=

Page 214: Chasing Bugs with the BeepBeep Event Stream Processor

FreezeFreeze

Returns the first event received, upon everyevent received

abb. . . a a a . . .

e : x = e0 e0 e0 ...

Page 215: Chasing Bugs with the BeepBeep Event Stream Processor

DelayDelay

Returns every the input trace, starting from itsn-th event

abc. . . b . . .

e : x = en en+1 en+2 ...

2

n

e : xn=

c

Page 216: Chasing Bugs with the BeepBeep Event Stream Processor

DecimateDecimate

Returns every n-th event of the input trace

abc. . . a . . .

e : x = e0 en e2n ...

2

n

Ψ

e : x= nie : xnΨ

i

Page 217: Chasing Bugs with the BeepBeep Event Stream Processor

COMPLEX PROCESSORS

Page 218: Chasing Bugs with the BeepBeep Event Stream Processor

WindowWindow

Simulates the application of a "slidingwindow" to a trace

Takes as arguments: another processor φand a window width n

Returns the result of φ after processingevents 0 to n-1...

Then the result of (a new instance of) φthat processes events 1 to n...

...an so on

Υ φn

Page 219: Chasing Bugs with the BeepBeep Event Stream Processor

Example: execution of the processoron the trace

WindowWindow

2 1 5 0Υ ++2

Υ2

2 12 1 2 12 3

2 11 5 2 11 6

2 15 0 2 15 5

2 1 5 0 3 6 5

Page 220: Chasing Bugs with the BeepBeep Event Stream Processor

WindowWindow

The window processor can take anyprocessor as an argument...

...i.e. the sliding window can be applied toanything.

Formally:

e : φ e : φ= n-1iΥn i

Page 221: Chasing Bugs with the BeepBeep Event Stream Processor

FilterFilter

Discards events from an input trace basedon a selection criterion

Takes as argument another processor φ

Evaluates φ on the trace that starts at event0; returns that event if the first eventreturned by φ is T

Same process on the trace that starts atevent 1...

...an so on

Φ φ

Page 222: Chasing Bugs with the BeepBeep Event Stream Processor

Example: execution of the processoron the trace

FilterFilter

2 1 5 0Φ∈2IN

Φ2 1 5 0 2 0

∈2IN

∈2IN2 1 5 0

Page 223: Chasing Bugs with the BeepBeep Event Stream Processor

FilterFilter

The filter can take any processor as anargument...

...including a processor that requires multipleinput events before outputting something

Formally:

e : φ e : φ=Φ 1 ΦΦ(e, φ) ,

Φ(e, φ) = { e0 if

no event otherwise

e : φ = T0

Page 224: Chasing Bugs with the BeepBeep Event Stream Processor

SpawnSpawn

Cumulative combination of a processor'soutput for every suffix of a trace

Creates one new instance of processorφ upon every new input event

Feeds each input event to all existinginstances of φ

Combines the value returned by eachinstance using function f

...and outputs it

Σ φf

Page 225: Chasing Bugs with the BeepBeep Event Stream Processor

Example: execution of the processoron the trace

SpaweSpawn

2 1 5 0Σ+

Σ+2 1 5 0 2 3 8

x

x

x

8

2 1 5 0 2 1 5 0

x1 5 0 1 5 0

x5 0 5 0

++

+

Page 226: Chasing Bugs with the BeepBeep Event Stream Processor

SpawnSpawn

Formally:

e :

e :

=1

Σ φf

e : φ 0 , f ( Σ φfe : φ 0 , e : φ 0 ,e : φ 0 , )Turns out to be a powerful device; dependingon φ and f, can provide many usefulprocessors...

Page 227: Chasing Bugs with the BeepBeep Event Stream Processor

SpawnSpawn

Count events Σ 1+

Cumulative sum Σ+

Set of all events Σ∪ +

= #= ++=∪

Page 228: Chasing Bugs with the BeepBeep Event Stream Processor

These processors can be freely composed

Compute the statistical moment of order n

CompositionComposition

n

Σ+

Σ+1

÷

Page 229: Chasing Bugs with the BeepBeep Event Stream Processor

These processors can be freely composed

Compute the statistical moment of order n

CompositionComposition

n

Σ+

Σ+1

÷

= #

Page 230: Chasing Bugs with the BeepBeep Event Stream Processor

These processors can be freely composed

Return sum of two successive events,only if it is greater than 5

CompositionComposition

++

Υ2Φ

> 5

Page 231: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Page 232: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Count pairs of successive events that aremore than one standard deviation fromthe mean

E(X)

-

Page 233: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Count pairs of successive events that aremore than one standard deviation fromthe mean

σ

E(X)

-

÷

Page 234: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Count pairs of successive events that aremore than one standard deviation fromthe mean

σ

E(X)

-

÷ Φ

> 1

Page 235: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Count pairs of successive events that aremore than one standard deviation fromthe mean

σ

E(X)

-

÷

X

Φ

> 1

Φ∧

Page 236: Chasing Bugs with the BeepBeep Event Stream Processor

All together nowAll together now

Count pairs of successive events that aremore than one standard deviation fromthe mean

E(X)

-

÷

X

Φ

> 1

Φ∧

Page 237: Chasing Bugs with the BeepBeep Event Stream Processor

AdvantagesAdvantages

No imperative constructs

No restrictions on what can be piped towhat (modulo type compatibility)

Streaming operation: outputs producedas inputs are being consumed

Implicit handling of buffering, duplication,etc.

Page 238: Chasing Bugs with the BeepBeep Event Stream Processor

A declarative event streamquery engine

Page 239: Chasing Bugs with the BeepBeep Event Stream Processor

abc. . . a . . .n cΨ

abc. . . b . . .n c

EVERY nTH OF (T)

TRIM n FROM (T)

Page 240: Chasing Bugs with the BeepBeep Event Stream Processor

WHERE2 1 5 0 2 0

C

C2 1 5 0

(T) WHERE condition

Page 241: Chasing Bugs with the BeepBeep Event Stream Processor

COMBINE (T) WITH f

Σ+2 1 5 0 2 3 8

f

f

8

2 1 5 0 2 1 5 0

f1 5 0 1 5 0

f5 0 5 0

++

+

Page 242: Chasing Bugs with the BeepBeep Event Stream Processor

a . . .b

a . . .b

FILE "filename"

SAVE (T) TO "filename"

Page 243: Chasing Bugs with the BeepBeep Event Stream Processor

WHEN @P IS A PROCESSOR:

THE SUM OF ( @P )

IS THE PROCESSOR

COMBINE (@P) WITH SUM.

Arbitrarysymbol

Grammar rule this symbolmust parse against

New grammar case

Grammar rule the caseis added toExpression the new casestands for

Page 244: Chasing Bugs with the BeepBeep Event Stream Processor

WHEN @P IS A PROCESSOR: THE COUNT OF ( @P ) IS THE PROCESSOR COMBINE (SELECT 1 FROM (@P)) WITH SUM.

WHEN @P IS A PROCESSOR: THE SUM OF ( @P ) IS THE PROCESSOR COMBINE (@P) WITH SUM.

WHEN @P IS A PROCESSOR: THE AVERAGE OF ( @P ) IS THE PROCESSOR SELECT (T.*) ÷ (U.*) FROM ( THE SUM OF (@P) AS T, THE COUNT OF (@P) AS U).

Page 245: Chasing Bugs with the BeepBeep Event Stream Processor

On every fifth trading day starting today,calculate the average closing price of MSFT for the five most recent trading days, and keepthe query standing for fifty trading days.

timestamp stockSymbol closingPrice

0 APPL 1039.30 MSFT 950.00 GOGL 433.31 MSFT 951.21 APPL 1038.3... ... ...

Page 246: Chasing Bugs with the BeepBeep Event Stream Processor

On every fifth trading day starting today,calculate the average closing price of MSFT for the five most recent trading days, and keepthe query standing for fifty trading days.

String line = br.readLine().trim();if (!line.isEmpty()) { String[] parts = line.split(","); if (parts[0].compareTo("ABC") != 0) { value_index++; sum += Double.parseDouble(parts[1]); if (value_index == 5) { double average = sum / 5; value_index = 0; sum = 0; return average;}}}

Page 247: Chasing Bugs with the BeepBeep Event Stream Processor

On every fifth trading day starting today,calculate the average closing price of MSFT for the five most recent trading days, and keepthe query standing for fifty trading days.

SELECT afd FROM ( SELECT S1.timestamp AS ts, AVG(S2.closingPrice) AS afd FROM (SELECT * FROM stocks WHERE stockSymbol = "MSFT") AS S1, (SELECT * FROM stocks WHERE stockSymbol = "MSFT") AS S2 WHERE (S2.timestamp - S1.timestamp) < 5 GROUP BY S1.timestamp) AS S3WHERE MOD(ts, 5) = 0;

Page 248: Chasing Bugs with the BeepBeep Event Stream Processor

On every fifth trading day starting today,calculate the average closing price of MSFT for the five most recent trading days, and keepthe query standing for fifty trading days.

EVERY 5TH OF ( APPLY (THE AVERAGE OF (*)) TO ( SELECT closingPrice FROM stocks) WHERE (stockSymbol) = ("MSFT")))) ON A WINDOW OF 5).

Page 249: Chasing Bugs with the BeepBeep Event Stream Processor

Calculate how many times the closing priceof MSFT is greater than 20 and the nextday, its closing price is less than 10.

Page 250: Chasing Bugs with the BeepBeep Event Stream Processor

Calculate how many times the closing priceof MSFT is greater than 20 and the nextday, its closing price is less than 10.

SELECT COUNT(*) FROM (SELECT * FROM stocks WHERE stockSymbol = "MSFT") AS S1, (SELECT * FROM stocks WHERE stockSymbol = "MSFT") AS S2 WHERE (S2.timestamp - S1.timestamp) = 1 AND S1.closingPrice > 20 AND S2.closingPrice < 10;

Page 251: Chasing Bugs with the BeepBeep Event Stream Processor

Calculate how many times the closing priceof MSFT is greater than 20 and the nextday, its closing price is less than 10.

WHEN @P IS A PROCESSOR: MY PATTERN IN ( @P ) IS THE PROCESSOR (SELECT (closingPrice) LESS THAN (20) FROM (@P)) AND (NEXT (SELECT (closingPrice) GREATER THAN (10) FROM (@P))).

THE COUNT OF (( MY PATTERN IN ( (SELECT closingPrice FROM stocks) WHERE (stockSymbol) = ("MSFT"))) WHERE (*) = (true)).

LinearTemporalLogic!

Page 252: Chasing Bugs with the BeepBeep Event Stream Processor

import ca.uqac.lif.cep.*;

public class MyProcessor extends SingleProcessor {

public Queue<Vector<Object>> compute(Vector<Object> inputs) {

}

public void build(Stack<Object> s) {

}}

. . . Create output events from input . . .

. . . Instantiate processor from parse stack . . .

<processor> := . . .<number> := . . .<string> := . . .

Add new rules to any symbol fromthe basic grammar

Page 253: Chasing Bugs with the BeepBeep Event Stream Processor

<processor> := <my_processor> ;

<my_processor> := INCREMENT ( <processor> ) BY <number> ;

Symbols already defined in basic grammar

Adds a new case to an existing rule

Page 254: Chasing Bugs with the BeepBeep Event Stream Processor

import ca.uqac.lif.cep.*;

public class MyProcessor extends SingleProcessor {

private int increment;

public Queue<Vector<Object>> compute(Vector<Object> inputs) { Queue<Vector<Object>> out = new Queue<Vector<Object>>(); Vector<Object> v = new Vector<Object>(); Integer i = (Integer) inputs.firstElement() + increment; v.addElement(i); out.put(v); return out; }

. . .

Page 255: Chasing Bugs with the BeepBeep Event Stream Processor

. . .

public void build(Stack<Object> s) { Number n = (Number) s.pop(); s.pop(); s.pop(); Processor p = (Processor) s.pop(); s.pop(); s.pop();

increment = n.intValue();

Connector.connect(p, this);

s.push(this); }}

Read contents ofparse stack

<number>BY(<processor>)INCREMENT

Set processor's statePipe it to its inputPut on parse stack

Page 256: Chasing Bugs with the BeepBeep Event Stream Processor

Some pre-packaged grammar extensions:

Manipulation of name-value tuples

Set theory

Formatted input (CSV, XML, JSON)

Graphing (histograms, scatterplots, ...)

Basic signal processing (smoothing, peak detection, ...)

Create your own!

Page 257: Chasing Bugs with the BeepBeep Event Stream Processor

It works

1500 Hz performance

Rapid prototyping -400 LOC3

What vs. how

https://liflab.github.io/beepbeep-3

Page 258: Chasing Bugs with the BeepBeep Event Stream Processor

A few pointersvvv

Mv LeuckerE Cv Schallhartv y4KK9Hv A Brief Account ofRuntime Verificationv J. Log. and Alg. Prog. 78 y5Hv

Dv Luckhamv y4KK4Hv The Power of Events: AnIntroduction to CEPv AddisonbWesleyv

Sv HalléE Rv Villemairev y4KG4Hv Runtime Enforcementof Web Service Message Contracts with Datav IEEETrans. Services Computing 5y4Hv

Sv VarvaressosE Kv LavoieE Av Blondin MasséE SvGabouryE Sv Hallév y4KG:Hv Automated Bug Finding inVideo Games: A Case Study for Runtime MonitoringvICST 2014v

Page 259: Chasing Bugs with the BeepBeep Event Stream Processor

http://liflab.ca

Page 260: Chasing Bugs with the BeepBeep Event Stream Processor

GAME OVER

YES NO

QUESTIONS ?

Page 261: Chasing Bugs with the BeepBeep Event Stream Processor

GAME OVER

YES NO

QUESTIONS ?