Data Flow Testing-UNIT2 - Part2
Data Flow Testing-UNIT2 - Part2
o Data Flow Testing is a structural testing method that examines how variables are
defined and used throughout a program.
o It uses control flow graphs to identify paths where variables are defined and then
utilized, aiming to uncover anomalies such as unused variables or incorrect
definitions.
o By focusing on the flow of data, it helps ensure that variables are properly handled
and used in the code.
3
Data - Flow Testing - Basics
A control-flow graph (CFG) and data-flow graph (DFG) are both used in data flow
testing to analyze a program's code and identify potential issues:
4
DATA FLOW MACHINES
There are two types of data flow machines with different architectures.
Von Neumann Machine Architecture:
This architecture features interchangeable storage of instructions and data
in the same memory units.
It executes one instruction at a time in the following, micro instruction sequence:
• Fetch instruction from memory
• Interpret instruction
• Fetch operands
• Process or Execute
• Store result
• Increment program counter
• GOTO 1
Multi-instruction, Multi-data machines (MIMD) Architecture:
These machines can fetch several instructions and objects in parallel.
They can also do arithmetic and logical operations simultaneously on different data objects.
The decision of how to sequence them depends on the compiler.
5
Data - Flow Testing - Basics - Motivation
Program Control flow with Von Neumann’s paradigm
BEGIN
Given m, n, p, q, find e. PAR DO Parallel Do
READ m, n, n,
a = n+m
e = (m+n+p+q) * (m+n-p-q) p, q
END PAR
b=p+q PAR DO
a := m+n
a := m + n
c=a+b b := p+q
b := p + q END PAR
c := a + b PAR DO
d := a - b c := a+b
d=a-b
d := a-b
e := c * d END PAR
e=c*d PAR DO
e := c * d
END PAR
6 Multiple representations of control flow graphs possible. END
Data - Flow Testing - Basics - Motivation
Program Flow using Data Flow Machines paradigm
n m p q
BEGIN
PAR DO
READ m, n, n, p, q
END PAR a := m+n b := p+q
PAR DO
a := m+n
b := p+q c := a+b d := a-b
END PAR
PAR DO
c := a+b
d := a-b
e := c * d
END PAR
PAR DO
e := c * d
END PAR The interrelations among the data items remain same.
7
END
Data - Flow Testing - Basics
Assumptions
• Problems in a control flow
• Problems with data objects
8
Data - Flow Testing - Basics
oConvert to a CFG
oAnnotate : program actions (weights)
Annotating control flow graphs with information about data objects helps in
understanding and analyzing how data flows through the program and how it
interacts with different control paths.
9
Data - Flow Testing - Basics
Used - (u)
• In a calculation - (c)
11
Data - Flow Testing - Basics – Data Flow Anomalies
12
Data - Flow Testing - Basics – Data Flow Anomalies
An anomaly is the one denoted by a two-character sequence of action
-k: Possibly anomalous. The variable is being killed (marked as unavailable), but it has not
been defined prior to this point. This could be a problem unless the variable was created in a
called routine or is a global variable.
-d: Normal case. This is the first time the variable is defined along this path, so it's okay.
-u: Possibly anomalous. The variable is being used without being explicitly defined earlier
on this path. This is fine if the variable is global and was previously defined, but otherwise, it
could indicate a problem
14
Data - Flow Testing - Basics – Data Flow Anomalies
k-:Normal case. The last action on this path was killing the variable. Nothing anomalous
here.
d-: Possibly anomalous. The variable was defined but not used before the program exits.
This could be okay if it's part of a global definition or if the variable was defined for use in
other routines.
u-: Normal case, but possibly a bug. The variable was used but not killed. This could
indicate a common bug, where dynamically allocated memory or an object was not returned
or freed after being used.
15
Data - Flow Testing - Basics – Data Flow Anomalies
Data flow anomaly model prescribes that an object can be in one of four distinct states:
K :- undefined, previously killed, does not exist
D :- defined but not yet used for anything
U :- has been used for computation or in predicate
A :- anomalous
These capital letters (K,D,U,A) denote the state of the variable and should not be confused with the
program action, denoted by lower case letters.
Unforgiving Data - Flow Anomaly Flow Graph: Unforgiving model, in which once a variable
becomes anomalous it can never return to a state of grace.
16
Data - Flow Testing - Basics
Data Flow Anomaly State graph u: The variable is used.
k: The variable is killed or deallocated.
Unforgiving Data flow state graph
d: The variable is defined or assigned a value.
States
Undefined K (Killed):
K
D (Defined but not used):
U (Used):
k, u A (Anomalous):
u
d, k
U D A Anomalous
u
d
Defined d, k, u
17 Used ref boris beizer
Data - Flow Testing - Basics
Data Flow Anomaly State graph
Forgiving Data flow state graph u A DD, DK, KU
k u
KU
K k
k u
d DK
k
d
u k
U D d
u
d
DD
u
18 d
Data - Flow Testing - Basics
19
Data - Flow Testing - Basics
20
Data - Flow Testing - Basics
21
Data - Flow Testing - Basics
22
Data Flow Model
o The data flow model is based on the program's control flow graph
o Here we annotate each link with symbols (for example, d, k, u, c, p) or
sequences of symbols (for example, dd, du, ddd) that denote the
sequence of data operations on that link with respect to the variable of
interest. Such annotations are called link weights.
o The control flow graph structure is same for every variable: it is the
weights that change.
23
Data - Flow Testing - Basics : Data Flow Model
Procedure to Build:
1. Entry & Exit nodes
2. Unique node identification
3. Weights on out link
4. Predicated nodes
5. Sequence of links
1. Join
2. Concatenate weights
3. The converse
24
Procedure to Build:
Node Creation and Naming:
Each statement in the program is represented by a unique node. Every node, except for entry and exit nodes, must have
at least one incoming and outgoing link.
Entry and Exit Nodes:
Entry nodes are dummy nodes added at the start of the program, for example, for statements like BEGIN.
Exit nodes are dummy nodes at the program’s conclusion, such as for statements (like END or RETURN) These
complete the graph by marking the start and end of the process.
Linking and Weighting:
Outlinks from simple statements are weighted by the sequence of data-flow actions that correspond to the code
execution order. This weight sequence may consist of multiple letters representing actions, such as cd or ckd for variable
assignments.
For languages that support complex structures like multiple assignments, the weight represents the order of object code
execution for each variable.
Predicate Nodes:
Predicate nodes (e.g., IF-THEN-ELSE, DO WHILE, CASE) are weighted based on the p-use (predicate use) on every
outlink, specific to that outlink’s data-flow.
Node Simplification:
A sequence of simple statements (nodes with one inlink and one outlink) can be condensed into a pair of nodes. The
weight between them becomes the concatenation of the link weights from the original sequence of nodes.
25
Data - Flow Testing - Basics : Data Flow Model
o If there are several data-flow actions on a given link for a given variable, then the
weight of the link is denoted by the sequence of actions on that link for that
variable.
o Conversely, a link with several data-flow actions on it can be replaced by a
succession of equivalent links, each of which has at most one data-flow action for
any variable.
26
Data Flow Model
Example: a –1
n
Z = b + ---------
START a - 1
INPUT a, b, n #INPUT (a, b, n):
Z := 0 #Variable Z is set to 0. This Z serves as the result accumulator
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
27
Data - Flow Testing - Basics – Data Flow model
Read a,b,n
Z := 0 Y Z := 1 Z := b + Z
1 2 5 6
P1 a = 1?
START
Z := (c-1)/(a-1)
INPUT a, b, n
Z := 0
r := 1 c:=1 IF a = 1 THEN Z := 1
P2 GOTO DONE1
3 4 r<n? r := 1 c := 1
r := r+1, c:= c*a POWER:
c := c * a
Y r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
CFG for the Example Z := b + Z
END
d or kd cd or ckd
d
1 2 5 6
a = 1?
P1
Y
d or kd
P2 START
3 4 r < n ? INPUT a, b, n
Z := 0
Y IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
-d c-
ckd or kd P2
3 4 r<n?
START
INPUT a, b, n
Y Z := 0
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
-d p-
ckd or kd P2
3 4 r<n?
START
INPUT a, b, n
Y Z := 0
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
P2
3 4 r<n?
START
Y INPUT a, b, n
Z := 0
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
P2
3 4 r<n?
START
INPUT a, b, n
Y Z := 0
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
c P2
3 4 r<n?
START
INPUT a, b, n
Y Z := 0
IF a = 1 THEN Z := 1
GOTO DONE1
r := 1 c := 1
POWER:
c := c * a
r := r + 1
IF r <= n THEN GO TO POWER
Z := (c – 1) / (a – 1)
DONE1:
Z := b + Z
END
35
Data - Flow Testing – Data Flow Testing Strategies
36
Data - Flow Testing – Data Flow Testing Strategies
6. All p-uses(APU)
Purpose:
It requires that every du path from every definition of every variable to every use
of that definition be exercised under some test.
o The All-du-paths (ADUP) strategy is the strongest data-flow testing strategy.
It ensures that:
o Every definition of every variable is tested.
o For each definition of a variable, every path from that definition to each of its uses
(whether computational or predicate use) is exercised under some test.
39
Data - Flow Testing – Data Flow Testing Strategies
40
Data - Flow Testing – Data Flow Testing Strategies
41
Data - Flow Testing – Data Flow Testing Strategies
42
Data - Flow Testing – Data Flow Testing Strategies
43
Data - Flow Testing – Data Flow Testing Strategies
44
Ordering the strategies Data Flow Testing Strategies
All du Paths
All Defs AD
All c uses (ACU) All P-uses APU
All Branches P2
45 ref boris
All Stmts P1 beizer
Data - Flow Testing – Data Flow Testing Strategies
Stmt1 var v
stmt2
Stmt3 var v
Stmt4 var v
Stmt s var v
46
Data - Flow Testing – Data Flow Testing Strategies
Dicing:
47
Data - Flow Testing – Data Flow Testing Strategies
Debugging:
• Select a slice.
• Narrow it to a dice.
Dynamic Slicing: