Lecture 5
Lecture 5
1
Prime Path exercise
2
Control Flow Graph(CFG)
3
4
Data Flow Graph Coverage for
Source Code
5
def
6
use
7
Sidetrips and Detours Example
1 2 3 4
0 1 2 4 5
1 2 5
0 1 2 4 5
3
Touring with a 4
3
detour
8
Exercise
Answer questions (a)-(f) for the graph defined by the following sets:
• N ={0, 1, 2, 3, 4, 5, 6, 7}
• N0 = {0} • Nf = {7}
• E = {(0,1), (1, 2), (1, 7), (2, 3), (2, 4), (3, 2), (4, 5), (4, 6), (5,
6), (6, 1)}
• def(0)=def(3)=use(5)=use(7) = {X}
9
Also consider the following test paths:
• t1 = [0,1,7]
• t2 = [0,1,2,4,6,1,7]
• t3 = [0,1,2,4,5,6,1,7]
• t4 = [0,1,2,3,2,4,6,1,7]
• t5 = [0,1,2,3,2,3,2,4,5,6,1,7]
• t6 = [0,1,2,3,2,4,6,1,2,4,5,6,1,7]
10
(a) Draw the graph.
(b) List all of the du-paths with respect to x. (Note: Include all du-paths,
even those that are subpaths of some other du-paths).
(c) For each test path, determine which du-paths that test path du-tours.
Consider direct touring only. Hint: A table is a convenient format for
describing the relationship.
(d) List a minimal test set that satisfies all-defs coverage with respect to
x (Direct tours only). Use the given test paths.
(e) List a minimal test set that satisfies all-uses coverage with respect to
x. (Direct tours only). Use the given test paths.
(f) List a minimal test set that satisfies all-du-paths coverage with
respect to x. (Direct tours only). Use the given test paths.
11
12
13
Structural Graph Coverage for
Design Elements
Graph coverage for design elements usually starts by creating graphs
that are based on couplings between software components.
Coupling measures the dependency relations between two units by
reflecting their interconnections; faults in one unit may affect the
coupled unit.
Coupling provides summary information about the design and the
structure of the software. Most test criteria for design elements
require that various connections among program components be
visited.
14
The most common graph used for structural design coverage is the
call graph. In a call graph, the nodes represent methods (or units) and
the edges represent method calls.
Figure 2.22 represents a small program that contains
six methods. Method A calls B, C, and D, and C in turn
calls E and F, and D also calls F.
15
Node coverage requires that each method be called at least once and
is also called method coverage. Edge coverage requires that each call
be executed at least once and is also called call coverage.
Figure 2.22, node coverage requires that each method be called at
least once, whereas edge coverage requires that F be called at least
twice, once from C and once from D.
16
Data Flow Graph Coverage for
Design Elements
Control connections among design elements are simple and
straightforward and tests based on them are probably not very
effective at finding faults. On the other hand, data flow connections
are often very complex and difficult to analyze. For a tester, that
should immediately suggest that they are a rich source for software
faults. The primary issue is where the defs and uses occur. When
testing program units, the defs and uses are in the same unit. During
integration testing, defs and uses are in different units. This section
starts with some standard compiler/program analysis terms.
17
Standard Compiler/Program Analysis
Terms
A caller is a unit that invokes another unit, the callee. The statement
that makes the call is the call site.
An actual parameter is in the caller; its value is assigned to a formal
parameter in the callee.
The interface between two units is the mapping of actual to formal
parameters.
18
The underlying premise of the data flow testing criteria for design
elements is that to achieve confidence in the interfaces between
integrated program units, it must be ensured that variables defined in
caller units be appropriately used in callee units.
This technique can be limited to the unit interfaces, allowing us to
restrict our attention to the last definitions of variables just before
calls to and returns from the called units, and the first uses of
variables just after calls to and returns from the called unit.
19
Example
20
Coupling Types
21
Last-def: The set of nodes that define a variable x for which there is a
def-clear path from the node through the call site to a use in the other
unit.
The variable can be passed as a parameter, a return value, or a
shared variable reference. If the function has no return statement, an
implicit return statement is assumed to exist at the last statement in
the method.
22
First-use: The set of nodes that have uses of y and for which there
exists a path that is def-clear and use-clear from the entry point (if
the use is in the callee) or the call site (if the use is in the caller) to
the nodes.
Fig 2.26 shows a caller F() and a callee G(). The callsite has two du-
pairs; x in F() is passed to a in G() and b in G() is returned and
assigned to y in F(). Note that the assignment to y in F() is explicitly
not the use, but considered to be part of the transfer. Its use is further
down, in the print(y) statement.
23
Example
last-defs and first-uses between two units with two partial CFGs. The
unit on the left, the caller, calls the callee
B, with one actual parameter, X, which is
assigned to formal parameter y. X is defined
at nodes 1, 2 and 3, but the def at node 1
cannot reach the call site at node 4, thus
the last-defs for X is the set {2, 3}. The formal
parameter y is used at nodes 11, 12, and 13,
but no use-clear path goes from the entry point at node 10 to 13, so the
first-uses for y is the set {11, 12}.
24
Example
The coupling du-pairs can be listed using pairs of triples. Each triple
gives a unit name, variable name, and a line number. The first triple
in a pair says where the variable is defined, and the second where it
is used. The complete set of coupling du-pairs for class Quadratic is
25
Source Code Example
26
CFG Example
27
Exercise 1
28
Solution
29
Exercise 2
30
Solution
31
Def and Use table
32
Thank You
33