lecture 17: software verification · topic area code quality assurance: content – 17–...

49
– 17 – 2016-07-14 – main – Softwaretechnik / Software-Engineering Lecture 17: Software Verification 2016-07-14 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universität Freiburg, Germany

Upload: others

Post on 16-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

–17

–2

016

-07-

14–

mai

n–

Softwaretechnik / Software-Engineering

Lecture 17: Software Verification

2016-07-14

Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universität Freiburg, Germany

Page 2: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Topic Area Code Quality Assurance: Content–

17–

20

16-0

7-14

–S

blo

ckco

nte

nt

2/44

• Introduction and Vocabulary

• Limits of Software Testing

• Glass-Box Testing

• Statement-, branch-, term-coverage.

• Other Approaches

• Model-based testing,

• Runtime verification.

• Software quality assurancein a larger scope.

• Program Verification

• partial and total correctness,

• Proof System PD.

• Review

VL 15

VL 16

...

VL 17

...

VL 18...

Page 3: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Content–

17–

20

16-0

7-14

–S

con

ten

t–

3/44

• Software quality assurance in a larger scope:

• vocabulary,

• fault, error, failure,

• concepts of software quality assurance(next to testing)

• Formal Program Verification

• Deterministic Programs

• Syntax

• Semantics

• Termination, Divergence

• Correctness of deterministic programs

• partial correctness,

• total correctness.

• Proof System PD

• The Verifier for Concurrent C

Page 4: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Software Quality Assurance

–17

–2

016

-07-

14–

mai

n–

4/44

Page 5: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Formal Methods in the Software Development Process–

17–

20

16-0

7-14

–S

intr

o–

5/44

Customer 2

Mmmh,

Software!

Requirements

JS1K = {(M.C, J · K1), (C.M, J · K1)}

Design

JS2K = {(M.TM .C, J · K1), (C.TC .M, J · K1)}

Implementation

JSK = {σ0

α1−→ σ

1

α2−→ σ

2· · · , . . . }

DevelopmentProcess/Project

Management

validate

analyse

verify

analyse

verify

analyse

validation—

The process of evaluating a system or com-ponent during or at the end of the develop-ment process to determine whether it satis-fies specified requirements.

Contrast with: verification.

IEEE 610.12 (1990)

verification—

(1) The process of evaluating a system or com-ponent to determine whether the prod-ucts of a given development phase satisfythe conditions imposed at the start of thatphase. Contrast with: validation.

(2) Formal proof of program correctness.IEEE 610.12 (1990)

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 6: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Vocabulary–

17–

20

16-0

7-14

–S

intr

o–

6/44

software quality assurance — See: quality assurance. IEEE 610.12 (1990)

quality assurance —

(1) A planned and systematic pattern of all actions necessary to provide ade-quate confidence that an item or product conforms to established techni-cal requirements.

(2) A set of activities designed to evaluate the process by which products aredeveloped or manufactured.

IEEE 610.12 (1990)

Note: in order to trust a product, it can be built well,or proven to be good (at best: both) — both is QA in the sense of (1).

westphal
Bleistift
westphal
Bleistift
Page 7: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Fault, Error, Failure–

17–

20

16-0

7-14

–S

intr

o–

7/44

fault — abnormal condi-tion that can cause an el-ement or an item to fail.

Note: Permanent, intermit-tent and transient faults (es-pecially soft-errors) are con-sidered.

Note: An intermittent faultoccurs time and time again,then disappears. This type offault can occur when a com-ponent is on the verge ofbreaking down or, for exam-ple, due to a glitch in a switch.

Some systematic faults (e.g.

timing marginalities) could

lead to intermittent faults.

ISO 26262 (2011)

error — discrepancybetween a computed,observed or measuredvalue or condition, andthe true, specified, ortheoretically correctvalue or condition.

Note: An error can arise asa result of unforeseen op-erating conditions or dueto a fault within the sys-tem, subsystem or, com-ponent being considered.

Note: A fault can manifest

itself as an error within the

considered element and

the error can ultimately

cause a failure.

ISO 26262 (2011)

failure — termina-tion of the ability ofan element, to per-form a function asrequired.

Note: Incorrect spec-

ification is a source of

failure.

ISO 26262 (2011)

We want to avoid failures, thus we try to detect faults and errors.

westphal
Bleistift
westphal
Bleistift
Page 8: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Concepts of Software Quality Assurance–

17–

20

16-0

7-14

–S

intr

o–

8/44

software qualityassurance

projectmanagement

organisational

softwareexamination

analytic

examination byhumans

non-mech.

inspection reviewmanualproof

comp. aidedhuman exam.

semi-mech.

e.g.interactive

prover

examinationwith computer

mechanical

staticchecking

analyse

checkagainstrules

consistencychecks

quantitativeexamina-

tion

dynamicchecking

(test)

execute

formalverification

prove

constructivesoftware

engineering

constructive

e.g. codegeneration

(Ludewig and Lichter, 2013)

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 9: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Three Basic Approaches–

17–

20

16-0

7-14

–S

intr

o–

9/44

(Σ×A)ω

all computationpaths satisfying the

specification

expectedoutcomes Soll

LSC: buy waterAC: trueAM: invariant I: strict

User CoinValidator ChoicePanel Dispenser

C50

pWATER

¬(C50 ! ∨ E1 ! ∨ pSOFT !

∨ pTEA! ∨ pFILLUP !)

water_in_stock

dWATER

OK

¬(dSoft ! ∨ dTEA!)

defines

×××

×

×execution of(In,Soll)

Reviewer

→ →input output

J · K

∈?

review

⊆ ?

J · K

⊆ ?

Testing Review Formal Verification

proveS |= S ,conclude

JSK ∈ JS K

Page 10: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Sequential, Deterministic While-Programs

–17

–2

016

-07-

14–

mai

n–

10/44

Page 11: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Deterministic Programs–

17–

20

16-0

7-14

–S

wh

ile–

11/44

Syntax:

S := skip | u := t | S1;S2 | if B then S1 else S2 fi | whileB do S1 od

where u ∈ V is a variable, t is a type-compatible expression, B is a Boolean expression.

Semantics: (is induced by the following transition relation) — σ : V → D(V )

(i) 〈skip, σ〉 → 〈E, σ〉

(ii) 〈u := t, σ〉 → 〈E, σ[u := σ(t)]〉

(iii)〈S1, σ〉 → 〈S2, τ〉

〈S1;S, σ〉 → 〈S2;S, τ〉

(iv) 〈if B then S1 else S2 fi, σ〉 → 〈S1, σ〉, if σ |= B,

(v) 〈if B then S1 else S2 fi, σ〉 → 〈S2, σ〉, if σ 6|= B,

(vi) 〈whileB do S od, σ〉 → 〈S;whileB do S od, σ〉, if σ |= B,

(vii) 〈whileB do S od, σ〉 → 〈E, σ〉, if σ 6|= B,

E denotes the empty program; define E;S ≡ S;E ≡ S.

Note: the first component of 〈S, σ〉 is a program (structural operational semantics (SOS)).

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 12: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example–

17–

20

16-0

7-14

–S

wh

ile–

12/44

(i) 〈skip, σ〉 → 〈E, σ〉 E;S ≡ S;E ≡ S

(ii) 〈u := t, σ〉 → 〈E, σ[u := σ(t)]〉

(iii)〈S1, σ〉 → 〈S2, τ〉

〈S1;S, σ〉 → 〈S2;S, τ〉

(iv) 〈if B then S1 else S2 fi, σ〉 → 〈S1, σ〉, if σ |= B,

(v) 〈if B then S1 else S2 fi, σ〉 → 〈S2, σ〉, if σ 6|= B,

(vi) 〈whileB do S od, σ〉 → 〈S;whileB do S od, σ〉, if σ |= B,

(vii) 〈whileB do S od, σ〉 → 〈E, σ〉, if σ 6|= B,

Consider program

S ≡ a[0] := 1; a[1] := 0;while a[x] 6= 0 do x := x+ 1 od

and a state σ with σ |= x = 0.

〈S, σ〉(ii),(iii)−−−−−−→ 〈a[1] := 0;while a[x] 6= 0 do x := x+ 1 od, σ[a[0] := 1]〉(ii),(iii)−−−−−−→ 〈while a[x] 6= 0 do x := x+ 1 od, σ′〉

(vi)−−−→ 〈x := x+ 1;while a[x] 6= 0 do x := x+ 1 od, σ′〉

(ii),(iii)−−−−−−→ 〈while a[x] 6= 0 do x := x+ 1 od, σ′[x := 1]〉

(vii)−−−→ 〈E, σ′[x := 1]〉

where σ′ = σ[a[0] := 1][a[1] := 0].

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 13: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Another Example–

17–

20

16-0

7-14

–S

wh

ile–

13/44

(i) 〈skip, σ〉 → 〈E, σ〉 E;S ≡ S;E ≡ S

(ii) 〈u := t, σ〉 → 〈E, σ[u := σ(t)]〉

(iii)〈S1, σ〉 → 〈S2, τ〉

〈S1;S, σ〉 → 〈S2;S, τ〉

(iv) 〈if B then S1 else S2 fi, σ〉 → 〈S1, σ〉, if σ |= B,

(v) 〈if B then S1 else S2 fi, σ〉 → 〈S2, σ〉, if σ 6|= B,

(vi) 〈whileB do S od, σ〉 → 〈S;whileB do S od, σ〉, if σ |= B,

(vii) 〈whileB do S od, σ〉 → 〈E, σ〉, if σ 6|= B,

Consider programS1 ≡ y := x; y := (x− 1) · x+ y

and a state σ with σ |= x = 3.

〈S1, σ〉(ii),(iii)−−−−−−→ 〈y := (x− 1) · x+ y, {x 7→ 3, y 7→ 3}〉

(ii)−−→ 〈E, {x 7→ 3, y 7→ 9}〉

Consider program S3 ≡ y := x; y := (x− 1) · x+ y; while 1 do skip od.

〈S3, σ〉(ii),(iii)−−−−−−→ 〈y := (x− 1) · x+ y;while 1 do skip od, {x 7→ 3, y 7→ 3}〉(ii),(iii)−−−−−−→ 〈while 1 do skip od, {x 7→ 3, y 7→ 9}〉

(vi)−−−→ 〈skip;while 1 do skip od, {x 7→ 3, y 7→ 9}〉

(i),(iii)−−−−−→ 〈while 1 do skip od, {x 7→ 3, y 7→ 9}〉

(vi)−−−→ . . .

Page 14: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Computations of Deterministic Programs–

17–

20

16-0

7-14

–S

wh

ile–

14/44

Definition. Let S be a deterministic program.

(i) A transition sequence of S (starting in σ) is a finite or infinite sequence

〈S, σ〉 = 〈S0, σ0〉 → 〈S1, σ1〉 → . . .

(that is, 〈Si, σi〉 and 〈Si+1, σi+1〉 are in transition relation for all i).

(ii) A computation (path) of S (starting in σ) is a maximal transition sequenceof S (starting in σ), i.e. infinite or not extendible.

(iii) A computation of S is said to

a) terminate in τ if and only if it is finite and ends with 〈E, τ〉,

b) diverge if and only if it is infinite.

S can diverge from σ if and only if a diverging computation starts in σ.

(iv) We use →∗ to denote the transitive, reflexive closure of →.

Lemma. For each deterministic program S and each state σ,there is exactly one computation of S which starts in σ.

westphal
Bleistift
westphal
Bleistift
Page 15: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Input/Output Semantics of Deterministic Programs–

17–

20

16-0

7-14

–S

wh

ile–

15/44

Definition.Let S be a deterministic program.

(i) The semantics of partial correctness is the function

MJSK : Σ → 2Σ

with MJSK(σ) = {τ | 〈S, σ〉 →∗ 〈E, τ〉}.

(ii) The semantics of total correctness is the function

Mtot JSK : Σ → 2Σ ∪̇ {∞}

with Mtot JSK(σ) = MJSK(σ) ∪ {∞ | S can diverge from σ}.

∞ is an error state representing divergence.

Note: MtotJSK(σ) has exactly one element, MJSK(σ) at most one.

Example: MJS1K(σ) = MtotJS1K(σ) = {τ | τ(x) = σ(x) ∧ τ(y) = σ(x)2}, σ ∈ Σ.

(Recall: S1 ≡ y := x; y := (x− 1) · x+ y)

westphal
Bleistift
westphal
Bleistift
Page 16: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Correctness of While-Programs

–17

–2

016

-07-

14–

mai

n–

16/44

Page 17: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Correctness of Deterministic Programs–

17–

20

16-0

7-14

–S

corr

ect

ne

ss–

17/44

Definition.Let S be a program over variables V , and p and q Boolean expressions over V .

(i) The correctness formula{p} S {q} (“Hoare triple”)

holds in the sense of partial correctness,denoted by |= {p} S {q}, if and only if

MJSK(JpK) ⊆ JqK.

We say S is partially correct wrt. p and q.

(ii) A correctness formula{p} S {q}

holds in the sense of total correctness,denoted by |=tot {p} S {q}, if and only if

MtotJSK(JpK) ⊆ JqK.

We say S is totally correct wrt. p and q.

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 18: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example: Computing squares (of numbers 0, . . . , 27)–

17–

20

16-0

7-14

–S

corr

ect

ne

ss–

18/44

• Pre-condition: p ≡ 0 ≤ x ≤ 27,

• Post-condition: q ≡ y = x2 .

Program S1:

1 i n t y = x ;2 y = ( x − 1 ) * x + y ;

|=? {p} S1 {q}

|=?tot {p} S1 {q}

Program S2:

1 i n t y = x ;2 i n t z ; // u n i n i t i a l i s e d3 y = ( ( x − 1 ) * x + y ) + z ;

|=? {p} S2 {q}

|=?tot {p} S2 {q}

Program S3:

1 i n t y = x ;2 y = ( x − 1 ) * x + y ;3 whi l e ( 1 ) ;

|=? {p} S3 {q}

|=?tot {p} S3 {q}

Program S4:

1 i n t x = re a d _ i n pu t ( ) ;2 i n t y = x + ( x−1 ) * x ;

|=? {p} S4 {q}

|=?tot {p} S4 {q}

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 19: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example: Correctness–

17–

20

16-0

7-14

–S

corr

ect

ne

ss–

19/44

Example

–17

–2

016

-07-1

4–

Sw

hile

5/18

(i) hskip, �i � hE, �i E;S � S;E � S

(ii) hu := t, �i � hE, �[u := �(t)]i

(iii)hS1, �i � hS2, �i

hS1;S, �i � hS2;S, �i

(iv) hif B then S1 else S2 �, �i � hS1, �i, if � |= B,

(v) hif B then S1 else S2 �, �i � hS2, �i, if � 6|= B,

(vi) hwhileB do S od, �i � hS;whileB do S od, �i, if � |= B,

(vii) hwhileB do S od, �i � hE, �i, if � 6|= B,

Consider program

S � a[0] := 1; a[1] := 0;while a[x] 6= 0 do x := x+ 1 od

and a state � with � |= x = 0.

hS, �i(ii),(iii)������� ha[1] := 0;while a[x] 6= 0 do x := x+ 1 od, �[a[0] := 1]i(ii),(iii)������� hwhile a[x] 6= 0 do x := x+ 1 od, ��i

(vi)���� hx := x+ 1;while a[x] 6= 0 do x := x+ 1 od, ��i

(ii),(iii)������� hwhile a[x] 6= 0 do x := x+ 1 od, ��[x := 1]i

(vii)���� hE, ��[x := 1]i

where �� = �[a[0] := 1][a[1] := 0].

• By the example, we have shown

|= {x = 0} S {x = 1}

and

|=tot {x = 0} S {x = 1}.

(because we only assumed σ |= x = 0 for

the example, which is exactly the precon-

dition.)

• We have also shown (= proved (!)):

|= {x = 0} S {x = 1 ∧ a[x] = 0}.

• The correctness formula {x = 2} S {true} does not hold for S.(For example, if σ |= a[i] 6= 0 for all i > 2.)

• In the sense of partial correctness, {x = 2 ∧ ∀ i ≥ 2 • a[i] = 1} S {false} also holds.

Page 20: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof-System PD

–17

–2

016

-07-

14–

mai

n–

20/44

Page 21: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof-System PD (for sequential, deterministic programs)

–17

–2

016

-07-

14–

Sp

d–

21/44

Axiom 1: Skip-Statement

{p} skip {p}

Axiom 2: Assignment

{p[u := t]} u := t {p}

Rule 3: Sequential Composition

{p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}

Rule 4: Conditional Statement

{p ∧B} S1 {q}, {p ∧ ¬B} S2 {q},

{p} if B then S1 else S2 fi {q}

Rule 5: While-Loop

{p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

Rule 6: Consequence

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

Theorem. PD is correct (“sound”) and (relative) complete for partial correctness ofdeterministic programs, i.e. ⊢PD {p} S {q} if and only if |= {p} S {q}.

westphal
Bleistift
Page 22: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example Proof–

17–

20

16-0

7-14

–S

pd

22/44

DIV ≡

=:SD

0

︷ ︸︸ ︷

a := 0; b := x; while

=:BD

︷ ︸︸ ︷

b ≥ y do

=:SD

1

︷ ︸︸ ︷

b := b− y; a := a+ 1 od

(The first (textually represented) program that has been formally verified (Hoare, 1969).

We can prove |= {x ≥ 0 ∧ y ≥ 0}DIV {a · y + b = x ∧ b < y}

by showing ⊢PD {x ≥ 0 ∧ y ≥ 0︸ ︷︷ ︸

=:pD

}DIV {a · y + b = x ∧ b < y︸ ︷︷ ︸

=:qD

}, i.e., derivability in PD:

(1)

{pD} SD0 {P},

P → P,

(2)

{P ∧ (BD)} SD1 {P}

{P}whileBD do SD1 od {P ∧ ¬(BD)},

(R5)(3)

P ∧ ¬(BD) → qD

{P}whileBD do SD1 od {qD}

(R6)

{pD} SD0 ; whileBD do SD

1 od {qD}

(R3)

(A1) {p} skip {p} (R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R5)

{p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(A2) {p[u := t]} u := t {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

westphal
Bleistift
Page 23: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example Proof–

17–

20

16-0

7-14

–S

pd

22/44

DIV ≡

=:SD

0

︷ ︸︸ ︷

a := 0; b := x; while

=:BD

︷ ︸︸ ︷

b ≥ y do

=:SD

1

︷ ︸︸ ︷

b := b− y; a := a+ 1 od

(The first (textually represented) program that has been formally verified (Hoare, 1969).

We can prove |= {x ≥ 0 ∧ y ≥ 0}DIV {a · y + b = x ∧ b < y}

by showing ⊢PD {x ≥ 0 ∧ y ≥ 0︸ ︷︷ ︸

=:pD

}DIV {a · y + b = x ∧ b < y︸ ︷︷ ︸

=:qD

}, i.e., derivability in PD:

(1)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P},

P → P,

(2)

{P ∧ (b ≥ y)} b := b− y; a := a+ 1 {P}

{P}while b ≥ y do b := b− y; a := a+ 1 od {P ∧ ¬(b ≥ y)},

(R5)(3)

P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y

{P}while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}

(R6)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x; while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}

(R3)

(A1) {p} skip {p} (R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R5)

{p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(A2) {p[u := t]} u := t {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

Page 24: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Example Proof Cont’d–

17–

20

16-0

7-14

–S

pd

23/44

(1)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P},

P → P,

(2)

{P ∧ (b ≥ y)} b := b− y; a := a+ 1 {P}

{P}while b ≥ y do b := b− y; a := a+ 1 od {P ∧ ¬(b ≥ y)},(R5)

(3)

P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y

{P}while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}(R6)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x; while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}(R3)

In the following, we show

(1) ⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P},

(2) ⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P},

(3) |= P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y.

As loop invariant, we choose (creative act!):

P ≡ a · y + b = x ∧ b ≥ 0

Page 25: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (1)–

17–

20

16-0

7-14

–S

pd

24/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (1) claims:

⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {0 · y + x = x ∧ x ≥ 0} a := 0 {a · y + x = x ∧ x ≥ 0} by (A2),

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 26: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (1)–

17–

20

16-0

7-14

–S

pd

24/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (1) claims:

⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {0 · y + x = x ∧ x ≥ 0} a := 0 {a · y + x = x ∧ x ≥ 0} by (A2),

• ⊢PD {a · y + x = x ∧ x ≥ 0} b := x {a · y + b = x ∧ b ≥ 0︸ ︷︷ ︸

≡P

} by (A2),

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 27: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (1)–

17–

20

16-0

7-14

–S

pd

24/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (1) claims:

⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {0 · y + x = x ∧ x ≥ 0} a := 0 {a · y + x = x ∧ x ≥ 0} by (A2),

• ⊢PD {a · y + x = x ∧ x ≥ 0} b := x {a · y + b = x ∧ b ≥ 0︸ ︷︷ ︸

≡P

} by (A2),

• thus, ⊢PD {0 · y + x = x ∧ x ≥ 0} a := 0; b := x {P} by (R3),

• using x ≥ 0 ∧ y ≥ 0 → 0 · y + x = x ∧ x ≥ 0 and P → P , we obtain

⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P}

by (R6).

Page 28: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Substitution–

17–

20

16-0

7-14

–S

pd

25/44

The rule ‘Assignment’ uses (syntactical) subsitution: {p[u := t]} u := t {p}

(In formula p, replace all (free) occurences of (program or logical) variable u by term t.)

Defined as usual, only indexed and bound variables need to be treated specially:

Expressions:

• plain variable x: x[u := t] ≡

{

t , if x = u

x , otherwise

• constant c:c[u := t] ≡ c.

• constant op, terms si :op(s1, . . . , sn)[u := t]≡ op(s1[u := t], . . . , sn[u := t]).

• conditional expression:(B ? s1 : s2)[u := t]≡ (B[u := t] ? s1[u := t] : s2[u := t])

Formulae:

• boolean expression p ≡ s:p[u := t] ≡ s[u := t]

• negation:(¬q)[u := t] ≡ ¬(q[u := t])

• conjunction etc.:(q ∧ r)[u := t]≡ q[u := t] ∧ r[u := t]

• quantifier:(∀x : q)[u := t] ≡ ∀ y : q[x := y][u := t]y fresh (not in q, t, u), same type as x.

• indexed variable, u plain or u ≡ b[t1, . . . , tm] and a 6= b:

(a[s1, . . . , sn])[u := t] ≡ a[s1[u := t], . . . , sn[u := t]])

• indexed variable, u ≡ a[t1, . . . , tm]:

(a[s1, . . . , sn])[u := t] ≡ (∧n

i=1 si[u := t] = ti ? t : a[s1[u := t], . . . , sn[u := t]])

westphal
Bleistift
Page 29: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (2)–

17–

20

16-0

7-14

–S

pd

26/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (2) claims:

⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {(a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0} b := b− y {(a+ 1) · y + b = x ∧ b ≥ 0}by (A2),

westphal
Bleistift
westphal
Bleistift
Page 30: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (2)–

17–

20

16-0

7-14

–S

pd

26/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (2) claims:

⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {(a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0} b := b− y {(a+ 1) · y + b = x ∧ b ≥ 0}by (A2),

• ⊢PD {(a+ 1) · y + b = x ∧ b ≥ 0} a := a+ 1 {a · y + b = x ∧ b ≥ 0︸ ︷︷ ︸

≡P

} by (A2),

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 31: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (2)–

17–

20

16-0

7-14

–S

pd

26/44

(A1) {p} skip {p} (R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(A2) {p[u := t]} u := t {p} (R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}(R6)

p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• (2) claims:

⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P}

where P ≡ a · y + b = x ∧ b ≥ 0.

• ⊢PD {(a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0} b := b− y {(a+ 1) · y + b = x ∧ b ≥ 0}by (A2),

• ⊢PD {(a+ 1) · y + b = x ∧ b ≥ 0} a := a+ 1 {a · y + b = x ∧ b ≥ 0︸ ︷︷ ︸

≡P

} by (A2),

• ⊢PD {(a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0} b := b− y; a := a+ 1 {P} by (R3),

• using P ∧ b ≥ y → (a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0 and P → P we obtain,

⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P}

by (R6).

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 32: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Proof of (3)–

17–

20

16-0

7-14

–S

pd

27/44

(3) claims|= P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y.

where P ≡ a · y + b = x ∧ b ≥ 0.

Proof: easy.

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 33: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Back to the Example Proof–

17–

20

16-0

7-14

–S

pd

28/44

We have shown:

(1) ⊢PD {x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P},

(2) ⊢PD {P ∧ b ≥ y} b := b− y; a := a+ 1 {P},

(3) |= P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y.

and

(1)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x {P},

P → P,

(2)

{P ∧ (b ≥ y)} b := b− y; a := a+ 1 {P}

{P}while b ≥ y do b := b− y; a := a+ 1 od {P ∧ ¬(b ≥ y)},(R5)

(3)

P ∧ ¬(b ≥ y) → a · y + b = x ∧ b < y

{P}while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}(R6)

{x ≥ 0 ∧ y ≥ 0} a := 0; b := x; while b ≥ y do b := b− y; a := a+ 1 od {a · y + b = x ∧ b < y}(R3)

thus

⊢PD {x ≥ 0∧y ≥ 0} a := 0; b := x; while b ≥ y do b := b− y; a := a+ 1 od︸ ︷︷ ︸

≡DIV

{a·y+b = x∧b < y}

and thus (since PD is sound) DIV is partially correct wrt.

• pre-condition: x ≥ 0 ∧ y ≥ 0,

• post-condition: a · y + b = x ∧ b < y.

IOW: whenever DIV is called with x and y such that x ≥ 0 ∧ y ≥ 0,then (if DIV terminates) a · y + b = x ∧ b < y will hold.

Page 34: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Once Again–

17–

20

16-0

7-14

–S

pd

29/44

(A1) {p} skip {p}

(A2) {p[u := t]} u := t {p}

(R3){p} S1 {r}, {r} S2 {q}

{p} S1; S2 {q}

(R4){p ∧B} S1 {q}, {p ∧ ¬B} S2 {q}

{p} if B then S1 else S2 fi {q}

(R5){p ∧B} S {p}

{p}whileB do S od {p ∧ ¬B}

(R6)p → p1, {p1} S {q1}, q1 → q

{p} S {q}

• P ≡ a · y + b = x ∧ b ≥ 0

{x ≥ 0 ∧ y ≥ 0}

{0 · y + x = x ∧ x ≥ 0}

• a := 0;

{a · y + x = x ∧ x ≥ 0}

• b := x;

{a · y + b = x ∧ b ≥ 0}

{P}

• while b ≥ y do

{P ∧ b ≥ y}

{(a+ 1) · y + (b− y) = x ∧ (b− y) ≥ 0}

• b := b− y;

{(a+ 1) · y + b = x ∧ b ≥ 0}

• a := a+ 1

{a · y + b = x ∧ b ≥ 0}

{P}

• od

{P ∧ ¬(b ≥ y)}

{a · y + b = x ∧ b < y}

westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
westphal
Bleistift
Page 35: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Literature Recommendation–

17–

20

16-0

7-14

–S

pd

30/44

Page 36: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Assertions

–17

–2

016

-07-

14–

mai

n–

31/44

Page 37: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Assertions–

17–

20

16-0

7-14

–S

asse

rt–

32/44

• Extend the syntax of deterministic programs by

S := · · · | assert(B)

• and the semantics by rule

〈assert(B), σ〉 → 〈E, σ〉 if σ |= B.

(If the asserted boolean expression B does not hold in state σ, the empty program is not reached;

otherwise the assertion remains in the first component: abnormal program termination).

Extend PD by axiom:

(A7) {p} assert(p) {p}

• That is, if p holds before the assertion, then we can continue with the derivation in PD.

If p does not hold, we “get stuck” (and cannot complete the derivation).

• So we cannot derive {true} x := 0; assert(x = 27) {true} in PD.

Page 38: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Modular Reasoning

–17

–2

016

-07-

14–

mai

n–

33/44

Page 39: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Modular Reasoning–

17–

20

16-0

7-14

–S

mo

du

lar

34/44

We can add another rule for calls of functions f : F (simplest case: only global variables):

(R7){p} F {q}

{p} f() {q}

“If we have ⊢ {p} F {q} for the implementation of function f ,then if f is called in a state satisfying p, the state after return of f will satisfy q.”

p is called pre-condition and q is called post-condition of f .

Example: if we have

• {true} read_number {0 ≤ result < 108}

• {0 ≤ x ∧ 0 ≤ y} add {(old(x) + old(y) < 108 ∧ result = old(x) + old(y)) ∨ result < 0}

• {true} display {(0 ≤ old(x) < 108 =⇒ ”old(x)”) ∧ (old(x) < 0 =⇒ ”-E-”)}

we may be able to prove our pocket calculator correct.

12345678+ 27

7 8 9 0

4 5 6 +

1 2 3 =

1 i n t main ( ) {2

3 whi l e ( t r u e ) {4 i n t x = read_number ( ) ;5 i n t y = read_number ( ) ;6

7 i n t sum = add ( x , y ) ;8

9 d i s p l a y ( sum ) ;10 }11 }

Page 40: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Return Values and Old Values–

17–

20

16-0

7-14

–S

mo

du

lar

35/44

• For modular reasoning, it’s often useful to refer in the post-condition

• to the return value as result ,

• the values of variable x at calling time as old(x).

• Can be defined using auxiliary variables:

• Transform functionT f() {. . . ; return expr ; }

(over variables V = {v1, . . . , vn}, result , voldi /∈ V ) to

T f() {

vold1 := v1; . . . ; voldn := vn;

. . . ;

result := expr ;

return result ;

}

over V ′ = V ∪ {vold | v ∈ V } ∪ {result}.

• Then old(x) is just an abbreviation for xold .

Page 41: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

The Verifier for Concurrent C

–17

–2

016

-07-

14–

mai

n–

36/44

Page 42: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

VCC–

17–

20

16-0

7-14

–S

vcc

37/44

• The Verifier for Concurrent C (VCC) basically implements Hoare-style reasoning.

• Special syntax:

• #include <vcc.h>

• _(requires p) — pre-condition, p is (basically) a C expression

• _(ensures q) — post-condition, q is (basically) a C expression

• _(invariant expr) — loop invariant, expr is (basically) a C expression

• _(assert p) — intermediate invariant, p is (basically) a C expression

• _(writes &v) — VCC considers concurrent C programs; we need to declare for eachprocedure which global variables it is allowed to write to (also checked by VCC)

• Special expressions:

• \thread_local(&v) — no other thread writes to variable v (in pre-conditions)

• \old(v) — the value of v when procedure was called (useful for post-conditions)

• \result — return value of procedure (useful for post-conditions)

westphal
Bleistift
Page 43: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

VCC Syntax Example–

17–

20

16-0

7-14

–S

vcc

38/44

1 #inc lude < vcc . h >2

3 i n t a , b ;4

5 vo id d i v ( i n t x , i n t y )6 _ ( r e q u i r e s x >= 0 && y >= 0)7 _ ( ensures a * y + b == x && b < y )8 _ ( w r i t e s &a )9 _ ( w r i t e s &b )

10 {11 a = 0;12 b = x ;13 whi l e ( b >= y )14 _ ( i n v a r i a n t a * y + b == x && b >= 0)15 {16 b = b − y ;17 a = a + 1 ;18 }19 }

DIV ≡ a := 0; b := x; while b ≥ y do b := b− y; a := a+ 1 od

{x ≥ 0 ∧ y ≥ 0}DIV {x ≥ 0 ∧ y ≥ 0}

westphal
Bleistift
Page 44: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

VCC Web-Interface–

17–

20

16-0

7-14

–S

vcc

39/44Example program DIV : http://rise4fun.com/Vcc/4Kqe

Page 45: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Interpretation of Results–

17–

20

16-0

7-14

–S

vcc

40/44

• VCC says: “verification succeeded”

We can only conclude that the tool— under its interpretation of the C-standard, under its platform assumptions (32-bit), etc. —

“thinks” that it can prove |= {p}DIV {q}.

Can be due to an error in the tool! (That’s a false negative then.)

Yet we can ask for a printout of the proof and check it manually

(hardly possible in practice) or with other tools like interactive theorem provers.

Note: |= {false} f {q} always holds.

That is, a mistake in writing down the pre-condition can make errors in the program go undetected.

• VCC says: “verification failed”

• May be a false positive.

The tool does not provide counter-examples in the form of a computation path,

it (only) gives hints on input values satisfying p and causing a violation of q.

→ try to construct a (true) counter-example from the hints.

or: → make pre-condition p or loop-invariant(s) stronger, and try again.

• Other case: “timeout” etc. — completely inconclusive outcome.

Page 46: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

VCC Features–

17–

20

16-0

7-14

–S

vcc

41/44

• For the exercises, we use VCC only for sequential, single-thread programs.

• VCC checks a number of implicit assertions:

• no arithmetic overflow in expressions (according to C-standard),

• array-out-of-bounds access,

• NULL-pointer dereference,

• and many more.

• VCC also supports:

• concurrency:different threads may write to shared global variables; VCC can check whether concurrent access toshared variables is properly managed;

• data structure invariants:we may declare invariants that have to hold for, e.g., records (e.g. the length field l is always equal tothe length of the string field str ); those invariants may temporarily be violated when updating thedata structure.

• and much more.

• Verification does not always succeed:

• The backend SMT-solver may not be able to discharge proof-obligations(in particular non-linear multiplication and division are challenging);

• In many cases, we need to provide loop invariants manually.

westphal
Bleistift
Page 47: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

Tell Them What You’ve Told Them. . .–

17–

20

16-0

7-14

–S

ttw

ytt

42/44

• There are more approaches to software quality assurancethan just testing.

• For example, program verification.

• Proof System PD can be used

• to prove

• that a given program is

• correct wrt. its specification.

This approach considers all inputs inside the specification!

• Tools like VCC implement this approach.

westphal
Bleistift
westphal
Bleistift
Page 48: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

References

–17

–2

016

-07-

14–

mai

n–

43/44

Page 49: Lecture 17: Software Verification · Topic Area Code Quality Assurance: Content – 17– 2016-07-14 –Sblockcontent– 2/44 • IntroductionandVocabulary • Limitsof Software

References–

17–

20

16-0

7-14

–m

ain

44/44

Hoare, C. A. R. (1969). An axiomatic basis for computer programming. Commun. ACM,12(10):576–580.

IEEE (1990). IEEE Standard Glossary of Software Engineering Terminology. Std 610.12-1990.

ISO (2011). Road vehicles – Functional safety – Part 1: Vocabulary. 26262-1:2011.

Ludewig, J. and Lichter, H. (2013). Software Engineering. dpunkt.verlag, 3. edition.