Model Based Testing
Model Based Testing
Oleg Sokolsky
?dime ? nickel
from user to machine from machine to user
initiative with user initiative with machine
S1 S2
machine cannot refuse user cannot refuse
! coffee ! tea
S3 S4 input output
LI LU
LI = { ?dime, ?nickel }
LU = { !coffee, !tea } L I LU = L I LU = L
Input-Output Transition Systems
Input-Output Transition Systems
?dime ?nickel
IOTS (LI ,LU ) LTS (LI LU )
?dime
?nickel
?dime IOTS is LTS with Input-Output
?nickel
!coffee !tea and always enabled inputs:
?dime
?dime ?nickel
?nickel for all states s,
?a
LI = { ?dime, ?nickel } for all inputs ?a LI : S
LU = { !coffee, !tea }
Preorders on IOTS
implementation specification
i imp s
environment environment
e e
i IOTS(LI,LU) s LTS(LILU)
environment environment
e e
i IOTS(LI,LU) s LTS(LILU)
i imp s e E . obs ( e, i ) obs (e,
s)
IOTS(LU,LI)
Input-Output Testing Relation
implementation specification
i iot s
environment environment
e e
i IOTS(LI,LU) s LTS(LILU)
i iot s e IOTS(LU,LI) .obs ( e, i ) obs (e, s )
?dime ?dime
?nickel ?nickel
?dime ?dime
?nickel ?nickel
!coffee !tea !coffee !tea
?dime ?dime
?dime ?nickel ?dime ?nickel
?nickel ?nickel
Conformance relation ioconf
• Finally…
i iot s L*.out( i after ) out( s after )
• Allow underspecification
– restrict to traces of s
i ioconf s =def
traces(s)L*.out(i after ) out(s after )
• ioconfF: use arbitrary F instead of traces of s
• Conformance relation ioco accounts for
repetitive quiescence
Test cases
• A test case is a deterministic IOTS(LU,LI) with
finite behaviors
– Note reversed inputs and outputs
– Do not allow choice between outputs or
between input and output pass
• Verdict function : S → {fail,pass} ?dime
pass ?dime
?nickel
output- ?dime ?dime
?nickel
enabled !coffee !tea
fail
not in
F after dime ?dime
!coffee and not ?dime ?nickel
!tea
quiescent ?nickel
pass fail
Wrong
Right output
output
Test purposes
• Where does F come from?
• Test purposes:
– Requirements, use cases
– Automata, message sequence charts
• Test purposes represent “interesting” or
“significant” behaviors
– Define “interesting” or “significant”…
• Can we come up with test purposes
automatically?
Summary: conformance testing
• Advantages:
– Very rigorous formal foundation
– Size of the test suite is controlled by use
cases
• Disadvantages:
– How much have we learned about the system
that passed the test suite?
– Does not guarantee coverage
Coverage-based testing
• Traditional:
– Tests are derived from the implementation
structure (code)
• Model-driven:
– Cover the model instead of code
– Model should be much closer to the
implementation in structure
• Relies on coverage criteria
Coverage criteria and tests
• [HongLeeSokolskyUral02]
• Control flow:
– all-states
– all-transitions
• Data flow:
– all-defs
– all-uses
– all-inputs
– all-outputs
• Test is a linear sequence of inputs and outputs
Specifications: EFSM
• Transition systems equipped with variables
• Transitions have guards and update blocks
t1: insert[m+x<=5]
/m:=m+x
t2: coffee[m>1]
/m:=m-1
IDLE BUSY
t3: done
t1: insert[m+x<=5]
All-uses coverage criterion
/m:=m+x EF(t1 & EXE[!(t1 | t2) U (t1 & EFexit)])
t2: coffee[m>1] EF(t1 & EXE[!(t1 | t2) U (t2 & EFexit)])
/m:=m-1 EF(t1 & EXE[!(t1 | t2) U (t4 & EFexit)])
EF(t1 & EXE[!(t1 | t2) U (t5 & EFexit)])
IDLE BUSY
EF(t2 & EXE[!(t1 | t2) U (t1 & EFexit)])
t3: done EF(t2 & EXE[!(t1 | t2) U (t2 & EFexit)])
EF(t2 & EXE[!(t1 | t2) U (t4 & EFexit)])
EF(t2
t5: & EXE[!(t1 | t2) U (t5 & EFexit)])
display/y:=m
t4: display/y:=m
Data flow chains
• Affect pair (v, t, v’, t’): the value of v used by t
affects the value of v’ defined at t’
– Either t=t’ ((v,t) directly affects (v’,t’)) or
– there is a du-pair (v’’,t,t’’) s.t. (v,t) directly affects
(v’’,t) and (v’’,t’’) affects (v’,t’)
t1: insert[m+x<=5] (x, t1) directly affects (m, t1)
/m:=m+x
t2: coffee[m>1] (x, t1) affects (y, t5)
/m:=m-1
IDLE BUSY
t3: done
System
model
Model
checker
Coverage A set of A set of
criterion logic witnesses
formulas
Test Generation
• Generating a witness for a formula
– Cost: the length of a witness
– A minimal-cost witness for a formula
• Existing model checkers generate a minimal-cost
witness by breadth-first search of state space
E[ U ]
Test Generation
• Costs
– The total length of witnesses or
– The number of witnesses
• Both optimization problems are NP-hard
E[ U ]
E[ U ]
E[ U ]
E[ U ]
Coverage for distributed systems
• What if our system is a collection of
components?
• Possible solutions:
– Generate tests for each components
• Clearly unsatisfactory; does not test integration
– Generate tests from the product of
component models
• Too many redundant tests
• Non-determinism is another problem
Example
• Producer-consumer with acknowledgements
send? S
t_fwd?
send t_fwd
t_fwd!
recv
t_bck? recv!
t_bck!
ack t_bck
ack! R
A
Covering product transition system
• Linear tests bring trouble:
send?.ack!.recv!
– May fail if the system chooses a different path
• Tests differ in interleavings
of independent events ack!
recv!
recv!
see ack?
t_fwd!
recv
t_bck? recv!
t_bck!
ack t_bck
ack! R
A
• TGV
– Based on symbolic ioconf
– LOTOS, SDL, UML
– http://www.irisa.fr/pampa/VALIDATION/TGV/TGV.html