6data Flow Testing
6data Flow Testing
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
1
Data Flow Testing – Basic Idea
3
Data Flow Testing – Basic Idea
6
Some Definitions
• Node n in the CFG of program P is a usage node of
v V, written as USE(v, n), iff the value
the variable
of the variable v is used at the statement fragment
corresponding to node n.
8
Some Definitions
• 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.
12
Some Definitions
• 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.
15
Some Definitions
• 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.
1. x = 5;
2. y = x + 3;
3. if (y > 10) {
4. z = y * 2;
5. } else {
6. z = y - 2;
7. }
8. y = 20; // new definition of y
9. print(z); 16
Some Definitions
The Control Flow Graph (CFG) of this program might
look like this:
1. Node 1: x = 5;
2. Node 2: y = x + 3;
3. Node 3: if (y > 10)
4. Node 4: z = y * 2;
5. Node 5: else
6. Node 6: z = y - 2;
7. Node 7: end if
8. Node 8: y = 20;
9. Node 9: print(z);
18
Some Definitions
• 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 .
Suppose we have a program P with the following code:
1. x = 5; // global definition
2. y = x + 3;
3. if (y > 10) {
4. z = y * 2;
5. } else {
6. z = y - 2;
7. }
8. print(z); // global c-use of x (indirectly through y and z)
19
Some Definitions
The Control Flow Graph (CFG) of this program might look like this:
1. Node 1: x = 5;
2. Node 2: y = x + 3;
3. Node 3: if (y > 10)
4. Node 4: z = y * 2;
5. Node 5: else
6. Node 6: z = y - 2;
7. Node 7: end if
8. Node 8: print(z);
According to the definition:-
•Node 1 is a global definition of x because:
There is a definition of x in Node 1.
There is a definition-clear (dc-)path from Node 1 to Node 8 (Node
1 → Node 2 → Node 3 → ... → Node 8).
Node 8 contains a global c-use of x (indirectly through y and z).
Note that x is live at Node 1 because its value is used later in the
program (indirectly through y and z). 20
Some Definitions
• 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.
Example: Suppose we have a program P with the following code:
1. x = 5;
2. y = x + 3;
3. z = y * 2;
The Control Flow Graph (CFG) of this program might look like this:
1. Node 1: x = 5;
2. Node 2: y = x + 3;
3. Node 3: z = y * 2;
According to the definition:-
Node 2 contains a global c-use of variable x because:
There is a c-use of x in Node 2 (x is used in the expression x + 3).
x has been defined in Node 1, which is a node other than Node 2.
1 read (z)
2 x=0
3 y=0
4 if (z 0) {
5 x = sqrt (z)
6 if (0 x && x 5)
7 y = f (x)
else
8 y = h (z)
}
9 y = g (x, y)
10 print (y)
23
Definition / Use Associations - Example
def-use associations for
variable z.
read (z)
x=0
y=0
if (z 0)
{
x = sqrt (z)
if (0 x && x
5)
y = f (x)
else
y = h (z)
}
y = g (x, y)
print (y) 24
Definition / Use Associations -
Example
def-use associations for
variable y.
read (z)
x=0
y=0
if (z 0)
{
x = sqrt (z)
if (0 x && x
5)
y = f (x)
else
y = h (z)
}
y = g (x, y)
print (y) 25
Example
26
27
28
29
30
31
32
33
34
35
du-paths
• Du-paths for stocks.
36
du-paths
Du-paths for stocks.
37
du-paths
Du-paths for locks.
– p1 = <13, 14>
– p2 = <13, 14, 15, 16>
– p3 = <19, 20, 14>
– p4 = <19, 20, 14, 15, 16>
38
du-paths
Du-paths for locks.
39
du-paths
Du-paths for totallocks.
•The du-paths for totalLocks will lead us to typical test
cases for computations.
41
du-paths
Du-paths for totallocks.
– p7 = <10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 14, 21,
22, 23, 24>
– p7 = <p6, 22, 23, 24>
42
du-paths
Du-paths for totallocks.
•Both are definition clear, and both have the loop iteration
problem.
43
du-paths
Du-paths for sales.
•There is one defining node for sales; therefore, all the du-
paths with respect to sales must be definition clear.
45
du-paths
Du-paths for sales.
•Two choices for du-paths begin with path p11: one choice
is the path <27, 28, 29, 30, 31,32, 33>, and the other is
the path <27, 28, 29, 34>.
46
du-paths
• Du-paths for commission.
In this case:
-Node 3 assigns a value to z, which is used at node 5.
-Node 2 assigns a value to y, which is used to compute z at
node 3.
-Node 1 assigns a value to x, which is used to compute y at
node 2.
62
Slicing using Control Flow Graphs
• Given a program P, and a program graph G(P) in which
statements and statement fragments are numbered,
and a set V of variables in P, the slice of the set of
variables V at statement fragment n, written as
S(V, n), is the set of node numbers of all
statement fragments in P prior to and including n
that contribute to the values of variables in V at
statement fragment n.
In this case:
- Node 5 assigns a value to w.
- Node 4 is the conditional statement that controls
whether Node 5 is executed.
- Node 3 assigns a value to z, which is used in the
conditional statement at Node 4.
- Node 2 assigns a value to y, which is used to compute
z at Node 3.
- Node 1 assigns a value to x, which is used to compute
y at Node 2.