1 / 42

Lecture 2

Lecture 2. White-box Testing and Structural Coverage. White-box Testing (aka. Glass-box or structural testing). An error may exist at a location Line numbers Boolean tests Expressions etc. If tests don’t exercise that location then error can never be observed

gabe
Download Presentation

Lecture 2

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. Lecture 2 White-box Testing and Structural Coverage

  2. White-box Testing (aka. Glass-box or structural testing) • An error may exist at a location • Line numbers • Boolean tests • Expressions etc. • If tests don’t exercise that location then error can never be observed • So identify and exercise locations • No loops – finitely many locations – good! • Loops – infinitely many locations – bad! • Loops + branches – exponential growth in locations with loop depth – very bad !!!!

  3. Structural Testing Structural testing is the process of exercising software with test scenarios written from the source code, not from the requirements. Usually structural testing has the goal to exercise a minimum collection of (combinations of) locations. How many locations and combinations are enough?

  4. Coverage • Coverage refers to the extent to which a given testing activity has satisfied its objectives. • “Enough” testing is defined in terms of coverage. • A major advantage of structural testing is that coverage can be easily and accurately defined. • Structural coverage measures

  5. Structural Testing – Problems! • What about sins of omission? – no path to go down! Unimplemented requirements! • What about dead code – is a path possible? • How to avoid redundant testing? • What about testing the user requirements? • How to handle combinatorial explosion of locations and their combinations?

  6. Requirements-based testing versus Structural testing (DO-178B) Software Requirements-based Test Generation HW/SW integration tests Integration tests Unit tests Software Requirements Coverage analysis Software Structure Coverage analysis End

  7. Problems with requirements-based testing • A test set that meets requirements coverage is not necessarily a thorough test set • Requirements may not contain a complete and accurate specification of all code behaviour • Requirements may be too coarse to assure that all implemented behaviours are tested • Requirements-based testing alone cannot confirm that code doesn’t include unintended functionality. Need structural testing too!

  8. Coverage Criteria 1: Control flow • Measure the flow of control between statements and sequences of statements • Examples: node coverage, edge coverage. • Mainly measured in terms of statement invocations (line numbers). • Exercise main flows of control.

  9. Coverage Criteria 2: Data Flow • Data flow criteria measure the flow of data between variable assignments (writes) and variable references (reads). • Examples: all-definitions, all-uses • Exercise paths between definition of a variable and is subsequent use.

  10. Coverage Criteria 3: Logic • Analyse the influence of all Boolean variables • Examples: predicate coverage, clause coverage, MCDC (FAA DO178B) • Exercise Boolean variables at control points.

  11. Control Flow Requirements • These are structural requirements on a test suite • They ignore functionality! • Easy to define using graph theory • Possible to automate generation by constraint solving • Easy to measure coverage!

  12. Starting Point: a Condensation Graph Assignments1 Cond1 Assignments2 Cond2 A node is either an assignment block or a Boolean test. Every program statement is associated with exactly one node. Assignments4 Assignments3

  13. Building condensation graphs • Boolean tests can be from: • If-then-else statements if (bexp) then .. else .. • If statements if (bexp) … • Loops (of any kind) while (bexp) … • An assignment block contains consecutive • assignments x = exp • return statements return exp • procedure/method calls myFunc(…) • expressions e.g. i++

  14. Graph Coverage • A path is a sequence of nodes n0 ,…, nkin a (condensation) graph G, such that each adjacent node pair, (ni, ni+1) forms an edge in G. • For control flow testing a test requirement tr(.) is a predicate on paths • Noden( p ) iffp passes through node n • Edgee (p) iffp has edge e

  15. Graph Coverage Definition: Given a set TR of test requirements for a graph criterion C, A test suite T satisfies C on graph G if, and only if for every test requirement tr(.)  TR, there is at least one testtinT such that for the path p in G taken by t, tr(p) is true (i.e. psatisfiestr(.))

  16. Why so Formal? • Answer: Sometimes coverage properties become very technical to define for efficiency reasons.

  17. Structural Coverage Criteria(Amman and Offut, Chapter 2) 2.1. Node Coverage (NC) SetTR contains each reachable node in G. Myers “NC is so weak that it is generally considered useless” 2.2. Edge Coverage (EC) Set TR contains each reachable path of length ≤ 1.

  18. Node vs. Edge Coverage p1 = n0, n1, n2 n0 x < y p2 = n0, n2 n1 x >= y TS1 = p1 satisfies node coverage n2 TS2 = p1, p2 satisfies edge coverage Abstract test cases

  19. 2.3 Edge-Pair Coverage (EPC = EC2) Set TR contains each reachable path of length ≤ 2. • Clearly we can continue this beyond 1,2 to ECn • Combinatorial explosion! • Doesn’t deal with loops, which have unbounded length.

  20. p1 = n0, n1, n3, n4 n0 p2 = n0, n2, n3, n5 x < y x >= y n1 n2 p3 = n0, n2, n3, n4 p4 = n0, n1, n3, n5 n3 w < y w >= y TS1 = p1, p2 satisfies edge coverage n4 n5 TS2 = p1, p2, p3, p4 satisfies edge-pair coverage

  21. Simple Paths • How to deal with code loops? • A path p is simple if it has no repetitions of nodes other than (possibly) the first and last node. • So a simple path p has no internal loops, but may itself be a loop • Problem: there are too many simple paths, since many are just sub-paths of longer simple paths.

  22. Prime Paths • A path p is primeiffp is a maximal simple path i.e. p cannot be extended without losing simplicity. • This cuts down the number of cases to consider 2.4. Prime Path Coverage (PPC) Set TR contains each prime path in G

  23. Prime Paths = (n0, n1, n2), (n0,n1,n3,n4), (n1,n3,n4,n1), (n3,n4,n1,n3), (n4,n1,n3,n4), (n3,n4,n1,n2) n0 n3 n1 n4 P1 = (n0, n1, n2) n2 P2 = (n0, n1, n3, n4, n1, n2) P3 = (n0, n1, n3, n4, n1, n3, n4, n1, n2) TS1 = p1, p3 satisfies prime path coverage TS2 = p1, p2 doesn’t satisfy prime path coverage! (why?)

  24. Computing Prime Paths • One advantage is that the set of all prime paths can be computed by a simple dynamic programming algorithm • See Amman and Offut for details • Then test cases can be derived manually (heuristic: start from longest paths?) or automatically.

  25. 2.7. Complete Path Coverage (CPC) Set TR contains all paths in G. Infeasible if G has infinitely many paths 2.8. Specified Path Coverage (SPC) SetTR contains a set S of test paths, where S is supplied as a parameter. Example. S contains paths that traverse every loop free path p in G and every loop in G both 0 and 1 times.

  26. Data Flow Criteria • A definition of a variable v is any statement that writes to v in memory • A use of v is any statement that readsv from memory. • A path p = (n1, .., nk) from a node n1 to a node nk is def-clear for v if for each 1 < j < k node nj has no statements which write to v

  27. Definition/Use Paths (du-paths) • A du-path w.r.t. v is a simple path p = (n1, .., nk) • Such that: • A statement in n1 writes to v • Path p is def-clear for v • A statement in nk reads v • du(n,v) = set of all du-paths wrtv starting at n • du(m,n,v) =set of all du-paths wrtv starting at m and ending at n

  28. Data flow coverage models • 2.9. All-defs Coverage (ADC) For each def-path set S = du(n, v) the set TR contains at least one path d in S. • 2.10 All-uses Coverage (AUC) For each def-pair set S = du(m,n,v) the set TR contains at least one path d in S. • 2.11 All-du-paths Coverage (ADUPC) For each def-pair set S = du(m,n,v) the set TR contains every path d in S.

  29. n0 write v n1 n2 n3 n4 n5 read v read v All-defs = (n0,n1,n3,n4) All-du-paths = (n0,n1,n3,n4) (n0,n1, n3,n5), (n0,n2, n3,n4), (n0,n2, n3,n5)  All-uses = (n0,n1,n3,n4) (n0,n1, n3,n5)

  30. Logic Coverage • Graph and data flow coverages force execution of certain paths (branches) through code. • They don’t necessarily exercise different ways of taking the same branch. • This number of ways may be finite and coverable. • Since a Boolean condition may contain many Boolean and data (int, float, object) variables, we may wish to consider exercising the condition in different ways.

  31. Clauses and Predicates • A clause is a Boolean valued expression with no Boolean valued sub-expression • Examples p, myGuard, x==y, x<=y, x>y • A predicate is a Boolean combination of clauses using &, I, !, • Let P be a set of predicates • For p  P, let Cp be the set of all clauses in p. • For logic coverage, a test requirement tr is a predicate on data values

  32. Logic Coverage Measures • 3.12 Predicate Coverage (PC) For each predicate p  P, the set TR contains two requirements: p is reached and evaluates to true, and p is reached and evaluates to false. • 3.13 Clause Coverage (CC) For each predicate p  P, and each clause c Cpthe set TR containstwo requirements: c is reached and evaluates to true, and c is reached and evaluates to false.

  33. Distributive vs. non-distributive • Note: this definition of PC is non-distributive, ie. We don’t take all combinations of all predicate values. • PC doesn’t necessarily achieve edge coverage! • Non-distributive PC – linear growth. • Distributive PC - exponential growth.

  34. Logic Coverage (cont) • 3.14 Combinatorial Coverage (CoC) For each predicate p  P, the set TR contains requirements so that p is reached, and the clauses c Cpevaluate to every possible combination of truth values. • CoC is also called multiple condition coverage (MCC).

  35. Active Clause Coverage • Clearly PC and CC grow linearly in the size of the Boolean predicate p • CoC grows exponentially. • Can we find something more expressive but still linear in-between? • Use notion of active variables which determine or influence the overall predicate value

  36. Determination Given a clause ci in a predicate p we say that cidetermines p iff the other clauses in p can be assigned values so that changing the truth value of ci changes the truth value of p. 3.43 Active Clause Coverage (ACC) For each predicate p Pand each clause c Cpwhich determinesp, the set TRcontains two requirements for c: c is reached and evaluates to true, and c is reached and evaluates to false.

  37. Ambiguity • ACC can be seen as ambiguous. • Do the other clauses get the same assignment when c is true and c is false, or can they have different assignments? • Problem of masking, overlap or side-effects between clauses • Consider e.g. c  !b (ciff not b) • Here b cannot have the same assignment for c = true and c = false

  38. Different Values • 3.15 General Active Clause Coverage (GACC)For each predicate p  P and each clause c Cpwhich determinesp, the set TR contains two requirements for c: cis reached and evaluates to true,and cis reached and evaluates to false. The values chosen for the other clauses d Cp, d  c, need not be the same in both cases.

  39. Same Values 3.15 Restricted Active Clause Coverage (RACC) For each predicate p  P and each clause c Cp which determinesp, the set TR contains two requirements for c: cis reached and evaluates to true,and cis reached and evaluates to false. The values chosen for the other clauses d Cp, d  c, must be the same in both cases. • So RACC is infeasible for c in c  !b

  40. Correlation • Another problem is that GACC does not imply PC. • Let p be the predicate a  b • Clearly a determines p (so does b) • If a = true then b = true so p = true • If a = false then b = false so p = true • Thus p never becomes false so PC fails!

  41. Handling Correlation 3.16 Correlated Active Clause Coverage (CACC) For each predicate p  P and each clause c Cp which determinesp, the set TR contains two requirements for c: cis reached and evaluates to true,and cis reached and evaluates to false. The values chosen for the other clauses d Cp , d  c, must cause p to be true in one case and false in the other. • Now CACC implies PC

  42. Safety Critical Testing: MCDC • In DO-178B, the Federal Aviation Authority (FAA) has mandated a minimum level of logic coverage for level A (highest safety) avionic software. • “Modified Condition Decision Coverage” (MCDC) • Has been some confusion about this definition • “Unique Cause MCDC” (original definition) is RACC • “Masking MCDC” (new definition) is CACC

More Related