Chapter-5-Data Flow Models - Testing
Chapter-5-Data Flow Models - Testing
DEPENDENCE, DATA FLOW MODELS, AND DATA FLOW TESTING: Definition-Use pairs; Data flow analysis; Classic analyses; From execution to conservative flow analysis; Data flow analysis with arrays and pointers; Inter-procedural analysis; Overview of data flow testing; Definition- Use associations; Data flow testing criteria; Data flow coverage with complex structures; The infeasibility problem. 7 Hrs
10/11/2011
Many program analyses and test design techniques use data flow information
Often in combination with control flow
10/11/2011
Def-Use Pairs
... if (...) { x = ... ; ... } y = ... + x + ... ; Def-Use path ... if (...) { x = ... ... Use: the value of x is extracted Definition : x gets a value
10/11/2011
public class GCD { public int gcd(int x, int y) { int tmp; // A: def x, y, tmp while (y != 0) { // B: use y tmp = x % y; // C: def tmp; use x, y x = y; // D: def x; use y y = tmp; // E: def y; use tmp } return x; // F: use x }
Collections by: Dr. U.P.Kulkarni
Ch 6, slide 5
A def-use pair is formed if and only if there is a definition-clear path between the definition and the use
10/11/2011
Definition-Clear or Killing
x = ... // A: def x q = ... x = y; // B: kill x, def x z = ... y = f(x); // C: use x
Path A..C is not definition-clear
Definition: x gets a value Definition: x gets a new value, old value is killed Use: the value of x is extracted
7
10/11/2011
10/11/2011
10/11/2011
10/11/2011
10
10/11/2011
11
and optimizing compilers Programmers can be told about : Unreachable code/ Dead code, Unused parameters to procedure, variables which are used before being given initial value
10/11/2011
12
Reaching Definition Analysis Live Variable Analysis Use-Definition chains(ud chains) Definition-use chains(du chains) ..
10/11/2011
13
10/11/2011
14
10/11/2011
15
10/11/2011
16
10/11/2011
17
10/11/2011
18
10/11/2011
19
10/11/2011
20
10/11/2011
21
10/11/2011
22
10/11/2011
23
10/11/2011
24
10/11/2011
25
10/11/2011
26
10/11/2011
27
10/11/2011
28
NODE IN 1 2 3 4 5 6 a bc b a c
USE a bc b a c
OUT a -
In[s] -a -
Def[n] a b c a a -
10/11/2011
29
NODE IN 1 2 3 4 5 6 ac bc b ac c
USE a bc b a c
OUT a bc b a ac -
In[s] a bc b a ac -
Def[n] a b c a -
10/11/2011
30
10/11/2011
31
10/11/2011
32
Interprocedural
Across several methods (and classes) or procedures
33
Context Sensitivity
foo() { sub() } (call) bar() { sub()
sub() {
(call)
(return) }
(return) }
A context-sensitive (intrarprocedural) analysis distinguishes sub() called from foo() from sub() called from bar(); A context-insensitive (interprocedural) analysis does not separate them, as if foo() could call sub() and sub() could then return to bar()
10/11/2011
Collections by: Dr. U.P.Kulkarni
34
10/11/2011
35
x = .... if .... 4 x = .... Value of x at 6 could be computed at 1 or at 4 Bad computation at 1 or 4 could be revealed only if they are used at 6 (1,6) and (4,6) are def-use (DU) pairs
defs at 1,4 use at 6
....
5
... y = x + ...
Terms
DU pair: a pair of definition and use for some variable, such that at least one DU path exists from the definition to the use
x = ... is a definition of x = ... x ... is a use of x
DU path: a definition-clear path on the CFG starting from a definition to a use of a same variable
Definition clear: Value is not replaced on path Note loops could create infinite DU paths between a def and a use
10/11/2011
Collections by: Dr. U.P.Kulkarni
37
Definition-clear path
1
2 3
....
5
... y = x + ...
C-use Uses of a variable that occurs within an expression as part of an assignment statement, in an output statement, as a parameter within a function call, and in subscript expressions, are classified as c-use, where the c in c-use stands for computational.
p-use The occurrence of a variable in an expression used as a condition in a branch statement such as an if and a while, is considered as a p-use. The p in puse stands for predicate.
For a given test case Identify possible defuse pairs covered Unreachable node
Example (contd.)
Neither of the two tests force the use of z defined on line 6, at line 9. To do so one requires a test that causes conditions at lines 5 and 8 to be true.
An MC/DC adequate test does not force the execution of this path and hence the divide by zero error is not revealed.
Example (contd.)
Verify that the following test set covers all def-use pairs of z and reveals the error.
Adequacy criteria
All DU pairs: Each DU pair is exercised by at least one test case All DU paths: Each simple (non looping) DU path is exercised by at least one test case All definitions: For each definition, there is at least one test case which exercises a DU pair containing it
(Every computed value is used somewhere)
46
Difficult cases
x[i] = ... ; ... ; y = x[j]
DU pair (only) if i==j
47
For testing, it may be preferrable to accept under-estimation of alias set rather than over-estimation or expensive analysis
Controversial: In other applications (e.g., compilers), a conservative over-estimation of aliases is usually required Alias analysis may rely on external guidance or other global analysis to calculate good estimates Undisciplined use of dynamic storage, pointer arithmetic, etc. may make the whole analysis infeasible
10/11/2011
48
Infeasibility
Consider the c-use at node 4 of z defined at node 5. For this c-use to be covered, control must arrive at node 5 ( X>0) and then move to node 4 through 6 , 2 and 3. This is not possible because edge (2,3) can be taken only if x<=0
Infeasibility
1 if (cond)
2
....
4
...
5 if (cond) 6 y = x + ...
7
....
Infeasibility The path-oriented nature of data flow analysis makes the infeasibility problem especially relevant
Combinations of elements matter! Impossible to (infallibly) distinguish feasible from infeasible paths. More paths = more work to check manually.
10/11/2011
51
Summary
Data flow testing attempts to distinguish important paths: Interactions between statements
Intermediate between simple statement and branch coverage and more expensive path-based structural testing
10/11/2011
52