Software Testing Lecture 5 Justin Pearson 2019 1 / 38 Covering - - PowerPoint PPT Presentation

software testing lecture 5
SMART_READER_LITE
LIVE PREVIEW

Software Testing Lecture 5 Justin Pearson 2019 1 / 38 Covering - - PowerPoint PPT Presentation

Software Testing Lecture 5 Justin Pearson 2019 1 / 38 Covering Logical Expressions Logic expressions show up in many situations Covering logical expressions has a long history, many are the covering criteria are mandated by the US FAA


slide-1
SLIDE 1

Software Testing Lecture 5

Justin Pearson 2019

1 / 38

slide-2
SLIDE 2

Covering Logical Expressions

◮ Logic expressions show up in many situations ◮ Covering logical expressions has a long history, many are the covering criteria are mandated by the US FAA in safety critical software. ◮ Logical expressions can come from many sources:

◮ Decisions in programs ◮ Finite State Machines and statecharts ◮ Requirements

2 / 38

slide-3
SLIDE 3

Interlude TCAS

◮ Traffic collision avoidance system (TCAS) Two aircraft flying towards each other, you have to decide which

  • ne goes up and which one goes down. From wikipedia:

The next step beyond identifying potential collisions is automatically negotiating a mutual avoidance manoeuver (currently, manoeuvers are restricted to changes in altitude and modification of climb/sink rates) between the two (or more) conflicting aircraft. These avoidance manoeuvers are communicated to the flight crew by a cockpit display and by synthesized voice instructions.

3 / 38

slide-4
SLIDE 4

TCAS

There are rather a lot of complicated interacting logical requirements that decide unambiguously how each aircraft should react.

4 / 38

slide-5
SLIDE 5

Covering Logical Expressions

◮ Typical balance in software testing:

◮ In theory, there are too many options to test everything. ◮ Find good coverage criteria that have a chance of covering useful cases. ◮ As usual there are no guarantees, but try to model cases that capture commonly occurring faults.

5 / 38

slide-6
SLIDE 6

Motivation

i f (( x>0 && y>0) | | z>0) { do something ;} else { s o m e t h i n g e l s e ;} Branch or edge coverage would only require one test case that executes the two branches. Instead, you might want to test all the possibilities of the logical expression.

6 / 38

slide-7
SLIDE 7

Motivation

x>0 y>0 z>0 ((x>0 && y>0) || z>0) T T T T T T F T T F T T T F F F F T T T F T F F F F T T F F F F So a test corresponding to the line TFT would require: x > 0, y ≤ 0 and z > 0. You would have to find a test path with these values.

7 / 38

slide-8
SLIDE 8

Logical Connectives: Revisions?

P Q P ∧ Q, P && Q T T T T F F F T F F F F P Q P ∨ Q, P || Q T T T T F T F T T F F F P Q P → Q T T T T F F F T T F F T P Q P ↔ Q T T T T F F F T F F F T P ¬P, !P T F F T P Q P ⊕ Q Exclusive Or T T F T F T F T T F F F

8 / 38

slide-9
SLIDE 9

Predicates and Clauses

◮ A predicate is an expression that evaluates to true or false. ◮ A predicate may contain:

◮ Boolean variables. ◮ Expressions evaluating to Boolean variables that contain comparison operation >, < , ==, >=, != , <= ◮ Boolean function calls.

◮ Internal structure is created by logical operators (see previous slide) ◮ A clause is a predicate with no logical operators.

◮ P ∧ Q is a predicate ◮ x>0 is a clause.

9 / 38

slide-10
SLIDE 10

Testing and Covering Predicates

◮ Reduce the artefact to a set of predicates ◮ State covering criteria in terms of predicates and clauses. ◮ P - the set of predicates. ◮ p is a single predicate in P. ◮ C - set of clauses in P. ◮ Cp - set of clauses in predicate p. ◮ c is a single clause in C.

10 / 38

slide-11
SLIDE 11

Predicate Coverage

Very simple and very blunt. ◮ Predicate Coverage (PC): For each p in P, the test requirements include that p evaluates to true and p evaluates to false.

11 / 38

slide-12
SLIDE 12

Predicate Coverage

i f ( x>0 | | y>0) { do something ;} else { s o m e t h i n g e l s e ;} i f ( z>0) { foo ;} else { bar ;} The predicates are x>0 || y>0 and z>0. So we have 4 test

  • requirements. So test case inputs could be x = 3 ∧ y = −10,

x = −3 ∧ y = −10, z = 20 and z = −120.

12 / 38

slide-13
SLIDE 13

Clause Coverage

◮ Not every clause is exercised. So we get a new coverage criterion. ◮ Clause Coverage (CC) - For each clause c in C, we have a test requirement that c evaluates to true and c evaluates to false.

13 / 38

slide-14
SLIDE 14

Clause Coverage

i f ( x>0 | | y>0) { do something ;} else { s o m e t h i n g e l s e ;} i f ( z>0) { foo ;} else { bar ;} The clause are x>0, y>0 and z>0. So we have 6 test requirements.

14 / 38

slide-15
SLIDE 15

Example

((a < b) ∨ D) ∧ (m ≥ n) ◮ Predicate true: a = 5, b = 10, D is true, m = 1 and n = 1. ◮ ((5 < 10) ∨ T) ∧ (1 ≥ 1) = (T ∨ T) ∧ T ◮ Predicate false: a = 10, b = 5, D is false, m = 1 and n = 1. ◮ ((5 < 10) ∨ F) ∧ (1 ≥ 1) = (T ∨ T) ∧ T ◮ (F ∨ F) ∧ T = F.

15 / 38

slide-16
SLIDE 16

Clause Coverage

((a < b) ∨ D) ∧ (m ≥ n) Test requirements ◮ a < b is true: a = 5, b = 10. ◮ a < b is false: a = 10, b = 5. ◮ D is true and D is false. ◮ m ≥ n is true: m = 1, n = 1. ◮ m ≥ n is false: m = 1, n = 2. We can do this with two test cases: ◮ a = 5, b = 10, D is true, m = 1 and n = 1. ◮ a = 10,b = 5, D is false, m = 1 and n = 2.

16 / 38

slide-17
SLIDE 17

Problems with Predicate and Clause Coverage

◮ Predicate coverage does not fully exercise all the clauses, especially in the presence of short circuit evaluation: P && Q ◮ If P is false then Q is never evaluated1 in C++.

1It is a bit more complicated than this. 17 / 38

slide-18
SLIDE 18

Problems with Predicate and Clause Coverage

◮ Clause coverage does not imply predicate coverage. ◮ We can satisfy clause coverage without causing the predicate to be true and false. (P ∨ Q) ∧ R ◮ Clauses P, Q and R. Thus, we have 6 test requirements P = T,P = F, Q = T,Q = F, R = T and R = F. ◮ (P = F ∨ Q = F) ∧ R = T evaluates to false. ◮ (P = T ∨ Q = T) ∧ R = F evaluates to false. ◮ All test requirements covered. So we need something better, all possibilities?

18 / 38

slide-19
SLIDE 19

Combinatorial Coverage

◮ Combinatorial Coverage For each p in P, the test requirement includes that each clause in Cp evaluates to each possible combination of truth values. ◮ That really means test all rows in the truth table.

19 / 38

slide-20
SLIDE 20

Combinatorial Coverage

◮ Simple, clean, neat, and comprehensive. ◮ But, it can be quite expensive 2N tests for N clauses. ◮ Lots of suggestions in the literature, but the general idea is simple:

◮ Test each clause independently from the other clauses.

◮ You have to work out what exactly does independent mean. The book uses the concept “making clauses active”.

20 / 38

slide-21
SLIDE 21

Active Clauses

◮ The major weakness of clause coverage is that the values do not always make a difference. ◮ We really want the test results of a clause to be a determining factor in the truth or falsehood of the predicate.

21 / 38

slide-22
SLIDE 22

Determination

◮ Major clause is the clause under consideration. ◮ Minor clause are the rest of the clauses. ◮ Let ci be the major clause in a predicate p. Then ci determines p if and only if the value of the remaining minor clauses are such that changing the value of Ci changes the value of p.

22 / 38

slide-23
SLIDE 23

Determining Predicates

◮ P = A ∨ B.

◮ Major clause A, and minor clause B. If B = F then A determines P. ◮ Major clause B, and minor clause A. If A = F then B determines P.

◮ Q = A ∧ B.

◮ if B = F then Q is always false. ◮ If B = T then A determines p.

23 / 38

slide-24
SLIDE 24

Determining Predicates

◮ For a determining clause you have to take into account the assignments of the minor clauses. ◮ Basic idea is: for each clause you want assignments to the minor clauses so that your clause becomes a determining clause. ◮ It becomes more complicated, when you consider how the different test requirements overlap.

24 / 38

slide-25
SLIDE 25

Active Clause Coverage

◮ Active Clause Coverage (ACC): For each predicate p in P and each major clause, choose values for the minor clauses so that the major clause determines p. The test requirements contain requirements so that the major clause evaluates to true and the major clause evaluates to false.

25 / 38

slide-26
SLIDE 26

Active Clause Coverage

P = A ∨ B ◮ A as the major clause.

◮ A = T, B = F ◮ A = F, B = F.

◮ B as the major clause.

◮ B = T, A = F ◮ B = F, A = F.

There is a source of ambiguity: Do the minor clauses have to have the same values when the major clause is true and false?

26 / 38

slide-27
SLIDE 27

Resolving the Ambiguity

P = A ∨ (B ∧ C) Major clause A: ◮ A = T, B = F, C = T ◮ A = F, B = F, C = F Do we allow different assignments to the minor clauses? Three possible criteria: ◮ Minor clauses do not need to be the same. ◮ Minor clauses do need to be the same. ◮ Minor clauses force predicate to become both true and false.

27 / 38

slide-28
SLIDE 28

General Active Clause Coverage

General Active Clause Coverage: For each predicate p in P and each major clause in Cp, choose minor clauses so that it determines p.Test requirements include that the major clause evaluates to true and false. The values of the minor clauses do not need to be the same. This is the most general definition.

28 / 38

slide-29
SLIDE 29

General Active Clause Coverage

General active clause coverage does not imply predicate coverage. P = A ↔ B ◮ Major clause A

◮ A = T, B = F , P = A ↔ B = F. ◮ A = F, B = T. P = A ↔ B = F.

◮ Major Clause B

◮ B = T, A = F, P = A ↔ B = F. ◮ B = F, A = T, P = A ↔ B = F.

We have general active clause coverage, but the predicate always evaluates to false. We really want clauses to cause predicates to evaluate to both true and false.

29 / 38

slide-30
SLIDE 30

Restricted Active Clause Coverage

◮ Restricted Active Clause Coverage: For each predicate and each major clause in each predicate, choose values of minor clauses so that the major determines the predicate.Test requirements include each major clause evaluates to true and

  • false. The values chosen for the minor clauses must be the

same. ◮ Been used in aviation software. ◮ No logical reason for the values of the minor clauses to be the same. ◮ We still haven’t solved the problem of the predicate evaluating to both true and false.

30 / 38

slide-31
SLIDE 31

Correlated Active Clause Coverage

◮ Correlated Active Clause Coverage: For each predicate and each major clause in each predicate, choose values of minor clauses so that the major clause determines the predicate. Test requirements include each major clause evaluates to true and false. The values of the minor clauses must be chosen such that the predicate evaluates to true and false.

31 / 38

slide-32
SLIDE 32

Correlated Active Clause Coverage

A ∧ (B ∨ C) ◮ Major Clause A.

◮ A = T, B = T, C = T, A ∧ (B ∨ C) = T ◮ A = F, B = T, C = F, A ∧ (B ∨ C) = F

32 / 38

slide-33
SLIDE 33

Making clauses determine a predicate

◮ Finding values for minor clauses is easy for simple predicates. ◮ A trick help with more complicated predicates. ◮ Pc=T, replace every occurrence of c by T. ◮ Pc=F, replace every occurrence of c by F. ◮ Solving Pc=T ⊕ Pc=F = T gives you the values of the minor clauses for the major clause c to determine the predicate. Remember that A ⊕ B is equivalent to (A ∨ B) ∧ ¬(A ∧ B).

33 / 38

slide-34
SLIDE 34

Making clauses determine a predicate

◮ P = A ∨ B, Major clause A.

◮ PA = PA=T ⊕ PA=F = (T ∨ B) ⊕ (F ∨ B) which gives T ⊕ B = ¬B. ◮ So B must be false.

◮ P = A ∧ B, Major clause A. ◮ PA = PA=T ⊕ PA=F = (T ∧ B) ⊕ (F ∧ B) which gives B ⊕ F = B. ◮ So B must be true.

34 / 38

slide-35
SLIDE 35

Making clauses determine a predicate

◮ P = A ∨ (B ∧ C), Major clause A.

◮ PA=T ⊕ PA=F = (T ∨ (B ∧ C)) ⊕ (F ∨ (B ∧ C)) which gives T ⊕ (B ∧ C) = ¬(B ∧ C) = ¬B ∨ ¬C. ◮ So B = F and C = T is a solution. ◮ A ∨ (F ∧ T) = A ∨ F.

35 / 38

slide-36
SLIDE 36

Determination is not always possible

Consider p = (a ∧ b) ∨ (a ∧ ¬b) ◮ pb=T ⊕ pb=F = (a ∧ T) ∨ (a ∧ ¬T) ⊕ (a ∧ F) ∨ (a ∧ ¬F) ◮ = (a ∨ F) ⊕ (F ∨ a) ◮ = a ⊕ a which is always false. If you think about this, then it should not be too surprising. In this case b is redundant.

36 / 38

slide-37
SLIDE 37

Logic Coverage Summary

◮ Combinatorial coverage gives too many test cases. ◮ Predicate coverage is too blunt. ◮ Clause coverage has to be refined to force the predicate to evaluate to both true and false. ◮ We want the test case to do some work, so we use correlated active clause coverage. The are lots of different variations, but it is important to remember major, minor clauses determining a predicate, requiring the predicate to be true or false. The variations are then on requirements on how the clauses

  • verlap.

Think about infeasible test requirements: X > 0 ∧ X < 0.

37 / 38

slide-38
SLIDE 38

Common Themes

◮ Define coverage, even in a finite case there are too many cases to consider. ◮ Look for restrictions, but look for restrictions that find test cases that actually do some work. ◮ Try to maximise the overlapping test cases for each requirement in order to minimise the number of test cases needed. ◮ As usual there are no (or very few) theoretical guarantees. ◮ In some domains standards are mandated.

38 / 38