1 / 47

Topics in Software Dynamic White-box Testing: Data-flow Testing

Topics in Software Dynamic White-box Testing: Data-flow Testing. Learning objectives. Understand why data flow criteria have been designed and used Recognize and distinguish basic DF criteria All DU pairs, all DU paths, all definitions

aldon
Download Presentation

Topics in Software Dynamic White-box Testing: Data-flow Testing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Topics in Software Dynamic White-box Testing: Data-flow Testing

  2. Learning objectives • Understand why data flow criteria have been designed and used • Recognize and distinguish basic DF criteria • All DU pairs, all DU paths, all definitions • Understand how the infeasibility problem impacts data flow testing • Appreciate limits and potential practical uses of data flow testing

  3. Motivation • Middle ground in structural testing • Node and edge coverage don’t test interactions • Path-based criteria require impractical number of test cases • And only a few paths uncover additional faults, anyway • Need to distinguish “important” paths • Intuition: Statements interact through data flow • Value computed in one statement, used in another • Bad value computation revealed only when it is used

  4. 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.

  5. Data-Flow Testing (Cont’d) • Data-flow testing • 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. • Example: 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.

  6. Data flow concept 1 • Value of x at 6 could be computed at 1 or at 4 • Bad computation at 1 or 4 could be revealed only if they are used at 6 • (1,6) and (4,6) aredef-use (DU) pairs • defs at 1,4 • use at 6 x = .... 2 if .... 3 4 .... x = .... 5 ... 6 y = x + ...

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

  8. (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 • ...

  9. (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.

  10. 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?

  11. 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); computation Predicate

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

  13. Static vs DynamicAnomaly 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.)

  14. 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.

  15. 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.

  16. 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)

  17. 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.)

  18. 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.

  19. 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.

  20. 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.

  21. 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.

  22. def-use Associations • A def-use association is a triple (x,d, u,), where: x is a variable, d is a node containing a definition of x, u is either a statement or predicate node containing a use of x, and there is a sub-path in the flow graph from d to uwith no other definition of x between d and u.

  23. Example: Def-Use Associations 1 read (x, y) SomeDef-Use Associations: (x, 1, 2), (x, 1, 4), … (y, 1, (3,t)), (y, 1, (3,f)), (y, 1, 5), … (z, 2, (3,t)),... 2 z = x + 2 3 z < y F T 5 4 y = y + 1 w = x + 1 6 print (x,y,w,z)

  24. Example: Def-Use Associations What are all the def-use associations for the program below? read (z)x = 0 y = 0if (z  0){ x = sqrt (z) if (0  x && x  5) y = f (x) else y = h (z) } y = g (x, y) print (y)

  25. Example: Def-Use Associations read (z)x = 0 y = 0if (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.

  26. Example: Def-Use Associations read (z)x = 0 y = 0if (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.

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

  28. Definition-clear path • 1,2,3,5,6 is a definition-clear path from 1 to 6 • x is not re-assigned between 1 and 6 • 1,2,4,5,6 is not a definition-clear path from 1 to 6 • the value of x is “killed” (reassigned) at node 4 • (1,6) is a DU pair because 1,2,3,5,6 is a definition-clear path 1 x = .... 2 if .... 3 4 .... x = .... 5 ... 6 y = x + ... (c) 2007 Mauro Pezzè & Michal Young

  29. Definition-Clear Paths • A path (i, n1, ..., nm, j) is called a definition-clear path with respect to x from node i to node j if it contains no definitions of variable x in nodes (n1, ..., nm , j) . • The family of data flow criteria requires that the test data execute definition-clear paths from each node containing a definition of a variable to specified nodes containing c-use and edges containing p-use of that variable.

  30. Data-Flow Testing Strategies • All du Paths (ADUP) • All Uses (AU) • Others not covered in this course …

  31. 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).

  32. 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”); Sa; if (y < 0) Sb; else print (x);

  33. An example: All-du-paths 1 y < o 6 F T read (x, y)i = 1 2 print x 7 8 Sb 3 i <= 2 F T 5 4 Sa 9 print(“hello”) i = i + 1 6 y < o

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

  35. Example: pow(x,y)du-Path for Variable x /* pow(x,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) a f i 6 p = 0 – y; d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h e 10 { 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

  36. Example: pow(x,y)du-Path for Variable x /* pow(x,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) a f i 6 p = 0 – y; d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h e 10 { 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

  37. Example: pow(x,y)du-Path for Variable y /* pow(x,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) a f i 6 p = 0 – y; d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h e 10 { 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

  38. Example: pow(x,y)du-Path for Variable y /* pow(x,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) a f i 6 p = 0 – y; d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h e 10 { 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

  39. Example: pow(x,y)du-Path for Variable y /* pow(x,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) a f i 6 p = 0 – y; d 7 else p = y; 1 5 8 9 14 16 17 8 z = 1.0; 9 while (p != 0) c h e 10 { 11 z = z * x; 12 p = p – 1; 13 } 14 if (y < 0) 15 z = 1.0 / z; 16 printf(z); 17 }

  40. 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.

  41. Effectiveness of Strategies • Ntafos compared 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. • Ntafos conducted two experiments:

  42. Results of 2 of the 14 Ntafos 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

  43. 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.

  44. 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.

  45. Summary • Data flow testing attempts to distinguish “important” paths: Interactions between statements • Intermediate between simple statement and branch coverage and more expensive path-based structural testing • Cover Def-Use (DU) pairs: From computation of value to its use • Intuition: Bad computed value is revealed only when it is used • Levels: All DU pairs, all DU paths, all defs (some use) • Limits: Aliases, infeasible paths • Worst case is bad (undecidable properties, exponential blowup of paths), so pragmatic compromises are required

  46. 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.

  47. 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.

More Related