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

Download Presentation

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

Loading in 2 Seconds...

- 144 Views
- Uploaded on
- Presentation posted in: General

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

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Software Testing & Quality AssuranceLecture 12Created by: Paulo AlencarModified by: Frank Xu

- Structural Testing
- Introduction – General Concepts
- Flow Graph Testing
- Data Flow Testing
- Definitions
- Some Basic Data Flow Analysis Algorithms
- Define/use Testing
- Slice Based Testing
- Guidelines and Observations

- Hybrid Methods
- Retrospective on Structural Testing

- 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

- Node n in the CFG of program P is a defining node of the variable vV, 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 vV, written as USE(v, n), iff the value of the variable v is used at the statement fragment corresponding to node n.

- 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

For X, Y Data Flows:

1INPUT X,Y

Z:= X+Y

Y:= X-Y

3IF Z>=0 GOTO SAM

4 JOE: Z:=Z-1

5 SAM: Z:=Z+V

U:=0

6LOOP

B(U),Q(V):=(Z+V)*U

7IF B(U)=0 GOTO JOE

Z:=Z-1

8IF Z=0 GOTO ELL

U:=U+1

9UNTIL U=z

B(U-1):=B(U+1)+Q(V-1)

10 ELL: B(U+Q(V)):=U+V

11IF U=V GOTO JOE

12IF U>V THEN U:=Z

13 YY:Z:=U

2END

LOOP

B(U)?

JOE

dcc

4

6

1

3

5

7

SAM

Z?

ELL

U,Z?

2

13

12

11

10

9

8

END

YY

U,V?

U,V?

For Z Data Flows:

1INPUT X,Y

Z:= X+Y

Y:= X-Y

3IF Z>=0 GOTO SAM

4 JOE: Z:=Z-1

5 SAM: Z:=Z+V

U:=0

6LOOP

B(U),Q(V):=(Z+V)*U

7IF B(U)=0 GOTO JOE

Z:=Z-1

8IF Z=0 GOTO ELL

U:=U+1

9UNTIL U=z

B(U-1):=B(U+1)+Q(V-1)

10 ELL: B(U+Q(V)):=U+V

11IF U=V GOTO JOE

12IF U>V THEN U:=Z

13 YY:Z:=U

2END

p

LOOP

B(U)?

JOE

d

1

3

4

5

6

7

p

cd

cd

c

SAM

Z?

cd

END

p

2

ELL

d

p

p

c

13

12

11

10

9

8

U,Z?

YY

U,V?

U,V?

p

- 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

- 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

- 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 n1is 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

What 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)

def-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)

def-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)

- 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

- 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

- 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

b

g

a

f

i

d

1

5

8

9

14

16

17

c

h

e

/* 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;

b

g

5

if (y < 0)

a

f

i

6

p = 0 – y;

d

7

else p = y;

1

5

8

9

14

16

17

8

z = 1.0;

9

while (p != 0)

c

h

e

10

{

11

z = z * x;

12

p = p – 1;

13

}

14

if (y < 0)

15

z = 1.0 / z;

16

printf(z);

17

}

/* 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;

b

g

5

if (y < 0)

a

f

i

6

p = 0 – y;

d

7

else p = y;

1

5

8

9

14

16

17

8

z = 1.0;

9

while (p != 0)

c

h

e

10

{

11

z = z * x;

12

p = p – 1;

13

}

14

if (y < 0)

15

z = 1.0 / z;

16

printf(z);

17

}

/* 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;

b

g

5

if (y < 0)

a

f

i

6

p = 0 – y;

d

7

else p = y;

1

5

8

9

14

16

17

8

z = 1.0;

9

while (p != 0)

c

h

e

10

{

11

z = z * x;

12

p = p – 1;

13

}

14

if (y < 0)

15

z = 1.0 / z;

16

printf(z);

17

}

/* 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;

b

g

5

if (y < 0)

a

f

i

6

p = 0 – y;

d

7

else p = y;

1

5

8

9

14

16

17

8

z = 1.0;

9

while (p != 0)

c

h

e

10

{

11

z = z * x;

12

p = p – 1;

13

}

14

if (y < 0)

15

z = 1.0 / z;

16

printf(z);

17

}

/* 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;

b

g

5

if (y < 0)

a

f

i

6

p = 0 – y;

d

7

else p = y;

1

5

8

9

14

16

17

8

z = 1.0;

9

while (p != 0)

c

h

e

10

{

11

z = z * x;

12

p = p – 1;

13

}

14

if (y < 0)

15

z = 1.0 / z;

16

printf(z);

17

}

public 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)

}

Initialize: value[]

AS, MIN, MAX

1

i=0; ti=0;

tv=0, sum=0

2

((ti < AS) &&

(value[i] != -999))

3

T

F

ti++;

(value[i] >= MIN &&

value[i] <= MAX)

7

4

tv > 0

T

T

F

F

tv++;

sum= sum+value[i]

av = (double) sum/tv

9

av = (double) -999

5

8

i++

10

return(av)

6

- 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