Sunteți pe pagina 1din 8

White Box Test Designing

Data Flow Coverage

Data flow coverage


Data flow testing selects test paths of a program according to the location of definitions and uses of variables in the program A variable is defined in a certain statement if it is assigned a (new) value
DEF(S) ={X | statement S contains a definition of X}

After that, a new value will be used in subsequent statements


USE(S) ={X | statement S contains a use of X}

Data flow coverage


Variable definition in statement X is alive in statement Y if there exists a path from X to Y in which that variable does not get assigned a new value in some intermediate node; such a path is called definition-clear Any path starting from a node at which variable x is defined and ending at a node at which x is used, without redefining x anywhere else along the path, is a def-clear path for x. Two types of variable use:
P-uses predicate uses (like those in the conditional part of an ifstatement) C-uses all other uses (like uses in computations or I/O statements)

Definitions and uses: Arrays


Arrays are also tricky. Consider the following declaration and two statements in C:

The first statement defines variable A. The second statement defines A and uses i , x, and y. Alternate: second statement defines A[i] and not the entire array A.

C-use
Uses of a variable that occur within an expression as part of an assignment statement, in an output statement, as a parameter within a function call, and in subscript expressions, are classified as c-use, where the ``c" in c-use stands for computational. How many c-uses of x can you find in the following statements?

Answer: 5

p-use
The occurrence of a variable in an expression used as a condition in a branch statement such as an if and a while, is considered as a p-use. The ``p" in p-use stands for predicate. How many p-uses of z and x can you find in the following statements?

Answer: 3 (2 of z and 1 of x)

Data Flow Test Criteria


First, we make sure every def reaches a use

All-defs coverage (ADC) : TR set consists of at least single definition-clear sub path from each definition to any particular use reached by that definition
Then we make sure that every def reaches all possible uses

All-uses coverage (AUC) : TR set consists of at least single definition-clear sub path from each definition to each use reached by that definition
Finally, we cover all the paths between defs and uses

All-du-paths coverage (ADUPC) : TR set consists of All definition-clear sub paths from each definition to each use reached by that definition

Data Flow Testing Example


Z = X*2 X = 42 0 1 3 2 5 4 6

Z = X-8

All-defs for X
[ 0, 1, 3, 4 ]

All-uses for X
[ 0, 1, 3, 4 ] [ 0, 1, 3, 5 ]

All-du-paths for X
[ 0, 1, 3, 4 ] [ 0, 2, 3, 4 ]

[ 0, 1, 3, 5 ]
[ 0, 2, 3, 5 ]

S-ar putea să vă placă și