0% found this document useful (0 votes)
82 views

Data Flow Testing Slice-Based Testing: Winter 2006

This document discusses slice-based testing and provides examples. It begins with definitions of program slicing and different types of nodes. It then gives examples of slices for different variables in a sample program, including presenting the slices as code snippets. Finally, it demonstrates finding a slice using the program dependency graph approach and presents the slice as code.

Uploaded by

Nishanth SY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Data Flow Testing Slice-Based Testing: Winter 2006

This document discusses slice-based testing and provides examples. It begins with definitions of program slicing and different types of nodes. It then gives examples of slices for different variables in a sample program, including presenting the slices as code snippets. Finally, it demonstrates finding a slice using the program dependency graph approach and presents the slice as code.

Uploaded by

Nishanth SY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Data Flow Testing

Slice-Based Testing
Winter 2006

Presented by Nikos Giannopoulos


[email protected]

ECE 453, Prof. Kontogiannis University of Waterloo 1


Agenda
 Slice-Based Testing Definitions
 Slice-Based Testing Examples

ECE 453, Prof. Kontogiannis University of Waterloo 2


Agenda
 Slice-Based Testing Definitions
 Slice-Based Testing Examples

ECE 453, Prof. Kontogiannis University of Waterloo 3


Slice-Based Testing Definitions

 Given a program P, and a program graph G(P)


in which statements and statement fragments
are numbered, and a set V of variables in P, the
slice on the variable set V at statement
fragment n, written S(V,n), is the set node
numbers of all statement fragments in P prior to
n that contribute to the values of variables in V
at statement fragment n
 The idea of slices is to separate a program into
components that have some useful meaning

ECE 453, Prof. Kontogiannis University of Waterloo 4


Slice-Based Testing Definitions
 We will include CONST declarations in slices
 Five forms of usage nodes
 P-use (used in a predicate (decision))
 C-use (used in computation)
 O-use (used for output, e.g. writeln())
 L-use (used for location, e.g. pointers)
 I-use (iteration, e.g. internal counters)
 Two forms of definition nodes
 I-def (defined by input, e.g. readln())
 A-def (defined by assignment)
 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
variable, v

ECE 453, Prof. Kontogiannis University of Waterloo 5


Slice-Based Testing Definitions

 If statement fragment n (in S(V,n)) is a defining


node for v, then n is included in the slice
 If statement fragment n (in S(V,n)) is a usage
node for v, then n is not included in the slice
 P-uses and C-uses of other variables are
included to the extent that their execution affects
the value of the variable v
 O-use, L-use, and I-use nodes are excluded
from slices
 Consider making slices compilable

ECE 453, Prof. Kontogiannis University of Waterloo 6


Agenda
 Slice-Based Testing Definitions
 Slice-Based Testing Examples

ECE 453, Prof. Kontogiannis University of Waterloo 7


Slice-Based Testing Examples
 Find the following
program slices
 S(commission,48)
 S(commission,40)
 S(commission,39)
 S(commission,38)
 S(sales,35)
 S(num_locks,34)
 S(num_stocks,34)
 S(num_barrels,34)

ECE 453, Prof. Kontogiannis University of Waterloo 8


Slice-Based Testing Examples

 S(commission,48)
 {1-5,8-11,13,14,
19-30,36,47,48,53}
 S(commission,40),
S(commission,39),
S(commission,38)
 {Ø}
 S(sales,35)
 {Ø}

ECE 453, Prof. Kontogiannis University of Waterloo 9


Slice-Based Testing Examples

 S(num_locks,34)
 {1,8,9,10,13,14,19,
22,23,24,26,29,30,
53}

ECE 453, Prof. Kontogiannis University of Waterloo 10


Slice-Based Testing Examples

 S(num_stocks,34)
 {1,8,9,10,13,14,20,
22-25,27,29,30,53}

ECE 453, Prof. Kontogiannis University of Waterloo 11


Slice-Based Testing Examples

 S(num_barrels,34)
 {1,8,9,10,13,14,
21-25,28,29,30,53}

ECE 453, Prof. Kontogiannis University of Waterloo 12


Slice-Based Testing Examples

 Find the program slice on int binSearch(int x, int v[], int n) {


int low = 0;
{1}
{2}

FinalUse(low). Use the int high = n – 1;


int mid;
{3}
{4}

Program Dependency while (low <= high) {


mid = (low + high) / 2;
{5}
{6}
if (x < v[mid]) {7}
Graph approach high = mid – 1; {8}
else if (x > v[mid]) {9}
low = mid + 1; {10}
else {11}
return mid; {12}
} {13}
return -1; {14}
} {15}

ECE 453, Prof. Kontogiannis University of Waterloo 13


Slice-Based Testing Examples

Program Dependency Graph

ECE 453, Prof. Kontogiannis University of Waterloo 14


Slice-Based Testing Examples

Slice based on the criterion FinalUse(low)

ECE 453, Prof. Kontogiannis University of Waterloo 15


Slice-Based Testing Examples

int binSearch(int x, int v[], int n) { {1}


int low = 0; {2} int binSearch(int x, int v[], int n) { {1}
int high = n – 1; {3} int low = 0; {2}
int mid; {4} int high = n – 1; {3}
while (low <= high) { {5} int mid; {4}
mid = (low + high) / 2; {6} while (low <= high) { {5}
if (x < v[mid])
high = mid – 1;
else if (x > v[mid])
{7}
{8}
{9}
→ mid = (low + high) / 2;
if (x < v[mid])
{6}
{7}
high = mid – 1; {8}
low = mid + 1; {10} Slice on FinalUse(low) else if (x > v[mid]) {9}
else {11} low = mid + 1; {10}
return mid; {12} } {13}
} {13} } {15}
return -1; {14}
} {15}

ECE 453, Prof. Kontogiannis University of Waterloo 16


Agenda
 Slice-Based Testing Definitions
 Slice-Based Testing Examples

ECE 453, Prof. Kontogiannis University of Waterloo 17


References

 Software Testing A Craftsman's Approach


2nd edition, Paul C. Jorgensen, CRC
Press (Chapter 10 (10.2))

ECE 453, Prof. Kontogiannis University of Waterloo 18

You might also like