From UML State-Machine Diagrams to Erlang Ake Fredlund, guez , - - PowerPoint PPT Presentation

from uml state machine diagrams to erlang
SMART_READER_LITE
LIVE PREVIEW

From UML State-Machine Diagrams to Erlang Ake Fredlund, guez , - - PowerPoint PPT Presentation

From UML State-Machine Diagrams to Erlang Ake Fredlund, guez , Lars- Ricardo J. Rodr Angel Herranz All wrongs reversed { rjrodriguez, lfredlund, aherranz } @fi.upm.es Universidad Polit ecnica de Madrid Madrid, Spain September


slide-1
SLIDE 1

From UML State-Machine Diagrams to Erlang

Ricardo J. Rodr´ ıguez, Lars-˚ Ake Fredlund, ´ Angel Herranz

All wrongs reversed

{rjrodriguez, lfredlund, aherranz}@fi.upm.es

Universidad Polit´ ecnica de Madrid Madrid, Spain

September 20th, 2013 XIII Jornadas sobre Programaci´

  • n y Lenguajes (PROLE)

Facultad de Inform´ atica, Universidad Complutense de Madrid

slide-2
SLIDE 2

Agenda

Outline

1

Motivation

2

A Transformation Approach

3

Related Work

4

Conclusions and Future Work

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 2 / 19

slide-3
SLIDE 3

Motivation

Outline

1

Motivation

2

A Transformation Approach

3

Related Work

4

Conclusions and Future Work

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 3 / 19

slide-4
SLIDE 4

Motivation

Motivation (I)

Software Development Life-Cycle

Phased involved for developing (and maintaining) software systems and code Deployment (production): what happens when faults (or changes) raise?

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 4 / 19

slide-5
SLIDE 5

Motivation

Motivation (I)

Software Development Life-Cycle

Phased involved for developing (and maintaining) software systems and code Deployment (production): what happens when faults (or changes) raise?

Were they initially taken into account? Otherwise → need to redesign

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 4 / 19

slide-6
SLIDE 6

Motivation

Motivation (I)

Software Development Life-Cycle

Phased involved for developing (and maintaining) software systems and code Deployment (production): what happens when faults (or changes) raise?

Were they initially taken into account? Otherwise → need to redesign

Model-Driven Engineering

Increase productivity, simplifying design Maximise compatibility between systems

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 4 / 19

slide-7
SLIDE 7

Motivation

Motivation (I)

Software Development Life-Cycle

Phased involved for developing (and maintaining) software systems and code Deployment (production): what happens when faults (or changes) raise?

Were they initially taken into account? Otherwise → need to redesign

Model-Driven Engineering

Increase productivity, simplifying design Maximise compatibility between systems

Verify correctness BEFORE deployment

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 4 / 19

slide-8
SLIDE 8

Motivation

Motivation (I)

Software Development Life-Cycle

Phased involved for developing (and maintaining) software systems and code Deployment (production): what happens when faults (or changes) raise?

Were they initially taken into account? Otherwise → need to redesign

Model-Driven Engineering

Increase productivity, simplifying design Maximise compatibility between systems

Verify correctness BEFORE deployment How?: Using model-checking

Proofs of correctness Counter-examples (why not correct)

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 4 / 19

slide-9
SLIDE 9

Motivation

Motivation (II)

We have mixed. . .

UML: standard de facto as modelling language

UML State Machines (UML-SMs): dynamic system behaviour Assumption: intercommunication through asynchronous channels

Erlang: functional and concurrent programming language

Native support for concurrency, distribution and fault tolerance Concurrency based on asynchronous message passing Widely used in the industry: T-Mobile, Ericsson, FB, WhatsApp. . .

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 5 / 19

slide-10
SLIDE 10

Motivation

Motivation (II)

We have mixed. . .

UML: standard de facto as modelling language

UML State Machines (UML-SMs): dynamic system behaviour Assumption: intercommunication through asynchronous channels

Erlang: functional and concurrent programming language

Native support for concurrency, distribution and fault tolerance Concurrency based on asynchronous message passing Widely used in the industry: T-Mobile, Ericsson, FB, WhatsApp. . .

Contributions

Minimise development time

Automatically generate Erlang code from UML-SMs

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 5 / 19

slide-11
SLIDE 11

Motivation

Motivation (II)

We have mixed. . .

UML: standard de facto as modelling language

UML State Machines (UML-SMs): dynamic system behaviour Assumption: intercommunication through asynchronous channels

Erlang: functional and concurrent programming language

Native support for concurrency, distribution and fault tolerance Concurrency based on asynchronous message passing Widely used in the industry: T-Mobile, Ericsson, FB, WhatsApp. . .

Contributions

Minimise development time

Automatically generate Erlang code from UML-SMs

Detect problems in early stages (save efforts and costs)

Apply Erlang-based model checking techniques into UML-SMs

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 5 / 19

slide-12
SLIDE 12

A Transformation Approach

Outline

1

Motivation

2

A Transformation Approach

3

Related Work

4

Conclusions and Future Work

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 6 / 19

slide-13
SLIDE 13

A Transformation Approach

A Transformation Approach: The Dining Philosophers (I)

Philosopher Fork

entry / p.acquired() acquire / defer BeingUsed Idle release acquire(p)

Please note: thinking time and fork grabbing order

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 7 / 19

slide-14
SLIDE 14

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-15
SLIDE 15

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-16
SLIDE 16

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end).

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-17
SLIDE 17

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end).

thinking(FL, FR) -> receive X -> thinking(FL, FR) after 1000 -> FL!{acquire, self()}, hungry(FL, FR) end.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-18
SLIDE 18

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end). thinking(FL, FR) -> ...

hungry(FL, FR) -> receive acquired -> FR!{acquire, self()}, waiting(FL, FR) end.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-19
SLIDE 19

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end). thinking(FL, FR) -> ... hungry(FL, FR) -> ...

waiting(FL, FR) -> receive acquired -> eating(FL, FR) end.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-20
SLIDE 20

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end). thinking(FL, FR) -> ... hungry(FL, FR) -> ... waiting(FL, FR) -> ...

eating(FL, FR) -> eatSpaghetti(), FL!release, FR!release, thinking(FL, FR).

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-21
SLIDE 21

A Transformation Approach

A Transformation Approach: The Dining Philosophers (II)

Philosopher

do / eatSpaghetti() exit / fL.release(); fR.release() Hungry Eating Waiting Thinking acquired / fR.acquire(self) [TOUT expired] / fL.acquire(self) acquired fL, fR do / setTimeout(1000)

P = {fL, fR} E = {acquired}

  • module(philosopher).
  • export([start/2]).

start(FL, FR) -> spawn(fun() -> thinking(FL, FR) end). thinking(FL, FR) -> ... hungry(FL, FR) -> ... waiting(FL, FR) -> ... eating(FL, FR) -> ...

A UML instance is an Erlang process

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 8 / 19

slide-22
SLIDE 22

A Transformation Approach

A Transformation Approach: The Dining Philosophers (III)

Fork

entry / p.acquired() acquire / defer BeingUsed Idle release acquire(p)

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 9 / 19

slide-23
SLIDE 23

A Transformation Approach

A Transformation Approach: The Dining Philosophers (III)

Fork

entry / p.acquired() acquire / defer BeingUsed Idle release acquire(p)

P = ∅ E = {acquire, release}

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 9 / 19

slide-24
SLIDE 24

A Transformation Approach

A Transformation Approach: The Dining Philosophers (III)

Fork

entry / p.acquired() acquire / defer BeingUsed Idle release acquire(p)

P = ∅ E = {acquire, release}

  • module(fork).
  • export([start/0]).

start() -> spawn(fun() -> idle() end).

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 9 / 19

slide-25
SLIDE 25

A Transformation Approach

A Transformation Approach: The Dining Philosophers (III)

Fork

entry / p.acquired() acquire / defer BeingUsed Idle release acquire(p)

P = ∅ E = {acquire, release}

  • module(fork).
  • export([start/0]).

start() -> spawn(fun() -> idle() end).

idle() -> receive {acquire, P} -> beingUsed(P); X -> idle() end.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 9 / 19

slide-26
SLIDE 26

A Transformation Approach

A Transformation Approach: The Dining Philosophers (III)

Fork

P = ∅ E = {acquire, release}

  • module(fork).
  • export([start/0]).

start() -> spawn(fun() -> idle() end). idle() -> ...

beingUsed(P) -> P!acquired(), receive release -> idle() end.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 9 / 19

slide-27
SLIDE 27

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-28
SLIDE 28

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

Assume that current state is BeingUsed, and acquire event is received

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-29
SLIDE 29

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

Assume that current state is BeingUsed, and acquire event is received

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-30
SLIDE 30

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

Assume that current state is BeingUsed, and acquire event is received acquire is received Something to do? acquire is received Something to do?

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-31
SLIDE 31

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

Assume that current state is BeingUsed, and acquire event is received acquire is received Something to do?

  • No. Do nothing.

acquire is received Something to do?

  • Yes. Defers it.

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-32
SLIDE 32

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Wait! Explain me about defer. . .

Assume that current state is BeingUsed, and acquire event is received acquire is received Something to do?

  • No. Do nothing.

Event has been discarded! acquire is received Something to do?

  • Yes. Defers it.

Event is (eventually) handled

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 10 / 19

slide-33
SLIDE 33

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Example system startup

run(N) -> Forks = lists:map (fun (_) -> fork:start() end , lists: lists:foreach (fun ({L,R}) -> philosopher:start(L, R) end , adjacen adjacent([])

  • > [];

adjacent([X|Xs]) -> lists:zip([X] ++ Xs, Xs ++ [X]).

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 11 / 19

slide-34
SLIDE 34

A Transformation Approach

A Transformation Approach: The Dining Philosophers (IV)

Example system startup

run(N) -> Forks = lists:map (fun (_) -> fork:start() end , lists: lists:foreach (fun ({L,R}) -> philosopher:start(L, R) end , adjacen adjacent([])

  • > [];

adjacent([X|Xs]) -> lists:zip([X] ++ Xs, Xs ++ [X]).

Using McErlang to verify correctness

> mce:start (#mce_opts{program=fun () -> dining:run(2) end , monitor=mce_mon_deadlock}). ... *** Monitor failed monitor error: deadlock

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 11 / 19

slide-35
SLIDE 35

A Transformation Approach

A Transformation Approach: Algorithm (VI)

Input data: UML-SM Output data: Erlang source code

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 12 / 19

slide-36
SLIDE 36

A Transformation Approach

A Transformation Approach: Algorithm (VI)

Input data: UML-SM Output data: Erlang source code

Algorithm steps (abstractedly)

1 Store parameters of initial transition (P) 2 Create the Erlang header (module, export, start) 3 Create a set of triggered events of current state (E) 4 Iterate for each state in the UML-SM 1 Convert entry, do activities to message passing 2 Special case: timeout activities 3 Iterate in the output transitions 1

Fill a receive Erlang skeleton properly

4 Convert exit activity to message passing

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 12 / 19

slide-37
SLIDE 37

Related Work

Outline

1

Motivation

2

A Transformation Approach

3

Related Work

4

Conclusions and Future Work

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 13 / 19

slide-38
SLIDE 38

Related Work

Related Work (I)

Automatic code generation (multi-threaded behaviour and asynchronous communication)

Translator compiler

C code from finite state machines with a synchronous semantics

PM-FORMS-03,AFLTY-ISORC-10

Aynchronous semantics with a state table to reacts to events

NT-SEA-03,KNNZ-ICSE-00

Design pattern forms implementing state machines

TKUY-ICRA-01

Java thread per state-chart and Java objects to represent event queues

KM-TOOLS-02

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 14 / 19

slide-39
SLIDE 39

Related Work

Related Work (I)

Automatic code generation (multi-threaded behaviour and asynchronous communication)

Translator compiler

C code from finite state machines with a synchronous semantics

PM-FORMS-03,AFLTY-ISORC-10

Aynchronous semantics with a state table to reacts to events

NT-SEA-03,KNNZ-ICSE-00

Design pattern forms implementing state machines

TKUY-ICRA-01

Java thread per state-chart and Java objects to represent event queues

KM-TOOLS-02

Interpreter to manage multi-threading and event queues → Erlang

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 14 / 19

slide-40
SLIDE 40

Related Work

Related Work (II)

Other model checkers

Branching time model-checking using JACK

GLM-HASE-99

Linear-time model checking using PROMELA

LMM-FAC-99

UML class diagrams, UML-SMs and UML Communication diagrams verified using Maude LTL

CEC-IJSEA-12

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 15 / 19

slide-41
SLIDE 41

Conclusions and Future Work

Outline

1

Motivation

2

A Transformation Approach

3

Related Work

4

Conclusions and Future Work

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 16 / 19

slide-42
SLIDE 42

Conclusions and Future Work

Conclusions and Future Work (I)

Conclusions

UML: standard as semi-formal modelling language

UML-SM: models system dynamics and its interaction

Modelling of concurrent and distributed systems

Erlang: functional language

Good support for concurrency and distribution

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 17 / 19

slide-43
SLIDE 43

Conclusions and Future Work

Conclusions and Future Work (I)

Conclusions

UML: standard as semi-formal modelling language

UML-SM: models system dynamics and its interaction

Modelling of concurrent and distributed systems

Erlang: functional language

Good support for concurrency and distribution

UML-SM → Erlang code

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 17 / 19

slide-44
SLIDE 44

Conclusions and Future Work

Conclusions and Future Work (I)

Conclusions

UML: standard as semi-formal modelling language

UML-SM: models system dynamics and its interaction

Modelling of concurrent and distributed systems

Erlang: functional language

Good support for concurrency and distribution

UML-SM → Erlang code

Contributions

Reduce development time

By automatically generating Erlang skeleton code

Enables validation of UML-SMs at an early development stage

Erlang-based model checking and testing techniques

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 17 / 19

slide-45
SLIDE 45

Conclusions and Future Work

Conclusions and Future Work (I)

Conclusions

UML: standard as semi-formal modelling language

UML-SM: models system dynamics and its interaction

Modelling of concurrent and distributed systems

Erlang: functional language

Good support for concurrency and distribution

UML-SM → Erlang code

Contributions

Reduce development time

By automatically generating Erlang skeleton code

Enables validation of UML-SMs at an early development stage

Erlang-based model checking and testing techniques

Also an alternative to Erlang code for “behaviour” pattern

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 17 / 19

slide-46
SLIDE 46

Conclusions and Future Work

Conclusions and Future Work (II)

Future Work

Extend to additional UML-SM constructs

Preemptive UML-SM activities Substates Entry, exit or alternative potins . . .

Apply to some real examples Tool support

Plugin for some UML CASE tool (e.g. Eclipse)

R.J. Rodr´ ıguez, L. Fredlund, A. Herranz From UML State-Machine Diagrams to Erlang PROLE 2013 18 / 19

slide-47
SLIDE 47

From UML State-Machine Diagrams to Erlang

Ricardo J. Rodr´ ıguez, Lars-˚ Ake Fredlund, ´ Angel Herranz

All wrongs reversed

{rjrodriguez, lfredlund, aherranz}@fi.upm.es

Universidad Polit´ ecnica de Madrid Madrid, Spain

September 20th, 2013 XIII Jornadas sobre Programaci´

  • n y Lenguajes (PROLE)

Facultad de Inform´ atica, Universidad Complutense de Madrid