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)

Slides:



Advertisements
Similar presentations
Marking Schema question1: 40 marks question2: 40 marks question3: 20 marks total: 100 marks.
Advertisements

Theory Of Automata By Dr. MM Alam
Graph Coverage (2).
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.
White Box Testing Techniques Dynamic Testing. White box testing(1) Source code is known and used for test design While executing the test cases, the internal.

Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis.
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
Copyright © Cengage Learning. All rights reserved.
Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
White-Box Testing Techniques II Originals prepared by Stephen M. Thebaut, Ph.D. University of Florida Dataflow Testing.
Coverage – “Systematic” Testing Chapter 20. Dividing the input space for failure search Testing requires selecting inputs to try on the program, but how.
Overview Graph Coverage Criteria ( Introduction to Software Testing Chapter 2.1, 2.2) Paul Ammann & Jeff Offutt.
1 Software Testing. 2 Path Testing 3 Structural Testing Also known as glass box, structural, clear box and white box testing. A software testing technique.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
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.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
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
1 Software Testing & Quality Assurance Lecture 13 Created by: Paulo Alencar Modified by: Frank Xu.
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;
Great Theoretical Ideas in Computer Science for Some.
Lecture 8CSE Intro to Cognitive Science1 Interpreting Line Drawings II.
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
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.
1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3
Software Dynamic White-box Testing Part 2: Data-flow Testing Lecture 7 Prof. Mostafa Abdel Aziem Mostafa.
White-Box Testing Statement coverage Branch coverage Path coverage
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
Paul Ammann & Jeff Offutt
PREPARED BY G.VIJAYA KUMAR ASST.PROFESSOR
Paul Ammann & Jeff Offutt
Control Flow Testing Handouts
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Software Testing and Maintenance 1
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Graph: Data Flow Criteria CS 4501 / 6501 Software Testing
Pushdown Automata.
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Paul Ammann & Jeff Offutt
Structural testing, Path Testing
White-Box Testing Techniques II
Paul Ammann & Jeff Offutt
CHAPTER 4 Test Design Techniques
Dataflow Testing G. Rothermel.
Arrays & Functions Lesson xx
Program Slicing Baishakhi Ray University of Virginia
White-Box Testing Techniques II
“White box” or “glass box” tests
Java Programming Loops
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
White-Box Testing Techniques II
Graph Coverage Criteria
Whitebox Testing.
Coursework 1 Due Tuesday, Feb 6, 2007 in the tutorial
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Unit III – Chapter 3 Path Testing.
Presentation transcript:

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) /* precondition p > 1 */ { int q = 2; while(p mod q > 0 AND q < sqrt(p) ) q := q+1 ; if (p mod q = 0) then print(q,''is the smallest factor'') else print(p, ``is prime'') ; } a)Draw the control for this program and (if it helps) the structural tree- form of this program. b)Calculate: –number of nodes –number of edges –number of simple paths –all paths with k=2

smallest(int p) (*p>1*) { int q = 2; while(p mod q > 0 AND q < sqrt p) do q := q+1 ; if (p mod q = 0) then print(q,’is factor’) else print(p,’is prime’) ; } Tree Program CFG S S S A1A1 A2A2 L3L3 A4A4 C5C5 A6A6 A7A7

S8S8 S6S6 S7S7 A2A2 A2A2 L3L3 A2A2 C4C4 A2A2 A2A2 Number of Nodes: F A () = 2 F s (m 1,m 2 ) = m 1 + m F C (m 1,m 2 ) = m 1 + m 2 F L (m 1 ) = m 1 + 1

S9S9 S7S7 S8S8 A1A1 A1A1 L3L3 A1A1 C4C4 A1A1 A1A1 Number of Edges: F A () = 1 F s (m 1,m 2 ) = m 1 + m 2 F C (m 1,m 2 ) = m 1 + m 2 +2 F L (m 1 ) = m 1 + 2

S4S4 S4S4 S4S4 A1A1 A1A1 L2L2 A1A1 C2C2 A1A1 A1A1 Number of simple paths A simple path is one in which no edge is traversed more than once nsp(A) = 1 nsp(S(P 1,P 2 )) = nsp(P 1 ) x nsp(P 2 ) nsp(C(P 1,P 2 )) = nsp(P 1 ) + nsp(P 2 ) nsp(L(P 1 )) = nsp(P1)+1

S6S6 S6S6 S6S6 A1A1 A1A1 L3L3 A1A1 C2C2 A1A1 A1A1 Number of All Paths (k=2) ap(A) = 1 ap(S(P 1,P 2 )) = ap(P 1 ) x ap(P 2 ) ap(C(P 1,P 2 )) = ap(P 1 ) + ap(P 2 ) ap(L(P 1 )) = ap(P1) 2 + ap(P1)+ 1

Tutorial 3, Q2 Consider the following simple program (in no particular language) to find the smallest prime factor of a number: smallest(int p) /* precondition p > 1 */ { int q = 2; while(p mod q > 0 AND q < sqrt(p) ) q := q+1 ; if (p mod q = 0) then print(q,''is the smallest factor'') else print(p, ``is prime'') ; } a)Draw the control for this program and annotate the nodes to indicate the definitions/uses of variables p and q. b)Label the nodes and give All DU Paths for p and q. c)Give a test suite which gives 100% coverage for All DU paths. d)Which of these paths are required for: AU, APU+C, ACU+P, APU, ACU, and AD coverage. e)Explain whether or not the “all predicate uses" test set is sufficient for branch coverage of this program?

smallest(int p) (*p>1*) { int q = 2; while(p mod q > 0 AND q < sqrt p) do q := q+1 ; if (p mod q = 0) then print(q,’is factor’) else print(p,’is prime’) ; } dupupucdupupuc Usage p q d u p u c, d u p u c For p For q Program CFG All DU paths

Required paths p q Actual path Test Input p=3 p=5 P=2 P=11 p=9 Test Output 3 is prime 5 is prime 2 is factor 11 is prime 3 is factor Badly drawn wiggly line indicates paths which subsume other paths

Other coverages: So to cover all du paths we need to have 5 test cases: p=3 and p=5 and p = 2, p=9 and p=11. Now to cover AU, we need only execute a single du path between each pair (d,u) that starts at a definition, d and ends at a use, u. However, we need to ensure that we have done this for both variables in the program. Let’s consider the variable p first. Of the du paths, we have 123 and 12343, but both these exercise the same pair (1,3) so just 123 will do. Also we don’t need both 1235 and , just 1235 would do. Finally, we don’t need and , just will do. In conclusion, we see that we only need to cover all uses of the variable p. There is only one definition of the variable p (at node 1) and the case which passes through hits all three uses of the variable p at 3, 5, and 7. Therefore, to cover all uses of the variable p, we need only execute (p=3). Notice how all du paths requires us (in this case) to go through the loop, whereas (for the variable p) AU does not. That is because there was a choice of du paths for each du pair, where one went through the loop and one did not. However, AU will force us to go through loops if the only du path from a definition to a use goes through a loop. This is the case with the variable q in this example, as we shall see. Let’s look at the AU criterion for the variable q. To understand the difference between All du paths coverage and AU coverage, we need to be clear in our mind about the distinction between a du path and a du pair. The start and end node of a DU path is a Definition and a Use respectively. The definition and use, together, form a du pair. We notice that the 8 du paths identified for q all have different du pairs. That is, there are 8 distinct du pairs for q, each of which corresponds to one of the du paths. This means that covering all uses of q will be the same as covering all du paths for q. Therefore we need the same three test inputs to achieve this.

For APU, we do not need to cover the computational uses of variables, but we must cover the predicate uses. Therefore, we could choose the same three test cases that we chose for AU, but this would be wasteful; we can manage with only two test cases for APU. I will show you how. Notice that, for variable q, we still need to cover the pair (2,5) without passing through 4 and also the pair (4,5), so we must have at least two test cases. However, because we do not need to also cover node 6 (the computational use of the variable q), we can use the path to cover the pair (2,5) for the variable q. This case, , will also cover all predicate uses of the variable p. So now we only need add a case for the pairs (4,3) and (4,5). Either of (p=9) or (p=5) would do. For ACU, we need to cover the computational use of the variable p. In fact, every test case that goes through node 7 does this. However, we need to cover all computational uses of the variable q also. To do this we need to go through node 6. Clearly this cannot re-use the test case for the variable p, since that has to go through node 7 and we cannot go through both nodes 7 and node 6 in the same test case. Now, for variable q, there are two definitions that reach the computational use at node 6, these are the definitions at nodes 2 and 4. The last criterion is easy: For AD, we need only hit all definitions of all variables that reach some use (of any kind – either predicate or computation). These occur at nodes 1,2 and 4, so any test case that goes through all three nodes will do. We could choose, (p=5) for example.

APU versus Branch Cover All predicate uses (as defined in the lecture) is not sufficient for branch coverage as it only requires each predicate to be tested in one direction, whereas branch coverage requires each predicate to be taken in both directions. For this program, as there are no predicates inside the body of the loop, 100% APU coverage is possible without entering the loop, whilst branch cover requires loop body to be executed.