introduction to software testing chapter 8.1 building testing tools –instrumentation paul ammann...
TRANSCRIPT
![Page 1: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/1.jpg)
Introduction to Software TestingChapter 8.1
Building Testing Tools –Instrumentation
Paul Ammann & Jeff Offutt
http://www.cs.gmu.edu/~offutt/softwaretest/
![Page 2: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/2.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 2
Chapter 8 Outline
1. Instrumentation for Graph and Logical Expression Criteria
2. Building Mutation Testing Tools
Instrumentation for Graph and Logical Expression Criteria
![Page 3: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/3.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 3
Categories of Test Tools• Research
• Private non-commercial
• Commercial
Advanced techniquesGeneratorsVery powerfulOften code-basedUsually incompleteGeneral purpose
Moderate techniquesAcceptorsMostly completeSome code-basedOften special purpose
Test managementSimple coverageMetricsCode independent
![Page 4: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/4.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 4
Types of Test Tools
1. Coverage analyzers (Acceptors)– What coverage ? (most common is
node)
– What level? (sometimes object code)
2. Flow graph generators
3. Metrics
4. Instrumentation support
5. Test execution automation– Runs scripts and reports results
– JUnit, HttpUnit, …
6. Capture / replay– Useful for GUIs
7. Stubs and Drivers
8. Test data generators– Graph path – based
– Data flow
– Logic based
– Functional
– Mutation
– Random
– Only random test data generators exist
![Page 5: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/5.jpg)
Tools Instrumentation
The key technology behind many test tools is “instrumentation”
![Page 6: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/6.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 6
Tools Instrumentation• Coverage analysis is measured with instrumentation• Instrument : One or more statements inserted into the program
to monitor some aspect of the program– Must not affect the behavior
– May affect timing
– Source level or object code level
public int min (int A, B){ int m = A; if (A > B) { m = B; } return (m);}
Mark: “if body is reached”
![Page 7: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/7.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 7
Instrumenting for Statement Coverage
1. Each node is given a unique id #– Node # or statement #
2. Create an array indexed by id #s – nodeCover [ ]
3. Insert an instrument at each node– nodeCover [ i ] ++;
4. Save nodeCover [ ] after each execution– Must accumulate results across multiple test cases
![Page 8: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/8.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 8
Statement Coverage Example
6
32
1
754
8
9
10
int nodeCover[] = {0,0,0,0,0,0,0,0,0,0}
nc [3]++nc [2]++
nc [5]++nc [4]++
nc [6]++nc [9]++
nc [7]++
nc [10]++
nc [8]++
Read (nodeCover [])nodeCover [1] ++
After running a sequence of After running a sequence of tests, any node for which tests, any node for which nodeCover[node] == 0nodeCover[node] == 0 has has notnot been covered. been covered.
![Page 9: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/9.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 9
Edge Coverage Instrumentation
6
32
1
754
8
9
10
int edgeCover[] = {0,0,0,0,0,0,0,0,0,0,0,0,0}
ec [2]++ec [1]++
Read (edgeCover [])
For each edge For each edge ee, put , put edgeCover[e]++edgeCover[e]++ on the edge. on the edge.
If If edgeCover[e] == 0edgeCover[e] == 0, , ee has has notnot been covered. been covered.
Note that the arrays could Note that the arrays could be booleanbe boolean
ec [7]++ec [8]++ ec [10]++
ec [9]++
ec [11]++
ec [12]++ ec [13]++
ec [3]++ ec [4]++ ec [6]++ec [5]++
![Page 10: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/10.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 10
CACC_Mark_1 (A, B){ if (!A) { // Don’t allow short circuit if (B) CACCCover[1]++; } else if (A) { if (B) CACCCover [2]++; else CACCCover[3]++ }}
CACC Coverage Instrumentation
6
32
1
54
if (A && B)
if (C && (D || E))
CACC_Mark_1 (A, B)
CACC_Mark_2 (C, D, E)
A && B CACCCover [ ]A && B CACCCover [ ]F t 1F t 1T t 2T t 2t F 3t F 3t T t T
![Page 11: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/11.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 11
CACC Coverage Instrumentation (2)CACC_Mark_2 (C, D, E){ if (! C) { if (D || E) CACCCover [4]++; } else if (! D) { if (! E) CACCCover [6]++; else { CACCCover [5]++; CACCCover [8]++; } } else // C and D if (! E) { CACCCover [5]++; CACCCover [7]++; } else CACCCover [5]++;}
C && (D || E) CC [ ]C && (D || E) CC [ ]F 4F 4T 5T 5
t F f 6t F f 6t T f 7t T f 7t f Ft f Ft f T 8t f T 8
t t t f f t
![Page 12: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/12.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 12
All-Uses Coverage Instrumentation
6
32
1
54
def (x, y)
use (x)use (x)
def (y)
use (y)
useCover [5, x, defCover[x]] ++
useCover [4, x, defCover[x]] ++
useCover [6, y, defCover[y]] ++
defCover [x] = 1defCover [y] = 1
defCover [y] = 2
For each variable, keep For each variable, keep track of its current track of its current defdef location.location.
At each At each useuse, increment a , increment a countercounter for the def that for the def that reached it.reached it.
![Page 13: Introduction to Software Testing Chapter 8.1 Building Testing Tools –Instrumentation Paul Ammann & Jeff Offutt offutt/softwaretest](https://reader035.vdocument.in/reader035/viewer/2022080905/56649e455503460f94b3a3c0/html5/thumbnails/13.jpg)
Introduction to Software Testing (Ch 8.1) © Ammann & Offutt 13
Instrumentation Summary• Instrumentation can be added in multiple copies of the program
– Source code
– Java byte code (or other intermediate code)
– Executable
• Instrumentation must not change or delete functionality– Only add new functionality
• Instrumentation may affect timing behavior• Requires the program to be parsed
– Once parsed, inserting instruments is straightforward
• Most challenging part is the user interface– Present reports as dumps of instrument arrays ?
– Present tables ?
– Program source with colored annotations ?
– Graph of program with colored annotations ?