Software Verification Graph Model. 2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.

Slides:



Advertisements
Similar presentations
Paul Ammann & Jeff Offutt
Advertisements

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
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.
Dependable Software Systems
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 5 Data Flow Testing
Topics in Software Dynamic White-box Testing Part 1: Control-flow Testing [Reading assignment: Chapter 7, pp plus many things in slides that are.
Topics in Software Dynamic White-box Testing: Data-flow Testing
© SERG Dependable Software Systems (Control-Flow Testing) Dependable Software Systems Topics in Control-Flow Testing Material drawn from [Beizer, Mancoridis]
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
Software Testing Mistake in coding is called error ,
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
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Presented By Dr. Shazzad Hosain Asst. Prof., EECS, NSU
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.
Overview Graph Coverage Criteria ( Introduction to Software Testing Chapter 2.1, 2.2) Paul Ammann & Jeff Offutt.
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
1 Graph Coverage (4). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section
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
Paul Ammann & Jeff Offutt
Introduction to Software Testing (2nd edition) Chapter 7.4 Graph Coverage for Design Elements 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
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.
Software Dynamic White-box Testing Part 2: Data-flow Testing Lecture 7 Prof. Mostafa Abdel Aziem Mostafa.
Chapter 2 : Graph Coverage (part 2)
Software Dynamic White-box Testing Lecture 6 Part 1: Control-flow Testing.
Paul Ammann & Jeff Offutt
Lab 7 Control-Flow Testing
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Software Testing and Maintenance 1
Paul Ammann & Jeff Offutt
Introduction to Software Testing Syntactic Logic Coverage Criteria
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Software Verification
Graph: Data Flow Criteria CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The.
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Graph: Data Flow Coverage Criteria 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
Paul Ammann & Jeff Offutt
Graph Coverage Criteria
Paul Ammann & Jeff Offutt
Tata Consultancy Services
COSC 4506/ITEC 3506 Software Engineering
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Presentation transcript:

Software Verification Graph Model

2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source Applied to DNF Specs FSMs Source Input Models Integ Source

3 Definition of a Graph A set N of nodes, N 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 E of edges, each edge from one node to another –( 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

5 Paths in Graphs Path : A sequence of nodes – [n 1, n 2, …, n M ] –Each pair of nodes is an edge Length : The number of edges –A single node is a path of length 0 Subpath : A subsequence of nodes in p is a subpath of p Reach (n) : Subgraph that can be reached from n A Few 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}

6 Control Flow Graphs A CFG models all executions of a method by describing control structures Nodes : Statements or sequences of statements (basic blocks) Edges : Transfers of control Basic Block : A sequence of statements such that if the first statement is executed, all statements will be (no branches) CFGs are sometimes annotated with extra information –branch predicates –defs –uses Rules for translating statements into graphs …

7 CFG : The if Statement 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; x = x + 1; } x >= y x < y y = 0 x = x + 1

8 CFG : The if-return Statement if (x < y) { return; } print (x); return; x >= y x < y return print (x) return No edge from node 2 to 3. The return nodes must be distinct.

9 Loops Loops require “extra” nodes to be added Nodes that do not represent statements or basic blocks

10 CFG : while and for Loops x = 0; while (x < y) { y = f (x, y); x = x + 1; } 1 x = 0 43 y =f(x,y) x = x + 1 x >= yx < y for (x = 0; x < y; x++) { y = f (x, y); } 1 x = x x >= yx < y y = f (x, y) 4 2 dummy node x = 0 implicitly initializes loop implicitly increments loop

11 CFG : do Loop, break and continue x = 0; do { y = f (x, y); x = x + 1; } while (x < y); println (y) 1 x = x >= y x < y y = f (x, y) x = x+1 1 x = 0 83 x = x + 1 break y < y =f(x,y) y == 0 y = y*2 continue x = 0; while (x < y) { y = f (x, y); if (y == 0) { break; } else if y < 0) { y = y*2; continue; } x = x + 1; } print (y);

12 CFG : The Case (switch) Structure read ( c) ; switch ( c ) { case ‘N’: y = 25; break; case ‘Y’: y = 50; break; default: y = 0; break; } print (y); 5 1 read ( c ); c == ‘N’ y = 0; break; 243 c == ‘Y’ default y = 50; break; y = 25; break; print (y);

Exponentiation Algorithm scanf(“%d %d”,&x, &y); 2 if (y < 0) pow = -y; else pow = y; 3 z = 1.0; 4 while (pow != 0) { z = z * x; pow = pow - 1; 5 } 6 if (y < 0) z = 1.0 / z; 7 printf (“%f”,z);

Bubble Sort Algorithm for (j=1; j<N; j++) { last = N - j + 1; 2 for (k=1; k<last; k++) { 3 if (list[k] > list[k+1]) { temp = list[k]; list[k] = list[k+1]; list[k+1] = temp; 4 } 5 } 6 } 7 print(“Done\n”);

© Ammann & Offutt Example Control Flow – Stats public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) { sum += numbers [ i ]; } med = numbers [ length / 2]; mean = sum / (double) length; varsum = 0; for (int i = 0; i < length; i++) { varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); } var = varsum / ( length ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); }

© Ammann & Offutt Control Flow Graph for Stats public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i < length; i++) { sum += numbers [ i ]; } med = numbers [ length / 2]; mean = sum / (double) length; varsum = 0; for (int i = 0; i < length; i++) { varsum = varsum + ((numbers [ I ] - mean) * (numbers [ I ] - mean)); } var = varsum / ( length ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); } i = 0 i >= length i < length i++ i >= length i < length i = 0 i

17 Test Paths and SESEs Test Path : A path that starts at an initial node and ends at a final node Test paths represent execution of test cases –Some test paths can be executed by many 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 –Single-entry, single-exit –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 ]

18 Tests and Test Paths 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

19 Visiting and Touring 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 Tour : A test path p tours subpath q if q is a subpath of p 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]

20 Data Flow Criteria Definition (def) : A location where a value for a variable is stored into memory 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 use (n) or use (e) : The set of variables that are used by node n or edge e 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}

Data Flow Coverage for Source def : a location where a value is stored into memory –x appears on the left side of an assignment ( x = 44 ;) –x is an actual parameter in a call and the method changes its value –x is a formal parameter of a method (implicit def when method starts) –x is an input to a program use : a location where variable’s value is accessed –x appears on the right side of an assignment –x appears in a conditional test –x is an actual parameter to a method –x is an output of the program –x is an output of a method in a return statement If a def and a use appear on the same node, then it is only a DU-pair if the def occurs after the use and the node is in a loop

22 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 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 nodes 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 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, v) – the set of du-paths that start at n i

Def-Use Pairs... if (...) { x =... ;... } y =... + x +... ; x =... if (...) {... y =... + x Definition: x gets a value Use: the value of x is extracted Def-Use path

Definition-Clear or Killing x =... // A: def x q =... x = y; // B: kill x, def x z =... y = f(x); // C: use x x = Definition: x gets a value Use: the value of x is extracted A x = y Definition: x gets a new value, old value is killed... y = f(x) B C Path B..C is definition-clear Path A..C is not definition- clear

25 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 Three criteria –Use every def –Get to every use –Follow all du-paths

26 Data Flow Test Criteria All-defs coverage (ADC) : For each set of du-paths S = du (n, v), TR contains at least one path d in S. All-uses coverage (AUC) : For each set of du-paths to uses S = du (n i, n j, v), TR contains at least one path d in S. All-du-paths coverage (ADUPC) : For each set S = du (ni, nj, v), TR contains every path d in S. 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

27 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 ]

Example: Definition and Uses 1. read (x, y); 2. z = x + 2; 3. if (z < y) 4 w = x + 1; else 5. y = y + 1; 6. print (x, y, w, z); What are the definitions and uses for the program below?

Example: Definition and Uses 1. read (x, y); 2. z = x + 2; 3. if (z < y) 4 w = x + 1; else 5. y = y + 1; 6. print (x, y, w, z); DefUse x, y zx z, y wx yy x, y, w, z

Example Data Flow – Stats public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0.0; for (int i = 0; i < length; i++) { sum += numbers [ i ]; } med = numbers [ length / 2 ]; mean = sum / (double) length; varsum = 0.o; for (int i = 0; i < length; i++) { varsum = varsum + ((numbers [ i ] - mean) * (numbers [ i ] - mean)); } var = varsum / ( length - 1 ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); }

public static void computeStats (int [ ] numbers) { int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0.0; for (int i = 0; i < length; i++) { sum += numbers [ i ]; } med = numbers [ length / 2 ]; mean = sum / (double) length; varsum = 0.o; for (int i = 0; i < length; i++) { varsum = varsum + ((numbers [ i ] - mean) * (numbers [ i ] - mean)); } var = varsum / ( length - 1 ); sd = Math.sqrt ( var ); System.out.println ("length: " + length); System.out.println ("mean: " + mean); System.out.println ("median: " + med); System.out.println ("variance: " + var); System.out.println ("standard deviation: " + sd); } Control Flow Graph for Stats ( numbers ) sum = 0 length = numbers.length i = 0 i >= length i < length sum += numbers [ i ] i++ med = numbers [ length / 2 ] mean = sum / (double) length varsum = 0 i = 0 i >= length i < length varsum = … i++ var = varsum / ( length ) sd = Math.sqrt ( var ) print (length, mean, med, var, sd)

CFG for Stats – With Defs & Uses def (1) = { numbers, sum, length } def (2) = { i } def (5) = { med, mean, varsum, i } use (5) = { numbers, length, sum } def (8) = { var, sd } use (8) = { varsum, length, mean, med, var, sd } use (3, 5) = { i, length } use (3, 4) = { i, length } def (4) = { sum, i } use (4) = { sum, numbers, i } use (6, 8) = { i, length } use (6, 7) = { i, length } def (7) = { varsum, i } use (7) = { varsum, numbers, i, mean }

Defs and Uses Tables for Stats NodeDefUse 1{ numbers, sum, length } { numbers } 2{ i } 3 4{ sum, i }{ numbers, i, sum } 5{ med, mean, varsum, i } { numbers, length, sum } 6 7{ varsum, i }{ varsum, numbers, i, mean } 8{ var, sd }{ varsum, length, var, mean, med, var, sd } EdgeUse (1, 2) (2, 3) (3, 4){ i, length } (4, 3) (3, 5){ i, length } (5, 6) (6, 7){ i, length } (7, 6) (6, 8){ i, length }

DU Pairs for Stats variableDU Pairs numbers(1, 4) (1, 5) (1, 7) length(1, 5) (1, 8) (1, (3,4)) (1, (3,5)) (1, (6,7)) (1, (6,8)) med(5, 8) var(8, 8) sd(8, 8) mean(5, 7) (5, 8) sum(1, 4) (1, 5) (4, 4) (4, 5) varsum(5, 7) (5, 8) (7, 7) (7, 8) i(2, 4) (2, (3,4)) (2, (3,5)) (2, 7) (2, (6,7)) (2, (6,8)) (4, 4) (4, (3,4)) (4, (3,5)) (4, 7) (4, (6,7)) (4, (6,8)) (5, 7) (5, (6,7)) (5, (6,8)) (7, 7) (7, (6,7)) (7, (6,8)) No def-clear path … different scope for i No path through graph from nodes 5 and 7 to 4 or 3 defs come before uses, do not count as DU pairs defs after use in loop, these are valid DU pairs

DU Paths for Stats variableDU PairsDU Paths numbers(1, 4) (1, 5) (1, 7) [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 7 ] length(1, 5) (1, 8) (1, (3,4)) (1, (3,5)) (1, (6,7)) (1, (6,8)) [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 8 ] [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 7 ] [ 1, 2, 3, 5, 6, 8 ] med(5, 8)[ 5, 6, 8 ] var(8, 8)No path needed sd(8, 8)No path needed sum(1, 4) (1, 5) (4, 4) (4, 5) [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 4, 3, 4 ] [ 4, 3, 5 ] variableDU PairsDU Paths mean(5, 7) (5, 8) [ 5, 6, 7 ] [ 5, 6, 8 ] varsum(5, 7) (5, 8) (7, 7) (7, 8) [ 5, 6, 7 ] [ 5, 6, 8 ] [ 7, 6, 7 ] [ 7, 6, 8 ] i(2, 4) (2, (3,4)) (2, (3,5)) (4, 4) (4, (3,4)) (4, (3,5)) (5, 7) (5, (6,7)) (5, (6,8)) (7, 7) (7, (6,7)) (7, (6,8)) [ 2, 3, 4 ] [ 2, 3, 5 ] [ 4, 3, 4 ] [ 4, 3, 5 ] [ 5, 6, 7 ] [ 5, 6, 8 ] [ 7, 6, 7 ] [ 7, 6, 8 ]

DU Paths for Stats – No Duplicates There are 38 DU paths for Stats, but only 12 unique [ 1, 2, 3, 4 ] [ 1, 2, 3, 5 ] [ 1, 2, 3, 5, 6, 7 ] [ 1, 2, 3, 5, 6, 8 ] [ 2, 3, 4 ] [ 2, 3, 5 ] [ 4, 3, 4 ] [ 4, 3, 5 ] [ 5, 6, 7 ] [ 5, 6, 8 ] [ 7, 6, 7 ] [ 7, 6, 8 ] 4 expect a loop not to be “entered” 2 require at least two iterations of a loop 6 require at least one iteration of a loop

Test Cases and Test Paths Test Case : numbers = (44) ; length = 1 Test Path : [ 1, 2, 3, 4, 3, 5, 6, 7, 6, 8 ] Additional DU Paths covered (no sidetrips) [ 1, 2, 3, 4 ] [ 2, 3, 4 ] [ 4, 3, 5 ] [ 5, 6, 7 ] [ 7, 6, 8 ] The five stars that require at least one iteration of a loop Test Case : numbers = (2, 10, 15) ; length = 3 Test Path : [ 1, 2, 3, 4, 3, 4, 3, 4, 3, 5, 6, 7, 6, 7, 6, 7, 6, 8 ] DU Paths covered (no sidetrips) [ 4, 3, 4 ] [ 7, 6, 7 ] The two stars that require at least two iterations of a loop Other DU paths require arrays with length 0 to skip loops But the method fails with index out of bounds exception… med = numbers [length / 2]; A fault was found

Example: Def-Use Associations read (z) x = 0 y = 0 if (z  0) { x = sqrt (z) if (0  x && x  5) y = f (x) else y = h (z) } y = g (x, y) print (y) def-use associations for variable z.

Example: Def-Use Associations read (z) x = 0 y = 0 if (z  0) { x = sqrt (z) if (0  x && x  5) y = f (x) else y = h (z) } y = g (x, y) print (y) def-use associations for variable x.

Example: Def-Use Associations read (z) x = 0 y = 0 if (z  0) { x = sqrt (z) if (0  x && x  5) y = f (x) else y = h (z) } y=g (x, y) print (y) def-use associations for variable y.

/* ABS This program function returns the absolute value of the integer passed to the function as a parameter. INPUT: An integer. OUTPUT: The absolute value if the input integer. */ 1 int ABS(int x) 2 { 3 if (x < 0) 4 x = -x; 5 return x; 6 } Using Control-flow Testing to Test Function ABS Consider the following function:

The Flowgraph for ABS /* ABS This program function returns the absolute value of the integer passed to the function as a parameter. INPUT: An integer. OUTPUT: The absolute value if the input integer. */ 1 int ABS(int x) 2 { 3 if (x < 0) 4 x = -x; 5 return x; 6 }

/* COUNT This program counts the number of characters and lines in a text file. INPUT: Text File OUTPUT: Number of characters and number of lines. */ 1 main(int argc, char *argv[]) 2 { 3 int numChars = 0; 4 int numLines = 0; 5 char chr; 6 FILE *fp = NULL; 7 Example: Using Control-flow Testing to Test Program COUNT Consider the following program:

8 if (argc < 2) 9 { 10 printf(“\nUsage: %s ”, argv[0]); 11 return (-1); 12 } 13 fp = fopen(argv[1], “r”); 14 if (fp == NULL) 15 { 16 perror(argv[1]); /* display error message */ 17 return (-2); 18 } Program COUNT (Cont’d)

19 while (!feof(fp)) 20 { 21 chr = getc(fp); /* read character */ 22 if (chr == ‘\n’) /* if carriage return */ 23 ++numLines; 24 else 25 ++numChars; 26 } 27 printf(“\nNumber of characters = %d”, numChars); 28 printf(“\nNumber of lines = %d”, numLines); 29 } Program COUNT (Cont’d)

The Flowgraph for COUNT The junction at line 12 and line 18 are not needed because if you are at these lines then you must also be at line 14 and 19 respectively.

An example: All-du-paths What are all the du-paths in the following program ? read (x,y); for (i = 1; i <= 2; i++) print ( “ hello ” ); if (y < 0) print (x);

Example: pow(x,y)

Def-Use Pairs (3) /** Euclid's algorithm */ public class GCD { public int gcd(int x, int y) { int tmp; // A: def x, y, tmp while (y != 0) { // B: use y tmp = x % y; // C: def tmp; use x, y x = y; // D: def x; use y y = tmp; // E: def y; use tmp } return x; // F: use x }

Find all DU for x and y Public int gcd (int x, int y) { int tmp; While (y!= 0) { tmp= x % y; x = y; y = tmp; } return x; } 50