1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven,...

83
1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Quasimodo

Transcript of 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven,...

Page 1: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

1

Model-Based Testing

and Test-Based Modelling

Jan Tretmans

Embedded Systems Institute, Eindhoven, NL

and Radboud University, Nijmegen, NL

Quasimodo

Page 2: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

2

Overview

1. Model-Based Testing

2. Model-Based Testing with Labelled Transition Systems

3. Model-Based Testing: A Wireless Sensor Network Node

4. Test-Based Modelling

Page 3: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

3

Software Testing

Page 4: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

4

checking or measuring

some quality characteristics

of an executing object

by performing experiments

in a controlled way

w.r.t. a specificationtester

specificationSUT

System Under Test

(Software) Testing

Page 5: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

5

Sorts of Testing

unit

integration

system

efficiency

maintainability

functionality

white box black box

phases

accessibility

aspects

usability

reliability

module

portability

Page 6: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

6

But also:

• ad-hoc, manual, error-prone

• hardly theory / research

• no attention in curricula

• not cool :

“if you’re a bad programmer

you might be a tester”

Testing is:

• important

• much practiced

• 30-50% of project effort

• expensive

• time critical

• not constructive

(but sadistic?)Attitude is changing:• more awareness• more professional

Paradox of Software Testing

Page 7: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

7

Trends in Software Development• Increasing complexity

• more functions, more interactions, more options and parameters

• Increasing size• building new systems from scratch is not possible anymore• integration of legacy-, outsourced-, off-the shelf components

• Blurring boundaries between systems• more, and more complex interactions between systems• systems dynamically depend on other systems, systems of systems

• Blurring boundaries in time• requirements analysis, specification, implementation, testing,

installation, maintenance overlap• more different versions and configurations

• What is a failure ?

Testing Challenges

Page 8: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

8

Models

Page 9: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

9

Formal Models?coin

?button

!alarm ?button

!coffee

modelSelected

workingConfiguration

noModelSelected

validConfiguration

addComponent(slot, component)_________________________

send mopdelDB: findComponent()send slot:bind()

removeComponent(slot)_________________________

send slot:unbind()

addComponent(slot, component)_________________________

send Component_DB: get_component()send slot:bind

deselectModel()selectModel(model)_________________

send modelDB: getModel(modelID,this)

removeComponent(slot)_________________________

send slot:unbind()

isLegalConfiguration()[legalConfig = true]

(Klaas Smit)

Page 10: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

10

Model-Based Testing

Page 11: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

11

SUT

System Under Testpass fail

Developments in Testing 1

1. Manual testing

Page 12: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

12

SUT

pass fail

test execution

TTCNTTCNtestcases

1. Manual testing

2. Scripted testing

Developments in Testing 2

Page 13: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

13

SUT

pass fail

test execution

1. Manual testing

2. Scripted testing

3. High-level

scripted testing

Developments in Testing 3

high-level

test notation

Page 14: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

14

system

model

SUT

TTCNTTCNTestcases

pass fail

model-basedtest

generation

test execution

1. Manual testing

2. Scripted testing

3. High-level

scripted testing

4. Model-based

testing

Developments in Testing 4

Page 15: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

15

Model-Based . . . . .

Verification, Validation, Testing, . . . . .

Page 16: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

16

Validation, Verification, and Testing

modelproperties

SUT

ideasideas

concreterealizations

ideaswishes

abstractmodels,math

validation

testing

verification

testing

validation

Page 17: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

17

formal world

concrete world

Verification is only as good as the validity of the model on

which it is based

Verification is only as good as the validity of the model on

which it is based

Verification and Testing

Model-based verification :• formal manipulation• prove properties• performed on model

Model-based testing :• experimentation• show error• concrete system

Testing can only show the presence of errors, not their

absence

Testing can only show the presence of errors, not their

absence

Page 18: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

18

Code Generation from a Model

A model is more (less)

than code generation:

• views

• abstraction

• testing of aspects

• verification and validation

of aspects

met

Page 19: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

19

Model-Based Testing

with Labelled Transition Systems

Page 20: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

20

system

model

SUT

TTCNTTCNTestcases

pass fail

model-basedtest

generation

test execution

Model-Based Testing

Page 21: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

21

MBT with Labelled Transition Systems

LTS

model

SUT behaving as

input-enabled LTS

TTCNTTCNTest

cases

pass fail

LTStest

execution

iocotest

generation

input/outputconformance

ioco

set ofLTS tests

Page 22: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

22

Models: Labelled Transition Systems

states

output actions

transitions

initial state

? = input! = output

?coin

?button

!alarm ?button

!coffee

Labelled Transition System: S, LI, LU, T, s0

input actions

Page 23: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

23

test case

model ! coin

! button

?alarm

?coffee ---

pass

specificationmodel

Models: Generation of Test Cases

?coin

?button

!alarm ?button

!coffee

fail fail

Page 24: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

24

specificationmodel

Models: Generation of Test Cases

?coin

?button

!alarm ?button

!coffee

test case

model ! button

! coin

? alarm

? coffee ---

fail pass fail

Page 25: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

25

p p = !x LU {} . p !x

out ( P ) = { !x LU | p !x , pP } { | p p, pP }

Straces ( s ) = { ( L {} )* | s }

p after = { p’ | p p’ }

Conformance: ioco

i ioco s =def Straces (s) : out (i after ) out (s after )

Page 26: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

26

i ioco s =def Straces (s) : out (i after ) out (s after )

Intuition:

i ioco-conforms to s, iff

• if i produces output x after trace , then s can produce x after

• if i cannot produce any output after trace ,

then s cannot produce any output after ( quiescence )

Conformance: ioco

Page 27: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

27

!coffee

?dime

?quart

?dime?quart

?dime?quart

?dime

!choc

?quart

!tea

!coffee

?dime

!tea

specificationmodel

Example: ioco

ioco

ioco

ioco

ioco

?dime

!coffee

?dime

!choc

?dime

!tea

Page 28: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

28

? x (x >= 0)

! y

(|yxy–x| < ε)

specificationmodel

! x

? x (x < 0)

? x (x >= 0)

SUT models

? x

LTS and ioco allow:

• non-determinism

• under-specification

• the specification of properties

rather than construction

Example: ioco

! -x

? x (x < 0)

? x (x >= 0)

? x

!error

Page 29: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

29

out (i after ?dub.?dub) = out (s after ?dub.?dub) = { !tea, !coffee }

i ioco s

s ioco i

out (i after ?dub..?dub) = { !coffee } out (s after ?dub..?dub) = { !tea, !coffee }

i ioco s =def Straces (s) : out (i after ) out (s after )

i

?dub

?dub

?dub ?dub

!tea

?dub

?dub

!coffee

?dub

s

!coffee

?dub

?dub

?dub ?dub

!tea

?dub

?dub

?dub

?dub

!tea

Page 30: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

30

Test Case

– ‘quiescence’ label

– tree-structured– finite, deterministic– final states pass and fail

– from each state pass, fail :• either one input !a

• or all outputs ?x and

!dub

!kwart

?tea

?coffee?tea

!dub

failfail

test case = labelled transition systemfailfail

?coffee?tea

failpass

?coffee?tea

failfail

?coffee?tea

?coffee

pass failpass

Page 31: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

31

Algorithm to generate a test case t(S)

from a transition system state set S, with S ( initially S = s0 after ).Apply the following steps recursively, non-deterministically:

1 end test case

pass

2 supply input !a

!a

t ( S after ?a )

Test Generation Algorithm: ioco

allowed outputs (or ): !x out ( S )

forbidden outputs (or ): !y out ( S )

3 observe all outputs

fail

t ( S after !x )

fail

allowed outputsforbidden outputs?y

?x

fail

t ( S after !x )

fail

allowed outputsforbidden outputs

?y ?x

Page 32: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

32

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

Page 33: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

33

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

Page 34: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

34

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

Page 35: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

35

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

!dime

Page 36: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

36

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

!dime ?coffee

?tea

fail fail

Page 37: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

37

?coffee

fail

?tea

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

!dime ?coffee

?tea

fail fail

pass

Page 38: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

38

Example: ioco Test Generation

specification

?dime

!coffee

?dime

test

!dime

?coffee ?tea

passfail fail

?coffee

?tea

fail fail ?coffee

?tea

passfail

Page 39: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

39

Test Result Analysis: Completeness

For every test t

generated with the ioco test generation algorithm we have:

• Soundness :

t will never fail with a correct implementation

i ioco s implies i passes t

• Exhaustiveness :

each incorrect implementation can be detected

with a generated test t

i ioco s implies t : i fails t

Page 40: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

40

LTS

model

SUT behaving as

input-enabled LTS

TTCNTTCNTest

cases

pass fail

LTStest

execution

iocotest

generation

input/outputconformance

ioco

set ofLTS tests

SUT passes tests

SUT ioco model

exhaustivesound

Completeness of MBT with ioco

Page 41: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

41

Model-Based Testing

More Theory

Page 42: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

42

? ?

S1 S2 e E . obs ( e, S1 ) = obs (e, S2 )

Testing Equivalences

S1 S2S1 S2

environment e environment e

Page 43: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

43

Test assumption :

SUT . mSUT MODELS .

t TEST . SUT passes t mSUT passes t

SUT mSUT

test t test t

MBT: Test Assumption

Page 44: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

44

s LTS

SUT

i ioco s

testtool

gen : LTS (TTS)

t SUT

SUT passes gen(s)

SUT comforms to s

soundexhaustive

Prove soundness and exhaustiveness:

mIOTS .

( tgen(s) . m passes t )

m ioco s

Test assumption :

SUTIMP . mSUT IOTS . tTTS .

SUT passes t mSUT passes t

Soundness and Completeness

pass fail

Page 45: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

45

SUT passes Ts def t Ts . SUT passes t

test hypothesis: t TEST . SUT passes t mSUT passes t

prove: m MOD. ( t Ts . m passes t ) m imp s

SUT passes Ts SUT conforms to s ?

define : SUT conforms to s iff mSUT imp s

SUT conforms to s

mSUT imp s

t Ts . mSUT passes t

t Ts . SUT passes t

SUT passes Ts

MBT : Completeness

Page 46: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

46

Genealogy of ioco

Labelled Transition SystemsLabelled Transition Systems

IOTS ( IOA, IA, IOLTS )

IOTS ( IOA, IA, IOLTS )

Testing Equivalences(Preorders)

Testing Equivalences(Preorders)

Refusal Equivalence(Preorder)

Refusal Equivalence(Preorder)

Canonical Testerconf

Canonical Testerconf Quiescent Trace PreorderQuiescent Trace Preorder

Repetitive QuiescentTrace Preorder

(Suspension Preorder)

Repetitive QuiescentTrace Preorder

(Suspension Preorder)

iocoioco

Trace PreorderTrace Preorder

Page 47: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

47

Variations on a Theme• i ioco s Straces(s) : out ( i after ) out ( s after )• i ior s ( L {} )* : out ( i after ) out ( s after )• i ioconf s traces(s) : out ( i after ) out ( s after )• i iocoF s F : out ( i after ) out ( s after )• i uioco s Utraces(s) : out ( i after ) out ( s after )• i mioco s multi-channel ioco• i wioco s non-input-enabled ioco• i eco e environmental conformance• i sioco s symbolic ioco• i (r)tioco s (real) timed tioco (Aalborg, Twente, Grenoble, Bordeaux,..... )

• i rioco s refinement ioco• i hioco s hybrid ioco• i qioco s quantified ioco• i poco s partially observable game ioco• i stiocoD s real time and symbolic data• . . . . . .

Page 48: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

48

Model-Based Testing :

There is Nothing More Practical than a Good Theory

• Arguing about validity of test cases

and correctness of test generation algorithms

• Explicit insight in what has been tested, and what not

• Use of complementary validation techniques: model checking, theorem

proving, static analysis, runtime verification, . . . . .

• Implementation relations for nondeterministic, concurrent,

partially specified, loose specifications

• Comparison of MBT approaches and error detection capabilities

Page 49: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

49

Test Selection

in Model-Based Testing

Page 50: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Test Selection

• Exhaustiveness never achieved in practice

• Test selection to achieve confidencein quality of tested product– select best test cases capable of detecting failures– measure to what extent testing was exhaustive

• Optimization problem

best possible testing within cost/time constraints

50

Page 51: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Test Selection: Approaches

1. random

2. domain / application specific: test purposes, test goals, …

3. model / code based: coverage

– usually structure based

51

test: a! x?

a? x!

a?x!

a? x!

100% 50%transition coverage

Page 52: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Test Selection: Semantic Coverage

52

implementations

correct implementations:

CS = { i | i ioco s }

passing implementations

PT = { i | i passes T }

measure for test quality:

area PT \ CS

FT

PT

CS

S

S’

weaker model s’:

{ i | i ioco s } { i | i ioco s’ }

Page 53: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

implementations

Test Selection: Lattice of Specifications

53

s1 is stronger than s2

s1 s2

{ i | i ioco s1 } { i | i ioco s2 }

CS1

S1

S2

if specs are input-enabledthen ioco is preorderthen ioco`

S3

ST ST

º top elementº allows any impl. chaos

LI ?

Lu !

Page 54: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Test Selection by Weaker Specification

54

but?on!

but? off!

but?on! off!

? x(x >= 0)

! y

(|yxy–x| < ε)

?x(0<x<10)

! y

(|yxy–x| < 2ε)

LI ?

Lu !

chaos

Page 55: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

55

Model-Based Testing

A Wireless Sensor Network Node

Page 56: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

56

warehouses:sense &control

tracingproducts:

actievelabels

trains:seat

reservation

health care: on-body networks

Wireless Sensor Networks

Page 57: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Myrianed: Wireless Sensor Network

RF ANTENNA

RF TRANCEIVER

(NORDIC SEMI)CPU

(ATMEL XMEGA128)

I/O INTERFACES

Page 58: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

58

• Communication inspiredon biology and human interaction

• Epidemic communication

• Analogy: spreading arumor or a virus

• MYRIANED “GOSSIP” protocol

• RF broadcast (2.4 Ghz ISM)

Myrianed: a WSN with Gossiping

Page 59: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

59

WSN: Typical Test

Put WSN nodes together:

end-to-end testing

Test all WSN nodes together,

i.e. test the Network

• provide inputs to network

• observe outputs from network

Page 60: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

60

WSN: Model-Based Conformance Test

Model-based testing of a single node:

• protocol conformance test

of the gMAC protocol

• according to ISO 9646

• local test method

• time is important in gMAC:

real-time model-based testing

Page 61: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

61

WSN Node in Protocol Layers

node 1

Application Layer

gMAC Layer

Radio Layer

Application Layer

gMAC Layer

Radio Layer

node 2

Application Layer

gMAC Layer

Radio Layer

node 3

Medium Layer

applicationinterface

radiointerface

Upper Tester

Lower Tester

Page 62: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

62

Local Test Method

applicationinterface

radiointerface

Upper Tester

Lower Tester

clocktick

GMAC layer

Approach:• only software, on host• simulated, discrete time

if(gMacFrame.currentSlotNumber > gMacFrame.lastFrameSlot) { gMacFrame.currentSlotNumber = 0; gMacFrame.syncState = gMacNextFrame.syncState; if (semaphore.appBusy == 1) {

mcTimerSet(SLOT_TIME); mcPanic(MC_FAULT_APPLICATION); return; }

Hardware

Software

Page 63: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

63

WSN: Test Architecture

Upper Tester

Lower Tester

GMAC layer: Software

Model-BasedTest Tool:

• TorXakis• JTorX• Uppaal-Tron

sockets

Adapter

• transform messages

• synchronize simulated time

sockets

Page 64: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

64

Models

modelSelected

workingConfiguration

noModelSelected

validConfiguration

addComponent(slot, component)_________________________

send mopdelDB: findComponent()send slot:bind()

removeComponent(slot)_________________________

send slot:unbind()

addComponent(slot, component)_________________________

send Component_DB: get_component()send slot:bind

deselectModel()selectModel(model)_________________

send modelDB: getModel(modelID,this)

removeComponent(slot)_________________________

send slot:unbind()

isLegalConfiguration()[legalConfig = true]

(Klaas Smit)

Page 65: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

65

system

model

SUT

TTCNTTCNTestcases

pass fail

model-basedtest

generation

test execution

Model-Based Testing

Page 66: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

SUT

66

TTCNTTCNTest

cases

model-basedtest

generation

WSN: Model-Based Testing

system

model

MBT

tool

Ctest

adapter

pass fail

test runs

WSN software on

PC

(vague) descriptions

guruad-hoc model

learning

Page 67: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

SUT

67

TTCNTTCNTest

cases

model-basedtest

generation

WSN: Test-Based Modeling

system

model

Uppaal-Tron

TorXakis

JTorX

adapter

pass fail

test runs

WSN software on

PC

???Make a model

from observations

made during testing

Page 68: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

68

Test-Based Modelling

Page 69: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Model-Based Testing

• IF there exists a model

THEN automatic generation of tests

69

TRUE

FALSE

• No models, or models difficult to obtain– complex, designers make no models, evolving– legacy, third party, outsourced, reuse, no documentation

Page 70: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

test execution

70

system

model

SUT

TTCNTTCNTestcases

model-based test

generationalgorithm

Model-Based Testing

Page 71: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

71

system

model

SUT

TTCNTTCNTestcases

learningalgorithm

test execution

Test-Based Modelling

Learninga model of SUT behaviourfrom observationsmade during test

• black-box reverse engineering

• test-based modelling

• automata learning

• observation-based modelling

• behaviour capture and testactive passive

Page 72: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

72

Validation, Verification, and Testing

modelproperties

SUT

ideasideas

concreterealizations

ideaswishes

abstractmodels,math

validation

learning

Page 73: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

73

Empirical Cycle

model

theoryphenomenon

predict

validate

model world physical world

Page 74: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

MBT and TBM

74

improveSUT

SUTmodel

MBT

conforming

yes

no

improvemodel

no

satisfied

more tests

yes

no

refinemodel

no

model world physical world

Page 75: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Basic MBT process:

1. make model

2. take SUT

3. generate tests

4. execute tests

5. assign verdict

is only decision process

75

MBT and TBM But MBT is also

1. SUT repair

2. model repair3. improve MBT: more tests

4. improve MBT: better model

until satisfied

iterative and

incremental process

agile mbtstarting point:1. SUT2. initial model3. or no model at all:

learning model from scratchby improving and refining

until satisfied

Satisfaction:• MBT: sufficient confidence

in correctness of SUT• TBM: sufficient confidence

in preciseness of model

Page 76: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

LI ?

Lu !

chaos

Learning: Precision

76

measure forlearning precision:( A \ B ) / A

S : precise, expensive : not precise, cheap

implementations

A

B

S’’

S’

S

SUT

Page 77: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

implementations

Learning: Lattice of Models

77

s1 is stronger than s2

s1 s2

{ i | i ioco s1 } { i | i ioco s2 }

CS1

S1

S2

if specs are input-enabledthen ioco is preorderthen ioco`

S3

ST

ST

chaos º model for any

SUT

most precise modelis testing equivalent to SUT

Page 78: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Refining Learned Models

78

but?on!

but? off!

but?on! off!

? x(x >= 0)

! y

(|yxy–x| < ε)

?x(0<x<10)

! y

(|yxy–x| < 2ε)

LI ?

Lu !

chaos

Page 79: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Refining Learned Models

79

but?on!

but? off!

but?on! off!

? x(x >= 0)

! y

(|yxy–x| < ε)

?x(0<x<10)

! y

(|yxy–x| < 2ε)

LI ?

Lu !

chaos

MBT and TBM:

two sides of same coin

Page 80: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Test-Based Modelling

• Algorithms, Active:– D. Angluin (1987) :

Learning regular sets from queries and counter-examples– LearnLib: Adaption of Angluin for FSM - Tool

• searching for unique, precise model– T. Willemse (2007) :

TBM – ioco-based Test-Based Modelling • approximation via n-bounded ioco

• Algorithms, Passive:– process mining: ProM - many algorithms and tool

• model generation from set of traces– Use as complete model, or as starting point for active testing

80

Page 81: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

Wireless Sensor Network:Passive Learningwith ProM

81

Page 82: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

TBM: Use of Learned Models

• No use for testing of SUT from which it was learned

• But for

– understanding, communication

– analysis, simulation, model-checking

– regression testing

– testing of re-implemented or re-factored system

– legacy replacement

– testing wrt. a reference implementation

82

Page 83: 1 Model-Based Testing and Test-Based Modelling Jan Tretmans Embedded Systems Institute, Eindhoven, NL and Radboud University, Nijmegen, NL Q uasimodo.

83

Thank You !