0% found this document useful (0 votes)
5 views18 pages

Graphs Data Flow

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
5 views18 pages

Graphs Data Flow

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 18

Data flow in graphs

Meenakshi D’Souza

International Institute of Information Technology


Bangalore.
Graph coverage criteria: Overview

Model software artifacts as graphs and look at coverage


criteria over graphs.
Structural coverage criteria.
Data flow coverage criteria.
Coverage criteria over call graphs.
Focus of this lecture: Understand the notion of data flow in
graphs.
Graphs with data

Graph models of programs can be tested adequately by


including values of variables (data values) as a part of the
model.
Data values are created at some point in the program and
used later. They can be created and used several times.
We deal with definition and use of data values.
We will define coverage criteria that track a definition(s) of a
variable with respect to its use(s).
Definition and use of values

A definition (def) is a location where a value of a variable is


stored into memory.
It could be through an input, an assignment statement etc.
A use is a location where a value of a variable is accessed.
It could be assigned to another variable, be a part of an if,
while or other conditions etc.
As a program executes, data values are carried from their defs
to uses. We call these du-pairs or def-use pairs.
A du-pair is a pair of locations (li , lj ) such that a variable v is
defined at li and used at lj .
Data in graphs

Let V be the set of variables that are associated with the


program artifact being modelled as a graph.
The subset of V that each node n (edge e) defines is called
def (n) (def (e)).
Typically, graphs from programs don’t have definitions on
edges.
Designs modeled as finite state machines have definitions as
side effects or actions on edges.
The subset of V that each node n (edge e) uses is called as
use(n) (use(e)).
Data in graphs: Example

Defs:
def (1) = {x},
z=x*2
def (5) = def (6) =
2 5
{z}.
1 4 7 Uses:
3 6
x=42 use(5) = {x},
z=x−5 use(6) = {x}.
Example: Pattern Matching

public class PatternIndex


{ public static void main (String[] argv)
{ if (argv.length != 2)
{ System.out.println
("java PatternIndex Subject Pattern");
return; }
String subject = argv[0];
String pattern = argv[1];
int n = 0;
if ((n = patternIndex(subject, pattern))==-1)
System.out.println ("Pattern is not a substring of the subject");
else
System.out.println ("Pattern string begins at character " + n);
}
Pattern Matching Example contd.

/**
* Find index of pattern in subject string
* @return index (zero-based) of 1st occurrence of pattern in subject; -1
if not found
* @throws NullPointerException if subject or pattern is null
*/

public static int patternIndex(String subject,String pattern)


{
final int NOTFOUND = -1;
int iSub = 0, rtnIndex = NOTFOUND;
boolean isPat = false;
int subjectLen = subject.length();
int patternLen = pattern.length();
Pattern Matching Example contd.

while (isPat == false && iSub + patternLen - 1 < subjectLen)


{ if (subject.charAt(iSub) == pattern.charAt(0))
{ rtnIndex = iSub; // Starting at zero
isPat = true;
for (int iPat = 1; iPat < patternLen; iPat++)
{ if(subject.charAt(iSub+iPat) != pattern.charAt(iPat))
{ rtnIndex = NOTFOUND;
isPat = false; }
break; // out of for loop
}
}
iSub ++;
}
return (rtnIndex);
Pattern Matching CFG
1

NOTFOUND=−1;iSub=0;rtnIndex=NOTFOUND;
2 isPat=false;subjectLen=subject.length;
patternLen=pattern.length

3
iSub+patternLen−1<subjectLen && isPat==false

4
subject[iSub]==pattern[0]

5 rtnIndex=iSub;
isPat=true;iPat=1

6
11
iPat<patternLen
return(rtnIndex)
7
subject[iSub+iPat]==
pattern[iPat]
break iPat++
iSub++ 10 8 9
rtnIndex=NOTFOUND;
isPat=false;
Pattern Matching: Defs and uses

1 def(1) = {subject,pattern}

def(2)={NOTFOUND,iSub,rtnIndex,isPat,subjectLen,patternLen}
2
use(2)={subject,pattern}

3
use(3,11)=use(3,4)={iSub,patternLen,subjectLen,isPat}
4
use(4,10)=use(4,5)={subject,iSub,pattern}

5 def(5)={rtnIndex,isPat,iPat}
use(5)={iSub}

6
11
use(6,10)=use(6,7)={iPat,patternLen}
use(11)={rtnIndex}
7
use(7,8)=use(7,9)={subject,pattern,iSub,iPat}

def(10)= 10 8 9
use(10)={iSub} def(9)=use(9)={iPat}
def(8)={rtnIndex,isPat}
use(8)={NOTFOUND}
Pattern Matching: Defs and uses

The parameters subject and pattern are forwarded


parameters and hence considered to be explicitly defined at
node 1.
Decision statements like if(subject[iSub]==pattern[0])
result in uses of the variables subject, iSub, pattern at
the edges (4,5) and (4,10).
This is similar for other decision statements too.
Node 9 both defines and uses the variable iPat due to the
statement iPat++ which is equivalent to iPat=iPat+1.
Data defs and uses

A def of a variable may or may not reach a particular use.


A def of a variable v at location li will not reach use of v at
location lj if there is no path from li to lj .
The value of v could be changed by another def before it
reaches an use.
A path from li to lj is def-clear with respect to variable v if v
is not given another value on any of the nodes or edges in the
path.
If there is a def-clear path from li to lj with respect to v , the
def of v at li reaches the use at lj .
Note: All the path definitions above are parameterized with
respect to a variable v .
Def-use paths

A du-path with respect to a variable v is a simple path that is


def-clear from a def of v to a use of v .
du-paths are parameterized by v .
They need to be simple paths.
There may be intervening uses on the path.
du(ni , nj , v ): The set of du-paths from ni to nj for variable v .
du(ni , v ): The set of du-paths that start at ni for variable v .
du-paths: Pattern Matching Example

There is a du-path for variable subject from node 1 to node


2.
subject is used at node 2 with a reference to its length
attribute.
Similarly, there is a du-path for variable subject from node 1
to each of the edges (4,5), (4,10), (7,8) and (7,9).
Due to the interpretation of iPat++ as iPat=iPat+1, the use
occurs before the def. So, a def-clear path goes from node 5
to node 9 for iPat.
Data defs and uses: Other definitions

In testing literature, there are two notions of uses available.


If v is used in a computational or output statement, the use is
referred to as a computation use (or c-use), and the pair is
denoted as dcu(li , lj , v ), where v is defined at li and used at lj .
If v is used in a conditional statement, its use is called as a
predicate use (or p-use).
For conditional use, two def-use pairs appear:
dpu(li , (lj , lt ), v ) and dpu(li , (lj , lf ), v ), where v is defined at li ,
used at lj , but has two opposite flow directions (lj , lt ) and
(lj , lf ).
The former denotes the true edge of the conditional statement
in which v is used; the latter the false edge.
Moving on... next lecture

We will look at coverage criteria for data flow testing in the next
module.
Credits

Part of the material used in these slides are derived from the
presentations of the book Introduction to Software Testing, by
Paul Ammann and Jeff Offutt.

You might also like