Formal Specification and Testing of Model Transformations Manuel W - - PowerPoint PPT Presentation

formal specification and testing of model transformations
SMART_READER_LITE
LIVE PREVIEW

Formal Specification and Testing of Model Transformations Manuel W - - PowerPoint PPT Presentation

Formal Specification and Testing of Model Transformations Manuel W im m er, Loli Burgueo, Lars Ham ann, Martin Gogolla, Antonio Vallecillo , Universidad de Mlaga/Univertt Bremen http://www.lcc.uma.es/~av Introduction Progress Bar MDE


slide-1
SLIDE 1

Formal Specification and Testing of Model Transformations

Manuel W im m er, Loli Burgueño, Lars Ham ann, Martin Gogolla, Antonio Vallecillo, Universidad de Málaga/Univertät Bremen

http://www.lcc.uma.es/~av

slide-2
SLIDE 2

Introduction

Progress Bar

slide-3
SLIDE 3

MDE

MDE is about formulating SE activities in terms of Models and Model Transform ations between them Models describe different views of the (same) system, at different levels of abstraction

Structural models, analysis models, behavioural models, run-time models, …

Model Transformations describe the relationships between these views

Refinement relations, development relations, abstraction relations, mapping relations, …

3 SFM 2012 Formal Specification and Testing of Model Transformations

slide-4
SLIDE 4

Model Transformation

A m odel transform ation is (1) The specification of the relationship between one set of source models and one set of output models (2) The process that generates such relationship

  • Krzysztof Czarnecki, Simon Helsen: “Feature-based survey of model transformation

approaches”. IBM Systems Journal 45(3): 621-646 (2006)

  • Davide di Ruscio, Romina Eramo, Alfonso Pierantonio: “Model Transformations”. Proc. of

SMF’12, LNCS 7320, 91-136, 2012.

SFM 2012 Formal Specification and Testing of Model Transformations 4

slide-5
SLIDE 5

Model Transformations

Although specified at a very high level of abstraction, m odel transform ations are becom ing very com plex as the complexity of the relations they are able to describe grows…

5 SFM 2012 Formal Specification and Testing of Model Transformations

slide-6
SLIDE 6

Model Transformation Challenges

6 SFM 2012 Formal Specification and Testing of Model Transformations

Chains of Transformations

Consider the MDA scenario: CIM -> PIM -> PSM -> Code

Higher Order Transformations

Transformations may produce transformations that may produce transformations …

Underspecified Metamodels

Consider the UML metamodel: many optional features, …

Com plexity of Input Models

Large graphs, combinatorial explosion how to combine model elements, …

No model transformation specifications exist

Is it possible to reuse an existing model transformation for a given scenario?

slide-7
SLIDE 7

7

Even very simple transformations may not be that simple!

SFM 2012 Formal Specification and Testing of Model Transformations

slide-8
SLIDE 8

Example 1

Persons to Families

8 SFM 2012 Formal Specification and Testing of Model Transformations

slide-9
SLIDE 9

Persons2Family Transformation in ATL

SFM 2012 Formal Specification and Testing of Model Transformations 9

slide-10
SLIDE 10

Persons2Family Transformation in ATL

10

This cannot be wrong!

SFM 2012 Formal Specification and Testing of Model Transformations

slide-11
SLIDE 11

Persons2Family Transformation in ATL

11

Have you tried this?

SFM 2012 Formal Specification and Testing of Model Transformations

slide-12
SLIDE 12

Not as easy as one might have thought

12

An internal error occurred during: "Launching Persons2Families". java.lang.ClassCastException:

  • rg.eclipse.m2m.atl.engine.emfvm.lib.OclUndefined cannot be cast to
  • rg.eclipse.m2m.atl.engine.emfvm.lib.HasFields

SFM 2012 Formal Specification and Testing of Model Transformations

slide-13
SLIDE 13

Example 2

Copy Transformation

13 ECMFA 2011 Formal Specification and Testing of Model Transformations

UniMM

Create a copy of a model by using a model transformation

slide-14
SLIDE 14

Copy Transformation in ATL

m odule Copier; create OUT : MM2 from I N : MM1; rule Student { from s1 : MM1!Student to s2 : MM2!Student ( name <- u1.name ) } rule Teacher { from t1 : MM1!Teacher to t2 : MM2!Teacher ( name <- u1.name ) } rule Tutor { from t1 : MM1!Tutor to t2 : MM2!Tutor ( name <- u1.name ) }

14 SFM 2012 Formal Specification and Testing of Model Transformations

It is so simple - this cannot be wrong!

slide-15
SLIDE 15

Let us try it out!

15 SFM 2012 Formal Specification and Testing of Model Transformations

S1 : Student name = Xavi T1 : Teacher name = Alonso S1 : Student name = Xavi T1 : Teacher name = Alonso I nput Model Output Model

slide-16
SLIDE 16

Not as easy as one might have thought

16

An internal error occurred during: "Launching Copier".

  • rg.eclipse.m2m.atl.engine.emfvm.VMException: Trying to

register several rules as default for element DynamicEObjectImpl@T2 (eClass: EClassImpl@1cebdb2a (name: Tutor) …) : Student and Teacher

SFM 2012 Formal Specification and Testing of Model Transformations

S1 : Student name = Xavi T1 : Teacher name = Alonso T2 : TUTOR name = Iniesta I nput Model

slide-17
SLIDE 17

Example 3

Class Diagrams 2 Relations Transformation

17 ECMFA 2011 Formal Specification and Testing of Model Transformations

Class Diagram Relations

Reuse a transformation that implements the “One Table per Class” strategy. But no other documentation is available…

Schema Table

tables *

Column

type : String * columns

Package

classes * attributes * general

Attribute

type : String

Class

*

Class2Relations.atl

Source MM Target MM

slide-18
SLIDE 18

Not as easy as one might have thought

18 ECMFA 2011 Formal Specification and Testing of Model Transformations

Input Model Output Model Person id : String {size < 10} Student /id : String {size < 7} Person id … Student id … id

It turns out that derived attributes are not properly treated by the transformation, i.e., invalid target models are produced

slide-19
SLIDE 19

Specification and Testing of Model Transformations

slide-20
SLIDE 20

Some questions

What is testing? What should be tested on a model transformation? Should all properties to the tested treated equally? Which are those properties? Should we always aim for the best?

SFM 2012 Formal Specification and Testing of Model Transformations 20

slide-21
SLIDE 21

MT Testing Landscape

21 Formal Specification and Testing of Model Transformations

Plethora of testing approaches for MTs ranging from

full verification to lightw eight certification

Tw o classification dim ensions Level on which they are defined

General ones are usable for all transformations Specific ones have to be defined for each transformation

Related to syntax or sem antics

“Syntactic” properties are checked on specifications

Conformance (G), Correct output models (S)

“Semantic” properties are checked on executions

E.g., Rule confluence (G), termination (G), preservation of some properties (S), etc.

SFM 2012

slide-22
SLIDE 22

General Transformation Properties

22 SFM 2012 Formal Specification and Testing of Model Transformations

TMM MT I m plem entation TM

ATL Metam odel ATL Model

Ex( TM)

Syntactic Properties Sem antic Properties

SoM TaM Ex( SoM) Ex( TaM)

slide-23
SLIDE 23

Specific Transformation Properties

23 SFM 2012 Formal Specification and Testing of Model Transformations

TMM MT I m plem entation TM Ex( TM)

Syntactic Properties Sem antic Properties

SoM TaM Ex( SoM) Ex( TaM) SMM SM Ex( SM)

describes > < fulfills

MT Specification

slide-24
SLIDE 24

Defining Specific, Syntactical Properties

24 SFM 2012 Formal Specification and Testing of Model Transformations

Model Level

Complete Models Model Fragments

Metam odel Level

Graphical Constraint Languages Textual Constraint Languages

slide-25
SLIDE 25

Com plete Models Model Fragm ents

Model Level Specification

25 SFM 2012 Formal Specification and Testing of Model Transformations

Ex( TM) SoM TaM TaM

=

Ex( TM) SoM TaM TaM Expected Target Model Actual Target Model Expected Target Model Actual Target Model Pros: Modeling Languages are enough to specify test cases Cons: Have to be defined for each new test source model

slide-26
SLIDE 26

Graphical Constraint Languages Textual Constraint Language

Metamodel Level Specification

26 SFM 2012 Formal Specification and Testing of Model Transformations

P(Mother2Female)

Families m:Member fam:Family mother f:Female

firstName=X lastName=Y fullName=X.concat(“_”).concat(Y)

Persons context MFDS inv Src_Trg_Mother2Female: Female.allInstances−> forAll( f | Family.allInstances−> exists ( fam | fam.mother.firstName.concat(’␣’).concat(fam.lastName) = f.fullName ) )

slide-27
SLIDE 27

Specifying and Testing Model Transformations: The Tracts Approach

slide-28
SLIDE 28

Motivation for Tracts

In general it is very difficult and expensive (time and computational complexity-wise) to validate in full the correctness of a model transformation (even the simplest ones). We propose a cost-effective MT testing approach based

  • n the concept of Tract, which is a generalization of the

concept of Model Transformation Contract.

28 SFM 2012 Formal Specification and Testing of Model Transformations

slide-29
SLIDE 29

Contracts as Specifications

29 SFM 2012 Formal Specification and Testing of Model Transformations

Transform ation I m plem entation Transform ation Specification describes fulfills

Specification: A document that specifies, in a complete, precise, verifiable manner, the requirements, design, behavior, or other characteristics of a system or component…

[IEEE Standard Computer Dictionary]

Implementation: (1) The process of translating a design into hardware components, software components, or both. (2) The result of the process in (1)

[IEEE Standard Computer Dictionary]

What? How? vs. Tracts ATL, ETL, QVT-R, QVT-O, RubyTL, TGG, GT, …

slide-30
SLIDE 30

Contracts as Filters

30 SFM 2012 Formal Specification and Testing of Model Transformations

Transform ation I m plem entation Transform ation Specification

Valid?

I nput Model Output Model

slide-31
SLIDE 31

Contracts as Oracles

31 SFM 2012 Formal Specification and Testing of Model Transformations

Transform ation I m plem entation Transform ation Specification

Valid?

I nput Model Output Model

slide-32
SLIDE 32

Contracts as Implementation

32 SFM 2012 Formal Specification and Testing of Model Transformations

Transform ation I m plem entation Transform ation Specification I nput Model Output Model

T

slide-33
SLIDE 33

Tracts Tracts

A Tract defines

a set of constraints on the source and target m etam odels, a set of source-target constraints, and a tract test suite (a collection of source models satisfying the source constraints)

33 SFM 2012 Formal Specification and Testing of Model Transformations

slide-34
SLIDE 34

34 Formal Specification and Testing of Model Transformations

Set-Theory based View on Tracts Tracts

SFM 2012

slide-35
SLIDE 35

35 Formal Specification and Testing of Model Transformations

Set-Theory based View on Tracts Tracts

SFM 2012

slide-36
SLIDE 36

The elements of a Tract

SFM 2012 36 Formal Specification and Testing of Model Transformations

slide-37
SLIDE 37

Black-box testing of MTs

For each tract

Input test suite models are automatically generated using ASSL Input models are transformed into output models by the transformation under test The results are checked with the USE tool against the constraints defined for the transformation

Different tracts are defined for every transformation

Each one defines either a use case or a special condition

  • r a negative test case

37 SFM 2012 Formal Specification and Testing of Model Transformations

slide-38
SLIDE 38

Source Metam odel: Fam ily Target Metam odel: Person

Tracts for the Families 2 Persons MT

SFM 2012 Formal Specification and Testing of Model Transformations 38

slide-39
SLIDE 39

Tract: Mem bers only - interested in families consisting

  • nly of members

Precondition Test Source Model

Example of Tract: “Members only”

SFM 2012 Formal Specification and Testing of Model Transformations 39

slide-40
SLIDE 40

Example of Tract: “Members only”

SFM 2012 40 Formal Specification and Testing of Model Transformations

Generation of source models is done by means of ASSL (A Snapshot Sequence Language) ASSL allows to generate Object Diagrams for Class Diagrams ASSL is an imperative programming language with features for randomly choosing attribute values or association ends ASSL supports backtracking for finding object diagrams with particular properties

slide-41
SLIDE 41

ASSL Code for I nput Model Generation

Example of Tract: “Members only”

SFM 2012 Formal Specification and Testing of Model Transformations 41

slide-42
SLIDE 42

Tract: Mem bers only - interested in families consisting

  • nly of members

Postcondition Transformation Result

Example of Tract: “Members only”

SFM 2012 Formal Specification and Testing of Model Transformations 42

slide-43
SLIDE 43

I ssue in Transform ation

Example of Tract: “Members only”

SFM 2012 Formal Specification and Testing of Model Transformations 43

slide-44
SLIDE 44

Possible Solution: Stronger Precondition Other Solutions?

Example of Tract: “Members only”

SFM 2012 Formal Specification and Testing of Model Transformations 44

slide-45
SLIDE 45

Source Metam odel: Person Target Metam odel: Fam ily

Tracts for the Person 2 Family MT

SFM 2012 Formal Specification and Testing of Model Transformations 45

slide-46
SLIDE 46

Tract: m fds - interested in families consisting of one mother, father, daughter, and son

Example of Tract: “mfds”

SFM 2012 Formal Specification and Testing of Model Transformations 46

mother(m)-father(f)-daughter(d)-son(s)

slide-47
SLIDE 47

Src_Constraints Trg_Constraint Src_Trg_Constraint

Tract constraints (1/2)

SFM 2012 47 Formal Specification and Testing of Model Transformations

Should we introduce Family.size = Person.size/4?

slide-48
SLIDE 48

Tract constraints (2/2)

SFM 2012 48 Formal Specification and Testing of Model Transformations

Src_Trg_Constraint

slide-49
SLIDE 49

SFM 2012 49 Formal Specification and Testing of Model Transformations

Mdfs Tract

slide-50
SLIDE 50

ASSL to generate the input models

SFM 2012 Formal Specification and Testing of Model Transformations 50

slide-51
SLIDE 51

Generation of negative cases

SFM 2012 Formal Specification and Testing of Model Transformations 51

slide-52
SLIDE 52

Kinds of problems found

Errors in the transformation code Errors in the Tract specification Source-target semantic gap/mismatches

Unmarried couples, families with a single father or mother, married couples whose members have maintained their last names,…cannot be transformed.

SFM 2012 Formal Specification and Testing of Model Transformations 52

slide-53
SLIDE 53

Summary

Pros:

Modular: Allows partitioning the input space into smaller, focused behavioural units Specific: allows defining specific tests for the input models Black-box: Tests the MT as-is, independent from implementation Cost-effective: Small tests are easy to define and to check

Cons:

It does not guarantee full correctness (“certification” vs. full validation) Completeness and coverage of input models is not guaranteed Tracts are not easy to specify in general

SFM 2012 Formal Specification and Testing of Model Transformations 53

slide-54
SLIDE 54

Tracts By-Example

slide-55
SLIDE 55

Source MM: State Machine Target MM: Lookup Table We want only one lookup table

Where each entry is an event of the source model

Tract exam ple: SM2 T ( StateMachine 2 LookUpTable)

slide-56
SLIDE 56

SM2T: More restrictions

Source MM: State Machine Target MM: Lookup Table Multiplicity constraints Uniqueness on names of the state machines Uniqueness on names of states within the same machine

SFM 2012 Formal Specification and Testing of Model Transformations 56

slide-57
SLIDE 57

SM2T: More restrictions

Source MM: State Machine Target MM: Lookup Table Multiplicity constraints Uniqueness on names of the State Machines Uniqueness on names of states within the same machine

SFM 2012 Formal Specification and Testing of Model Transformations 57

slide-58
SLIDE 58

Tracts for SM2T

Six Tracts to start w ith

slide-59
SLIDE 59

Tracts for SM2T

slide-60
SLIDE 60

Tracts for SM2T

slide-61
SLIDE 61

Tract example: Constraints

Tract for SM2 : Src_Constraints Trg_Constraint

slide-62
SLIDE 62

Tract example: Constraints

Tract for SM2 : Src_Trg_Constraint

T

Event Change sm from State toState x SM2 A B LookUpTable

slide-63
SLIDE 63

ASSL Code for SM2

slide-64
SLIDE 64

Exercise 1: Specify and implement

Copy Transformation

64 ECMFA 2011 Formal Specification and Testing of Model Transformations

UniMM

Create a copy of a model by using a model transformation a) What tracts do we need? b) Identify use cases c) Write the ATL transformation d) Prove its correctness

slide-65
SLIDE 65

Exercise2: nSM2fSM

nSM2fSM: Translate a nested state machine into a flat state machine Implementation: In-place Transformation Specification: What Tracts do we need?

S1 S2 S3 S2 .1 S2 .2

a c b d

S1 S3 S2 .1 S2 .2

a c b d b d

slide-66
SLIDE 66

Tractable Model Transformation Typing

slide-67
SLIDE 67

Motivation for MT Typing

SFM 2012 Formal Specification and Testing of Model Transformations 67

MDE tackles complexity of large systems, but this requires to m odel-in-the-large

This results in m egam odels

Increasing need for precise and abstract mechanisms

Reason about the designed systems Test individual components

Assigning types to models and model transformations and arrange them in type hierarchies Light-weight approach to type model transformations using tracts

slide-68
SLIDE 68

[ISO/IEC 10746-2]

Subtype/supertype: A type A is a subtype of a type B, and B is a supertype of A, if every <X> which satisfies A also satisfies B. Type (of an <X>): A predicate characterizing a collection of <X>s.

Definitions: Type and Subtype/Supertype

slide-69
SLIDE 69

Typing models

Model types are needed fo describing the signature of model operations The type of a model is basically its metamodel We can talk about “subtyping” and “safe replaceability”

M’ extends M iff M’ contains all classes, attributes and relationships of M, and M’ imposes the same or weaker constraints than M

SFM 2012 Formal Specification and Testing of Model Transformations 69

slide-70
SLIDE 70

Typing Models (2/2)

CD_struct Package

classes * * general

Attribute

type : String

Class

*

CD_struct_behav Package

classes * * general

Attribute

type : String

Class

*

Operation

type : String

  • perations

* isAbstract : Boolean

slide-71
SLIDE 71

Typing MTs (1/2)

TL T

ATL Metam odel ATL Model

T T’ N N’ M M’

«conformsTo»

slide-72
SLIDE 72

To reason properly about subtype relationships between transformations, the behavioural type of a transformation must be considered But…

Typing model transformation as operations is difficult Type of any behavioral software artefact is complex; manipulating and reasoning about behavioural types expensive Current types capture full behaviour of the artefact independently from any context of use Traditionally requires heavyweight reasoning techniques and tools such as theorem provers

Typing MTs (2/2)

slide-73
SLIDE 73

Model Transformation Typing using Tracts

T

T ’ T ’ N N’ M M’ Legend:

M, M’ … Source MMs N, N’ … Target MMs T, T ‘ … T, T ‘ … Tracts

T T’

< fulfills < fulfills

slide-74
SLIDE 74

Model Transformation Typing by Example

slide-75
SLIDE 75

Model Transformation Typing by Example Three Transformations

slide-76
SLIDE 76

Model Transformation Typing: Relationships between Transformations

slide-77
SLIDE 77

Correctness of a MT implementation

check that a given transformation conforms to a tract, i.e., it conforms to a certain type

Safe substitutability of MTs; two step process:

first input models are automatically generated and then for each of these we can check whether the transformation fulfils the associated tract

I ncrem ental and system atic transformation development

extend source and target metamodels by subtyping through small increments accompanied by corresponding tracts including test suites; benefit: rapid and direct feedback provided

Declarative vs im perative tracts

  • nly the relationship between source and target elements can

be characterized; but tracts also be described in an operational way when including operations mapping source elements to target elements

Discussion

slide-78
SLIDE 78

Tool Support for Tracts

slide-79
SLIDE 79

Tracts Tool Support based on USE

SFM 2012 Formal Specification and Testing of Model Transformations 79

USE - The UML-based Specification Environm ent

Modeling of UML Class Diagrams and Object Diagrams Support for full OCL ASSL for generating Object Diagrams Powerful API for validating models

slide-80
SLIDE 80

SFM 2012 80 Formal Specification and Testing of Model Transformations

Metamodels as Class Diagrams

slide-81
SLIDE 81

SFM 2012 81 Formal Specification and Testing of Model Transformations

Models as Object Diagrams

slide-82
SLIDE 82

SFM 2012 82 Formal Specification and Testing of Model Transformations

Checking the Tracts

slide-83
SLIDE 83

Test ATL Model Transformations for EMF-based Models

Bridge EMF and USE

SFM 2012 Formal Specification and Testing of Model Transformations 83

slide-84
SLIDE 84

Tracts for EMF

http://atenea.lcc.uma.es/index.php/Main_Page/Resources/Tracts

SFM 2012 Formal Specification and Testing of Model Transformations 84

slide-85
SLIDE 85

Tracts for EMF

Tim e for a Tool Dem o!

SFM 2012 Formal Specification and Testing of Model Transformations 85

slide-86
SLIDE 86

The Future of Tracts

slide-87
SLIDE 87

Next steps

Incorporate existing works on the effective generation

  • f input test cases, oracles, test inputs coverage

Study tracts properties:

composability, subsumption, refinement,…

Tracts for bi-directional transformations Improve engineering aspects

Visual specification of tracts Diagnostics Improve tool support

Define libraries of tracts

87 SFM 2012 Formal Specification and Testing of Model Transformations

slide-88
SLIDE 88

Manuel W im m er, Loli Burgueño, Lars Ham ann, Martin Gogolla, Antonio Vallecillo, Universidad de Málaga/Univertät Bremen

http://www.lcc.uma.es/~av

Thanks!

100 % Completed!