Slide Model Spec In OTS cafeobj Công nghệ phần mềm | Trường Đại học Công nghệ, Đại học Quốc gia Hà Nội

Slide Model Spec In OTS cafeobj Công nghệ phần mềm | Trường Đại học Công nghệ, Đại học Quốc gia Hà Nội . Tài liệu được sưu tầm và biên soạn dưới dạng PDF gồm 13 trang giúp bạn tham khảo, củng cố kiến thức và ôn tập đạt kết quả cao trong kỳ thi sắp tới. Mời bạn đọc đón xem!

Thông tin:
13 trang 4 tuần trước

Bình luận

Vui lòng đăng nhập hoặc đăng ký để gửi bình luận.

Slide Model Spec In OTS cafeobj Công nghệ phần mềm | Trường Đại học Công nghệ, Đại học Quốc gia Hà Nội

Slide Model Spec In OTS cafeobj Công nghệ phần mềm | Trường Đại học Công nghệ, Đại học Quốc gia Hà Nội . Tài liệu được sưu tầm và biên soạn dưới dạng PDF gồm 13 trang giúp bạn tham khảo, củng cố kiến thức và ôn tập đạt kết quả cao trong kỳ thi sắp tới. Mời bạn đọc đón xem!

7 4 lượt tải Tải xuống
1
Modeling and Specification
in OTS/CafeOBJ
CafeOBJ Team of JAIST
LectureNote8, i613-0712
2
Topics
z What is QLOCK?
z Modeling and Description of QLOCK in OTS
z Formal specification of QLOCK in CafeOBJ
z Formal specification of mutual exclusion
2
LectureNote8, i613-0712
3
Modeling, Specifying, and Verifying (MSV)
in CafeOBJ
1. By understanding a problem to be
modeled/specified, determine several sorts of
objects (entities, data, agents, states) and
operations (functions, actions, events) over
them for describing the problem
2. Define the meanings/functions of the
operations by declaring equations over
expressions/terms composed of the operations
3. Write proof scores for properties to be verified
LectureNote8, i613-0712
4
MSV with proof scores in CafeOBJ
Understand problem
and construct model
Write system spec SPsys and
Write property spec SPprop
Construct proof score of
SPprop w.r.t. SPsys
3
LectureNote8, i613-0712
5
An example: mutual exclusion protocol
Assume that many agents (or processes) are
competing for a common equipment, but at
any moment of time only one agent can use
the equipment. That is, the agents are
mutually excluded in using the equipment. A
protocol (mechanism or algorithm) which can
achieve the mutual exclusion is called “mutual
exclusion protocol”.
LectureNote8, i613-0712
6
QLOCK (locking with queue):
a mutual exclusion protocol
Remainder Section
Critical Section
Is i at the top
of the queue?
cs
Put its name i into the
bottom of the queue
Remove/get the
top of the queue
wt
rm
true
false
Each agent i is executing:
: atomic action
4
LectureNote8, i613-0712
7
QLOCK: basic assumptions/characteristics
z There is only one queue and all agents/processes
share the queue.
z Any basic action on the queue is inseparable (or
atomic). That is, when any action is executed on the
queue, no other action can be executed until the
current action is finished.
z There may be unbounded number of agents.
z In the initial state, every agents are in the remainder
section (or at the label rm), and the queue is empty.
The property to be shown is that at most one agent
is in the critical section (or at the label cs) at any
moment.
LectureNote8, i613-0712
8
Global (or macro) view of QLOCK
k
ji
i
k
j
is i?
is j?
put
get
get
: queue
: agents
put
5
LectureNote8, i613-0712
9
Modeling QLOCK (via Signature Diagram)
with OTS (Observational Transition System)
k
j
i
i
k
j
is i?
is j?
put
get
get
put
Queue
Label
Pid
Sys
want
try
pc
queue
exit
init
LectureNote8, i613-0712
10
Signature for QLOCKwithOTS
z Sys is the sort for representing the state space of the system.
z Pid is the sort for the set of agent/process names.
z Label is the sort for the set of labels; i.e. {rm, wt, cs}.
z Queue is the sort for the queues of Pid
z pc (program counter) is an observer returning a label where
each agent resides.
z queue is an observer returning the current value of the
waiting queue of Pid.
z want is an action for agent i of putting its name/id into the
queue.
z try is an action for agent i of checking whether its name/id
is at the top of the queue.
z exit is an action for agent i of removing/getting its name/id
from the top of the queue.
6
LectureNote8, i613-0712
11
Observation declaration
action declaration
visible sort declaration
Hiden sort declaration
CafeOBJ signature for QLOCKwithOTS
-- state space of the system
*[Sys]*
-- visible sorts for observation
[Queue Pid Label]
-- observations
bop pc : Sys Pid -> Label
bop queue : Sys -> Queue
-- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
LectureNote8, i613-0712
12
Module LABEL specifying
(via tight denotation/semantics) labels
mod! LABEL {
[Label]
ops rm wt cs : -> Label
pred (_=_) : Label Label {comm}
var L : Label
eq (L = L) = true .
eq (rm = wt) = false .
eq (rm = cs) = false .
eq (wt = cs) = false .
}
Predicate (_ = _) defines identity relation
among rm, wt, and cs.
qlock.mod
7
LectureNote8, i613-0712
13
Module PID specifying (via loose denotation)
agent/process names/identifiers
mod* PID {
[Pid < PidErr]
op none : -> PidErr
pred (_=_) : PidErr PidErr {comm}
var I : Pid .
eq (I = I) = true .
eq (none = I) = false .
-- (none = none) is not defined intentionally
}
z The constant none of the sort PidErr is intended to
indicate the result of getting top of the empty queue.
z Any element in the sort Pid is defined not equal to none,
that is, return false for predicate (_ = _) .
z Notice that (none = none) does not reduced to true or
false.
qlock.mod
LectureNote8, i613-0712
14
Module QUEUE specifying queue (1)
-- an parameterized module
mod* TRIVerr {
[Elt < EltErr]
op none : -> EltErr
}
mod! QUEUE(D :: TRIVerr) {
[Queue]
-- constructors
op empty : -> Queue {constr}
op _,_ : Queue Elt.D -> Queue {constr l-assoc}
-- operators
op put : Elt.D Queue -> Queue
op get : Queue -> Queue
op top : Queue -> EltErr.D
op empty? : Queue -> Bool
qlock.mod
8
LectureNote8, i613-0712
15
Module QUEUE specifying queue (2)
-- an parameterized module
-- CafeOBJ variables
var Q : Queue
vars X Y : Elt.D
-- equations
eq put(X,empty) = empty,X .
eq put(X,(Q,Y)) = put(X,Q),Y .
-- get(empty) is not defined intentionally
eq get((Q,X)) = Q .
eq top(empty) = (none):EltErr.D .
eq top((Q,X)) = X .
eq empty?(empty) = true .
eq empty?((Q,X)) = false .
}
qlock.mod
LectureNote8, i613-0712
16
QLOCK using operators
in the CafeOBJ module QUEUE
Remainder Section
Critical Section
top(queue)=i
cs
put(queue,i)
get(queue)
wt
rm
true
false
Each agent i is executing:
: atomic action
9
LectureNote8, i613-0712
17
Module QLOCK specifying QLOCK (1-1)
view TRIVerr2PID from TRIVerr to PID {
sort Elt -> Pid,
sort EltErr -> PidErr,
op (none):EltErr -> (none):PidErr }
mod* QLOCK {
pr(LABEL)
pr(QUEUE(D <= TRIVerr2PID))
*[Sys]*
-- any initial state
op init : -> Sys
-- observations
bop pc : Sys Pid -> Label
bop queue : Sys -> Queue
-- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
-- for any initial state
eq pc(init,I:Pid) = rm .
eq queue(init) = empty .
qlock.mod
LectureNote8, i613-0712
18
Module QLOCK specifying QLOCK (1-2)
mod* QLOCK {
pr(LABEL)
pr(QUEUE(PID{sort Elt -> Pid,
sort EltErr -> PidErr,
op (none):EltErr -> none):PidErr}))
*[Sys]*
-- any initial state
op init : -> Sys
-- observations
bop pc : Sys Pid -> Label
bop queue : Sys -> Queue
-- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
-- for any initial state
eq pc(init,I:Pid) = rm .
eq queue(init) = empty .
qlock.mod
10
LectureNote8, i613-0712
19
Module QLOCK specifying QLOCK (2)
var S : Sys . vars I J : Pid .
-- for want
op c-want : Sys Pid -> Bool {strat: (0 1 2)}
eq c-want(S,I) = (pc(S,I) = rm) .
--
ceq pc(want(S,I),J)
= (if I = J then wt else pc(S,J) fi)
if c-want(S,I) .
ceq queue(want(S,I)) = put(I,queue(S))
if c-want(S,I) .
ceq want(S,I) = S
if not c-want(S,I) .
qlock.mod
LectureNote8, i613-0712
20
Module QLOCK specifying QLOCK (3)
-- for try
op c-try : Sys Pid -> Bool {strat: (0 1 2)}
eq c-try(S,I) = (pc(S,I) = wt and top(queue(S)) = I) .
--
ceq pc(try(S,I),J)
= (if I = J then cs else pc(S,J) fi) if c-try(S,I) .
eq queue(try(S,I)) = queue(S) .
ceq try(S,I) = S if not c-try(S,I) .
-- for exit
op c-exit : Sys Pid -> Bool {strat: (0 1 2)}
eq c-exit(S,I) = (pc(S,I) = cs) .
--
ceq pc(exit(S,I),J)
= (if I = J then rm else pc(S,J) fi) if c-exit(S,I) .
ceq queue(exit(S,I)) = get(queue(S)) if c-exit(S,I) .
ceq exit(S,I) = S if not c-exit(S,I) .
}
qlock.mod
11
LectureNote8, i613-0712
21
(_ =*= _) is congruent for OTS
The binary relation (S1:Sys =*= S2:Sys) is defined to
be true iff S1 and S2 have the same observation values.
OTS style of defining the possible changes of the values of
obervations is characterized by the equations of the form:
o(a(s,d),d’) = ...o
1
(s,d
1
)...o
2
(s,d
2
)...o
n
(s,d
n
)...
for appropriate data values of d,d’,d
1
,d
2
,...,d
n
.
It can be shown that OTS style guarantees
that (_ =*= _) is congruent with respect
to all actions.
LectureNote8, i613-0712
22
R
QLOCK
(set of reachable states) of
OTS
QLOCK
(OTS defined by the module QLOCK)
-- any initial state
op init : -> Sys
-- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
Signature determining R
QLOCK
R
QLOCK
= {init}
{want(s,i)|sR
QLOCK
,iPid}
{try(s,i) |sR
QLOCK
,iPid}
{exit(s,i)|sR
QLOCK
,iPid}
Recursive definition of R
QLOCK
12
LectureNote8, i613-0712
23
Mutual exclusion property
as an invariant
mod INV1 {
pr(QLOCK)
-- declare a predicate to verify to be an invariant
pred inv1 : Sys Pid Pid
-- CafeOBJ variables
var S : Sys .
vars I J : Pid .
-- define inv1 to be the mutual exclusion property
eq inv1(S,I,J)
= (((pc(S,I) = cs) and (pc(S,J) = cs)) implies I = J) .
}
INV1 |= sR
QLOCK
i,jPid.inv1(s,i,j)
Formulation of proof goal for mutual exclusion property
invariants-0.mod
LectureNote8, i613-0712
24
Induction scheme
induced by the structure of R
QLOCK
mx(s) =def= i,jPid.inv1(s,i,j)
{ INV1 |= mx(init),
INV1{mx(s)=true} |= k . mx(want(s,k)),
INV1{mx(s)=true} |= k . mx(try(s,k)),
INV1{mx(s)=true} |= k . mx(exit(s,k)) }
implies
INV1 |= sR
QLOCK
.mx(s)
13
LectureNote8, i613-0712
25
Schematic signature diagram for OTS
Hidden Sort
(State Space)
Visible Sort
(Data)
...
...
Action
(method)
Action
(method)
Observation
(attribute)
Observation
(attribute)
Visible Sorts
(Data)
Visible Sorts
(Data)
Visible Sort
(Data)
...
VSs
HSs
Coherent
| 1/13

Preview text:

Modeling and Specification in OTS/CafeOBJ CafeOBJ Team of JAIST Topics z What is QLOCK?
z Modeling and Description of QLOCK in OTS
z Formal specification of QLOCK in CafeOBJ
z Formal specification of mutual exclusion LectureNote8, i613-0712 2 1
Modeling, Specifying, and Verifying (MSV) in CafeOBJ
1. By understanding a problem to be
modeled/specified, determine several sorts of
objects (entities, data, agents, states) and
operations (functions, actions, events) over
them for describing the problem

2. Define the meanings/functions of the
operations by declaring equations over
expressions/terms composed of the operations

3. Write proof scores for properties to be verified LectureNote8, i613-0712 3
MSV with proof scores in CafeOBJ Understand problem and construct model Write system spec SPsys and Write property spec SPprop Construct proof score of SPprop w.r.t. SPsys LectureNote8, i613-0712 4 2
An example: mutual exclusion protocol
Assume that many agents (or processes) are
competing for a common equipment, but at
any moment of time only one agent can use
the equipment. That is, the agents are
mutually excluded in using the equipment. A
protocol (mechanism or algorithm) which can
achieve the mutual exclusion is called “mutual exclusion protocol”.
LectureNote8, i613-0712 5 QLOCK (locking with queue): a mutual exclusion protocol
Each agent i is executing: : atomic action Put its name i into the bottom of the queue wt false Is i at the top of the queue? rm Remainder Section true Critical Section Remove/get the cs top of the queue LectureNote8, i613-0712 6 3
QLOCK: basic assumptions/characteristics
z There is only one queue and all agents/processes share the queue.
z Any basic action on the queue is inseparable (or
atomic). That is, when any action is executed on the
queue, no other action can be executed until the
current action is finished.

z There may be unbounded number of agents.
z In the initial state, every agents are in the remainder
section (or at the label rm), and the queue is empty.
The property to be shown is that at most one agent
is in the critical section (or at the label cs) at any moment.
LectureNote8, i613-0712 7
Global (or macro) view of QLOCK : queue i : agents put is i? get k j i k put is j? get j LectureNote8, i613-0712 8 4
Modeling QLOCK (via Signature Diagram)
with OTS (Observational Transition System) Pid pc Label want i put is i? get try k j i k queue put Queue is j? get exit j Sys init LectureNote8, i613-0712 9 Signature for QLOCKwithOTS z
Sys is the sort for representing the state space of the system. z
Pid is the sort for the set of agent/process names. z
Label is the sort for the set of labels; i.e. {rm, wt, cs}. z
Queue is the sort for the queues of Pid z
pc (program counter) is an observer returning a label where each agent resides. z
queue is an observer returning the current value of the waiting queue of Pid. z
want is an action for agent i of putting its name/id into the queue. z
try is an action for agent i of checking whether its name/id
is at the top of the queue.
z
exit is an action for agent i of removing/getting its name/id from the top of the queue. LectureNote8, i613-0712 10 5
CafeOBJ signature for QLOCKwithOTS
-- state space of the system *[Sys]* Hiden sort declaration
-- visible sorts for observation [Queue Pid Label]
visible sort declaration -- observations
bop pc : Sys Pid -> Label Observation declaration
bop queue : Sys -> Queue -- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys action declaration
bop exit : Sys Pid -> Sys LectureNote8, i613-0712 11 Module LABEL specifying
(via tight denotation/semantics) labels”qlock.mod mod! LABEL { [Label]
ops rm wt cs : -> Label
pred (_=_) : Label Label {comm} var L : Label eq (L = L) = true . eq (rm = wt) = false . eq (rm = cs) = false . eq (wt = cs) = false . }
Predicate (_ = _) defines identity relation among rm, wt, and cs. LectureNote8, i613-0712 12 6
Module PID specifying (via loose denotation)
agent/process names/identifiers qlock.mod mod* PID { [Pid < PidErr] op none : -> PidErr
pred (_=_) : PidErr PidErr {comm} var I : Pid . eq (I = I) = true . eq (none = I) = false .
-- (none = none) is not defined intentionally }
z The constant none of the sort PidErr is intended to
indicate the result of getting top of the empty queue.
z Any element in the sort Pid is defined not equal to none,
that is, return false for predicate (_ = _) .
z Notice that (none = none) does not reduced to true or false. LectureNote8, i613-0712 13
Module QUEUE specifying queue(1) -- an parameterized module qlock.mod mod* TRIVerr { [Elt < EltErr] op none : -> EltErr }
mod! QUEUE(D :: TRIVerr) { [Queue] -- constructors
op empty : -> Queue {constr}
op _,_ : Queue Elt.D -> Queue {constr l-assoc} -- operators
op put : Elt.D Queue -> Queue
op get : Queue -> Queue
op top : Queue -> EltErr.D
op empty? : Queue -> Bool LectureNote8, i613-0712 14 7
Module QUEUE specifying queue(2) -- an parameterized module qlock.mod -- CafeOBJ variables var Q : Queue vars X Y : Elt.D -- equations
eq put(X,empty) = empty,X .
eq put(X,(Q,Y)) = put(X,Q),Y .
-- get(empty) is not defined intentionally eq get((Q,X)) = Q .
eq top(empty) = (none):EltErr.D . eq top((Q,X)) = X .
eq empty?(empty) = true .
eq empty?((Q,X)) = false . } LectureNote8, i613-0712 15 QLOCK using operators in the CafeOBJ module QUEUE
Each agent i is executing: : atomic action put(queue,i) wt false top(queue)=i rm true Remainder Section Critical Section get(queue) cs LectureNote8, i613-0712 16 8
Module QLOCK specifying QLOCK(1-1) qlock.mod
view TRIVerr2PID from TRIVerr to PID { sort Elt -> Pid,
sort EltErr -> PidErr,
op (none):EltErr -> (none):PidErr } mod* QLOCK { pr(LABEL)
pr(QUEUE(D <= TRIVerr2PID)) *[Sys]* -- any initial state op init : -> Sys -- observations
bop pc : Sys Pid -> Label
bop queue : Sys -> Queue -- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
-- for any initial state
eq pc(init,I:Pid) = rm .
eq queue(init) = empty . LectureNote8, i613-0712 17
Module QLOCK specifying QLOCK(1-2) qlock.mod mod* QLOCK { pr(LABEL)
pr(QUEUE(PID{sort Elt -> Pid,
sort EltErr -> PidErr,
op (none):EltErr -> none):PidErr})) *[Sys]* -- any initial state op init : -> Sys -- observations
bop pc : Sys Pid -> Label
bop queue : Sys -> Queue -- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
-- for any initial state
eq pc(init,I:Pid) = rm .
eq queue(init) = empty . LectureNote8, i613-0712 18 9
Module QLOCK specifying QLOCK(2) qlock.mod
var S : Sys . vars I J : Pid . -- for want
op c-want : Sys Pid -> Bool {strat: (0 1 2)}
eq c-want(S,I) = (pc(S,I) = rm) . -- ceq pc(want(S,I),J)
= (if I = J then wt else pc(S,J) fi) if c-want(S,I) .
ceq queue(want(S,I)) = put(I,queue(S)) if c-want(S,I) . ceq want(S,I) = S if not c-want(S,I) . LectureNote8, i613-0712 19
Module QLOCK specifying QLOCK(3) qlock.mod -- for try
op c-try : Sys Pid -> Bool {strat: (0 1 2)}
eq c-try(S,I) = (pc(S,I) = wt and top(queue(S)) = I) . -- ceq pc(try(S,I),J)
= (if I = J then cs else pc(S,J) fi) if c-try(S,I) . eq
queue(try(S,I)) = queue(S) .
ceq try(S,I) = S if not c-try(S,I) . -- for exit
op c-exit : Sys Pid -> Bool {strat: (0 1 2)}
eq c-exit(S,I) = (pc(S,I) = cs) . -- ceq pc(exit(S,I),J)
= (if I = J then rm else pc(S,J) fi) if c-exit(S,I) .
ceq queue(exit(S,I)) = get(queue(S)) if c-exit(S,I) .
ceq exit(S,I) = S if not c-exit(S,I) . } LectureNote8, i613-0712 20 10
(_ =*= _) is congruent for OTS
The binary relation (S1:Sys =*= S2:Sys) is defined to
be true iff S1 and S2 have the same observation values.

OTS style of defining the possible changes of the values of
obervations is characterized by the equations of the form:

o(a(s,d),d’) = ...o (s,d )...o (s,d )...o (s,d )... 1 1 2 2 n n
for appropriate data values of d,d’,d ,d ,...,d . 1 2 n
It can be shown that OTS style guarantees
that (_ =*= _) is congruent with respect to all actions.
LectureNote8, i613-0712 21 R (set of reachable states) of QLOCK OTS
(OTS defined by the module QLOCK) QLOCK
Signature determining RQLOCK -- any initial state op init : -> Sys -- actions
bop want : Sys Pid -> Sys
bop try : Sys Pid -> Sys
bop exit : Sys Pid -> Sys
Recursive definition of RQLOCK R = {init} QLOCK
{want(s,i)|sR
,iPid} QLOCK
{try(s,i) |sR
,iPid} QLOCK
{exit(s,i)|sR
,iPid} QLOCK LectureNote8, i613-0712 22 11 Mutual exclusion property as an invariant invariants-0.mod mod INV1 { pr(QLOCK)
-- declare a predicate to verify to be an invariant pred inv1 : Sys Pid Pid -- CafeOBJ variables var S : Sys . vars I J : Pid .
-- define inv1 to be the mutual exclusion property eq inv1(S,I,J)
= (((pc(S,I) = cs) and (pc(S,J) = cs)) implies I = J) . }
Formulation of proof goal for mutual exclusion property
INV1 |= sR
i,jPid.inv1(s,i,j) QLOCK LectureNote8, i613-0712 23 Induction scheme
induced by the structure of RQLOCK
mx(s) =def= i,jPid.inv1(s,i,j) { INV1 |= mx(init),
INV1{mx(s)=true} |= k . mx(want(s,k)),
INV1{mx(s)=true} |= k . mx(try(s,k)),
INV1{mx(s)=true} |= k . mx(exit(s,k)) } implies
INV1 |= sR .mx(s) QLOCK LectureNote8, i613-0712 24 12
Schematic signature diagram for OTS Visible Sorts Visible Sorts (Data) Action Action (Data) ... (method) (method) VSs Hidden Sort Coherent HSs (State Space) ... Observation Observation (attribute) ... (attribute) Visible Sort Visible Sort (Data) (Data) LectureNote8, i613-0712 25 13