Tata Consultancy Services

Slides:



Advertisements
Similar presentations
DATAFLOW TESTING DONE BY A.PRIYA, 08CSEE17, II- M.s.c [C.S].
Advertisements

Tutorial 3, Q1 Answers Consider the following simple program (in no particular language) to find the smallest prime factor of a number: smallest(int p)
Data Flow Testing (DFT) Data flow testing is NOT the same as constructing Design Diagrams in the form of data-flow-diagrams (DFD) or E-R diagrams. It is.
1 Testing and Maintainability. 2 Bibliography Fagan, M.E. Design and Code Inspections to Reduce errors in Program Development, IBM Journal 3: (1976).
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
Software Testing and Quality Assurance
Dependable Software Systems
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 5 Data Flow Testing
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
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
Path selection criteria Tor Stålhane & ‘Wande Daramola.
Software testing techniques Testing criteria based on data flow
Presented By Dr. Shazzad Hosain Asst. Prof., EECS, NSU
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
CPS120: Introduction to Computer Science Decision Making in Programs.
Coverage Estimating the quality of a test suite. 2 Code Coverage A code coverage model calls out the parts of an implementation that must be exercised.
Software Verification Graph Model. 2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Overview Structural Testing Introduction – General Concepts
Path selection criteria Tor Stålhane & Wande Daramola.
White-Box Testing Techniques I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 7.
Software Dynamic White-box Testing Part 2: Data-flow Testing Lecture 7 Prof. Mostafa Abdel Aziem Mostafa.
Software Dynamic White-box Testing Lecture 6 Part 1: Control-flow Testing.
CS223: Software Engineering Lecture 26: Software Testing.
Software Testing and QA Theory and Practice (Chapter 5: Data Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Lab 7 Control-Flow Testing
PREPARED BY G.VIJAYA KUMAR ASST.PROFESSOR
Software Testing Techniques (STT)
Software TestIng White box testing.
EGR 2261 Unit 11 Pointers and Dynamic Variables
Paul Ammann & Jeff Offutt
CS223: Software Engineering
UNIT – II TRANSACTION FLOW TESTING
Overview 4 major memory segments Key differences from Java stack
Control Flow Testing Handouts
EKT120 COMPUTER PROGRAMMING
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Software Testing and Maintenance 1
Paul Ammann & Jeff Offutt
CS1371 Introduction to Computing for Engineers
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Lab 8 Data-Flow Testing.
Structural testing, Path Testing
White-Box Testing Techniques
CHAPTER 4 Test Design Techniques
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Overview 4 major memory segments Key differences from Java stack
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Topics Introduction to File Input and Output
Chapter 14 - Advanced C Topics
Pointers, Dynamic Data, and Reference Types
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Graph Coverage for Source Code
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
White-Box Testing Techniques I
Control Structure Testing
Examining Variables on Flow Paths
Chapter8: Statement-Level Control Structures April 9, 2019
COSC 4506/ITEC 3506 Software Engineering
Paul Ammann & Jeff Offutt
Topics Introduction to File Input and Output
More C++ Classes Systems Programming.
CHAPTER 6 Testing and Debugging.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing and QA Theory and Practice (Chapter 5: Data Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
BASICS OF DATA FLOW TESTING:  DATA FLOW TESTING: o Data flow testing is the name given to a family of test strategies based on selecting paths through.
Presentation transcript:

Tata Consultancy Services Data-Flow Testing Prof C R Muthukrishnan I.I.T Madras & Tata Consultancy Services DA-IICT, Feb 22, 2005

Dependable Software Systems 4/24/2019 Dependable Software Systems Data-Flow Testing

Data-Flow Testing Data-flow testing uses the control flowgraph to explore the unreasonable things that can happen to data (i.e., anomalies). Consideration of data-flow anomalies leads to test path selection strategies that fill the gaps between complete path testing and branch or statement testing.

Data-Flow Testing (Cont’d) Data-flow testing is the name given to a family of test strategies based on selecting paths through the program’s control flow in order to explore sequences of events related to the status of data objects. E.g., Pick enough paths to assure that: Every data object has been initialized prior to its use. All defined objects have been used at least once.

Data Object Categories (d) Defined, Created, Initialized (k) Killed, Undefined, Released (u) Used: (c) Used in a calculation (p) Used in a predicate

(d) Defined Objects An object (e.g., variable) is defined when it: appears in a data declaration is assigned a new value is a file that has been opened is dynamically allocated ...

(k) Killed Objects An object is killed when it is: released (e.g., free) or otherwise made unavailable (e.g., out of scope) a loop control variable when the loop exits a file that has been closed ...

(u) Used Objects An object is used when it is part of a computation or a predicate. A variable is used for a computation (c) when it appears on the RHS (sometimes even the LHS in case of array indices) of an assignment statement. A variable is used in a predicate (p) when it appears directly in that predicate.

Data-Flow Anomalies A data-flow anomaly is denoted by a two character sequence of actions. E.g., ku: Means that an object is killed and then used. dd: Means that an object is defined twice without an intervening usage.

Example E.g., of a valid (not anomalous) scenario where variable A is a dpd: A = C + D; if(A > 0) X = 1; else X = -1; A = B + C;

Two Letter Combinations for d k u dd: Probably harmless, but suspicious. dk: Probably a bug. du: Normal situation. kd: Normal situation. kk: Harmless, but probably a bug. ku: Definitely a bug. ud: Normal situation (reassignment). uk: Normal situation. uu: Normal situation.

Single Letter Situations A leading dash means that nothing of interest (d, k, u) occurs prior to the action noted along the entry-exit path of interest. A trailing dash means that nothing of interest happens after the point of action until the exit.

Single Letter Situations -k: Possibly anomalous: Killing a variable that does not exist. Killing a variable that is global. -d: Normal situation. -u: Possibly anomalous, unless variable is global. k-: Normal situation. d-: Possibly anomalous, unless variable is global. u-: Normal situation.

Data-Flow Anomaly State Graph state of variable action K k u,k anomalous state d d d,k U D A u u k,u,d

Data-Flow Anomaly State Graph with Variable Redemption k k u KU K u k d d k u d u DK D U k d u d u k DD d

Static vs Dynamic Anomaly Detection Static Analysis is analysis done on source code without actually executing it. E.g., Syntax errors are caught by static analysis.

Static vs Dynamic Anomaly Detection (Cont’d) Dynamic Analysis is analysis done as a program is executing and is based on intermediate values that result from the program’s execution. E.g., A division by 0 error is caught by dynamic analysis. If a data-flow anomaly can be detected by static analysis then the anomaly does not concern testing. (Should be handled by the compiler.)

Anomaly Detection Using Compilers Compilers are able to detect several data-flow anomalies using static analysis. E.g., By forcing declaration before use, a compiler can detect anomalies such as: -u ku Optimizing compilers are able to detect some dead variables.

Is Static Analysis Sufficient? Questions: Why isn’t static analysis enough? Why is testing required? Could a good compiler detect all data-flow anomalies? Answer: No. Detecting all data-flow anomalies is provably unsolvable.

Static Analysis Deficiencies Current static analysis methods are inadequate for: Dead Variables: Detecting unreachable variables is unsolvable in the general case. Arrays: Dynamically allocated arrays contain garbage unless they are initialized explicitly. (-u anomalies are possible)

Static Analysis Deficiencies (Cont’d) Pointers: Impossible to verify pointer values at compile time. False Anomalies: Even an obvious bug (e.g., ku) may not be a bug if the path along which the anomaly exists is unachievable. (Determining whether a path is or is not achievable is unsolvable.)

Data-Flow Modeling Data-flow modeling is based on the control flowgraph. Each link is annotated with: symbols (e.g., d, k, u, c, p) sequences of symbols (e.g., dd, du, ddd) that denote the sequence of data operations on that link with respect to the variable of interest.

Control Flowgraph Annotated for X and Y Data Flows 1 INPUT X,Y Z:= X+Y Y:= X-Y 3 IF Z>=0 GOTO SAM 4 JOE: Z:=Z-1 5 SAM: Z:=Z+V U:=0 6 LOOP B(U),Q(V):=(Z+V)*U 7 IF B(U)=0 GOTO JOE Z:=Z-1 8 IF Z=0 GOTO ELL U:=U+1 9 UNTIL U=z B(U-1):=B(U+1)+Q(V-1) 10 ELL: B(U+Q(V)):=U+V 11 IF U=V GOTO JOE 12 IF U>V THEN U:=Z 13 YY:Z:=U 2 END LOOP B(U)? JOE dcc 1 3 4 5 6 7 SAM Z? ELL U,Z? Z? 2 13 12 11 10 9 8 END YY U,V? U,V?

Control Flowgraph Annotated for Z Data Flows 1 INPUT X,Y Z:= X+Y Y:= X-Y 3 IF Z>=0 GOTO SAM 4 JOE: Z:=Z-1 5 SAM: Z:=Z+V U:=0 6 LOOP B(U),Q(V):=(Z+V)*U 7 IF B(U)=0 GOTO JOE Z:=Z-1 8 IF Z=0 GOTO ELL U:=U+1 9 UNTIL U=z B(U-1):=B(U+1)+Q(V-1) 10 ELL: B(U+Q(V)):=U+V 11 IF U=V GOTO JOE 12 IF U>V THEN U:=Z 13 YY:Z:=U 2 END p LOOP B(U)? JOE d 1 3 4 5 6 7 p cd cd c SAM Z? cd p ELL d p p c 2 13 12 11 10 9 8 Z? U,Z? END YY U,V? U,V? p

Definition-Clear Path Segments A Definition-clear Path Segment (w.r.t. variable X) is a connected sequence of links such that X is defined on the first link and not redefined or killed on any subsequent link of that path segment.

Definition-Clear Path Segments for Variable Z (Cont’d) LOOP B(), U? JOE d 1 3 4 5 6 7 p cd cd c SAM Z? cd p ELL d p p 2 13 c 12 11 10 9 8 Z? END YY U,V? U,V? U,Z? p

Non Definition-Clear Path Segments for Variable Z (Cont’d) LOOP B(), U? JOE d 1 3 4 5 6 7 p cd cd c SAM Z? cd p ELL d p p 2 13 c 12 11 10 9 8 Z? END YY U,V? U,V? U,Z? p

Simple Path Segments A Simple Path Segment is a path segment in which at most one node is visited twice. E.g., (7,4,5,6,7) is simple. Therefore, a simple path may or may not be loop-free.

Loop-free Path Segments A Loop-free Path Segment is a path segment for which every node is visited at most once. E.g., (4,5,6,7,8,10) is loop-free. path (10,11,4,5,6,7,8,10,11,12) is not loop-free because nodes 10 and 11 are visited twice.

du Path Segments A du Path is a path segment such that if the last link has a use of X, then the path is simple and definition clear.

Data-Flow Testing Strategies All du Paths (ADUP) All Uses (AU) All p-uses/some c-uses (APU+C) All c-uses/some p-uses (ACU+P) All Definitions (AD) All p-uses (APU) All c-uses (ACU)

All du Paths Strategy (ADUP) ADUP is one of the strongest data-flow testing strategies. ADUP requires that every du path from every definition of every variable to every use of that definition be exercised under some test All du Paths Strategy (ADUP).

Example: pow(x,y) b g a f i d 1 5 8 9 14 16 17 c h e

Example: pow(x,y) du-Path for Variable x This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout. */ 1 void pow (int x, y) 2 { 3 float z; 4 int p; b g 5 if (y < 0) 6 p = 0 – y; a f i d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h 10 { e 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

Example: pow(x,y) du-Path for Variable x This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout. */ 1 void pow (int x, y) 2 { 3 float z; 4 int p; b g 5 if (y < 0) 6 p = 0 – y; a f i d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h 10 { e 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

Example: pow(x,y) du-Path for Variable y This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout. */ 1 void pow (int x, y) 2 { 3 float z; 4 int p; b g 5 if (y < 0) 6 p = 0 – y; a f i d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h 10 { e 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

Example: pow(x,y) du-Path for Variable y This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout. */ 1 void pow (int x, y) 2 { 3 float z; 4 int p; b g 5 if (y < 0) 6 p = 0 – y; a f i d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h 10 { e 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

Example: pow(x,y) du-Path for Variable y This program computes x to the power of y, where x and y are integers. INPUT: The x and y values. OUTPUT: x raised to the power of y is printed to stdout. */ 1 void pow (int x, y) 2 { 3 float z; 4 int p; b g 5 if (y < 0) 6 p = 0 – y; a f i d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h 10 { e 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

Example: Using du-Path Testing to Test Program COUNT Consider the following program: /* 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                 

Program COUNT (Cont’d) 8                  if (argc < 2) 9                  { 10              printf(“\nUsage: %s <filename>”, 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              }

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.

du-Path for argc

du-Path for argc

du-Path for argv[]

du-Path for argv[]

du-Path for numChars

du-Path for numChars

du-Path for numChars

du-Path for numLines

du-Path for numLines

du-Path for numLines

du-Path for chr

du-Path for chr

du-Path for fp

du-Path for fp

du-Path for fp

All Uses Strategy (AU) AU requires that at least one path from every definition of every variable to every use of that definition be exercised under some test. Hence, at least one definition-clear path from every definition of every variable to every use of that definition be exercised under some test. Clearly, AU < ADUP.

All p-uses/Some c-uses Strategy (APU+C) APU+C requires that for every variable and every definition of that variable include at least one definition-free path from the definition to every predicate use. If there are definitions of the variable that are not covered by the above prescription, then add computational-use test cases to cover every definition.

All c-uses/Some p-uses Strategy (ACU+P) ACU+P requires that for every variable and every definition of that variable include at least one definition-free path from the definition to every computational use. If there are definitions of the variable that are not covered by the above prescription, then add predicate-use test cases to cover every definition.

All Definitions Strategy (AD) AD requires that for every variable and every definition of that variable include at least one definition-free path from the definition to a computational or predicate use. AD < ACU+P and AD < APU+C.

All p-uses (APU) All c-uses (ACU) APU is the same as APU+C without the C requirement. APU < APU+C. ACU is the same as ACU+P without the P requirement. ACU < ACU+P.

Relative Strength of Data-Flow Testing Strategies All Paths All du Paths All Uses Cannot Compare All c-uses/ Some p-uses All p-uses/ Some c-uses All Definitions All c-uses All p-uses Cannot Compare

Effectiveness of Strategies compare Random, Branch, and All uses testing strategies on 14 Kernighan and Plauger programs. Kernighan and Plauger programs are a set of mathematical programs with known bugs that are often used to evaluate test strategies.

Results of Experiments Mean Number of Test Cases Percentage of Bugs Found Strategy Random Branch All Uses 35 3.8 11.3 93.7 91.6 96.3 Mean Number of Test Cases Percentage of Bugs Found Strategy Random Branch All Uses 100 34 84 79.5 85.5 90.0

Data-Flow Testing Tips Resolve all data-flow anomalies. Try to do all data-flow operations on a variable within the same routine (i.e., avoid integration problems). Use strong typing and user defined types when possible.

Data-Flow Testing Tips (Cont’d) Use explicit (rather than implicit) declarations of data when possible. Put data declarations at the top of the routine and return data objects at the bottom of the routine.

Summary Data are as important as code. Define what you consider to be a data-flow anomaly. Data-flow testing strategies span the gap between all paths and branch testing.

Summary AU has the best payoff for the money. It seems to be no worse than twice the number of required test cases for branch testing, but the results are much better. Path testing with Branch Coverage and Data-flow testing with AU is a very good combination.

Questions welcome Thank you