Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Code Coverage
Code coverage describes the degree to which the source code of a program has been tested
Code Coverage
It is a form of testing that inspects the code directly and is therefore a form of white box testing It considers the following:
a) b) c)
Function Coverage: Has each function in the program been called? Statement Coverage: Has each line of the source code been executed? Decision Coverage: Also known as Branch coverage. Has each control structure (such as an if statement) evaluated both to true and false?
Software Testing
05/02/2011
Code Coverage
d)
Condition Coverage or Predicate Coverage: Has each Boolean subexpression evaluated both to true and false (this does not necessarily imply decision coverage)?
e)
Path Coverage: Has every possible route through a given part of the code been executed?
f)
Entry/Exit Coverage: Has every possible call and return of the function been executed?
Software Testing
05/02/2011
Software Testing
05/02/2011
10/4/2012
Cyclomatic Complexity
Also called conditional complexity Used to measure the complexity of a program It directly measures the number of linearly independent paths through a program's source code Its aim is to derive a logical complexity measure of a procedural design and use this as a guide for defining a basic set of execution paths. The number of test cases is proportional to the size of the program. More precisely, the value of Cyclomatic Complexity can be seen as an upper bound for the number of test cases needed for path coverage, as it is a measure of the number of the independent paths
5 Software Testing 05/02/2011 6 Software Testing
Cyclomatic Complexity
Cyclomatic complexity is computed using control flow graphs, so we will introduce control flow graphs
05/02/2011
Cyclomatic Complexity
A control flow graph (CFG) is a representation, using graph notation, of all paths that might be traversed through a program during its execution On a flow graph:
o Arrows called edges represent flow of control o Circles called nodes represent one or more actions o Areas bounded by edges and nodes called regions o A predicate node is a node containing a condition o succ[n] is the set containing the successors of a node n o pred[n] is the set containing the predecessors of a node n
Software Testing Software Testing
Cyclomatic Complexity
05/02/2011
05/02/2011
10/4/2012
Cyclomatic Complexity
In the first CFG, succ[1] = {2,3}, succ[2] = succ[3] = {4}, pred[4] = {2,3}, pred[2] = pred[3] = {1}
Data Flow Testing (or Data Flow Analysis) is a technique for gathering information about the possible set of values calculated at various points in a computer program A program unit accepts inputs, performs computations, assigns new values to variables, and returns results
2) 3)
Number Predicate Nodes + 1 Number of regions of flow graph. (area surrounded by nodes/edges)
Software Testing
05/02/2011
10
Software Testing
05/02/2011
Identify paths to execute them Paths are identified based on data flow testing criteria Static data flow testing
o Identify potential defects, commonly known as data flow anomaly o Analyze source code o Do not execute code
11
Software Testing
05/02/2011
12
Software Testing
05/02/2011
10/4/2012
Definition (def) : A location where a value for a variable is stored into memory Use : A location where a variables value is accessed def (n) or def (e) :The set of variables that are defined by node n or edge e use (n) or use (e) :The set of variables that are used by node n or edge e
13
Software Testing
05/02/2011
14
Software Testing
05/02/2011
10/4/2012
17
Software Testing
05/02/2011
18
Software Testing
05/02/2011
Application of live variable analysis: the value of dead variables need not to be saved at the end of a basic block
Definitions of in, out, gen, kill depend on the type of the analysis we want to perform
19 Software Testing 05/02/2011 20 Software Testing 05/02/2011
10/4/2012
a)
Push liveness across edges: If a variable is live-in at a node n then it is live-out at all nodes in pred[n]
a)
Push liveness across nodes: If a variable is live-out at node n and not in def[n] then the variable is also live-in at n
21
Software Testing
Software Testing
23
Software Testing
05/02/2011
24
Software Testing
05/02/2011
10/4/2012
25
Software Testing
05/02/2011
26
Software Testing
05/02/2011
Test data set 1: a = -1, b = -1 covers pairs 1,2 for a; 1 for b and 1 for c => the flow is S-1-2-7-E
Test data set 5: a = 11, b = -1 covers pairs 1,3,4,5,7 for a; 2 for b => the flow is S-1-2-3-4-6-{2-3-4-6}+
b)
Test data set 2: a = 11, b = 12 covers pairs 1,3,4,5,6 for a; 1,2 for b and 1 for c => the flow is S-1-2-3-4-6-2-7-E
f)
Test data set 6: a = 9, b = 1 covers pairs 1,3,4,5,7, 5 for b => the flow is S-1-2-3-5-6-{2-3-5-6}+
c)
Test data set 3: a = 11, b = 9 covers pairs 1,3,4,5 for a; 2,5 for b => the flow is S-1-2-3-4-6-2-3-5-6-2-3-5-6-{2-3-5-6}+
27
Software Testing
05/02/2011
28
Software Testing
05/02/2011
10/4/2012
in 4
o => is live in 1-2-7 and in 1-2-3-5-6-2-7 paths o => is dead in 1-2-3-4-6-2-7
Variable b:
o is dead in every path containing 2-4-5, because we assign a new value for b
in 5
o => is live in 1-2-7 and in 1-2-3-4-6-2-7 paths o => is dead in 1-2-3-5-6-2-7 (contains 2-4-6)
29
Software Testing
05/02/2011
30
Software Testing
05/02/2011
Exercises
31
Software Testing
05/02/2011
32
Software Testing
05/02/2011
10/4/2012
Exercises
Exercises
33
Software Testing
05/02/2011
34
Software Testing
05/02/2011
END
35
Software Testing
05/02/2011