Delta-oriented Monitor Specification Eric Bodden, Kevin Falzon Ka I - - PowerPoint PPT Presentation

delta oriented monitor specification
SMART_READER_LITE
LIVE PREVIEW

Delta-oriented Monitor Specification Eric Bodden, Kevin Falzon Ka I - - PowerPoint PPT Presentation

Delta-oriented Monitor Specification Eric Bodden, Kevin Falzon Ka I Pun, Volker Stolz EC-SPRIDE, Darmstadt Universitetet i Oslo October 2012 GROUP Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA12 Motivation What


slide-1
SLIDE 1

Delta-oriented Monitor Specification

Eric Bodden, Kevin Falzon Ka I Pun, Volker Stolz

EC-SPRIDE, Darmstadt Universitetet i Oslo

October 2012

GROUP Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-2
SLIDE 2

Motivation

◮ What is RV? ◮ Does ABS support infrastructure for RV?

(before: aspect-oriented programming)

◮ How do we define variable protocols for different products? ◮ How do we make protocols part of the spec/file?

(machine readable protocols)

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-3
SLIDE 3

Runtime Verification

Use protocol to describe permitted API use. Here: CoCoME.

s b f startSale finishSale enterItem pay i n t e r f a c e Cashdesk { Unit s t a r t S a l e ( ) ; Unit e n t e r I t e m ( I n t code , I n t qty ) ; Unit f i n i s h S a l e ( ) ; I n t pay ( I n t given ) ; }

Transition labels: method names (of a single class)

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-4
SLIDE 4

Guards and Binders

◮ Transitions of form: g&m(x0, . . . , xn) ◮ Guard g may refer to previously bound variable ◮ Variables xi bound to actual parameters during run ◮ Requires wellformedness of automaton/LTS m s b f setExpress(bool mode) startSale startSale finishSale enterItem cashPay !mode & cardPay

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-5
SLIDE 5

Formalization (Automaton)

Θ := VAR → VAL : set of variable bindings over values.

◮ Base automaton M: Q, Σ × −

− → VAR, q0, θ0, Γ

◮ Alphabet with a list of formal parameters ◮ Initial variable binding θ0 ∈ VAR → VAL

Transitions Γ : Q × (Σ × − − → VAR) × (Θ → B) × ((Θ × − − → VAL) → Θ) × Q Single transition:

(q, θ)

e(c0,...,cn)

− − − − − − →M (q′, θ′) := (q, e(x0, . . . , xn), guard, binding, q′) ∈ Γ ∧ guard(θ) ∧ binding(θ, c) = θ′

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-6
SLIDE 6

Formalization (Wellformedness)

Need classical def-before-use analysis on variables. Assume vars : Γ → 2VAR. Transition S, a, g, b, T is wellformed, iff vars(g) ⊆ defsM(S) where defsM(S) : Q → 2VAR

defsM(S) :=    dom(θ0) iff s = q0;

  • γ∈Γ

(defsM(Sp) ∪ {x0, . . . , xn})

  • therwise

γ = (Sp, e(x0, . . . , xn), g, θ, S)

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-7
SLIDE 7

Formalization (Wellformedness)

Need classical def-before-use analysis on variables. Assume vars : Γ → 2VAR. Transition S, a, g, b, T is wellformed, iff vars(g) ⊆ defsM(S)

m s b f setExpress(bool mode) startSale startSale finishSale enterItem cashPay !mode & cardPay

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-8
SLIDE 8

So much for RV

Back to Software Engineering!

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-9
SLIDE 9

ABS and Deltas

Our Cashdesk: simple OO. (Actually not even OO.) Unit enterItem ( I n t code , I n t qty ) { Item item = s t o r e . lookup ( code ) ; t o t a l = t o t a l + qty ∗ p r i c e ( item ) ; items = Cons ( item , items ) ; } More interesting: variability with Deltas.

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-10
SLIDE 10

Variability

Optional payment with credit card:

d e l t a C r e d i t modi fies c l a s s Cashdesk adds Bool cardPay ( CCData cc ) { return s t o r e . a u t h o r i z e ( cc ) ; } adds I n t cashPay ( I n t given ) { return pay ( given ) ; }

Express mode with restricted functionality:

d e l t a Express ( I n t k ) modi fies c l a s s Cashdesk adds Bool mode = F a l s e ; adds Unit s e t E x p r e s s ( Bool m) { mode = m; } modi fies Unit e n t e r I t e m ( I n t code , I n t qty ) { // You are allowed to buy k items i n ExpressMode i f (mode && l e n g t h ( items ) == k ) { a s s e r t F a l s e ;} e l s e {

  • r i g i n a l ( code , qty ) ; }

Deltas are not oblivious—Express-delta must know about items.

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-11
SLIDE 11

Our Product Line

Special case from use case:

d e l t a ExpressCC modi fies c l a s s Cashdesk modi fies Bool cardPay ( CCData cc ) { a s s e r t ˜mode ; // Not allowed i n e x p r e s s mode return

  • r i g i n a l ( cc ) ;

} p r o d u c t l i n e CoCoME f e a t u r e s Express , C r e d i t ; d e l t a C r e d i t when C r e d i t ; d e l t a Express (10) when Express ; d e l t a ExpressCC a f t e r C r e d i t when Express && C r e d i t ; product C r e d i t ( C r e d i t ) ; product Ex ( Express ) ; product CCEx( Express , C r e d i t ) ;

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-12
SLIDE 12

Back to Protocols!

Observation: Monitoring becomes a feature just like other variabilities. How to describe protocols for different products? Alternatives:

◮ Give new protocol per product

Disadvantage: presumably unwieldily large

◮ Give base protocol,

attach protocol-change to delta √

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-13
SLIDE 13

Formalization (Delta automaton)

Delta automaton ∆ :=

  • Q∆, Σ∆ × −

− → VAR, q∆

0 , θ∆ 0 , Γ∆ +, Γ∆ −

  • with:

◮ Q∆ new introduced states, ◮ Σ∆ × −

− → VAR new symbols,

◮ q∆ 0 an optional redefined start state, ◮ θ∆ 0 new initial bindings, ◮ Γ∆ + and Γ∆ − transitions added/removed.

Given base automaton M =

  • QM, ΣM, qM

0 , ΓM

, delta automaton ∆ =

  • Q∆, Σ∆, q∆

0 , Γ∆ +, Γ∆ −

  • .

Application of ∆ to M: M′ := M ↓ ∆

Q′ := QM ∪ Q∆ Σ

′ × −

− → VAR := ΣM × − − → VAR ∪ Σ∆ × − − → VAR, q′ := qM if q∆

0 = ⊥, q∆ 0 otherwise

θ′ := θM if θ∆

0 = ⊥, otherwise:

λc.(case θ∆

0 (c) = ⊥ ⇒ θM 0 (c); otherwise, θ∆ 0 (c))

Γ′ := (ΓM ∪ Γ∆

+) − Γ∆ −

(Check resulting automaton for wellformedness.)

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-14
SLIDE 14

Protocol Deltas (Credit Card Payment)

s0 s1 finishSale startSale cardPay [cashPay/pay] ∆CC := ∅, no new state {cashPay, cardPay}, new alphabets ⊥, ⊥, no new initial state/symbols {(f , cashPay, λs.true, λ(s, c).s, s), transitions added (f , cardPay, λs.true, λ(s, c).s, s)}, {(f , pay, λs.true, λ(s, c).s, s)} transition removed

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-15
SLIDE 15

Protocol Deltas (Express Mode/Special Case)

s0 s1 s2 setExpress(bool mode) startSale startSale s0 s1 finishSale !mode & cardPay startSale setExpress {m}, {setExpress}, m, λc.(case c = “mode” ⇒ true), {(m, setExpress, λs.true, λ(s, x). (λy.(case y = “mode” ⇒ x;

  • therwise ⇒ s(y))), s),

(m, ǫ, λs.true, λ(s, c).s, b)}, ∅ ∅, ∅, ⊥, ⊥, {(f , cardPay, λ s.(¬s(”mode”)), λ(s, c).s, m)}, {(f , cardPay, λs.true, λ(s, c).s, m)}

Note: “before” advice relocates initial state!

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-16
SLIDE 16

Generating Monitor Deltas

  • Straightforward. Base monitor:

s b f startSale finishSale enterItem pay (More interesting if more than one incoming edge. . . )

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-17
SLIDE 17

Generating Monitor Deltas

  • Straightforward. Base monitor:

data State = I n i t | Buying | F i n i s h e d ; d e l t a Monitor modi fies c l a s s Cashdesk adds State s t a t e = I n i t ; modi fies Unit s t a r t S a l e ( ) { i f ( s t a t e == I n i t ) {

  • r i g i n a l ( ) ;

s t a t e = Buying ; } e l s e { a s s e r t F a l s e ; }} modi fies Unit e n t e r I t e m ( I n t code , I n t qty ) i f ( s t a t e == Buying ) {

  • r i g i n a l ( code , qty ) ;

} e l s e { a s s e r t F a l s e ; }} modi fies Unit f i n i s h S a l e () i f ( s t a t e == Buying ) { o r i g i n a l ( ) ; s t a t e = F i n i s h e d ;} e l s e { a s s e r t F a l s e ;}} modi fies I n t pay ( I n t given ) I n t r e s = −1; i f ( s t a t e == F i n i s h e d ) { r e s = o r i g i n a l ( given ) ; s t a t e = I n i t ;} e l s e { a s s e r t F a l s e ;} /∗ e n d i f ∗/ return r e s ; }

(More interesting if more than one incoming edge. . . )

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-18
SLIDE 18

Binding and Testing State

Introduce state variable:

d e l t a ExpressMon modi fies c l a s s Cashdesk adds Maybe<Bool> monMode = Just ( F a l s e ) ; modi fies Unit s e t E x p r e s s ( Bool m) { monMode = Just (m) ; // r e c o r d mode // Only allowed between s a l e s i f ( s t a t e == I n i t ) {

  • r i g i n a l (m) ;

} e l s e { a s s e r t F a l s e ; } } d e l t a ExpressCCMon { modi fies c l a s s Cashdesk { modi fies Bool cardPay ( CCData cc ) { a s s e r t ˜ fromJust (monMode ) ; return

  • r i g i n a l ( cc ) ;

}

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-19
SLIDE 19

Combined Monitors

s0 s1 s2 setExpress(bool mode) startSale startSale s0 s1 finishSale !mode & cardPay startSale setExpress s b f startSale finishSale enterItem pay m s b f setExpress(bool mode) startSale startSale finishSale enterItem cashPay !mode & cardPay

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-20
SLIDE 20

More Scenarios & Future Work

◮ Store protocol in annotations (see Bodden/Stolz 2006) ◮ Use protocol to implement QueueManager

—resulting monitor no longer depends on single object. Problem: ABS doesn’t support static factories; no way to connect to global monitor?

◮ Teach guards about object identities, quantification,

allow general function calls

◮ Example: o = p & o.m(x)

(for LTL: [RV 2007])

◮ Danger:

  • .m()

− → ·

p.n()

− → (“hidden” monitor)

◮ In actor setting:

◮ role of callee? ◮ what to do (skip instead of assert False?)

◮ Not only enforce protocol—contribute behaviour.

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12

slide-21
SLIDE 21

Conclusion

◮ Monitoring is just another feature ◮ Monitoring for SPLs:

base monitor + delta monitors (both as deltas) instead of defining monitors for products

◮ Wellformedness checked afterwards ◮ Similar effects wrt. ordering like deltas for programs,

monitor delta is applied after corresponding code delta

Delta-oriented Monitor Specification Bodden/Falzon/Pun/Stolz ISoLA’12