Upload
shonda-carpenter
View
214
Download
0
Tags:
Embed Size (px)
Citation preview
ECE453/SE465 Prof. Alencar University of Waterloo 1
Data Flow TestingSlice-Based Testing
Winter 2007Based on the tutorials by Prof. Kontogiannis, Winter 2006
Presented by Akhilesh Kumar, Aleh [email protected], [email protected]
ECE453/SE465 2University of Waterloo
AgendaAgenda
Slice-Based Testing DefinitionsSlice-Based Testing Definitions Slice-Based Testing ExamplesSlice-Based Testing Examples
ECE453/SE465 3University of Waterloo
AgendaAgenda
Slice-Based Testing DefinitionsSlice-Based Testing Definitions Slice-Based Testing ExamplesSlice-Based Testing Examples
ECE453/SE465 4University of Waterloo
Slice-Based Testing DefinitionsSlice-Based Testing Definitions
Given a program P, and a program graph G(P) Given a program P, and a program graph G(P) in which statements and statement fragments in which statements and statement fragments are numbered, and a set V of variables in P, the are numbered, and a set V of variables in P, the slice on the variable set V at statement slice on the variable set V at statement fragment nfragment n, written S(V,n), is the set node , written S(V,n), is the set node numbers of all statement fragments in P prior to numbers of all statement fragments in P prior to n that contribute to the values of variables in V n that contribute to the values of variables in V at statement fragment nat statement fragment n
The idea of slices is to separate a program into The idea of slices is to separate a program into components that have some useful meaningcomponents that have some useful meaning
ECE453/SE465 5University of Waterloo
Slice-Based Testing DefinitionsSlice-Based Testing Definitions
We will include CONST declarations in slicesWe will include CONST declarations in slices Five forms of usage nodesFive forms of usage nodes
P-use (used in a predicate (decision))P-use (used in a predicate (decision)) C-use (used in computation)C-use (used in computation) O-use (used for output, e.g. writeln())O-use (used for output, e.g. writeln()) L-use (used for location, e.g. pointers)L-use (used for location, e.g. pointers) I-use (iteration, e.g. internal counters)I-use (iteration, e.g. internal counters)
Two forms of definition nodesTwo forms of definition nodes I-def (defined by input, e.g. readln())I-def (defined by input, e.g. readln()) A-def (defined by assignment)A-def (defined by assignment)
For now, we presume that the slice S(V,n) is a slice on For now, we presume that the slice S(V,n) is a slice on one variable, that is, the set V consists of a single one variable, that is, the set V consists of a single variable, vvariable, v
ECE453/SE465 6University of Waterloo
Slice-Based Testing DefinitionsSlice-Based Testing Definitions
If statement fragment n (in S(V,n)) is a defining If statement fragment n (in S(V,n)) is a defining node for v, then n is included in the slicenode for v, then n is included in the slice
If statement fragment n (in S(V,n)) is a usage If statement fragment n (in S(V,n)) is a usage node for v, then n is not included in the slicenode for v, then n is not included in the slice
P-uses and C-uses of other variables are P-uses and C-uses of other variables are included to the extent that their execution affects included to the extent that their execution affects the value of the variable vthe value of the variable v
O-use, L-use, and I-use nodes O-use, L-use, and I-use nodes are excludedare excluded from slicesfrom slices
Consider making slices compilableConsider making slices compilable
ECE453/SE465 7University of Waterloo
AgendaAgenda
Slice-Based Testing DefinitionsSlice-Based Testing Definitions Slice-Based Testing ExamplesSlice-Based Testing Examples
ECE453/SE465 8University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
Find the following Find the following program slicesprogram slices
S(commission,48)S(commission,48) S(commission,40)S(commission,40) S(commission,39)S(commission,39) S(commission,38)S(commission,38) S(sales,35)S(sales,35) S(num_locks,34)S(num_locks,34) S(num_stocks,34)S(num_stocks,34) S(num_barrels,34)S(num_barrels,34)
ECE453/SE465 9University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
S(commission,48)S(commission,48) {1-5,8-11,13,14, {1-5,8-11,13,14,
19-30,36,47,48,53}19-30,36,47,48,53} S(commission,40), S(commission,40),
S(commission,39), S(commission,39), S(commission,38)S(commission,38) {{ØØ}}
S(sales,35)S(sales,35) {{ØØ}}
ECE453/SE465 10University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
S(num_locks,34)S(num_locks,34) {1,8,9,10,13,14,19, {1,8,9,10,13,14,19,
22,23,24,26,29,30, 22,23,24,26,29,30, 53}53}
ECE453/SE465 11University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
S(num_stocks,34)S(num_stocks,34) {1,8,9,10,13,14,20, {1,8,9,10,13,14,20,
22-25,27,29,30,53}22-25,27,29,30,53}
ECE453/SE465 12University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
S(num_barrels,34)S(num_barrels,34) {1,8,9,10,13,14, 21-{1,8,9,10,13,14, 21-
25,28,29,30,53}25,28,29,30,53}
ECE453/SE465 13University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
Find the program slice on Find the program slice on FinalUse(low). Use the FinalUse(low). Use the Program Dependency Program Dependency Graph approachGraph approach
int binSearch(int x, int v[], int n) { {1}int binSearch(int x, int v[], int n) { {1}
int low = 0;int low = 0; {2} {2}
int high = n – 1;int high = n – 1; {3} {3}
int mid; {4}int mid; {4}
while (low <= high) { {5}while (low <= high) { {5}
mid = (low + high) / 2; {6}mid = (low + high) / 2; {6}
if (x < v[mid])if (x < v[mid]) {7} {7}
high = mid – 1; {8}high = mid – 1; {8}
else if (x > v[mid])else if (x > v[mid]) {9} {9}
low = mid + 1; {10}low = mid + 1; {10}
elseelse {11} {11}
return mid; {12}return mid; {12}
} {13}} {13}
return -1; {14}return -1; {14}
} {15}} {15}
ECE453/SE465 14University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
Program Dependency GraphProgram Dependency Graph
ECE453/SE465 15University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
Slice based on the criterion FinalUse(low)Slice based on the criterion FinalUse(low)
ECE453/SE465 16University of Waterloo
Slice-Based Testing ExamplesSlice-Based Testing Examples
int binSearch(int x, int v[], int n) { {1}int binSearch(int x, int v[], int n) { {1}
int low = 0;int low = 0; {2} {2}
int high = n – 1;int high = n – 1; {3} {3}
int mid; {4}int mid; {4}
while (low <= high) { {5}while (low <= high) { {5}
mid = (low + high) / 2; {6}mid = (low + high) / 2; {6}
if (x < v[mid])if (x < v[mid]) {7} {7}
high = mid – 1; {8}high = mid – 1; {8}
else if (x > v[mid])else if (x > v[mid]) {9} {9}
low = mid + 1; {10}low = mid + 1; {10}
elseelse {11} {11}
return mid; {12}return mid; {12}
} {13}} {13}
return -1; {14}return -1; {14}
} {15}} {15}
int binSearch(int x, int v[], int n) { {1}int binSearch(int x, int v[], int n) { {1}
int low = 0;int low = 0; {2} {2}
int high = n – 1;int high = n – 1; {3} {3}
int mid; {4}int mid; {4}
while (low <= high) { {5}while (low <= high) { {5}
mid = (low + high) / 2; {6}mid = (low + high) / 2; {6}
if (x < v[mid])if (x < v[mid]) {7} {7}
high = mid – 1; {8}high = mid – 1; {8}
else if (x > v[mid])else if (x > v[mid]) {9} {9}
low = mid + 1; {10}low = mid + 1; {10}
} {13}} {13}
} {15}} {15}
→→Slice on FinalUse(low)Slice on FinalUse(low)
ECE453/SE465 17University of Waterloo
AgendaAgenda
Slice-Based Testing DefinitionsSlice-Based Testing Definitions Slice-Based Testing ExamplesSlice-Based Testing Examples
ECE453/SE465 18University of Waterloo
ReferencesReferences
Software Testing A Craftsman's Approach Software Testing A Craftsman's Approach 2nd edition, Paul C. Jorgensen, CRC 2nd edition, Paul C. Jorgensen, CRC Press (Chapter 10 (10.2))Press (Chapter 10 (10.2))