0% found this document useful (0 votes)
5 views61 pages

Du Prog Slicing V2

The document discusses data flow testing, a technique used to identify improper use of data values in programming. It outlines the life cycle of variables, the states of data, and various anomalies that can occur, such as defined but unused variables. Additionally, it covers methods like Define/Use Testing and Program Slicing to ensure that every definition of a variable is traced to its uses and vice versa.

Uploaded by

Hamza Main
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views61 pages

Du Prog Slicing V2

The document discusses data flow testing, a technique used to identify improper use of data values in programming. It outlines the life cycle of variables, the states of data, and various anomalies that can occur, such as defined but unused variables. Additionally, it covers methods like Define/Use Testing and Program Slicing to ensure that every definition of a variable is traced to its uses and vice versa.

Uploaded by

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

Data Flow Testing

Code Complete 2nd Edition. Page 510 onwards

2004 A Practitioner's Guide to Software Test Design_Good chapter 11


What is the mistake?
What is the mistake?

The value printed will be whatever value was "left over" in the memory
location to which x has been assigned, not necessarily what the
programmer wanted or expected.
Introduction – Technique
 Variables that contain data values have a
defined life cycle.

 After creation they are defined, they are


used, and they are killed (destroyed).
States of Data
Defined (d) – initialized but not yet used
An occurrence of a variable in the program is a definition of
the variable if a value is bound to the variable at that occurrence.

Used (u) – has been used for some computation as an argument to a


routine or something else
An occurrence of a variable in the program is a use of the
variable if the value of the variable is referred at that
occurrence

Killed (k) - data once defined has been undefined some how,
e.g. if it was a pointer , it may have been freed.
Predicate Uses and
Computation Uses

 A use of a variable is a predicate use (p-use) if the


variable is in a predicate and its value is used to
decide an execution path
Example: if(p>3) then do this;

 A use of a variable is a computation use (c-use)


if the value of the variable is used to compute a
value for defining another variable or as an output
value.
Example: sum = p+1;
Introduction

 Data flow testing is a powerful tool to detect improper use of


data values due to coding errors.

 Data flow testing uses the control flow graph to explore the
unreasonable things that can happen to data (data flow
anomalies).
Data flow anomalies
 Variable that is defined but never used

 Variable that is used but never defined

 Variable that is defined twice before it is


used
Possibilities
Time-sequenced pairs of defined
(d), used (u), and killed (k):

Defined and defined again—not invalid but suspicious.


dd
Probably a programming error.
du Defined and used—perfectly correct. The normal case.
Defined and then killed—not invalid but probably a
dk
programming error.
ud Used and defined—acceptable.
uu Used and used again—acceptable.
uk Used and killed—acceptable.
Time-sequenced pairs of defined
(d), used (u), and killed (k):

Killed and defined—acceptable. A variable is killed and


kd
then redefined.
Killed and used—a serious defect. Using a variable that
ku
does not exist or is undefined is always an error.
kk Killed and killed—probably a programming error.
Find Bugs
Paths for x variable
 First path
1
2

 Second path
1
3
Find Bugs
Paths for y variable
 Path
Find Bugs
Paths for z variable
 Path 1
Find Bugs
Paths for z variable
 Path 2
Issues Identified
Data flow Testing
The data flow testing process is to choose
enough test cases so that:

 Every "define" is traced to each of its "uses"

 Every "use" is traced from its corresponding


"define"
Two mainline forms
 1. Define use Testing

 2. Program slicing
DU Testing
Define/Use Testing
1. Defining Node
 Defining Node (n)
◦ Of variable v -> DEF(v, n)

 Example:
◦ Input statement
◦ Assignment statement
◦ Loop control statement
◦ Procedure calls

 When the code corresponds to such statements


the contents of memory associated with the
variables are changed.
Define/Use Testing
2. Usage Node
 Usage Node (n)
◦ Of variable v -> USE(v, n)

 Example:
◦ Output statement
◦ Conditional statement
◦ Loop control statement
◦ Assignment statements

 When the code corresponds to such statements


the contents of memory associated with the
variables are unchanged.
Define/Use Testing
2. Usage Node
 Usage Node (n)
◦ Of variable v -> USE(v, n)

◦ P-use : if the statement is a predicate statement


◦ C-use : if the statement is a computational
statement.

◦ Out degrees of both the nodes ??


Define/Use Testing
3. du path
 a path w.r.t variable v such that for some v
there are defined and usage nodes
DEF(v,m) & USE (v,n) such that m and n are
initial and final nodes of the path.
Define/Use Testing
4. dc path
 A du path with initial and final nodes
DEF(v,m) & USE (v,n) such that no other
node in the path is a defining node of v.
Definition Clear Paths

 A path (i, ni, n2, …, nm, j) is a definition-clear path for a


variable x from i to j if ni through nm do not contain
a definition of x.
(1, 2, 4)

(1, 2, 3, 5)
Example
1. void f() {
2. float x;
3. float y;
4. x = read();
5. y = read();
6. if (x > 0)
7. x += 10;
8. y = y / x;
9. write(x);
10. write(y);
11. }
Example
Variable define Use
1. void f() { X 4,7 6,7,8,9
2. float x;
3. float y; Y 5,8 8,10

4. x = read();
5. y = read();
6. if (x > 0)
7. x += 10;
8. y = y / x;
9. write(x);
10. write(y);
11. }
Example Variable define Use
X 4,7 6,7,8,9
1. void f() {
2. float x;
3. float y; DU paths for Can also be
4. x = read(); variable X written as
4,5,6 4-6
5. y = read();
4,5,6,7 4-7
6. if (x > 0) 4,5,6,7,8 4-8
7. x += 10; 4,5,6,7,8,9 4-9
8. y = y / x; 7,6 7-6
9. write(x); 7,7 7-7

10. write(y); 7,8 7-8


7,8,9 7-9
11. }
Example Variable define Use
X 4,7 6,8,9
1. void f() {
2. float x;
3. float y; DU paths Can also Feasible
4. x = read(); for be ?
variable written
5. y = read(); X as
6. if (x > 0) 4,5,6 4-6 Yes

7. x += 10; 4,5,6,7,8 4-8 Yes


4,5,6,7,8,9 4-9 Yes
8. y = y / x;
7,6 7-6 No
9. write(x); 7,8 7-8 Yes
10. write(y); 7,8,9 7-9 Yes
11. } 4,5,6,7 4-7 Yes
7,7 7-7 ?
Example Variable define Use
X 4,7 6,8,9
1. void f() {
2. float x;
DU Can Feasibl DC or
3. float y; paths also be e? not ?
4. x = read(); for written
variabl as
5. y = read(); e X
6. if (x > 0) 4,5,6 4-6 Yes DC
7. x += 10;
4,5,6,7,8 4-8 Yes Not DC
8. y = y / x;
9. write(x); 4,5,6,7,8 4-9 Yes Not DC
,9
10. write(y);
7,6 7-6 No -
11. } 7,8 7-8 Yes DC
7,8,9 7-9 Yes DC
Define/Use Nodes for
Variables
Define/Use Nodes for
Variables
Some define/use paths
 Lock price
 Stock price
 Barrel price
 Stocks
 Total stocks
 Locks
 Sales

 Find paths?
 Tell whether they are definition clear or not ?
Du path for locks

 Path 1 : 13,14
 Path 2: 13,14,15,16
 Path 3: 19,20,14
 Path 4: 19, 20, 14, 15, 16

 What test cases are covered regarding loops?


◦ Bypass the loop
◦ Begin the loop
◦ Repeat the loop
◦ Exit the loop

 Are these paths definition clear?


Du Path for Total Locks
 10-16
 10-21
 10-24
 16-16
 16-21
 16-24

 See if some path is overlapping we can


ignore them.
Du path for sales
 27-28
 27-29
 27-33

Overlapping ?? If we cover the 3rd path first


two are covered.
Some
define/us
e paths
Define/
use
paths for
Commiss
ion
Advantages

 A variable that is declared but never used


within the program.

 A variable that is used but never declared.

 A variable that is defined multiple times


before it is used.

 De-allocating a variable before it is used.


Program slicing
Program Slicing
 a program slice is a set of program
statements that contributes to, or affects
the value of, a variable at some point in a
program

 The idea of program slicing is to separate a


program into components that have some
useful (functional) meaning.

 program slice is executable


Guidelines
 All statements where variables are defined and
redefined should be considered.
 All statements where variables are receiving
values externally should be considered.
 All statements where output of a variable is
printed should be considered.
 All the statements where relevant output is
printed should be considered.
 The status of all variables may be considered at
last statement of the program.
slicing
 Consider the following portion of a
program:
 S(c,5) =
1.a=3 ;  S(C,3)=
2.b=6 ;
3.c=b2 ;
4.d=a2+b2 ;
5.c=a+b ;
slicing
 Consider the following portion of a
program:
 S(c,5) = 1,2,5
1.a=3 ;  S(C,3)= 2,3
2.b=6 ;
3.c=b2 ;
4.d=a2+b2 ;
5.c=a+b ;
slicing
 Consider the following program. Create slices based on
slicing criterion.
1. void main()
2. {
3. int a,b,c,d,e;
4. printf(“Enter the values of a,b, and c\n”);
5. scanf(“%d %d %d”,&a,&b,&c);
6. d=a+b;
7. e=b+c;
8. printf(“%d”,d);
9. printf(“%d”,e);
10.}
 1 void main()
 2{
 3 float A,B,C;
 4 clrscr();
 5 printf("Enter number 1:\n");
 6 scanf("%f", &A);
 7 printf("Enter number 2:\n");
 8 scanf("%f", &B);
 9 printf("Enter number 3:\n");
 10 scanf("%f", &C);
 11 if(A>B) {
 12 if(A>C) {
 13 printf("The largest number is: %f\n",A);
 14 }
 15 else {
 16 printf("The largest number is: %f\n",C);
 17 }
 18 }
 19 else {
 20 if(C>B) {
 21 printf("The largest number is: %f\n",C);
 22 }
 23 else {
 24 printf("The largest number is: %f\n",B);
 25 }
 26 }
 27 getch();
 1. S(A,6)=(1,2,3,4,5,6,28)
 2. S(A, 13)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)
 3. S(A, 28)=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,27,28)
 4. S(B, 8)=(1,2,3,4,7,8,28)
 5. S(B,
24)=(1,2,3,4,5,6,7,8,9,10,11,19,20,23,24,25,26,27,28)
 6. S(B,
28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,23,24,25,26,27,28)
 7. S(C, 10)=(1,2,3,4,9,10,28)
 8. S(C, 16)=(1,2,3,4,5,6,7,8,9,10,11,12,15,16,17,18,27,28)
 9. S(C, 21)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)
 10. S(C, 28)=(1,2,3,4,5,6,7,8,9,10,11,19,20,21,22,26,27,28)
Progra
m
Slicing

You might also like