Constructing and Using

Slides:



Advertisements
Similar presentations
8. Static Single Assignment Form Marcus Denker. © Marcus Denker SSA Roadmap  Static Single Assignment Form (SSA)  Converting to SSA Form  Examples.
Advertisements

Path Analysis Why path analysis for test case design?
Chapter 6 Path Testing Software Testing
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
Introduction to Graphs
Introduction to Graph “theory”
TECH Computer Science Graphs and Graph Traversals  // From Tree to Graph  // Many programs can be cast as problems on graph Definitions and Representations.
CS447/ECE453/SE465 Prof. Alencar University of Waterloo 1 CS447/ECE453/SE465 Software Testing Tutorial Winter 2008 Based on the tutorials by Prof. Kontogiannis,
Graphs.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
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 methodology.
A Complexity Measure THOMAS J. McCABE Presented by Sarochapol Rattanasopinswat.
CIS Computer Programming Logic
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
1 Topics Intro. to Graphs (11.1) A B C D EF G. 2 Definition (p.650) A graph G = V(G) + E(G) A set of vertices (or nodes), V(G) = {v 1, v 2, …, v n } A.
Introduction to Graph “theory” Why do we care about graph theory in testing and quality analysis? –The “flow” (both control and data) of a design, within.
Graphs. 2 Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
COMP 6710 Course NotesSlide 7-0 Auburn University Computer Science and Software Engineering Course Notes Set 7: Review of Graphs Computer Science and Software.
BASIS PATH TESTING.
Homework #5 Due: October 31, 2000 Christine Kang Graph Concepts and Algorithms.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
Excursions in Modern Mathematics, 7e: Copyright © 2010 Pearson Education, Inc. 5 The Mathematics of Getting Around 5.1Euler Circuit Problems 5.2What.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
Copyright © Curt Hill Graphs Definitions and Implementations.
Computer Science 313 – Advanced Programming Topics.
Graph Concepts Elif Tosun 252a-aa (All graphics created by using demo/graphwin/gw*)
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
The for Statement A most versatile loop
Lecture 5.4: Paths and Connectivity
BASIS PATH TESTING.
Data Structures Graphs - Terminology
Basic Concepts Graphs For more notes and topics visit:
Graphs.
Automata and Languages What do these have in common?
C.Eng 213 Data Structures Graphs Fall Section 3.
Structural testing, Path Testing
CS202 - Fundamental Structures of Computer Science II
Refresh and Get Ready for More
Program Slicing Baishakhi Ray University of Virginia
Control Flow Analysis CS 4501 Baishakhi Ray.
Introduction to Programming
Introduction to Programming
Executes a block of statements only if a test is true
Conditional Construct
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
Topic 4: Flow Analysis Some slides come from Prof. J. N. Amaral
Copyright © by Curt Hill
ME 142 Engineering Computation I
How does the complexity of the flow of control affect test cases?
Graphs.
Control Flow Analysis (Chapter 7)
Control Structure Testing
Decision I (if Statement)
5 The Mathematics of Getting Around
Examining Variables on Flow Paths
Graphs.
Graphs.
Graphs.
Graphs.
Paths and Connectivity
Paths and Connectivity
Graphs.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

Constructing and Using Flow Graphs Constructing and Using Copyright © 2001- 2017 Curt Hill

Flow Charts In program design and documentation we often use a flow chart You will remember flow charts from earlier courses There are several shapes connected by arrows Circle – start or stop Rectangle – processing block Diamond – a decision Notice the flow of control structures in the next picture Copyright © 2001- 2017 Curt Hill

Flow Chart Example Copyright © 2001- 2017 Curt Hill

Notes Flow charts were developed in the 1920s to describe processes They were very popular in the early computer years (1950s to 1970s) In this presentation we are more interested in flow graphs Flow graphs are based graph theory Thus they are able to use numerous theorems from graph theory Copyright © 2001- 2017 Curt Hill

Flow Graphs AKA Control Flow Graph (CFG) A flow graph is a simplified flow chart Looks more like a graph theory diagram Both flow charts and flow graphs are directed graphs Only two constructs A node which is a circle An arrow which is an edge between two nodes Copyright © 2001- 2017 Curt Hill

Flow Graph Example Copyright © 2001- 2017 Curt Hill

Charts and Graphs The rectangles of a flow chart typically represent one or more sequential flow statements Thus we often have several rectangles one leading to another This is fine for some things but not what we want in flow graphs that we are currently considering Copyright © 2001- 2017 Curt Hill

Interest We are not interested in sequential statements We wish to collapse them into a block This is also a common thing for a compiler In our normal flow graph any adjacent set of non-flow statements is collapsed into one Even if one is a control flow node Copyright © 2001- 2017 Curt Hill

Better Example 11 1 11 1 2,3 2 6 3 4,5 4 7 8 7 6 8 From Pressman 5 9 10 Copyright © 2001- 2017 Curt Hill

Observations When we collapse these nodes the following becomes true Thus for every arc A->B Outdegree of A > 1 or indegree of B > 1 or both Next we take another detour through graph theory Copyright © 2001- 2017 Curt Hill

Mathematical definitions Nodes or Vertices A location or point May have a number of properties Arcs or Edges Connector of nodes Directional or bidirectional May also have other properties, eg. cost 2 1 3 6 4 5 Copyright © 2001- 2017 Curt Hill

Mathematical definitions 2 Indegree of a node Number of arcs ending at node Outdegree Number of arcs starting at node Directed or digraph Arcs are one directional only Undirected Node indegree = node outdegree Not of interest today 1 3 6 4 5 Copyright © 2001- 2017 Curt Hill

Directed graph Flow graphs are directed Flow must start at a node and finish at a node We denote these with arrows We cannot back up in a program Each node may point at zero or more arcs Each node may be pointed at by zero or more arcs Copyright © 2001- 2017 Curt Hill

Connectivity 2 A and B together is a disconnected graph with two components A is strongly connected There is a path from every node to every other node B is weakly connected No path leads to 7 1 3 6 4 5 A B 9 8 7 Copyright © 2001- 2017 Curt Hill

Graph Theory Concepts Path Reachability Domination A series of edges from one node to another Reachability A path exists from one node to another If no path exists from the start node that part of the graph can be removed – AKA dead code Domination If all paths from A to C go through B then B dominates C EG. a loop header dominates the loop Copyright © 2001- 2017 Curt Hill

Consider this code int f1, f2, total=0, counter=1; while(!infile){ cin >> f1 >> f2 if(f1==0){ total+=f1; counter++; } else if(f2 == 0){ cout << total<<counter; counter = 0; } else total -= f2; cout << f1 << f2; } // end while cout << counter; Copyright © 2001- 2017 Curt Hill

Flow Graph 9 1 4 3 6 5 7 8 2 Copyright © 2001- 2017 Curt Hill From Pressman 7 8 Copyright © 2001- 2017 Curt Hill

Construction There is only one start and one end Any return statements make an arc to the one end Predicates include the following: If, while, for, case Breaks make an arc to the first statement after a loop/switch Continue makes an arc to then end of the loop Copyright © 2001- 2017 Curt Hill

More Construction An if may will be merged with prior sequential statements Loops will not – there is a branch to the beginning A for distinguishes between initialization and rest of loop The initialization may merge with preceding assignments It is the case of the switch which is the real predicate Multiple cases with one piece of code become one predicate Copyright © 2001- 2017 Curt Hill

Consider this code int f1, f2, total=0, counter=1; while(!infile){ cin >> f1 >> f2 if(f1==0){ total+=f1; counter++; } else if(f2 == 0){ cout << total<<counter; counter = 0; } else total -= f2; cout << f1 << f2; } // end while cout << counter; Copyright © 2001- 2017 Curt Hill

Flow Graph int f1, f2, total=0, counter=1; while(!infile){ cin >> f1 >> f2 if(f1==0){ total+=f1; counter++; } else if(f2 == 0){ cout << total<<counter; counter = 0; } else total -= f2; cout << f1 << f2; } // end while cout << counter; 9 1 2 4 3 5 6 From Pressman 7 8 Copyright © 2001- 2017 Curt Hill

Observation The cin and if were merged. The two assignments in the then and else were also merged We may merge a predecessor with an if, but not a successor Copyright © 2001- 2017 Curt Hill

Conclusion Flow graphs are a common way to represent programs Emphasis is on flow of control Allows us to apply graph theory to program flow This will be needed for measures such as Cyclomatic Complexity Copyright © 2001- 2017 Curt Hill