Compiled with reference from:
Software Testing Techniques: Boris Beizer
Craft of Software Testing: Brain Marrick
Unit 2
Control Flow Graphs and Path Testing
ref boris beizer
2
We will see in Unit 2:
In addition we have also,
U2
Control Flow Graphs and Path Testing
ref boris beizer
3
Path Testing Definition
A family of structural test techniques based on judiciously selecting a set of test paths through the programs.
Code Coverage: During unit testing: # stmts executed at least once / total # stmts
U2
Control Flow Graphs and Path Testing
ref boris beizer
4
Path Testing contd..
Assumptions:
Observations
U2
Control Flow Graphs and Path Testing
ref boris beizer
5
Control Flow Graph
A simplified, abstract, and graphical representation of a program’s control structure using process blocks, decisions and junctions.
U2
Do Process A
Process Block
Decisions
Junctions
Case Statement
IF
A = B ?
NO: ELSE DO
YES: THEN DO
1
2
1
CASE-OF
2
N
CASE 1
CASE 2
CASE N
Control Flow Graph Elements
Control Flow Graphs and Path Testing
ref boris beizer
6
Control Flow Graph Elements:
Process Block:
Junction:
Decisions:
Case Statements:
U2
Control Flow Graphs and Path Testing
ref boris beizer
7
Control Flow Graph Vs Flow Charts
U2
Control Flow Graph | Flow Chart |
Compact representation of the program | Usually a multi-page description |
Focuses on Inputs, Outputs, and the control flow into and out of the block. | Focuses on the process steps inside |
Inside details of a process block are not shown | Every part of the process block are drawn |
Control Flow Graphs and Path Testing
ref boris beizer
8
U2
Creation of Control Flow Graph from a program
INPUT X, Y
Z := X + Y
V := X - Y
IF Z >= 0 GOTO SAM
JOE: Z := Z + V
SAM: Z := Z - V
FOR N = 0 TO V
Z := Z - 1
NEXT N
END
INPUT X, Y
Z >= 0 ?
Z := X + Y
V := X - Y
Z := Z - V
Z := Z + V
SAM
JOE
NO
N := 0
Z := Z - 1
LOOP
N = V ?
NO
YES
END
One to One Flow Chart
N := N+1
Control Flow Graphs and Path Testing
ref boris beizer
9
U2
Creation of Control Flow Graph from a program
INPUT X, Y
Z := X + Y
V := X - Y
IF Z >= 0 GOTO SAM
JOE: Z := Z + V
SAM: Z := Z - V
FOR N = 0 TO V
Z := Z - 1
NEXT N
END
Simplified Flow Graph
Z >= 0 ?
P1
P3
P2
SAM
JOE
NO
P4
LOOP
N = V ?
NO
YES
END
P5
Control Flow Graphs and Path Testing
ref boris beizer
10
U2
Creation of Control Flow Graph from a program
INPUT X, Y
Z := X + Y
V := X - Y
IF Z >= 0 GOTO SAM
JOE: Z := Z + V
SAM: Z := Z - V
FOR N = 0 TO V
Z := Z - 1
NEXT N
END
Simplified Flow Graph
1
2
3
4
5
6
7
Control Flow Graphs and Path Testing
Linked List Notation of a Control Flow Graph
Node Processing, label, Decision Next-Node
1 (BEGIN; INPUT X, Y; Z := X+Y ; V := X-Y) : 2
2 ( Z >= 0 ? ) : 4 (TRUE)
: 3 (FALSE)
3 (JOE: Z := Z + V) : 4
4 (SAM: Z := Z – V; N := 0) : 5
5 (LOOP; Z := Z -1) : 6
6 (N = V ?) : 7 (FALSE)
: END (TRUE)
7 (N := N + 1) : 5
ref boris beizer
11
U2
1
2
3
4
5
6
7
Control Flow Graphs and Path Testing
ref boris beizer
12
Path Testing Concepts
Link is a single process (block) in between two nodes.
Node is a junction or decision.
Segment is a sequence of links. A path consists of many segments.
Path segment is a succession of consecutive links that belongs to the same path. (3,4,5)
Length of a path is measured by # of links in the path or # of nodes traversed.
Name of a path is the set of the names of the nodes along the path. (1,2,3 4,5, 6)
(1,2,3,4, 5,6,7, 5,6,7, 5,6)
Path-Testing Path is an “entry to exit” path through a processing block.
U2
Control Flow Graphs and Path Testing
ref boris beizer
13
Path Testing Concepts..
Single entry and single exit routines are preferable.
Called well-formed routines.
Formal basis for testing exists.
Tools could generate test cases.
U2
Control Flow Graphs and Path Testing
ref boris beizer
14
Path Testing Concepts..
Multi-entry / Multi-exit routines: (ill-formed)
Large # of inter-process interfaces. Creates problem in Integration.
More # test cases and also a formal treatment is more difficult.
U2
Multi-
entry
routine
Multi-
Exit
Routine
Valid only for x
Valid for x or y
Valid only for Y
Called by x, y
Valid for caller A, B
Valid for caller A
Valid for caller B, C
Control Flow Graphs and Path Testing
ref boris beizer
15
Path Testing Concepts contd..
Convert a multi-entry / exit routine to a single entry / exit routine:
U2
Begin N
Begin
Begin 1
1
2
N
Begin 2
Case
Exit N
Exit 1
Exit 2
1
2
N
SET E = 1
SET E = 1
SET E = 1
Control Flow Graphs and Path Testing
ref boris beizer
16
Path Testing Concepts contd..
Test Strategy for Multi-entry / exit routines
U2
Control Flow Graphs and Path Testing
ref boris beizer
17
Path Testing Concepts
A minimal set of paths to be able to do complete testing.
U2
Complete Path Testing prescriptions:
♦ Point 1 => point 2 and 3. ♦ Point 2 & 3 are not the same
♦ Point 1 is impractical. ♦ For a structured language, Point 3 => Point 2
Control Flow Graphs and Path Testing
ref boris beizer
18
Path Testing Concepts
Path Testing Criteria :
Execute all possible control flow paths thru the program; but typically restricted to entry-exit paths.
Implies 100% path coverage. Impossible to achieve.
Execute all statements in the program at least once under the some test.
100% statement coverage => 100% node coverage.
Denoted by C1
C1 is a minimum testing requirement in the IEEE unit test standard: ANSI 87B.
Execute enough tests to assure that every branch alternative has been exercised at least once under some test.
Denoted by C2
Objective: 100% branch coverage and 100% Link coverage.
For well structured software, branch testing & coverage include statement coverage
U2
Control Flow Graphs and Path Testing
ref boris beizer
19
Picking enough (the fewest) paths for achieving C1+C2
U2
Z >= 0 ?
P1
SAM
NO
LOOP
N = V ?
NO
YES
END
2
b
a
1
c
e
f
g
d
5
4
3
6
Paths | Decisions | Process-link | |||||||
| 2 | 5 | a | b | c | d | e | f | g |
abdeg | Y | Y | Y | Y | | Y | Y | | Y |
acdeg | No | Y | Y | | Y | Y | Y | | Y |
abdefeg | Y | N | Y | Y | | Y | Y | Y | Y |
acdefeg | No | Y | Y | | Y | Y | Y | Y | Y |
Make small changes in the path changing only 1 link or node at a time.
Control Flow Graphs and Path Testing
ref boris beizer
20
Revised path selection Rules
U2
Control Flow Graphs and Path Testing
ref boris beizer
21
Bugs in iterative statements apparently are not discovered by C1+C2.
But by testing at the boundaries of loop variable.
Types of Iterative statements
Let us denote the Minimum # of iterations by nmin
the Maximum # of iterations by nmax
the value of loop control variable by V
the #of test cases by T
the # of iterations carried out by n
U2
Control Flow Graphs and Path Testing
ref boris beizer
22
Testing of path involving loops…
Case 1. nmin = 0, nmax = N, no excluded values
1. Bypass the loop.
If you can’t, there is a bug, nmin ≠ 0 or a wrong case.
2. Could the value of loop (control) variable V be negative?
could it appear to specify a –ve n ?
3. Try one pass through the loop statement: n = 1
4. Try two passes through the loop statement: n = 2
To detect initialization data flow anomalies:
Variable defined & not used in the loop, or
Initialized in the loop & used outside the loop.
5. Try n = typical number of iterations : nmin < n < nmax
6. Try n = nmax -1
7. Try n = nmax
8. Try n = nmax + 1.
What prevents V (& n) from having this value?
What happens if it is forced?
U2
2
1
Control Flow Graphs and Path Testing
ref boris beizer
23
Testing of path involving loops…
Case 2. nmin = +ve, nmax = N, no excluded values
1. Try nmin - 1
Could the value of loop (control) variable V be < nmin?
What prevents that ?
2. Try nmin
3. Try nmin + 1
4. Once, unless covered by a previous test.
5. Twice, unless covered by a previous test.
4. Try n = typical number of iterations : nmin < n < nmax
5. Try n = nmax -1
6. Try n = nmax
7. Try n = nmax + 1.
What prevents V (& n) from having this value?
What happens if it is forced?
Note: only a case of no iterations, n = 0 is not there.
U2
2
1
Control Flow Graphs and Path Testing
ref boris beizer
24
Path Testing Concepts…
Case 3. Single loop with excluded values
1. Treat this as single loops with excluded values as two sets.
2. Example:
V = 1 to 20 excluding 7,8,9 and10
Test cases to attempt are for:
V = 0,1,2,4,6,7 and V = 10,11,15,19,20,21
(underlined cased are not supposed to work)
U2
2
1
Control Flow Graphs and Path Testing
ref boris beizer
25
Testing of path involving loops…
U2
3
2
4
1
Control Flow Graphs and Path Testing
ref boris beizer
26
Testing of path involving loops…
U2
3
2
4
1
Control Flow Graphs and Path Testing
ref boris beizer
27
Testing of path involving loops…
U2
4
3
2
1
Control Flow Graphs and Path Testing
ref boris beizer
28
Testing of path involving loops…
U2
5
4
3
2
1
6
Control Flow Graphs and Path Testing
ref boris beizer
29
Testing of path involving loops…
Loop Testing Times
Case: Testing nested loops with combination of extreme values leads to long test times.
U2
Control Flow Graphs and Path Testing
ref boris beizer
30
Effectiveness of Path Testing
U2
Control Flow Graphs and Path Testing
ref boris beizer
31
Effectiveness of Path Testing
Test design process at all levels at least as effective at catching bugs as is running the test designed by that process.
U2
Control Flow Graphs and Path Testing
ref boris beizer
32
Predicates, Predicate Expressions
Path
Predicate
Compound Predicate
Path Predicate
“ X > 0 is True “ AND “W is either negative or equal to 122” is True
U2
Control Flow Graphs and Path Testing
ref boris beizer
33
Predicates, Predicate Expressions…
Predicate Interpretation
An input vector is a set of inputs to a routine arranged as a one dimensional array.
INPUT X, Y INPUT X
ON X GOTO A, B, C IF X < 0 THEN Y:= 2
A: Z := 7 @ GOTO H ELSE Y := 1
B: Z := -7 @ GOTO H IF X + Y*Y > 0 THEN …
C: Z := 0 @ GOTO H
H: DO SOMETHING
K: IF X + Z > 0 GOTO GOOD ELSE GOTO BETTER
U2
Control Flow Graphs and Path Testing
ref boris beizer
34
Predicates, Predicate Expressions…
Process Dependency
X is odd Add an even # to X
U2
Control Flow Graphs and Path Testing
ref boris beizer
35
Predicates, Predicate Expressions…
Correlation
U2
Control Flow Graphs and Path Testing
ref boris beizer
36
Predicates, Predicate Expressions…
Path Predicate Expression
If X 5 > 0 .OR. X 6 < 0 then
X1 + 3X2 + 17 >= 0
X3 = 17
X4 – X1 >= 14 X2
U2
Control Flow Graphs and Path Testing
ref boris beizer
37
Predicates, Predicate Expressions…
A: X 5 > 0 E: X 6 < 0
B: X1 + 3X2 + 17 >= 0 F: X1 + 3X2 + 17 >= 0
C: X3 = 17 G: X3 = 17
D: X4 – X1 >= 14 X2 H: X4 – X1 >= 14 X2
Converting into the predicate expression form:
A B C D + E B C D ⇒ ( A + E ) B C D
If we take the alternative path for the expression: D then
(A + E ) B C D
U2
Control Flow Graphs and Path Testing
ref boris beizer
38
Predicates, Predicate Expressions…
Predicate Coverage:
U2
Control Flow Graphs and Path Testing
ref boris beizer
39
Testing blindness
interaction of some statements makes a buggy predicate work, and
the bug is not detected by the selected input values.
by ignoring the # of paths to arrive at it.
U2
Control Flow Graphs and Path Testing
ref boris beizer
40
Testing blindness
Correct Buggy
X := 7 X := 7
IF Y > 0 THEN … IF X + Y > 0 THEN … (check for Y=1)
Correct Buggy
IF Y = 2 THEN … IF Y = 2 THEN ..
IF X + Y > 3 THEN … IF X > 1 THEN … (check for any X>1)
Correct Buggy
X := A X := A
IF X - 1 > 0 THEN … IF X + A -2 > 0 THEN … (check for any X,A)
U2
Control Flow Graphs and Path Testing
ref boris beizer
41
Achievable Paths
AD + AE + BCD + BCE
A solution found => path is achievable. Otherwise the path is unachievable.
U2
Control Flow Graphs and Path Testing
ref boris beizer
42
Path Sensitization
U2
Heuristic procedures:
Choose an easily sensitizable path set, & pick hard-to-sensitize paths to achieve more coverage.
Identify all the variables that affect the decisions. For process dependent variables, express the nature of the process dependency as an equation, function, or whatever is convenient and clear. For correlated variables, express the logical, arithmetic, or functional relation defining the correlation.
It’s the act of finding a set of solutions to the path predicate expression.
In practice, for a selected path finding the required input vector is not difficult. If there is difficulty, it may be due to some bugs.
Control Flow Graphs and Path Testing
ref boris beizer
43
Path Sensitization… Heuristic procedures: contd..
U2
Control Flow Graphs and Path Testing
ref boris beizer
44
Examples for Path Sensitization
1. Simple Independent Uncorrelated Predicates
U2
2. Independent Correlated Predicates
3. Dependent Predicates
4. Generic
Control Flow Graphs and Path Testing
ref boris beizer
45
Examples for Path Sensitization..
1. Simple Independent Uncorrelated Predicates
U2
1
4
2
7
6
A
C
B
D
9
3
5
10
8
a
b
e
c
d
f
h
l
i
j
k
m
B
_
B
A
_
A
_
C
_
D
D
C
Path Predicate Values Path Predicate Values
abcdef A •C abcdef A •C
aghcimkf •A B C D abcimjef A C •D
aglmjef •A •B •D abcimkf A C D
aghcdef •A B •C
aglmkf •A •B •D
4 predicates => 16 combinations
Set of possible paths = 8
A Simple case of solving inequalities. (obtained by the procedure for finding a covering set of paths)
Control Flow Graphs and Path Testing
ref boris beizer
46
Examples for Path Sensitization …
2. Correlated Independent Predicates
U2
1
4
2
6
Y
Y
3
5
a
c
g
d
b
f
_
Y
Y
Y
_
Y
Correlated paths => some paths are unachievable
ie., redundant paths.
ie., n decisions but # paths are < 2n
Due to practice of saving code which makes
the code very difficult to maintain.
Eliminate the correlated decisions.
Reproduce common code.
1
4
2
6
Y
3
a
c
g
f
b
e
_
Y
Y
5
4’
5’
d
d’
Correlated decision removed & CFG simplified
If a chosen sensible path is not achievable,
- there’s a bug.
- design can be simplified.
- get better understanding of correlated decisions
Control Flow Graphs and Path Testing
ref boris beizer
47
U2
Examples for Path Sensitization …
3. Dependent Predicates
Usually most of the processing does not affect the control flow.
Use computer simulation for sensitization in a simplified way.
Dependent predicates contain iterative loop statements usually.
For Loop statements:
Determine the value of loop control variable for a certain # of iterations, and then
work backward to determine the value of input variables (input vector).
Control Flow Graphs and Path Testing
ref boris beizer
48
U2
Examples for Path Sensitization …
4. The General Case
No simple procedure to solve for values of input vector for a selected path.
1. Select cases to provide coverage on the basis of functionally sensible paths.
Well structured routines allow easy sensitization.
Intractable paths may have a bug.
If the solution is not found, path is not achievable, it could be a bug.
5. Continue until the entrance & therefore have established a set of input conditions for the path.
4. Continue tracing along the path. Pick the broadest range of values for variables affected
and consistent with values that were so far determined.
3. Start at the end of the path and list the predicates while tracing the path in reverse.
Each predicate imposes restrictions on the subsequent (in reverse order) predicate.
2. Tackle the path with the fewest decisions first. Select paths with least # of loops.
Control Flow Graphs and Path Testing
ref boris beizer
49
U2
Examples for Path Sensitization …
4. The General Case contd..
Alternately:
1. In the forward direction, list the decisions to be traversed.
For each decision list the broadest range of input values.
Advantages & Disadvantages of the two approaches:
The forward method is usually less work.
you do not know where you are going as you are tracing the graph.
3. Continue. Some decisions may be dependent on and/or correlated with earlier ones.
2. Pick a path & adjust all input values. These restricted values are used for next decision.
4. The path is unachievable if the input values become contradictory, or, impossible.
If the path is achieved, try a new path for additional coverage.
Control Flow Graphs and Path Testing
ref boris beizer
50
PATH INSTRUMENTATION
Output of a test:
Results observed. But, there may not be any expected output for a test.
U2-1
Expected Outcome:
Any expected change or the lack of change at the output (predicted as part of design).
Actual Outcome:
Observed outcome
Outcome:
Any change or the lack of change at the output.
Control Flow Graphs and Path Testing
ref boris beizer
51
PATH INSTRUMENTATION
Coincidental Correctness:
When expected & actual outcomes match,
(the expected outcome may be achieved due to a wrong reason)
U2-1
X = 16
CASE SELECT
Y := X - 14
Here
Y is 2
Y := 2
Y := X mod 14
Path Instrumentation is what we have to do confirm that the outcome was achieved by the intended path.
Control Flow Graphs and Path Testing – Questions from previous exams
ref boris beizer
52
U2
1. General strategy:
2. Traversal or Link Makers:
Simple and effective
PATH INSTRUMENTATION METHODS
Control Flow Graphs and Path Testing
ref boris beizer
53
Single Link Marker Instrumentation: An example
U2
Input
A,B,C
A = 7?
j
i
B$ =
“a” ?
k
No
No
o
C =
0 ?
l
n
m
No
B$ =
“d” ?
p
No
C ≤
0 ?
q
s
r
No
Sample path: i j n
Control Flow Graphs and Path Testing
ref boris beizer
54
Single Link Marker Instrumentation: Not good enough
U2
Problem:
Processing in the links may be chewed open by bugs. Possibly due to GOTO statements, control takes a different path, yet resulting in the intended path again.
m
A = 7?
j
i
No
k
?
n
No
Process C
Process A
Process B
Process D
Control Flow Graphs and Path Testing
ref boris beizer
55
Double Link Marker Instrumentation:
U2
The problem is solved.
Two link markers specify the path name and both the beginning & end of the link.
m
A = 7?
j
i
o
?
q
Process C
Process A
Process B
Process D
r
n
l
p
Control Flow Graphs and Path Testing
ref boris beizer
56
PATH INTRUMENTATION techniques…
3. Link Counters Technique:
U2
Expect an even count = double the length.
If there are no loops, the link counts are = 1.
Control Flow Graphs and Path Testing
ref boris beizer
57
PATH INTRUMENTATION techniques…
3. Link Counters Technique: contd..
Check list for the procedure:
U2
This procedure and the checklist could solve the problem of Instrumentation.
Control Flow Graphs and Path Testing
ref boris beizer
58
PATH INTRUMENTATION techniques…
U2
Limitations
If the presence or absence of probes modifies things (for example in the data base) in a faulty way, then the probes hide the bug in the program.
Control Flow Graphs and Path Testing
ref boris beizer
59
U2
PATH INTRUMENTATION - IMPLEMENTATION
For Unit testing : Implementation may be provided by a comprehensive test tool.
For higher level testing or for testing an unsupported language:
For Languages supporting conditional assembly or compilation:
For language not supporting conditional assembly / compilation:
In general:
Control Flow Graphs and Path Testing
ref boris beizer
60
U2
Implementation & Application of Path Testing
To achieve C1 or C2 coverage:
Weaknesses of Path testing:
Control Flow Graphs and Path Testing
ref boris beizer
61
U2
Implementation & Application of Path Testing
Control Flow Graphs and Path Testing
ref boris beizer
62
U2
Implementation & Application of Path Testing
Control Flow Graphs and Path Testing
ref boris beizer
63
U2
Implementation & Application of Path Testing
Control Flow Graphs and Path Testing
ref boris beizer
64
U2
Process of path testing during rehosting
Implementation & Application of Path Testing
Application of path testing to Rehosting..
functionalities (which were not possible in the old environment.)
Control Flow Graphs and Path Testing – Questions from previous exams
ref boris beizer
65
For reference – just to see that we have covered these:
Q. Define Path Testing. Explain three path testing criteria.
Q. Illustrate with an example, how statement and branch coverage can be achieved during path selection. Write all steps involved in it.
Q. Write the effectiveness and limitations of path testing.
Q. Define Path Sensitization. Explain heuristic procedure for sensitizing paths with the help of an example.
Q. How can a program control structure be represented graphically? Explain with the help of required diagrams.
Q. How is a flowchart differed from a control flow chart?
Q. Explain about Multi entry and Multi exit routines & fundamental path selection criteria
Q. Explain about path instrumentation. How are link counters useful in Path Instrumentation method?
Q. Write about implementation of path testing. What are the various applications of path testing?
Q. Categorize different kinds of loops and explain.
U2
Software Testing Methodology
ref boris beizer
66
To Unit 3 Transaction flow testing…
U2