26
1 Software Testing & Quality Assurance Lecture 12 Created by: Paulo Alencar

Software Testing & Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

  • Upload
    marc

  • View
    47

  • Download
    0

Embed Size (px)

DESCRIPTION

Software Testing & Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu. Overview. Structural Testing Introduction – General Concepts Flow Graph Testing Data Flow Testing Definitions Some Basic Data Flow Analysis Algorithms Define/use Testing Slice Based Testing - PowerPoint PPT Presentation

Citation preview

Page 1: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

1

Software Testing & Quality Assurance

Lecture 12

Created by: Paulo Alencar

Page 2: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

2

OverviewStructural Testing

Introduction – General ConceptsFlow Graph TestingData Flow Testing

DefinitionsSome Basic Data Flow Analysis AlgorithmsDefine/use TestingSlice Based TestingGuidelines and Observations

Hybrid MethodsRetrospective on Structural Testing

Page 3: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

3

Data Flow Testing – Basic Idea

• Data-flow testing involves selecting entry/exit paths with the objective of covering certain data definition and use patterns, commonly known as data-flow criteria

• An outline of data-flow testing is as follows:– Draw a data flow graph for the program– Select data-flow testing criteria– Identify paths in the data-flow graph to satisfy the selection

criteria (i.e. all-defs, all-uses, all-P-uses/some-C-uses etc.)– Produce test cases for the selected paths

Page 4: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

4

Some Definitions (1)

• Node n in the CFG of program P is a defining node of the variable v V, written as DEF(v, n), iff the value of the variable v is unambiguously defined at the statement fragment corresponding to node n.

• Node n in the CFG of program P is a usage node of the variable v V, written as USE(v, n), iff the value of the variable v is used at the statement fragment corresponding to node n.

Page 5: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

5

Some Definitions (2)

• A usage node USE(v, n), is a predicate use (denoted as P-use) iff the statement n is a predicate statement, otherwise USE(v, n) is a computation use or C-use

• The nodes corresponding to predicate uses have always an outdegree ≥ 2, and nodes corresponding to computation uses always have outdegree ≤ 1

Page 6: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

6

Annotated Control Flow - Example For X, Y Data Flows:1 INPUT X,Y Z:= X+Y Y:= X-Y3 IF Z>=0 GOTO SAM4 JOE: Z:=Z-15 SAM: Z:=Z+V

U:=06 LOOP

B(U),Q(V):=(Z+V)*U7 IF B(U)=0 GOTO JOE

Z:=Z-18 IF Z=0 GOTO ELL

U:=U+19 UNTIL U=z

B(U-1):=B(U+1)+Q(V-1)10 ELL: B(U+Q(V)):=U+V11 IF U=V GOTO JOE12 IF U>V THEN U:=Z13 YY:Z:=U2 END

1 3 4 5 6 7

2 8910111213

Z?

END YY U,V? U,V?

U,Z?ELL

SAM

LOOP B(U)?dcc

JOE

Page 7: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

7

Annotated Control Flow - Example For Z Data Flows:

1 INPUT X,Y Z:= X+Y Y:= X-Y3 IF Z>=0 GOTO SAM4 JOE: Z:=Z-15 SAM: Z:=Z+V

U:=06 LOOP

B(U),Q(V):=(Z+V)*U7 IF B(U)=0 GOTO JOE

Z:=Z-18 IF Z=0 GOTO ELL

U:=U+19 UNTIL U=z

B(U-1):=B(U+1)+Q(V-1)10 ELL: B(U+Q(V)):=U+V11 IF U=V GOTO JOE12 IF U>V THEN U:=Z13 YY:Z:=U2 END

1 3 4 5 6 7

2

8910111213

Z?END

YY U,V? U,V? U,Z?

ELL

SAM

LOOP B(U)?d JOEp

p cd cd c

cdp

d c p p

p

Page 8: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

8

Some Definitions (3)

• A definition-use (sub)path with respect to a variable v (denoted as du-path) is a (sub)path in PATHS(P), where PATHS(P) is the set of all possible paths in the CFG of program P, such that, for some v in V, there are define and usage nodes DEF(v, m) and USE(v, n) such that m, and n are the initial and final nodes in the path respectively.

• A definition-clear (sub)path with respect to a variable v (denoted as dc-path) is a definition-use path in PATHS(P) with initial nodes DEF(v, m) and USE(v, n) such that there no other node in the path is a defining node for v

Page 9: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

9

Some Definitions (4)

• A global definition is a definition of a variable x in node n if there is a definition of x in node n and there is a definition-clear path from n to some node m containing a global c-use of x, or containing a p-use of x. Note x is live at n

• A global c-use of variable x in node n is a c-use of variable x in node n and x has been defined in a node other than n

Page 10: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

10

Some Definitions (5)

• Simple path is a path in which all nodes except possibly the first and the last are distinct

• Loop free path is a path in which all nodes are distinct

• Complete path is a path from the entry node to the exit node of the CFG

• Du-Path with respect to variable x at node n1 is a path [n1, n2, …. nk] where n1 has a global definition of x and either

– Node nk has a global c-use of x and [n1….nk] is def-clear simple path with respect to x or,

– Node nk has a p-use of x and [n1….nj] is a def-clear loop-free path with respect to x

Page 11: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

11

Definition / Use Associations - ExampleWhat are the def-use associations for the program below?

1 read (z)2 x = 0 3 y = 04 if (z 0) {5 x = sqrt (z)6 if (0 x && x 5)7 y = f (x) else8 y = h (z) }9 y = g (x, y)10 print (y)

Page 12: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

12

Definition / Use Associations - Exampledef-use associations for variable z.

read (z)x = 0 y = 0if (z 0){

x = sqrt (z)if (0 x && x

5)y = f (x)

elsey = h (z)

}y = g (x, y)print (y)

Page 13: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

13

Definition / Use Associations - Exampledef-use associations for variable y.

read (z)x = 0 y = 0if (z 0){

x = sqrt (z)if (0 x && x

5)y = f (x)

elsey = h (z)

}y = g (x, y)print (y)

Page 14: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

14

Define / Use Information - Example

Variable Defined at Used at Comment

locks 9 Declaration

locks 22 READ

locks 23 Predicate use

locks 26 Computation Use

stocks 9 READ

stocks 27 Computation Use

num_locks 26 Assignment

num_locks 26 Computation Use

num_locks 33 WRITE

Page 15: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

15

DU-Path Test Coverage Criteria

• The basic idea is to use def-use information as defined in the previous slides and specific criteria in order to obtain specific paths in the CFG graph. These paths will then help us define specific test cases

• Let T be a set of feasible complete paths in the program’s P CFG, and V be the set of all variables in the program P

Page 16: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

16

DU-Path Coverage Criteria (1)

• The set T satisfies the All-Defs criterion for a program P iff for every variable v in V, T contains definition clear (sub)paths from every defining node of v to a use of v. Note: Reaching definitions set)

• The set T satisfies the All-Uses criterion for the program P iff for every variable v in V, T contains definition-clear (sub)paths from every defining node of v to every use of v, and to the successor node of each USE(v, n) Note: def-use chains set

• We can distinguish between an All-C-Uses, or an All-P-Uses set

Page 17: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

17

DU-Path Coverage Criteria (2)

• The set T satisfies the All-P-Uses/Some-C-Uses criterion for a program P iff for every variable v in V, T contains definition-clear (sub)paths from every defining node of v to every p-use of v, and if a definition of v has no p-uses, there is a definition-clear path to at least one c-use

• The set T satisfies the All-C-Uses/Some-P-Uses criterion for a program P iff for every variable v in V, T contains definition-clear (sub)paths from every defining node of v to every c-use of v, and if a definition of v has no c-uses, there is a definition-clear path to at least one p-use

• The set T satisfies the All-DU-Paths criterion for the program P iff for every variable v in V, T contains definition-clear (sub)paths from every defining node of v to every use of v, and to the successor node of each USE(v, n), and that these paths are either

Page 18: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

18

All-DU-Paths: pow(x,y) - Example/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614 17a

b

c

d

e

f

g

h

i

Page 19: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

19

All-DU-Paths – Variable x/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614a

b

c

d

e

f

g

h

i17

Page 20: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

20

All-DU-Paths – Variable x/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614 17a

b

c

d

e

f

g

h

i

Page 21: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

21

All-DU-Paths – Variable y/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614 17a

b

c

d

e

f

g

h

i

Page 22: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

22

All-DU-Paths – Variable y/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614 17a

b

c

d

e

f

g

h

i

Page 23: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

23

All-DU-Paths – Variable y/* pow(x,y) This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout.*/1 void pow (int x, y)2 {3 float z;4 int p;5 if (y < 0)6 p = 0 – y;7 else p = y;8 z = 1.0;9 while (p != 0)10 {11 z = z * x;12 p = p – 1;13 }14 if (y < 0)15 z = 1.0 / z;16 printf(z);17 }

1 5 8 9 1614 17a

b

c

d

e

f

g

h

i

Page 24: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

24

Examplepublic static double ReturnAverage(int value[], int AS, int MIN, int MAX) {

int i, ti, tv, sum;

double av;

i = 0; ti = 0; tv = 0; sum = 0;

while (ti < AS && value [i] != -999) {

ti++;

if (value[i] >= MIN && value[i} <= MAX) {

tv++;

sum = sum + value[i];

}

i++;

}

if (tv > 0)

av = (double) sum/tv;

else

av = (double) -999;

return (av)

}

Page 25: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

25

ExampleInitialize: value[]AS, MIN, MAX

i=0; ti=0; tv=0, sum=0

((ti < AS) && (value[i] != -999))

tv > 0

av = (double) -999av = (double) sum/tv

return(av)

ti++;(value[i] >= MIN &&value[i] <= MAX)

F

F

F TT

T

tv++; sum= sum+value[i]

i++

1

2

3

4

5

6

7

8

10

9

Page 26: Software Testing &  Quality Assurance Lecture 12 Created by: Paulo Alencar Modified by: Frank Xu

26

Examples

• Global c-use of variable tv : node 9 (tv is defined in nodes 2 and 5)• Def-clear paths with respect to variable tv: 2-3-4-5, 2-3-4-6• Simple paths: 2-3-4-5 and 3-4-6-3• All-defs criterion paths for tv:

– 1-2-3-4-5-6-3-7-9-10, and with p-uses – 1-2-3-7-8-10 and 1-2-3-4-5-6-3-7-9-10

• All-c-uses criterion paths for ti: – 1-2-3-4-5-6-3-7-8-10, – 1-2-3-4-5-6-3-7-9-10, – 1-2-3-4-6-3-7-8-10, – 1-2-3-4-6-3-7-9-10

• All-p-uses criterion paths for tv:– 1-2-3-7-8-10– 1-2-3-7-9-10– 1-2-3-4-5-6-3-7-8-10– 1-2-3-4-5-6-3-7-9-10

• All-p-uses/some-c-uses criterion paths for i: 1-2-3-4-5-6-3-7-9-10• All-c-uses/some-p-uses criterion paths for AS: 1-2-3-4-5-6-3-7-9-10• All-uses: Conjuction of all-c-uses and all-p-uses• All-du-paths for tv: 1-2-3-4-5-6-3-7-8-10 …. 1-2-3-7-9-10