Overview Graph Coverage Criteria ( Introduction to Software Testing Chapter 2.1, 2.2) Paul Ammann & Jeff Offutt.

Slides:



Advertisements
Similar presentations
Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks.
Advertisements

Data Flow Coverage. Reading assignment L. A. Clarke, A. Podgurski, D. J. Richardson and Steven J. Zeil, "A Formal Evaluation of Data Flow Path Selection.
Introduction to Software Testing Chapter 1 Paul Ammann & Jeff Offutt SUMMARY OF PARTS 1 AND 2 FROM LAST WEEK.
Paul Ammann & Jeff Offutt
Graph Coverage (2).
CITS5501 Software Quality and Testing Logic and Path Coverage From Introduction to Software Testing, 2 nd ed, Ammann & Offutt.
Graph Coverage Criteria Structural Coverage Criteria : Defined on a graph just in terms of nodes and edges Data Flow Coverage Criteria : Requires a graph.
Introduction to Software Testing Chapter 2.1, 2.2 Overview Graph Coverage Criteria Paul Ammann & Jeff Offutt
Lecture 2 White-box Testing and Structural Coverage.
COVERAGE CRITERIA FOR TESTING 1. ill-defined terms in Testing  complete testing  exhaustive testing  full coverage Are poorly defined terms because.
The Application of Graph Criteria: Source Code  It is usually defined with the control flow graph (CFG)  Node coverage is used to execute every statement.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
Topics in Software Dynamic White-box Testing: Data-flow Testing
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
Introduction to Software Testing Chapter 1 Introduction Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
White-Box Testing Techniques II Originals prepared by Stephen M. Thebaut, Ph.D. University of Florida Dataflow Testing.
Software Testing and Maintenance Lecture 4 Graph Coverage for Design Element Paul Ammann & Jeff Offutt Instructor: Hossein Momeni Mazandaran.
Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
Introduction to Software Testing Chapters 1-5 Coverage Summary Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt
Software Verification Graph Model. 2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt.
Software Testing and Maintenance Lecture 2.1 Overview Graph Coverage
Overview Structural Testing Introduction – General Concepts
1 Graph Coverage (3). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section 2.2 ◦ Section
Concurrency Analysis for Correct Concurrent Programs: Fight Complexity Systematically and Efficiently Moonzoo Kim Computer Science, KAIST.
Control Flow Graphs : The if Statement 1 if (x < y) { y = 0; x = x + 1; } else { x = y; } x >= yx < y x = y y = 0 x = x + 1 if (x < y) { y = 0;
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
Paul Ammann & Jeff Offutt
Data Flow Coverage Criteria
Software Testing and Maintenance Lecture 3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt Instructor: Hossein Momeni Mazandaran.
Data Flow Testing. Introduction to Software Testing (Ch 2) © Ammann & Offutt 2 Definition of a Graph A set N of nodes, N is not empty A set N 0 of initial.
Introduction to Software Testing. Graph Coverage For Specifications 2 Call graphs for classes often wind up being disconnected, and in many cases, such.
Chapter 2 : Graph Coverage (part 2)
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Software Testing and Maintenance 1
Paul Ammann & Jeff Offutt
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Graph: Data Flow Criteria CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Graph: Data Flow Coverage Criteria CS 4501 / 6501 Software Testing
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Graph Coverage for Source Code
Paul Ammann & Jeff Offutt
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Graph Coverage Criteria
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
White-Box Testing Techniques II
Graph Coverage Criteria
Paul Ammann & Jeff Offutt
George Mason University
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Graph-based Test Coverage (A&O Ch. 1, 2. 1 – 2. 3) (2nd Ed: 2,3,5,7
Presentation transcript:

Overview Graph Coverage Criteria ( Introduction to Software Testing Chapter 2.1, 2.2) Paul Ammann & Jeff Offutt

Hierarchy of Structural/graph SW Coverages 2/60 Simple Round Trip Coverage SRTC Node Coverage NC Edge Coverage EC Edge-Pair Coverage EPC Prime Path Coverage PPC Complete Path Coverage CPC Complete Round Trip Coverage CRTC All-DU-Paths Coverage ADUP All-uses Coverage AUC All-defs Coverage ADC Complete Value Coverage CVC (SW) Model checking Concolic testing

Covering Graphs (2.1) Graphs are the most commonly used structure for testing Graphs are the most commonly used structure for testing Graphs can come from many sources Graphs can come from many sources Control flow graphs Control flow graphs Design structure Design structure FSMs and statecharts FSMs and statecharts Use cases Use cases Tests usually are intended to “cover” the graph in some way Tests usually are intended to “cover” the graph in some way 3

Definition of a Graph A set N of nodes, N is not empty A set N of nodes, N is not empty A set N 0 of initial nodes, N 0 is not empty A set N 0 of initial nodes, N 0 is not empty A set N f of final nodes, N f is not empty A set N f of final nodes, N f is not empty A set E of edges, each edge from one node to another A set E of edges, each edge from one node to another ( n i, n j ), i is predecessor, j is successor ( n i, n j ), i is predecessor, j is successor 4

Three Example Graphs N 0 = { 0 } N f = { 3 } N 0 = { } N f = { 3 } N 0 = { 0, 1, 2 } N f = { 7, 8, 9 } Not a validgraph

Paths in Graphs Path : A sequence of nodes – [n 1, n 2, …, n M ] Path : A sequence of nodes – [n 1, n 2, …, n M ] Each pair of nodes is an edge Each pair of nodes is an edge Length : The number of edges Length : The number of edges A single node is a path of length 0 A single node is a path of length 0 Subpath : A subsequence of nodes in p is a subpath of p Subpath : A subsequence of nodes in p is a subpath of p Reach (n) : Subgraph that can be reached from n Reach (n) : Subgraph that can be reached from n Paths [ 0, 3, 7 ] [ 1, 4, 8, 5, 1 ] [ 2, 6, 9 ] Reach (0) = { 0, 3, 4, 7, 8, 5, 1, 9 } Reach ({0, 2}) = G Reach([2,6]) = {2, 6, 9}

Test Paths and SESEs Test Path : A path that starts at an initial node and ends at a final node Test Path : A path that starts at an initial node and ends at a final node Test paths represent execution of test cases Test paths represent execution of test cases Some test paths can be executed by many tests Some test paths can be executed by many tests Some test paths cannot be executed by any tests Some test paths cannot be executed by any tests SESE graphs : All test paths start at a single node and end at another node SESE graphs : All test paths start at a single node and end at another node Single-entry, single-exit Single-entry, single-exit N0 and Nf have exactly one node N0 and Nf have exactly one node Double-diamond graph Four test paths [ 0, 1, 3, 4, 6 ] [ 0, 1, 3, 5, 6 ] [ 0, 2, 3, 4, 6 ] [ 0, 2, 3, 5, 6 ]

Visiting and Touring Visit : A test path p visits node n if n is in p Visit : A test path p visits node n if n is in p A test path p visits edge e if e is in p A test path p visits edge e if e is in p Tour : A test path p tours subpath q if q is a subpath of p Tour : A test path p tours subpath q if q is a subpath of p 8 Path [ 0, 1, 3, 4, 6 ] Visits nodes 0, 1, 3, 4, 6 Visits edges (0, 1), (1, 3), (3, 4), (4, 6) Tours subpaths (0, 1, 3), (1, 3, 4), (3, 4, 6), (0, 1, 3, 4), (1, 3, 4, 6)

Tests and Test Paths path (t) : The test path executed by test t path (t) : The test path executed by test t path (T) : The set of test paths executed by the set of tests T path (T) : The set of test paths executed by the set of tests T Each test executes one and only one test path Each test executes one and only one test path A location in a graph (node or edge) can be reached from another location if there is a sequence of edges from the first location to the second A location in a graph (node or edge) can be reached from another location if there is a sequence of edges from the first location to the second Syntactic reach : A subpath exists in the graph Syntactic reach : A subpath exists in the graph Semantic reach : A test exists that can execute that subpath Semantic reach : A test exists that can execute that subpath 9

Tests and Test Paths 10 test 1 test 2 test 3 many-to-one test 1 test 2 test 3 many-to-many Test Path 1 Test Path 2 Test Path 3 Non-deterministic software – a test can execute different test paths Test Path Deterministic software – a test always executes the same test path

Testing and Covering Graphs (2.2) We use graphs in testing as follows : We use graphs in testing as follows : Developing a model of the software as a graph Developing a model of the software as a graph Requiring tests to visit or tour specific sets of nodes, edges or subpaths Requiring tests to visit or tour specific sets of nodes, edges or subpaths 11 Test Requirements (TR) : Describe properties of test paths Test Criterion : Rules that define test requirements Satisfaction : Given a set TR of test requirements for a criterion C, a set of tests T satisfies C on a graph if and only if for every test requirement in TR, there is a test path in path(T) that meets the test requirement tr Structural Coverage Criteria : Defined on a graph just in terms of nodes and edges Data Flow Coverage Criteria : Requires a graph to be annotated with references to variables

Node and Edge Coverage Edge coverage is slightly stronger than node coverage Edge coverage is slightly stronger than node coverage 12 The “length up to 1” allows for graphs with one node and no edges NC and EC are only different when there is an edge and another subpath between a pair of nodes (as in an “if- else” statement) Node Coverage : TR = { 0, 1, 2 } Test Path = [ 0, 1, 2 ] Edge Coverage : TR = { (0,1), (0, 2), (1, 2) } Test Paths = [ 0, 1, 2 ] [ 0, 2 ] 1 2 0

Paths of Length 1 and 0 A graph with only one node will not have any edges A graph with only one node will not have any edges 13 It may be boring, but formally, Edge Coverage needs to require Node Coverage on this graph 0 Otherwise, Edge Coverage will not subsume Node Coverage –So we define “length up to 1” instead of simply “length 1” 1 0 We have the same issue with graphs that only have one edge – for Edge Pair Coverage …

Covering Multiple Edges Edge-pair coverage requires pairs of edges, or subpaths of length 2 Edge-pair coverage requires pairs of edges, or subpaths of length 2 14 The “length up to 2” is used to include graphs that have less than 2 edges The logical extension is to require all paths … Unfortunately, this is impossible if the graph has a loop, so a weak compromise is to make the tester decide which paths:

Structural Coverage Example 15 Node Coverage TR NC = { 0, 1, 2, 3, 4, 5, 6 } Test Paths: [ 0, 1, 2, 3, 6 ] [ 0, 1, 2, 4, 5, 4, 6 ] Edge Coverage TR EC ={(0,1),(0,2),(1,2), (2,3), (2,4), (3,6), (4,5),(4,6), (5,4)} Test Paths: [ 0, 1, 2, 3, 6 ] [ 0, 2, 4, 5, 4, 6 ] Edge-Pair Coverage TR EPC = { [0,1,2], [0,2,3], [0,2,4], [1,2,3], [1,2,4], [2,3,6], [2,4,5], [2,4,6], [4,5,4], [5,4,5], [5,4,6] } Test Paths: [ 0, 1, 2, 3, 6 ] [ 0, 1, 2, 4, 6 ] [ 0, 2, 3, 6 ] [ 0, 2, 4, 5, 4, 5, 4, 6 ] Complete Path Coverage Test Paths: [ 0, 1, 2, 3, 6 ] [ 0, 1, 2, 4, 6 ] [ 0, 1, 2, 4, 5, 4, 6 ] [ 0, 1, 2, 4, 5, 4, 5, 4, 6 ] [ 0, 1, 2, 4, 5, 4, 5, 4, 5, 4, 6 ] … 5

Loops in Graphs If a graph contains a loop, it has an infinite number of paths If a graph contains a loop, it has an infinite number of paths Thus, CPC is not feasible Thus, CPC is not feasible SPC is not satisfactory because the results are subjective and vary with the tester SPC is not satisfactory because the results are subjective and vary with the tester Attempts to “deal with” loops: Attempts to “deal with” loops: 1980s : Execute each loop, exactly once ([4, 5, 4] in previous example) 1980s : Execute each loop, exactly once ([4, 5, 4] in previous example) 1990s : Execute loops 0 times, once, more than once 1990s : Execute loops 0 times, once, more than once 2000s : Prime paths 2000s : Prime paths 16

Simple Paths and Prime Paths Simple Path : A path from node n i to n j is simple, if no node appears more than once, except possibly the first and last nodes are the same Simple Path : A path from node n i to n j is simple, if no node appears more than once, except possibly the first and last nodes are the same No internal loops No internal loops Includes all other subpaths Includes all other subpaths A loop is a simple path A loop is a simple path Prime Path : A simple path that does not appear as a proper subpath of any other simple path Prime Path : A simple path that does not appear as a proper subpath of any other simple path 17 Simple Paths : [ 0, 1, 3, 0 ], [ 0, 2, 3, 0], [ 1, 3, 0, 1 ], [ 2, 3, 0, 2 ], [ 3, 0, 1, 3 ], [ 3, 0, 2, 3 ], [ 1, 3, 0, 2 ], [ 2, 3, 0, 1 ], [ 0, 1, 3 ], [ 0, 2, 3 ], [ 1, 3, 0 ], [ 2, 3, 0 ], [ 3, 0, 1 ], [3, 0, 2 ], [ 0, 1], [ 0, 2 ], [ 1, 3 ], [ 2, 3 ], [ 3, 0 ], [0], [1], [2], [3] Prime Paths : [ 0, 1, 3, 0 ], [ 0, 2, 3, 0], [ 1, 3, 0, 1 ], [ 2, 3, 0, 2 ], [ 3, 0, 1, 3 ], [ 3, 0, 2, 3 ], [ 1, 3, 0, 2 ], [ 2, 3, 0, 1 ]

Prime Path Coverage A simple, elegant and finite criterion that requires loops to be executed as well as skipped A simple, elegant and finite criterion that requires loops to be executed as well as skipped 18 Will tour all paths of length 0, 1, … That is, it subsumes node, edge, and edge-pair coverage

Prime Path Example The previous example has 38 simple paths The previous example has 38 simple paths Only nine prime paths Only nine prime paths 19 Prime Paths [ 0, 1, 2, 3, 6 ] [ 0, 1, 2, 4, 5 ] [ 0, 1, 2, 4, 6 ] [ 0, 2, 3, 6 ] [ 0, 2, 4, 5] [ 0, 2, 4, 6 ] [ 5, 4, 6 ] [ 4, 5, 4 ] [ 5, 4, 5 ] Execute loop once Execute loop more than once Execute loop 0 times

‘!’ means path terminates Len 2 [0, 1, 2] [0, 2, 3] [0, 2, 4] [1, 2, 3] [1, 2, 4] [2, 3, 6] ! [2, 4, 6] ! [2, 4, 5] ! [4, 5, 4] * [5, 4, 6] ! [5, 4, 5] * Simple & Prime Path Example Len 0 [0] [1] [2] [3] [4] [5] [6] ! Len 1 [0, 1] [0, 2] [1, 2] [2, 3] [2, 4] [3, 6] ! [4, 6] ! [4, 5] [5, 4] ‘*’ means path cycles Len 3 [0, 1, 2, 3] [0, 1, 2, 4] [0, 2, 3, 6] ! [0, 2, 4, 6] ! [0, 2, 4, 5] ! [1, 2, 3, 6] ! [1, 2, 4, 5] ! [1, 2, 4, 6] ! Len 4 [0, 1, 2, 3, 6] ! [0, 1, 2, 4, 6] ! [0, 1, 2, 4, 5] ! Prime Paths Simple paths Note that paths w/o ! or * cannot be prime paths

Round Trips Round-Trip Path : A prime path that starts and ends at the same node Round-Trip Path : A prime path that starts and ends at the same node 21 These criteria omit nodes and edges that are not in round trips That is, they do not subsume edge-pair, edge, or node coverage

Infeasible Test Requirements An infeasible test requirement cannot be satisfied An infeasible test requirement cannot be satisfied Unreachable statement (dead code) Unreachable statement (dead code) A subpath that can only be executed if a contradiction occurs (X > 0 and X 0 and X < 0) 22 Practical recommendation – Best Effort Touring – Satisfy as many test requirements as possible without sidetrips – Allow sidetrips to try to satisfy unsatisfied test requirements Most test criteria have some infeasible test requirements It is usually undecidable whether all test requirements are feasible When sidetrips are not allowed, many structural criteria have more infeasible test requirements However, always allowing sidetrips weakens the test criteria

Touring, Sidetrips and Detours Prime paths do not have internal loops … test paths might Prime paths do not have internal loops … test paths might 23 Tour : A test path p tours subpath q if q is a subpath of p Tour With Sidetrips : A test path p tours subpath q with sidetrips iff every edge in q is also in p in the same order The tour can include a sidetrip, as long as it comes back to the same node Tour With Detours : A test path p tours subpath q with detours iff every node in q is also in p in the same order

Sidetrips and Detours Example Touring with a sidetrip Touring with a detour abcd Touring without sidetrips or detours

25 Weaknesses of the Purely Structural Coverage /* TC1: x= 1, y= 1; TC2: x=-1, y=-1;*/ void foo(int x, int y) { if ( x > 0) x++; else x--; if(y >0) y++; else y--; assert (x * y >= 0); } x> 0 x++x-- yesno y> 0 y++y-- assert(x*y>=0 ) Purely structural coverage (e.g., branch coverage) alone cannot improve the quality of target software sufficiently -> Advanced semantic testing should be accompanied

Final Remarks Why are coverage criteria important for testing? 2. Why is branch coverage popular in industry? 3. Why is prime path coverage not use in practice? 4. Why is it difficult to reach 100% branch coverage of real-world programs?

Data Flow Coverage 27

Data Flow Criteria Definition : A location where a value for a variable is stored into me mory Definition : A location where a value for a variable is stored into me mory Use : A location where a variable’s value is accessed Use : A location where a variable’s value is accessed def (n) or def (e) : The set of variables that are defined by node n or edge e 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 use (n) or use (e) : The set of variables that are used by node n or edge e 28 Goal: Try to ensure that values are computed and used correctly X = 42 Z = X-8 Z = X*2 Defs: def (0) = {X} def (4) = {Z} def (5) = {Z} Uses: use (4) = {X} use (5) = {X}

DU Pairs and DU Paths DU pair : A pair of locations (l i, l j ) such that a variable v is defined at l i and used at l j DU pair : A pair of locations (l i, l j ) such that a variable v is defined at l i and used at l j Def-clear : A path from l i to l j is def-clear with respect to variable v, if v is not given another value on any of the n odes or edges in the path Def-clear : A path from l i to l j is def-clear with respect to variable v, if v is not given another value on any of the n odes or edges in the path Reach : If there is a def-clear path from l i to l j with respect to v, the def of v at l i reaches the use at l j Reach : If there is a def-clear path from l i to l j with respect to v, the def of v at l i reaches the use at l j du-path : A simple subpath that is def-clear with respect to v from a def of v to a use of v du-path : A simple subpath that is def-clear with respect to v from a def of v to a use of v du (n i, n j, v) – the set of du-paths from n i to n j du (n i, n j, v) – the set of du-paths from n i to n j du (n i, v) – the set of du-paths that start at n i du (n i, v) – the set of du-paths that start at n i 29

Touring DU-Paths A test path p du-tours subpath d with respect to v if p tours d and the subpath taken is def-clear with respect to v A test path p du-tours subpath d with respect to v if p tours d and the subpath taken is def-clear with respect to v Sidetrips can be used, just as with previous touring Sidetrips can be used, just as with previous touring Three criteria Three criteria Use every def Use every def Get to every use Get to every use Follow all du-paths Follow all du-paths 30

Data Flow Test Criteria 31 Then we make sure that every def reaches all possible uses Finally, we cover all the paths between defs and uses First, we make sure every def reaches a use

Data Flow Testing Example X = 42 Z = X-8 Z = X*2 All-defs for X [ 0, 1, 3, 4 ] All-uses for X [ 0, 1, 3, 4 ] [ 0, 1, 3, 5 ] All-du-paths for X [ 0, 1, 3, 4 ] [ 0, 2, 3, 4 ] [ 0, 1, 3, 5 ] [ 0, 2, 3, 5 ]

Graph Coverage Criteria Subsumption 33 Simple Round Trip Coverage SRTC Node Coverage NC Edge Coverage EC Edge-Pair Coverage EPC Prime Path Coverage PPC Complete Path Coverage CPC Complete Round Trip Coverage CRTC All-DU-Paths Coverage ADUP All-uses Coverage AUC All-defs Coverage ADC Assumptions for Data Flow Coverage 1.Every use is preceded by a def 2.Every def reaches at least one use 3.For every node with multiple outgoing edges, at least one variable is used on each out edge, and the same variables are used on each out edge.