Dataflow Testing
Dataflow Testing
White-box Testing
Part 2: Data-flow Testing
x is a variable,
d is a node containing a definition of x,
u is either a statement or predicate node
containing a use of x,
3 z<y
(y, 1, (3,t)), (y, 1, (3,f)), (y, 1, 5), …
(z, 2, (3,t)),...
T F
w=x+1 5 y=y+1
4
6 print (x,y,w,z)
Example: Def-Use
Associations
What are all the def-use associations for the program
below?
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)
Example: Def-Use
Associations
read (z)
def-use associations for variable 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)
Example: Def-Use
Associations
read (z) def-use associations for variable
x=0 x.
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)
Example: Def-Use
Associations
read (z)
x=0 def-use associations for variable y.
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)
Definition-Clear Paths
• A path (i, n1, ..., nm, j) is called a definition-clear path
with respect to x from node i to node j if it contains
no definitions of variable x in nodes (n1, ..., nm , j) .
read (x,y);
for (i = 1; i <= 2; i++)
print (“hello”);
Sa;
if (y < 0)
S b;
else
print (x);
An example: All-du-paths
1 y<o
6
read (x, y) T F
2 i=1
print x
Sb 7 8
3 i <= 2
T F
print(“hello”) 4 5 Sa
9
i=i+1
6 y<o
Example: pow(x,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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
Example: pow(x,y)
du-Path for 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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
Example: pow(x,y)
du-Path for 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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
Example: pow(x,y)
du-Path for 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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
Example: pow(x,y)
du-Path for 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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
Example: pow(x,y)
du-Path for 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) b g
6 p = 0 – y; a d f i
7 else p = y; 1 5 8 9 14 16 17
8 z = 1.0;
9 while (p != 0)
10 { c e h
11 z = z * x;
12 p = p – 1;
13 }
14 if (y < 0)
15 z = 1.0 / z;
16 printf(z);
17 }
All Uses Strategy (AU)
• AU requires that at least one path from every
definition of every variable to every use of
that definition be exercised under some test.
• Hence, at least one definition-clear path from
every definition of every variable to every use
of that definition be exercised under some
test.
• Clearly, AU < ADUP.
Effectiveness of Strategies
• Ntafos compared Random, Branch,
and All uses testing strategies on 14
Kernighan and Plauger programs.
• Kernighan and Plauger programs are a
set of mathematical programs with
known bugs that are often used to
evaluate test strategies.
• Ntafos conducted two experiments:
Results of 2 of the 14
Ntafos Experiments
Mean Number Percentage of
Strategy of Test Cases Bugs Found
Random 35 93.7
Branch 34 85.5