Chapter 4 Part II
Chapter 4 Part II
SEng5441
KIoT
Department of Software Engineering
1
Basic Idea
• A program unit such as a function, accepts input values, performs computations while assigning new
values to local and global variables, and, finally, produces output values.
• Therefore, one can imagine a kind of “flow” of data values between variables along a path of program
execution
• A data value computed in a certain step of program execution is expected to be used in a later step.
Example: Obtain a file pointer ……. use it later.
– If the later use is never verified, we do not know if the earlier assignment is acceptable.
• Two motivations of data flow testing
1. a memory location corresponding to a program variable is accessed in a desirable way. For
example, a memory location may not be read before writing into the location.
2. it is desirable to verify the correctness of a data value generated for a variable—this is
performed by observing that all the uses of the value produce the desired results.
• Idea: A programmer can perform a number of tests on data values.
– These tests are collectively known as data flow testing.
2
General Idea
• Data flow testing can be performed at two conceptual levels.
– Static data flow testing
– Dynamic data flow testing
x = f1(y);
x = f2(z);
• The first statement has a fault -- the intended one might be: w = f1(y).
• The second statement has a fault – the intended one might be: v = f2(z).
• There is a missing statement in between the two: v = f3(x) may be the desired
statement that should go in between the two given statements.
– Example: Consider x = f(x, y). in which a new value is assigned to the variable x.
– If the value of x is not used in any subsequent computation, then we should be suspicious of the
computation represented by x = f (x, y). Hence, this form of anomaly is called “defined but not
referenced.
6
Data Flow Anomaly…
• The concept of a state-transition diagram is used to model a program variable to identify
data flow anomaly.
• Components of the state-transition diagrams
– The states
• U: Undefined state: meaning that just a memory location has been allocated to the variable but no
value has yet been assigned.
• D: Defined but not referenced
• R: Defined and referenced: The variable remains in the R state as long as the programmer keeps
referencing the value of the variable. If the programmer assigns a new value to the variable, the
variable moves back to the D state.
• A: Abnormal, a programming anomaly has occurred.
– The actions
• d: define the variable, a process of assigning a value to the variable
• r: reference (or, read) read the value of the variable
• u: undefine the variable, the programmer can take an action to the variable
7
Data Flow Anomaly
8
Data Flow Anomaly…
• Obvious question: What is the relationship between the Type 1, Type 2, and
Type 3 anomalies and Figure 1?
• The three types of anomalies (Type 1, Type 2, and Type 3) are found in the
diagram in the form of action sequences:
– Type 1: dd
– Type 2: ur
– Type 3: du
• Detection of data flow anomaly via program instrumentation
– Program instrumentation: Insert new code to monitor the states of variables.
– If the state sequence contains dd, ur, or du sequence, a data flow anomaly is said to occur.
• What to do after detecting a data flow anomaly?
– Investigate the cause of the anomaly.
– To fix an anomaly, write new code or modify the existing code.
9
Overview of Dynamic Data Flow Testing
• The above motivation indicates that certain kinds of paths are executed in data flow
10
testing.
Overview of Dynamic Data Flow Testing…
11
Data Flow Graph
• A data flow graph is drawn with the objective of identifying data definitions and their uses
• Each occurrence of a data variable(The life cycle of data in programming code) is classified as follows:
– Definition: it includes defining, creation and initialization of data variables and the allocation of the memory to its
data object.
– Example :
– Usage: This occurs when the value is fetched from the memory location of the variable. There are two forms of
uses of a variable.
• Computation use (c-use): This directly affects the computation being performed. In a c-use, a potentially
new value of another variable or of the same variable is produced.
• Predicate use (p-use): This refers to the use of a variable in a predicate controlling the flow of execution.
13
– Example: if (y > 100) { …} /* y has been used in a condition. */
Data Flow Graph
– The entry node has a definition of each edge parameter and each nonlocal variable used in the
program.
14
Data Flow Graph
• Example code: ReturnAverage() from Chapter 3
public static double ReturnAverage(int value[], int AS, int MIN, int MAX ) { /* Function: ReturnAverage Computes the average of all
those numbers in the input array in the positive range [MIN,
MAX]. The maximum size of the array is AS. But, the array size could be smaller than AS in which case the end of input is represented by -999. */
17
Data Flow Terms
• Global definition: A node i has a global definition of variable x if node i has a definition of x and
there is a def-clear path w.r.t. x from node i to some
node containing a global c-use, or
edge containing a p-use of variable x.
• Simple path: A simple path is a path in which all nodes, except possibly the first
and the last, are distinct.
– Example: Paths (2 – 3 – 4 – 5) and (3 – 4 – 6 – 3) are simple paths.
• Loop-free paths: A loop-free path is a path in which all nodes are distinct.
• Complete path: A complete path is a path from the entry node to the exit node.
19
Data Flow Terms
• Edge (nj, nk) has a p-use of x and (n1 – n2 – … – nj – nk) is a def-clear, loop-free path
w.r.t. x.
– Example: Considering the global definition and global c-use of variable tv in nodes 2 and
5, respectively, (2 – 3 – 4 – 5) is a du-path.
– Example: Considering the global definition and p-use of variable tv in nodes 2 and on edge
(7, 9), respectively, (2 – 3 – 7 – 9) is a du-path.
20
Data Flow Testing Criteria
21
Data Flow Testing Criteria
1. All-defs
– For each variable x and each node i, such that x has a global definition in node i, select a
complete path which includes a def-clear path from node i to
– Example (partial): Consider tv with its global definition in node 2. Variable tv has a global c-use
in node 5, and there is a def-clear path (2 – 3 – 4 – 5) from node 2 to node 5. Choose a complete
path (1 – 2 – 3 – 4 – 5 – 6 – 3 – 7 – 9 – 10) that includes the def-clear path (2 – 3 – 4 – 5) to
satisfy the all-defs criterion.
22
Data Flow Testing Criteria
2. All-c-uses
– For each variable x and each node i, such that x has a global definition in node i, select
complete paths which include def-clear paths from node i to all nodes j such that there is a
global c-use of x in j.
– Example (partial): Consider variable ti, which has a global definition in 2 and a global c-use
in node 4. From node 2, the def-clear path to 4 is (2 – 3 – 4). One may choose the complete
path (1 – 2 – 3 – 4 – 6 – 3 – 7 – 8 – 10). (There are three other complete paths.)
3. All-p-uses
– For each variable x and each node i, such that x has a global definition in node i, select
complete paths which include def-clear paths from node i to all edges (j, k) such that there is a
p-use of x on (j, k).
– Example (partial): Consider variable tv, which has a global definition in 2 and p-uses on
edges (7, 8) and (7, 9). From node 2, there are def-clear paths to (7, 8) and (7, 9), namely (2 –
3 – 7 – 8) and (2 – 3 – 7 – 9). The two complete paths are: (1 – 2 – 3 – 7 – 8 – 10) and (1 – 2 –
3 – 7 – 9 – 10).
23
Data Flow Testing Criteria
4. All-p-uses/some-c-uses
– This criterion is identical to the all-p-uses criterion except when a variable x has no p-use. If x
has no p-use, then this criterion reduces to the some-c-uses criterion.
– Some-c-uses: For each variable x and each node i, such that x has a global definition in node i,
select complete paths which include def-clear paths from node i to some nodes j such that there
is a global c-use of x in j.
– Example (partial): Consider variable i, which has a global definition in 2. There is no p-use of
i. Corresponding to the global definition of I in node 2, there is a global c-use of I in 6. The def-
clear path from node 2 to 6 is (2 – 3 – 4 – 5 – 6). A complete path that includes the above def-
clear path is (1 – 2 – 3 – 4 – 5 – 6 – 3-7 – 9 – 10).
24
Data Flow Testing Criteria
5. All-c-uses/some-p-uses
– This criterion is identical to the all-c-uses criterion except when a variable x has no c-use. If x has no
global c-use, then this criterion reduces to the some-p-uses criterion.
– Some-p-uses: For each variable x and each node i, such that x has a global definition in node i,
select complete paths which include def-clear paths from node i to some edges (j, k) such that there
is a p-use of x on (j, k).
– Example: Let us obtain paths to satisfy the all-c-uses/some-p-uses criterion with respect to variable
AS. We find just one global definition of AS in node 1. There is no global c-use of AS in Figure 4.
Thus, we consider some p-uses of AS. Corresponding to the global definition of AS in node 1, there
are p-uses of AS on edges (3, 7) and (3, 4), and there are def-clear paths from node 1 to those two
edges, namely, 1-2-3-7 and 1-2-3-4, respectively. There are many complete paths that include those
two def-clear paths. One such example path is given as 1-2-3-4-5-6-3-7-9-10.
25
Data Flow Testing Criteria
6. All-uses
This criterion is the conjunction to the all-p-uses criterion and the all-c-uses criterion.
7. All-du-paths
• For each variable x and for each node i, such that x has a global definition in node i,
select complete paths which include all du-paths from node i
– To all nodes j such that there is a global c-use of x in j, and
26
Comparison of Data Flow Testing Criteria
• Includes relationship: Given two test selection criteria c1 and c2, c1 includes c2
if for every def/use graph, any set of complete paths of the graph that
satisfies c1 also satisfies c2.
• Strictly includes relationship: Given two test selection criteria c1 and c2, c1
strictly includes c2 provided c1 includes c2 and for some def/use graph, there
is a set of complete paths of the graph that satisfies c2 but not c1.
27
Comparison of Data Flow Testing Criteria…
Figure 5: The relationship among DF (data flow) testing criteria [6] (©[1988] IEEE).
28
Feasible Paths and Test Selection Criteria
29
Comparison of Testing Techniques
30
Figure 6: The relationship among the FDF (feasible data flow) testing criteria [6] (©[1988] IEEE).
Comparison of Testing Techniques…
32