Professional Documents
Culture Documents
Algebraic Specification and Verification With Cafeobj Part 3 - Cloudsync
Algebraic Specification and Verification With Cafeobj Part 3 - Cloudsync
Algebraic Specification and Verification With Cafeobj Part 3 - Cloudsync
CafeOBJ
Part 3 CloudSync
Norbert Preining
ESSLLI 2016
1/29
2/29
3/29
3/29
3/29
3/29
3/29
CloudSync
4/29
stamp
tmp
idle
stamp
state
idle
pc-2
pc-1
state
state
idle
stamp
tmp
pc-
Cloud
CloudSync in images
state
idle
stamp
tmp
5/29
Cloud
CloudSync in images
state
busy
stamp
gotvalue
stamp
tmp
state
pc-2
pc-1
state
idle
stamp
tmp
pc-
transition: gotvalue
state
idle
stamp
tmp
6/29
Cloud
CloudSync in images
state
busy
stamp
update
stamp
tmp
state
pc-2
pc-1
state
idle
stamp
tmp
pc-
idle
stamp
tmp
7/29
Cloud
CloudSync in images
state
idle
stamp
state
idle
stamp
tmp
pc-2
pc-1
state
idle
stamp
tmp
pc-
transition: gotoidle
state
idle
stamp
tmp
8/29
Specification
ClLabel:
{idlecl, busy}
mod! CLLABEL {
[ClLabelLt < ClLabel]
ops idlecl busy : -> ClLabelLt {constr} .
eq (L1:ClLabelLt = L2:ClLabelLt) = (L1 == L2) .
}
9/29
Specification
ClLabel:
PcLabel:
{idlecl, busy}
{idlepc, gotvalue, updated}
mod! PCLABEL {
[PcLabelLt < PcLabel]
ops idlepc gotvalue updated : -> PcLabelLt {constr} .
eq (L1:PcLabelLt = L2:PcLabelLt) = (L1 == L2) .
}
10/29
Specification
ClLabel:
PcLabel:
ClState:
{idlecl, busy}
{idlepc, gotvalue, updated}
ClLabel
mod! CLSTATE {
pr(PAIR(NAT, CLLABEL{sort Elt -> ClLabel})*{
sort Pair -> ClState, op fst -> fst.clstate,
op snd -> snd.clstate })
}
11/29
Specification
ClLabel:
PcLabel:
ClState:
PcState:
{idlecl, busy}
{idlepc, gotvalue, updated}
ClLabel
PcLabel
mod! PCSTATE {
pr(3TUPLE(NAT, NAT,
PCLABEL{sort Elt -> PcLabel})*
{sort 3Tuple -> PcState})
}
12/29
Specification
ClLabel:
PcLabel:
ClState:
PcState:
PcStates:
{idlecl, busy}
{idlepc, gotvalue, updated}
ClLabel
PcLabel
MultiSet(PcState)
mod! PCSTATES {
pr(MULTISET(PCSTATE{sort Elt -> PcState})*
{sort MultiSet -> PcStates})
}
13/29
Specification
ClLabel:
PcLabel:
ClState:
PcState:
PcStates:
State:
{idlecl, busy}
{idlepc, gotvalue, updated}
ClLabel
PcLabel
MultiSet(PcState)
ClState PcStates
mod! STATE {
pr(PAIR(CLSTATE{sort Elt -> ClState},PCSTATES
{sort Elt -> PcStates})*{sort Pair -> State})
}
14/29
Transitions
GetValue:
15/29
Transitions
GetValue:
15/29
Transitions
GetValue:
Update:
16/29
Transitions
GetValue:
Update:
16/29
Transitions
GetValue:
Update:
GotoIdle:
17/29
Transitions
GetValue:
Update:
GotoIdle:
17/29
CloudSync
Final specication is combination of the three transitions
(included modules are shared!)
mod! CLOUD {
pr(GETVALUE + UPDATE + GOTOIDLE)
}
18/29
CloudSync
Final specication is combination of the three transitions
(included modules are shared!)
mod! CLOUD {
pr(GETVALUE + UPDATE + GOTOIDLE)
}
Goal
18/29
CloudSync
Final specication is combination of the three transitions
(included modules are shared!)
mod! CLOUD {
pr(GETVALUE + UPDATE + GOTOIDLE)
}
Goal
If PC is in updated state, then the values of the Cloud and the PC
agree.
18/29
Verification
Hoare style proof
19/29
Verification
Hoare style proof
1) show invariant for all initial states
19/29
Verification
Hoare style proof
1) show invariant for all initial states
2) show that invariant is preserved over transitions
19/29
Verification
Hoare style proof
1) show invariant for all initial states
2) show that invariant is preserved over transitions
In details
- dene a set of predicates
initial State Bool
19/29
Verification
Hoare style proof
1) show invariant for all initial states
2) show that invariant is preserved over transitions
In details
- dene a set of predicates
initial State Bool
- dene a set of predicates
invariant State Bool
19/29
Verification
Hoare style proof
1) show invariant for all initial states
2) show that invariant is preserved over transitions
In details
- dene a set of predicates
initial State Bool
- dene a set of predicates
invariant State Bool
- show for all states
initial() invariant()
19/29
Verification
Hoare style proof
1) show invariant for all initial states
2) show that invariant is preserved over transitions
In details
- dene a set of predicates
initial State Bool
- dene a set of predicates
invariant State Bool
- show for all states
initial() invariant()
- show for all states
invariant() invariant( )
where is any transition
19/29
How to prove
Question
How to prove a statement like
initial() invariant()
?
20/29
How to prove
Question
How to prove a statement like
initial() invariant()
?
Answer
Show it for any element of a covering set of state expressions.
20/29
Covering set
most general: (state variable) every state is an instance of
21/29
Covering set
most general: (state variable) every state is an instance of
more general {1 , , } such that
= ( )
i.e., every state term is an instance of one of the elements of the
covering set
21/29
Covering set
ops s1 s2
ops M N K
eq s1 = <
eq s2 = <
eq s3 = <
eq t1 = <
eq t2 = <
eq t3 = <
s3 s4 t1 t2 t3 t4 : -> State .
: -> Nat . var PCS : PcStates .
< N, idlecl > , ( << M; K; idlepc >> PCS ) > .
< N, idlecl > , ( << M; K; gotvalue >> PCS ) > .
< N, idlecl > , ( << M; K; updated >> PCS ) > .
< N, busy > , ( << M; K; idlepc >> PCS ) > .
< N, busy > , ( << M; K; gotvalue >> PCS ) > .
< N, busy > , ( << M; K; updated >> PCS ) > .
22/29
Initial predicates
cl-is-idle:
23/29
Initial predicates
cl-is-idle:
Cloud is initially idle
pcs-are-idle: all PCs are initially idle
24/29
Initial predicates
cl-is-idle:
Cloud is initially idle
pcs-are-idle: all PCs are initially idle
init:
cl-is-idle & pcs-are-idle
mod! INITIALSTATE {
pr(INITPREDS)
op init-name : -> PredNameSeq .
eq init-name = cl-is-idle-name pcs-are-idle-name .
pred init : State .
eq init(S:State) = apply(init-name, S) .
}
25/29
Invariant predicates
goal: all PCs in updated state agree with Cloud
26/29
Invariant predicates
goal: all PCs in updated state agree with Cloud
if Cloud is idle then all PCs, too
only at most one PC is out of the idle state
all PCs in gotvalue state have their tmp value equal to the Cloud value
if Cloud is in busy state, then the value of the Cloud and the gotvalue
of the Pcs agree
26/29
init(s1)
init(s2)
init(s3)
init(t1)
init(t2)
init(t3)
implies
implies
implies
implies
implies
implies
invariant(s1)
invariant(s2)
invariant(s3)
invariant(t1)
invariant(t2)
invariant(t3)
.
.
.
.
.
.
-------
OK
OK
OK
OK
OK
OK
27/29
28/29
inv-condition(s1, SS) . -- OK
inv-condition(s2, SS) . -- OK
inv-condition(s3, SS) . -- OK
inv-condition(t1, SS) . -- OK
The following condition does not reduce directly
to true, we will deal with it later on
inv-condition(t2, SS) . -- BAD
inv-condition(t3, SS) . -- OK
29/29
inv-condition(s1, SS) . -- OK
inv-condition(s2, SS) . -- OK
inv-condition(s3, SS) . -- OK
inv-condition(t1, SS) . -- OK
The following condition does not reduce directly
to true, we will deal with it later on
inv-condition(t2, SS) . -- BAD
inv-condition(t3, SS) . -- OK
29/29