Lecture 15: UML State Machines & Software Quality Assurance - - PowerPoint PPT Presentation

lecture 15 uml state machines software quality assurance
SMART_READER_LITE
LIVE PREVIEW

Lecture 15: UML State Machines & Software Quality Assurance - - PowerPoint PPT Presentation

Softwaretechnik / Software-Engineering Lecture 15: UML State Machines & Software Quality Assurance 2018-07-02 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universitt Freiburg, Germany 15 2018-07-02 main


slide-1
SLIDE 1

– 15 – 2018-07-02 – main –

Softwaretechnik / Software-Engineering

Lecture 15: UML State Machines & Software Quality Assurance

2018-07-02

  • Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universität Freiburg, Germany

slide-2
SLIDE 2

Topic Area Architecture & Design: Content

– 15 – 2018-07-02 – Sblockcontent –

2/67

  • Introduction and Vocabulary
  • Software Modelling
  • model; views / viewpoints; 4+1 view
  • Modelling structure
  • (simplified) class & object diagrams
  • (simplified) object constraint logic (OCL)
  • Principles of Design
  • modularity, separation of concerns
  • information hiding and data encapsulation
  • abstract data types, object orientation
  • Design Patterns
  • Modelling behaviour
  • communicating finite automata (CFA)
  • Uppaal query language
  • CFA vs. Software
  • Model-driven/-based Software Engineering
  • Unified Modelling Language (UML)
  • basic and hierarchical state-machines

VL 11 . . . VL 12 . . . VL 13 . . . VL 14 . . . VL 15 . . .

slide-3
SLIDE 3

Content I (Architecture & Design)

– 15 – 2018-07-02 – Scontent –

3/67

  • CFA vs. Software
  • a CFA model is software
  • CFA at Work
  • drive to configuration, scenarios, invariants
  • tool demo (verifier).
  • Model-based/-driven Software Engineering
  • Unified Modelling Language
  • Brief History
  • Sub-Languages
  • UML Modes
  • UML State Machines
  • Hierarchical State Machines
  • Core State Machines
  • steps and run-to-completion steps
  • Rhapsody
slide-4
SLIDE 4

CFA vs. Software

– 15 – 2018-07-02 – main –

4/67

slide-5
SLIDE 5

A CFA Model Is Software

– 15 – 2018-07-02 – Scfasw –

5/67

  • Definition. Software is a finite description S of a (possibly infinite)

set S of (finite or infinite) computation paths of the form σ0

α1

− → σ1

α2

− → σ2 · · · where

  • σi ∈ Σ, i ∈ N0, is called state (or configuration), and
  • αi ∈ A, i ∈ N0, is called action (or event).

The (possibly partial) function · : S → S is called interpreta- tion of S.

  • Let C(A1, . . . , An) be a network of CFA.
  • Σ = Conf
  • A = Act
  • C = {π =

ℓ0, ν0

λ1

− − → ℓ1, ν1

λ2

− − → ℓ2, ν2

λ3

− − → · · · | π is a computation path of C}.

  • Note: the structural model just consists of the set of variables and the locations of C.
slide-6
SLIDE 6

Example: Software Specification

– 15 – 2018-07-02 – Scfasw –

6/67

http://commons.wikimedia.org (CC-by-sa 4.0, Dirk Ingo Franke)

Alphabet:

  • M

– dispense cash only,

  • C

– return card only,

  • M

C

– dispense cash and return card.

  • Customer: “I don’t care about the order of M and C”

S1 =

  • M.C
  • C.M
  • M

C

ω

  • Refined Specification: “be consistent: either always M.C or always C.M”

S2 = (M.C)ω or (C.M)ω

  • Design Idea: “consider human errors: always do C.M”

S1 = (C.M)ω

  • Implementation (goal): software S2 behaves according to the design idea.
slide-7
SLIDE 7

Formal Methods in the Software Development Process

– 15 – 2018-07-02 – Scfasw –

7/67

Customer 2 Mmmh, Software!

Requirements S1 = {(M.C, · 1), (C.M, · 1)} Design S2 = {(M.TM.C, · 1), (C.TC.M, · 1)} S1 = {σ1

α1

1

− − → σ1

1 α1

2

− − → σ1

2 · · · , . . . }

Implementation S2 = {σ2

α2

1

− − → σ2

1 α2

2

− − → σ2

2 · · · , . . . }

Development Process/ Project Management

validate analyse verify analyse verify analyse

slide-8
SLIDE 8

CFA and Queries at Work

– 15 – 2018-07-02 – main –

8/67

slide-9
SLIDE 9

Example: Vending Machine — Model Architecture

– 15 – 2018-07-02 – Scfaatwork –

9/67

CoinValidator User ChoicePanel WaterDispenser SoftDispenser TeaDispenser Service

C50, E1 WATER, SOFT, TEA OK DWATER DSOFT DTEA DOK FILLUP

ENVIRONMENT SYSTEM

half_idle request_sent tea_selected soft_selected water_selected idle DOK? OK! water_enabled := false, soft_enabled := false, tea_enabled := false DTEA! DWATER! DSOFT! tea_enabled TEA? soft_enabled SOFT? water_enabled WATER?

  • Shared variables:
  • bool water_enabled, soft_enabled, tea_enabled;
  • int w = 3, s = 3, t = 3;
  • Note: Our model does not use scopes (“information hiding”) for channels.

That is, ‘Service’ could send ‘WATER’ if the modeler wanted to.

slide-10
SLIDE 10

Design Sanity Check: Drive to Configuration

– 15 – 2018-07-02 – Scfaatwork –

10/67

  • Question: Is is (at all) possible to have no water in the vending machine model?

(Otherwise, the design is definitely broken.)

  • Approach: Check whether a configuration satisfying

w = 0 is reachable, i.e. check NVM | = ∃♦ w = 0. for the vending machine model NVM.

slide-11
SLIDE 11

Design Check: Scenarios

– 15 – 2018-07-02 – Scfaatwork –

11/67

  • Question: Is the following existential LSC satisfied by the model?

(Otherwise, the design is definitely broken.)

LSC: buy tea AC: true AM: initial I: permissive

User Coin Validator Choice Panel C50 C50 C50 TEA ¬E1!

  • Approach: Use the following newly created CFA ‘Scenario’

end_of_scenario TEA! C50! C50! C50!

instead of User and check whether location end_of_scenario is reachable, i.e. check N ′

VM |

= ∃♦ Scenario.end_of_scenario. for the modified vending machine model N ′

VM.

slide-12
SLIDE 12

Design Verification: Invariants

– 15 – 2018-07-02 – Scfaatwork –

12/67

  • Question: Is it the case that the “tea” button is only enabled

if there is e 1.50 in the machine?

(Otherwise, the design is broken.)

  • Approach: Check whether the implication

tea_enabled = ⇒ CoinValidator.have_c150 holds in all reachable configurations, i.e. check NVM | = ∀ tea_enabled imply CoinValidator.have_c150 for the vending machine model NVM.

drink_ready have_c150 have_e1 have_c100 have_c50 idle OK? OK? OK? OK? E1? tea_enabled := (t > 0) C50? water_enabled := (w > 0), tea_enabled := (t > 0) C50? tea_enabled := (t > 0) E1? soft_enabled := (s > 0) C50? soft_enabled := (s > 0) C50? water_enabled := (w>0)

slide-13
SLIDE 13

Design Verification: Sanity Check

– 15 – 2018-07-02 – Scfaatwork –

13/67

  • Question: Is the “tea” button ever enabled?

(Otherwise, the considered invariant tea_enabled = ⇒ CoinValidator.have_c150 holds vacuously.)

  • Approach: Check whether a configuration satisfying water_enabled = 1 is reachable.

Exactly like we did with w = 0 earlier.

slide-14
SLIDE 14

Design Verification: Another Invariant

– 15 – 2018-07-02 – Scfaatwork –

14/67

  • Question: Is it the case that, if there is money in the machine

and water in stock, that the “water” button is enabled?

  • Approach: Check

NVM | = ∀ (CoinValidator.have_c50 or CoinValidator.have_c100 or CoinValidator.have_c150) imply water_enabled.

drink_ready have_c150 have_e1 have_c100 have_c50 idle OK? OK? OK? OK? E1? tea_enabled := (t > 0) C50? water_enabled := (w > 0), tea_enabled := (t > 0) C50? tea_enabled := (t > 0) E1? soft_enabled := (s > 0) C50? soft_enabled := (s > 0) C50? water_enabled := (w>0)

slide-15
SLIDE 15

Recall: Universal LSC Example

– 15 – 2018-07-02 – Scfaatwork –

15/67

LSC: buy water AC: true AM: invariant I: strict User CoinValidator ChoicePanel Dispenser C 5 p W A T E R

¬(C50! ∨ E1! ∨ pSOFT! ∨ pTEA! ∨ pFILLUP!)

water_in_stock d W A T E R O K

¬(dSoft! ∨ dTEA!)

slide-16
SLIDE 16

Content I (Architecture & Design)

– 15 – 2018-07-02 – Scontent –

16/67

  • CFA vs. Software
  • a CFA model is software
  • CFA at Work
  • drive to configuration, scenarios, invariants
  • tool demo (verifier).
  • Model-based/-driven Software Engineering
  • Unified Modelling Language
  • Brief History
  • Sub-Languages
  • UML Modes
  • UML State Machines
  • Hierarchical State Machines
  • Core State Machines
  • steps and run-to-completion steps
  • Rhapsody
slide-17
SLIDE 17

Model-based/-driven Software Engineering

– 15 – 2018-07-02 – main –

17/67

slide-18
SLIDE 18

– 15 – 2018-07-02 – Smdse –

18/67

slide-19
SLIDE 19

Model-Driven Software Engineering

– 15 – 2018-07-02 – Smdse –

19/67

  • (Jacobson et al., 1992): “System development is model building.”
  • Model based software engineering (MBSE): some (formal) models are used.
  • Model driven software engineering (MDSE): all artefacts are (formal) models.

Idea Structure Declarative Behaviour

  • Declarative

Behaviour′

  • Structure′

Constructive Behaviour

  • Structure′′

Constructive Behaviour′

  • Implementation

elicit refine refine refine refine

requirements model requirements/ constraints design system model | =? | =?

generate/ program

slide-20
SLIDE 20

– 15 – 2018-07-02 – Smdse –

20/67

slide-21
SLIDE 21

Development Approaches

– 15 – 2018-07-02 – Smdse –

21/67 task, problem

  • utside-in

inside-out top-down bottom-up

user interface system software, hardware

  • top-down risk: needed functionality hard to realise on target platform.
  • bottom-up risk: lower-level units do not “fit together”.
  • inside-out risk: user interface needed by customer hard to realise with existing system,
  • outside-in risk: elegant system design not reflected nicely in (already fixed) UI.
slide-22
SLIDE 22

Transform vs. Write-Down-and-Check

– 15 – 2018-07-02 – Smdse –

22/67

slide-23
SLIDE 23

Code Generation from CFA: A Simple Example

– 15 – 2018-07-02 – Simpl –

23/67

W0 dispense Wi FILLUP? w := 3 FILLUP? w := 3 w == 0 DOK! w > 0 DOK! DWATER? w := w - 1

int w := 3; typedef {Wi, dispense, W0} st_T; st_T st := Wi; SetAct take_action( Act α ) { SetAct R := ∅; if st = Wi : if α = DWATER? : w := w − 1; st := dispense; if (w = 0) R := R ∪ {DOK!}; if (w > 0) R := R ∪ {DOK!}; α = FILLUP? : w := 3; st := Wi; R := R ∪ {DWATER?, FILLUP?}; else : R := R ∪ {DWATER?, FILLUP?} fi; st = dispense : if α = DOK! ∧ w = 0 : st := W0; R := R ∪ {FILLUP?}; α = DOK! ∧ w > 0 : st := Wi; R := R ∪ {FILLUP?}; else : R := R ∪ {DOK?} fi; st = W0 : if α = FILLUP? : w := 3; st := Wi; R := R ∪ {DWATER?, FILLUP?}; else : R := R ∪ {FILLUP?} fi; fi; return R; }

slide-24
SLIDE 24

Content I (Architecture & Design)

– 15 – 2018-07-02 – Scontent –

24/67

  • CFA vs. Software
  • a CFA model is software
  • CFA at Work
  • drive to configuration, scenarios, invariants
  • tool demo (verifier).
  • Model-based/-driven Software Engineering
  • Unified Modelling Language
  • Brief History
  • Sub-Languages
  • UML Modes
  • UML State Machines
  • Hierarchical State Machines
  • Core State Machines
  • steps and run-to-completion steps
  • Rhapsody
slide-25
SLIDE 25

Unified Modelling Language

– 15 – 2018-07-02 – main –

25/67

slide-26
SLIDE 26

A Brief History of the Unified Modelling Language (UML)

– 15 – 2018-07-02 – Sumloutlook –

26/67

http://wikimedia.org (CC nc-sa 3.0, User:AutumnSnow) http://wikimedia.org (CC nc-sa 3.0, User:AutumnSnow) http://wikimedia.org (Public domain, Johannes Fasolt) use case model domain object model analysis model design model class... implementation model ... testing model may be expressed in terms of structured by realized by implemented by tested in
  • Boxes/lines and automata are used to visualise software for ages.
  • 1970’s, Software Crisis™ — Idea: learn from engineering disciplines

in order to handle growing complexity.

Modelling languages: Flowcharts, Nassi-Shneiderman, Entity-Relation Diagrams

  • Mid 1980’s: Statecharts (Harel, 1987), StateMate™ (Harel et al., 1990)
  • Early 1990’s, advent of Object-Oriented-Analysis/Design/Programming

— Inflation of notations and methods, most prominent:

  • Object-Modeling Technique (OMT) (Rumbaugh et al., 1990)
  • Booch Method and Notation (Booch, 1993)
  • Object-Oriented Software Engineering (OOSE) (Jacobson et al., 1992)

Each “persuasion” selling books, tools, seminars...

  • Late 1990’s: joint effort of “the three amigos” UML 0.x and 1.x

Standards published by Object Management Group (OMG): “international, open membership, not-for-profit computer industry consortium”. Much criticised for lack of formality.

  • Since 2005: UML 2.x, split into infra- and superstructure documents.
  • Syntax: pretty precisely defined.
  • Semantics: natural language, thus informal.
slide-27
SLIDE 27

UML Overview (OMG, 2007b, 684)

– 15 – 2018-07-02 – Sumloutlook –

27/67

Figure A.5 - The taxonomy of structure and behavior diagram

Diagram Structure Diagram Behavior Diagram Interaction Diagram Use Case Diagram Activity Diagram Composite Structure Diagram Class Diagram Component Diagram Deployment Diagram Sequence Diagram Interaction Overview Diagram Object Diagram State Machine Diagram Package Diagram Communication Diagram Timing Diagram

OCL

Dobing and Parsons (2006)

slide-28
SLIDE 28

UML and the Pragmatic Attribute

– 15 – 2018-07-02 – Sumlmode –

28/67

Recall: definition “model” (Glinz, 2008, 425): (iii) the pragmatic attribute, i.e. the model is built in a specific context for a specific purpose. Examples for context/purpose: Floorplan as sketch: Floorplan as blueprint: Floorplan as program: +

wiringplan

+

windows

+

...

slide-29
SLIDE 29

With UML it’s the Same [http://martinfowler.com/bliki]

– 15 – 2018-07-02 – Sumlmode –

29/67

The last slide is inspired by Martin Fowler, who puts it like this: “[...] people differ about what should be in the UML because there are differing fundamental views about what the UML should be. I came up with three primary classifications for thinking about the UML: UmlAsSketch, UmlAsBlueprint, and UmlAsProgrammingLanguage. ([...] S. Mellor independently came up with the same classifications.) So when someone else’s view of the UML seems rather different to yours, it may be because they use a different UmlMode to you.” Claim:

  • This not only applies to UML as a language (what should be in it etc.?),
  • but at least as well to each individual UML model.
slide-30
SLIDE 30

UML-Mode of the Lecture: As Blueprint

– 15 – 2018-07-02 – Sumlmode –

30/67

+

wiringplan

+

windows

+

...

Sketch

In this UmlMode developers use the UML to help communicate some aspects of a

  • system. [...]

Sketches are also useful in documents, in which case the focus is communication ra- ther than completeness. [...] The tools used for sketching are lightweight drawing tools and often people aren’t too particular about keeping to every strict rule of the UML. Most UML diagrams shown in books, such as mine, are sketches. Their emphasis is on selective communication rather than complete specification. Hence my sound-bite “comprehensive- ness is the enemy of comprehensibility”

Blueprint

[...] In forward engineering the idea is that blueprints are developed by a designer whose job is to build a detailed design for a programmer to code up. That design should be sufficiently complete that all design decisions are laid out and the programming should follow as a pretty straightforward activity that requires little thought. [...] Blueprints require much more sophisticated tools than sketches in

  • rder to handle the details required for

the task. [...] Forward engineering tools support dia- gram drawing and back it up with a repository to hold the information. [...]

ProgrammingLanguage

If you can detail the UML enough, and provide semantics for everything you need in software, you can make the UML be your programming language. Tools can take the UML diagrams you draw and compile them into executable code. The promise of this is that UML is a higher level language and thus more productive than current programming languages. The question, of course, is whether this promise is true. I don’t believe that graphical program- ming will succeed just because it’s graph-

  • ical. [...]

Our goal:

  • be precise to avoid misunderstandings.
  • allow formal analysis of consistency/implication on the design level — find errors early.

Yet we tried to be consistent with the (informal semantics) from OMG (2007a,b) as far as possible.

slide-31
SLIDE 31

UML State Machines

– 15 – 2018-07-02 – main –

31/67

slide-32
SLIDE 32

Composite (or Hierarchical) States

– 15 – 2018-07-02 – Sumlstm –

32/67

  • OR-states, AND-states Harel (1987).
  • Composite states are about abbreviation, structuring, and avoiding redundancy.

n

  • w

e s resigned X/ X/ X/ X/

  • n
  • w

e s resigned X/ n fastN

  • w

fastW e fastE s fastS F/ F/

  • n
  • w

e s

  • slow

fast F/ F/

slide-33
SLIDE 33

Example

– 15 – 2018-07-02 – Sumlstm –

33/67

Idle waitOK have_c100_or_e1> have_c100 have_e1 have_c150> have_c50> drinkReady Idle waitOK have_c100_or_e1> have_c100 have_e1 have_c150> have_c50> drinkReady E1/itsChanger

  • >giveback_100()

C50/itsChoicePanel

  • >enable_Water();

E1/ itsChanger

  • >giveback_100()

C50 C50/ itsChanger

  • >giveback_50()

C50 E1/itsChoicePanel->enableSoft(); E1 C50 OK Entry Action: itsChoicePanel

  • >enable_Water();

Entry Action: itsChoicePanel

  • >enable_Soft();

Entry Action: itsChoicePanel

  • >enable_Tea();

Tea_selected Inactive Soft_selected Water_selected Request_sent Tea_selected Inactive Soft_selected Water_selected Request_sent TEA[Tea_enabled] /itsDrinkDispenser

  • >GEN(DTEA)

/itsDrinkDispenser

  • >GEN(DSOFT);

if (itsCoinValidator

  • >IS_IN(have_c150))

itsChanger->giveback_50(); WATER[Water_enabled] /disable_all(); SOFT[Soft_enabled] /itsDrinkDispenser

  • >GEN(DWATER);

if (itsCoinValidator->IS_IN(have_c150)) itsChanger->giveback_100(); else if (itsCoinValidator->IS_IN(have_c100)) itsChanger->giveback_50();

  • n
  • n

T2 Tea_out T1 T3 S2 Soft_out S1 S3 W2 Water_out W1 W3 FillingUp

  • n

T2 Tea_out T1 T3 S2 Soft_out S1 S3 W2 Water_out W1 W3 FillingUp DTEA/ Prepare_Tea(); itsCoinValidator

  • >GEN(OK);

DTEA/ Prepare_Tea(); itsCoinValidator

  • >GEN(OK);

DTEA/ Prepare_Tea(); itsCoinValidator

  • >GEN(OK);

DSOFT/ Prepare_Soft(); itsCoinValidator

  • >GEN(OK);

DSOFT/ Prepare_Soft(); itsCoinValidator

  • >GEN(OK);

DSOFT/ Prepare_Soft(); itsCoinValidator

  • >GEN(OK);

DWATER/ Prepare_Water(); itsCoinValidator

  • >GEN(OK);

DWATER/ Prepare_Water(); itsCoinValidator

  • >GEN(OK);

DWATER/ Prepare_Water(); itsCoinValidator

  • >GEN(OK);

FILLUP/itsCoinValidator

  • >update_ChoicePanel();
slide-34
SLIDE 34

Would be Too Easy. . .

– 15 – 2018-07-02 – Sumlstm –

34/67

  • s1

s2

  • s3

s8 s4

  • s5

s6

E/ F/ F/ E/ G/

s7 [true]/ F/ → “Software Design, Modelling, and Analysis with UML” in some winter semesters.

slide-35
SLIDE 35

UML Core State Machines

– 15 – 2018-07-02 – Sumlstm –

35/67

C D

x : Int = 27 itsD 0..1 itsC 0..1

  • signal
  • E
  • signal
  • F
  • signal
  • G

s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0 annot ::=

  • event[. event]∗
  • trigger

[ [ guard ] ] [ / action]

  • with
  • event ∈ E,

(optional)

  • guard ∈ ExprS

(default: true, assumed to be in ExprS )

  • action ∈ ActS

(default: skip, assumed to be in ActS )

slide-36
SLIDE 36

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1

slide-37
SLIDE 37

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2

slide-38
SLIDE 38

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2

slide-39
SLIDE 39

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2 3 s2 1 27 s3 G ready for u1

slide-40
SLIDE 40

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2 3 s2 1 27 s3 G ready for u1 4.a s2 1 s1 1 G ready for u1

slide-41
SLIDE 41

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2 3 s2 1 27 s3 G ready for u1 4.a s2 1 s1 1 G ready for u1 5.a s1 1 s1 1

slide-42
SLIDE 42

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2 3 s2 1 27 s3 G ready for u1 4.a s2 1 s1 1 G ready for u1 5.a s1 1 s1 1 4.b s1 1 27 s3

slide-43
SLIDE 43

Event Pool and Run-To-Completion

– 15 – 2018-07-02 – Sumlstm –

36/67 s1 s2

E/itsD ! F G

s1 s2

F[x > 0]

s3

/itsC ! G /x := 0

u1 : C

state : {s1, s2} stable : Bool

u2 : D x = 27

state : {s1, s2, s3} stable : Bool

itsD itsC

u1 u2 step state stable x state stable event pool s1 1 27 s1 1 E ready for u1 1 s2 1 27 s1 1 F ready for u2 2 s2 1 27 s2 3 s2 1 27 s3 G ready for u1 4.a s2 1 s1 1 G ready for u1 5.a s1 1 s1 1 4.b s1 1 27 s3 5.b s1 1 s1 1

slide-44
SLIDE 44

Rhapsody Architecture

– 15 – 2018-07-02 – Sumlstm –

37/67

C.h D.h C.cpp D.cpp MainDefaultComponent.cpp

DfltCmp.exe

generate build / make (compiler) run E! go

“D just stepped from s1 to s2 by transition t”

slide-45
SLIDE 45

Content I (Architecture & Design)

– 15 – 2018-07-02 – Scontent –

38/67

  • CFA vs. Software
  • a CFA model is software
  • CFA at Work
  • drive to configuration, scenarios, invariants
  • tool demo (verifier).
  • Model-based/-driven Software Engineering
  • Unified Modelling Language
  • Brief History
  • Sub-Languages
  • UML Modes
  • UML State Machines
  • Hierarchical State Machines
  • Core State Machines
  • steps and run-to-completion steps
  • Rhapsody
slide-46
SLIDE 46

Tell Them What You’ve Told Them. . .

– 15 – 2018-07-02 – Sttwytt –

39/67

  • We can use tools like Uppaal to
  • check and verify CFA design models against requirements.
  • CFA (and state charts)
  • can easily be implemented using the translation scheme.
  • Wanted: verification results carry over to the implementation.
  • if code is not generated automatically,

verify code against model.

  • UML State Machines are
  • principally the same thing as CFA,

yet provide more convenient syntax.

  • Semantics uses
  • asynchronous communication,
  • run-to-completion steps

in contrast to CFA.

(We could define the same for CFA, but then the Uppaal simulator would not be useful any more.)

  • Mind UML Modes.
slide-47
SLIDE 47

Code Quality Assurance

– 15 – 2018-07-02 – main –

40/67

slide-48
SLIDE 48

Topic Area Code Quality Assurance: Content

– 15 – 2018-07-02 – Sblockcontent2 –

41/67

  • Introduction and Vocabulary
  • Test case, test suite, test execution.
  • Positive and negative outcomes.
  • Limits of Software Testing
  • Glass-Box Testing
  • Statement-, branch-, term-coverage.
  • Other Approaches
  • Model-based testing,
  • Runtime verification.
  • Program Verification
  • partial and total correctness,
  • Proof System PD.
  • Review

VL 15 . . . VL 16 . . . VL 17 . . . VL 18 . . .

slide-49
SLIDE 49

Content (Part II)

– 15 – 2018-07-02 – Scontent2 –

42/67

  • Introduction
  • quotes on testing,
  • systematic testing vs. ‘rumprobieren’.
  • Test Case
  • definition,
  • execution,
  • positive and negative.
  • Test Suite
  • Limits of Software Testing
  • Software examination paths
  • Is exhaustive testing feasible?
  • Range vs. point errors
  • More Vocabulary
slide-50
SLIDE 50

Testing: Introduction

– 15 – 2018-07-02 – main –

43/67

slide-51
SLIDE 51

Quotes On Testing

– 15 – 2018-07-02 – Stestquotes –

44/67 “Testing is the execution of a program with the goal to discover errors.”

(G. J. Myers, 1979)

“Testing is the demonstration of a program or system with the goal to show that it does what it is supposed to do.”

(W. Hetzel, 1984)

“Software testing can be used to show the presence of bugs, but never to show their absence!”

(E. W. Dijkstra, 1970)

Rule-of-thumb: (fairly systematic) tests discover half of all errors.

(Ludewig and Lichter, 2013)

slide-52
SLIDE 52

Preliminaries

– 15 – 2018-07-02 – Stestintro –

45/67

Recall:

  • Definition. Software is a finite description S of a (possibly infinite) set S of (finite or

infinite) computation paths of the form σ0

α1

− − → σ1

α2

− − → σ2 · · · where

  • σi ∈ Σ, i ∈ N0, is called state (or configuration), and
  • αi ∈ A, i ∈ N0, is called action (or event).

The (possibly partial) function · : S → S is called interpretation of S.

  • From now on, we assume that states consist of an input and an output/internal part, i.e.,

there are Σin and Σout such that Σ = Σin × Σout.

  • Computation paths are then of the form

π = σi σo

  • α1

− − → σi

1

σo

1

  • α2

− − → · · ·

  • We use π ↓ Σin to denote π = σi

α1

− − → σi

1 α2

− − → · · · , i.e. the projection of π onto Σin.

slide-53
SLIDE 53

Test Case

– 15 – 2018-07-02 – Stestintro –

46/67

  • Definition. A test case T over Σ and A is a pair (In, Soll ) consisting of
  • a description In of sets of finite input sequences,
  • a description Soll of expected outcomes,

and an interpretation · of these descriptions:

  • In ⊆ (Σin × A)∗,

Soll ⊆ (Σ × A)∗ ∪ (Σ × A)ω

Examples:

  • Test case for procedure strlen : String → N, s denotes parameter, r return value:

T = (s = "abc", r = 3) s = "abc" = {σi

τ

− → σi

1 | σ0(s) = "abc"},

r = 3 = {σ0

τ

− → σ1 | σ1(r) = 3}, Shorthand notation: T = ("abc", 3).

  • “Call strlen() with string "abc", expect return value 3.”
slide-54
SLIDE 54

Test Case

– 15 – 2018-07-02 – Stestintro –

46/67

  • Definition. A test case T over Σ and A is a pair (In, Soll ) consisting of
  • a description In of sets of finite input sequences,
  • a description Soll of expected outcomes,

and an interpretation · of these descriptions:

  • In ⊆ (Σin × A)∗,

Soll ⊆ (Σ × A)∗ ∪ (Σ × A)ω

Examples:

  • Test case for vending machine.

T = (C50, WATER; DWATER) C50, WATER = {σi

C50

− − → σi

1 τ

− → · · ·

τ

− → σi

j−1 WATER

− − − − − → σi

j},

DWATER = {σ0

α1

− − → · · ·

αk

− − → σk−1

DWATER

− − − − − − → σk | k ≤ 10},

  • “Send event C50 and any time later WATER, expect DWATER after 10 steps the latest.”
slide-55
SLIDE 55

Test Case

– 15 – 2018-07-02 – Stestintro –

46/67

  • Definition. A test case T over Σ and A is a pair (In, Soll ) consisting of
  • a description In of sets of finite input sequences,
  • a description Soll of expected outcomes,

and an interpretation · of these descriptions:

  • In ⊆ (Σin × A)∗,

Soll ⊆ (Σ × A)∗ ∪ (Σ × A)ω

Note:

  • Input sequences can consider
  • input data, possibly with timing constraints,
  • other interaction, e.g., from network,
  • initial memory content,
  • etc.
  • Input sequences may leave degrees of freedom to tester.
  • Expected outcomes may leave degrees of freedom to system.
slide-56
SLIDE 56

Executing Test Cases

– 15 – 2018-07-02 – Stestintro –

47/67

  • A computation path

π = σi σo

  • α1

− − → σi

1

σo

1

  • α2

− − → · · · from S is called execution of test case (In, Soll ) if and only if

  • there is n ∈ N such that σ0

α1

− − → . . .

αn

− − → σn ↓ Σin ∈ In.

(“A prefix of π corresponds to an input sequence”).

Execution π of test case T is called

  • successful (or positive) if and only if π /

∈ Soll.

  • Intuition: an an error has been discovered.
  • Alternative: test item S failed to pass the test.
  • Confusing: “test failed”.
  • unsuccessful (or negative) if and only if π ∈ Soll.
  • Intuition: no error has been discovered.
  • Alternative: test item S passed the test.
  • Okay: “test passed”.
slide-57
SLIDE 57

Test Suite

– 15 – 2018-07-02 – Stestintro –

48/67

  • A test suite is a finite set of test cases {T1, . . . , Tn}.
  • An execution of a test suite is a set of computation paths,

such that there is at least one execution for each test case.

  • An execution of a test suite is called positive

if and only if at least one test case execution is positive. Otherwise, it is called negative.

slide-58
SLIDE 58

Not Executing Test Cases

– 15 – 2018-07-02 – Stestintro –

49/67

  • Consider the test case

T = ("", 0) for procedure strlen.

(“Empty string has length 0.”)

  • A tester observes the following software behaviour:

π = {s → NULL, r → 0}

  • =σ0

τ

− → program-abortion

  • σ1
  • Test execution positive or negative?

Note:

  • If a tester does not adhere to an allowed input sequence of T, π is not a test execution.

Thus π is neither positive nor negative (only defined for test executions).

  • Same case: power outage (if continuous power supply is considered in input sequence).
slide-59
SLIDE 59

Tests vs. Systematic Tests

– 15 – 2018-07-02 – Stestintro –

50/67 Test — (one or multiple) execution(s) of a program on a computer with the goal to find errors.

(Ludewig and Lichter, 2013)

Not (even) a test (in the sense of this weak definition):

  • any inspection of the program (no execution),
  • demo of the program (other goal),
  • analysis by software-tools for, e.g., values of metrics (other goal),
  • investigation of the program with a debugger (other goal).

Systematic Test — a test such that

  • (environment) conditions are defined or precisely documented,
  • inputs have been chosen systematically,
  • results are documented and assessed according to criteria

that have been fixed before.

(Ludewig and Lichter, 2013)

(Our) Synonyms for non-systematic tests: Experiment, ‘Rumprobieren’. In the following: test means systematic test; if not systematic, call it experiment.

slide-60
SLIDE 60

So Simple?

– 15 – 2018-07-02 – main –

51/67

slide-61
SLIDE 61

Environmental Conditions

– 15 – 2018-07-02 – Stesttooeasy –

52/67

Strictly speaking, a test case is a triple (In, Soll, Env) comprising a description Env of (environmental) conditions. Env describes any aspects which could have an effect

  • n the outcome of a test execution and cannot

be specified as part of In, such as:

  • Which program (version) is tested?
  • Built with which compiler, linker, etc.?
  • Test host (OS, architecture, memory size, connected devices (configuration?), etc.)?
  • Which other software (in which version, configuration) is involved?
  • Who is supposed to test when?
  • etc. etc.

→ test executions should be (as) reproducible and objective (as possible). Full reproducibility is hardly possible in practice — obviously (err, why...?).

  • Steps towards reproducibility and objectivity:
  • have a fixed build environment,
  • use a fixed test host which does not do any other jobs,
  • execute test cases automatically (test scripts).
slide-62
SLIDE 62

Content (Part II)

– 15 – 2018-07-02 – Scontent2 –

53/67

  • Introduction
  • quotes on testing,
  • systematic testing vs. ‘rumprobieren’.
  • Test Case
  • definition,
  • execution,
  • positive and negative.
  • Test Suite
  • Limits of Software Testing
  • Software examination paths
  • Is exhaustive testing feasible?
  • Range vs. point errors
  • More Vocabulary
slide-63
SLIDE 63

The Limits of Software Testing

– 15 – 2018-07-02 – main –

54/67

slide-64
SLIDE 64

Software Examination (in Particular Testing)

– 15 – 2018-07-02 – Slimits –

55/67

  • In each examination, there are two paths from

the specification to results:

  • the production path (using model, source code,

executable, etc.), and

  • the examination path

(using requirements specifications).

  • A check can only discover errors
  • n exactly one of the paths.
  • If a difference is detected:

examination result is positive.

  • What is not on the paths, is not checked;

crucial: specification and comparison.

Recall:

checking procedure shows no error reports error artefact has error yes false negative true positive no true negative false positive

specification implement specification comprehend specification “is”-result requirements

  • n result

compare examination result ✔/✘/? information flow development information flow examination (Ludewig and Lichter, 2013)

slide-65
SLIDE 65

Recall: Quotes On Testing

– 15 – 2018-07-02 – Slimits –

56/67 “Software testing can be used to show the presence of bugs, but never to show their absence!”

(E. W. Dijkstra, 1970)

slide-66
SLIDE 66

Why Can’t We Show The Absence of Errors (in General)?

– 15 – 2018-07-02 – Slimits –

57/67

Consider a simple pocket calculator for adding 8-digit decimals:

12345678 + 27 7 8 9 4 5 6 + 1 2 3 =

  • Requirement: If the display shows x, +, and y, then after pressing

= ,

  • the sum of x and y is displayed if x + y has at most 8 digits,
  • otherwise “-E-” is displayed.
  • With 8 digits, both x and y range over [0, 108 − 1].
  • Thus there are 1016 = 10, 000, 000, 000, 000, 000 possible input pairs (x, y) to be

considered for exhaustive testing, i.e. testing every possible case!

  • And if we restart the pocket calculator for each test,

we do not know anything about problems with sequences of inputs...

(Local variables may not be re-initialised properly, for example.)

slide-67
SLIDE 67

Observation: Software Usually Has Many Inputs

– 15 – 2018-07-02 – Slimits –

58/67

  • Example: Simple Pocket Calculator.

With ten thousand (10,000) different test cases (that’s a lot!), 9,999,999,999,990,000 of the 1016 possible inputs remain uncovered. In other words: Only 0.0000000001% of the possible inputs are covered, 99.9999999999% not touched.

  • In diagrams: (red: uncovered, blue: covered)

108 108

slide-68
SLIDE 68

Point vs. Range Errors

– 15 – 2018-07-02 – Spointrange –

59/67

  • Software is (in general) not continous.
  • Consider a continuous function, e.g. the one to the right:

ε δ

For sufficiently small ε-environments of an input, the outputs differ only by a small amount δ.

  • Physical systems are (to a certain extent) continous:
  • For example, if a bridge endures a single car of 1000 kg,

we strongly expect the bridge to endure cars of 990 kg or 1010 kg.

  • And anything of weight smaller than 1000 kg can be expected to be endured.
  • For software, adjacent inputs may yield
  • arbitrarily distant output values.

Vocabulary:

  • Point error: an isolated input value triggers the error.
  • Range error: multiple “neighbouring” inputs trigger the error.
  • For software, (in general, without extra information)

we can not conclude from some values to others.

slide-69
SLIDE 69

Content (Part II)

– 15 – 2018-07-02 – Scontent2 –

60/67

  • Introduction
  • quotes on testing,
  • systematic testing vs. ‘rumprobieren’.
  • Test Case
  • definition,
  • execution,
  • positive and negative.
  • Test Suite
  • Limits of Software Testing
  • Software examination paths
  • Is exhaustive testing feasible?
  • Range vs. point errors
  • More Vocabulary
slide-70
SLIDE 70

Tell Them What You’ve Told Them. . .

– 15 – 2018-07-02 – Sttwytt2 –

65/67

  • Testing is about
  • finding errors, or
  • demonstrating scenarios.
  • A test case consists of
  • input sequences and
  • expected outcome(s).
  • A test case execution is
  • positive if an error is found,
  • negative if no error is found.
  • A test suite is a set of test cases.
  • Distinguish (among others),
  • glass-box test: structure (or source code) of test item available,
  • black-box test: structure not available.
slide-71
SLIDE 71

References

– 15 – 2018-07-02 – main –

66/67

slide-72
SLIDE 72

References

– 15 – 2018-07-02 – main –

67/67 Booch, G. (1993). Object-oriented Analysis and Design with Applications. Prentice-Hall. Dobing, B. and Parsons, J. (2006). How UML is used. Communications of the ACM, 49(5):109–114. Glinz, M. (2008). Modellierung in der Lehre an Hochschulen: Thesen und Erfahrungen. Informatik Spektrum, 31(5):425–434. Harel, D. (1987). Statecharts: A visual formalism for complex systems. Science of Computer Programming, 8(3):231–274. Harel, D., Lachover, H., et al. (1990). Statemate: A working environment for the development of complex reactive systems. IEEE Transactions on Software Engineering, 16(4):403–414. Jacobson, I., Christerson, M., and Jonsson, P. (1992). Object-Oriented Software Engineering - A Use Case Driven

  • Approach. Addison-Wesley.

Ludewig, J. and Lichter, H. (2013). Software Engineering. dpunkt.verlag, 3. edition. OMG (2007a). Unified modeling language: Infrastructure, version 2.1.2. Technical Report formal/07-11-04. OMG (2007b). Unified modeling language: Superstructure, version 2.1.2. Technical Report formal/07-11-02. Rumbaugh, J., Blaha, M., Premerlani, W., Eddy, F., and Lorensen, W. (1990). Object-Oriented Modeling and Design. Prentice Hall.