33
The Implementation of Control Flow Graph and Test Cases submitted in partial fulfillment of the requirements for software verification, validation and testing of Master of Engineering In Software Engineering Submitted to: Submitted by: Mr. Ajay Kumar Sukhpal Singh AP (CSED) 801131024 Computer Science & Engineering Department THAPAR UNIVERSITY, PATIALA (Formerly known as Thapar Institute of Engg. & Tech.) (Established under section 3 of UGC Act, 1956 vide notification # F-12/84-U.3 of Government of India)

Software Verification, Validation and Testing

Embed Size (px)

DESCRIPTION

The Implementation of Control Flow Graph and Test Cases

Citation preview

Page 1: Software Verification, Validation and Testing

The Implementation of

Control Flow Graph

and Test Cases submitted in partial fulfillment of the requirements

for software verification, validation and testing of

Master of Engineering

In

Software Engineering

Submitted to: Submitted by:

Mr. Ajay Kumar Sukhpal Singh

AP (CSED) 801131024

Computer Science & Engineering Department

THAPAR UNIVERSITY, PATIALA (Formerly known as Thapar Institute of Engg. & Tech.)

(Established under section 3 of UGC Act, 1956 vide notification # F-12/84-U.3 of Government of India)

Page 2: Software Verification, Validation and Testing

TO WHOM IT MAY CONCERN

7th

May, 2012

I hereby declare that, Sukhpal Singh, Roll No. 801131024 of Thapar University Patiala, have

undergone a project from 2nd

January to 7th

May, 2012. I worked on ‘Implementation of

Control Flow Graph’ project during the software verification, validation and testing lab under

the supervision of project guide Mr. Ajay Kumar. It is my heartfelt pleasure and deepest sense

of gratitude to offer my humble and sincere thanks towards Mr. Ajay Kumar, my project guide,

for his valuable and constant assistance, cooperation, and incisive criticism in my work towards

my goal.

Student’s Signatures Signature of Project Guide

Page 3: Software Verification, Validation and Testing

TABLE OF CONTENTS

1. Control Flow…………………………………………………………….1

2. Control Flow Graph…………………………………………………….1

3. Control Flow Diagram…………………………………………………..1

4. Browsing…………………………………………………………………2

5. Test Cases………………………………………………………………..5

5.1 For Loop……………………………………………………………..5

5.2 If………………………………………………………………………7

5.3 If-else-for……………………………………………………………..9

5.4 Nested if……………………………………………………………..11

5.5 If-for…………………………………………………………………13

5.6 If with two conditions……………………………………………….15

5.7 Switch case…………………………………………………………...17

6. Test Cases………………………………………………………………..19

Page 4: Software Verification, Validation and Testing

1

1. Control Flow:

In computer science, control flow (or alternatively, flow of control) refers to the order in

which the individual statements, instructions or function calls of an imperative or a

declarative program are executed or evaluated. Within an imperative programming language,

a control flow statement is a statement whose execution results in a choice being made as to

which of two or more paths should be followed. For non-strict functional languages,

functions and language constructs exist to achieve the same result, but they are not

necessarily called control flow statements.

The kinds of control flow statements supported by different languages vary, but can be

categorized by their effect:

continuation at a different statement (unconditional branch or jump),

executing a set of statements only if some condition is met (choice - i.e., conditional

branch),

executing a set of statements zero or more times, until some condition is met (i.e.,

loop - the same as conditional branch),

executing a set of distant statements, after which the flow of control usually returns

(subroutines, coroutines, and continuations),

Stopping the program, preventing any further execution (unconditional halt).

Interrupts and signals are low-level mechanisms that can alter the flow of control in a way

similar to a subroutine, but usually occur as a response to some external stimulus or event

(that can occur asynchronously), rather than execution of an 'in-line' control flow statement.

Self-modifying code can also be used to affect control flow through its side effects, but does

not usually involve an explicit control flow statement.

At the level of machine or assembly language, control flow instructions usually work by

altering the program counter. For some CPUs the only control flow instructions available are

conditional or unconditional branch instructions (also called jumps).

2. Control flow Graph:

In a control flow graph each node in the graph represents a basic block, i.e. a straight-line

piece of code without any jumps or jump targets; jump targets start a block, and jumps end a

block. Directed edges are used to represent jumps in the control flow. There are, in most

presentations, two specially designated blocks: the entry block, through which control enters

into the flow graph, and the exit block, through which all control flow leaves.

3. Control Flow Diagram:

A control flow diagram (CFD) is a diagram to describe the control flow of a business process,

process or program. A control flow diagram can consist of a subdivision to show sequential

steps, with if-then-else conditions, repetition, and/or case conditions. Suitably annotated

geometrical figures are used to represent operations, data, or equipment, and arrows are used

to indicate the sequential flow from one to another.

Page 5: Software Verification, Validation and Testing

2

4. Browsing:

First of all we have to browse a file from the system by click on the browse that is displaying

on a main page. The main page has three sections

Program: Which the user has to be browsed.

Control flow graph: This is diagrammatic representation of the program with the

help of nodes and edges to calculate the cyclomatic complexity of program.

Linear Independent Paths: These are different possible paths from starting of

control to the end of the program.

Nodes: Displaying the total nodes of a browsed program.

There are two buttons are available on main page.

Browse file: It is used to browse the file from system.

Show Graph: It is used to display the control flow graph of browsed program.

Figure 1: Screenshot of main page

Step 1: Click on “browse file” then it displays a new window for browsing.

Page 6: Software Verification, Validation and Testing

3

Figure 2: Screenshot of browsing a file

Step 2: Select an appropriate file.

Step 3: Click on “open” then program will be browsed and displayed on main page.

Figure 3: Screenshot of browsed program

Page 7: Software Verification, Validation and Testing

4

Step 4: Click on “show graph” then control flow graph, node and linearly independent paths

will be displayed on main page.

Figure 4: Screenshot of displayed CFG

This program works for:

For loop

If statement

If - else – for

For - if

Nested if

If statement (with two conditions)

Switch case

Page 8: Software Verification, Validation and Testing

5

5. Test Cases:

5.1 Program: For Loop

main()

{

int i;

for(i=0;i<=3;i++)

{

print i;

}

}

Control Flow Graph 1:

Figure 5: CFG for For loop

Page 9: Software Verification, Validation and Testing

6

Screenshot 1:

Figure 6: Screenshot of CFG for For loop

Page 10: Software Verification, Validation and Testing

7

5.2 Program: If (Alterations)

main()

{

int a, b;

if(a<=b)

{

print a;

}

else

{

print b;

}

}

Control Flow Graph 2:

Figure 7: CFG for If

Page 11: Software Verification, Validation and Testing

8

Screenshot 2:

Figure 8: Screenshot of CFG for If

Page 12: Software Verification, Validation and Testing

9

5.3 Program: If - else - for

main()

{

if (a<=b)

Print a;

else

for(i=0;i<=3;i++)

{

print i;

}

}

Control Flow Graph 3:

Figure 9: CFG for If – else- for

Page 13: Software Verification, Validation and Testing

10

Screenshot 3:

Figure 10: Screenshot of CFG for If – else- for

Page 14: Software Verification, Validation and Testing

11

5.4 Program: Nested if

main()

{

int a, b;

if(a<=b)

{

if(a<=b)

{ print a;

}

else

{ print b;

}

}

else

{

print b;

}

}

Control Flow Graph 4:

Figure 11: CFG for Nested if

Page 15: Software Verification, Validation and Testing

12

Screenshot 4:

Figure 12: Screenshot of CFG for Nested if

Page 16: Software Verification, Validation and Testing

13

5.5 Program: If-for

main()

{

int a,b,i;

if (a<=b)

{

for(i=0;i<=3;i++)

{

print i;

}

}

}

Control Flow Graph 5:

Figure 13: CFG for if-for

Page 17: Software Verification, Validation and Testing

14

Screenshot 5:

Figure 14: Screenshot of CFG for if-for

Page 18: Software Verification, Validation and Testing

15

5.6 Program: If with two conditions

main()

{

int a, b;

if(a<b && a==b)

{

print a;

}

else

{

print b;

}

}

Control Flow Graph 6:

Figure 15: CFG for If with two conditions

Page 19: Software Verification, Validation and Testing

16

Screenshot 6:

Figure 16: Screenshot of CFG for If with two conditions

Page 20: Software Verification, Validation and Testing

17

5.7 Program: Switch Case

void main()

{

int i=10;

switch(i)

{

case 1:

print i++;

break;

case 2:

print i--;

break;

default:

print i;

}

}

Control Flow Graph 7:

Page 21: Software Verification, Validation and Testing

18

Figure 17: CFG for switch

Screenshot 7:

Figure 18: Screenshot of CFG for switch

Page 22: Software Verification, Validation and Testing

19

6. Test Cases

1. To generate the test cases by applying various testing methods to the switch case

program.

CASES (i): 1<= i<=5

1. View marks

2. Update marks

3. Add marks

4. Delete marks

5. Find marks

Marks (m): 0<=m<=100

Roll_No. (r): 1<=r<=30

A) Equivalence Class Testing Methods:

1. Weak Normal Equivalence Class Testing:

Test Case Options(i) Marks(m) Roll_No.(r)

T1 3 15 60

2. Strong Normal Equivalence Class Testing:

The test case of this class is same as weak normal equivalence class testing

because there are no any subintervals (No equivalence class).

3. Weak Robust Equivalence Class Testing:

Test Case Options(i) Roll_No.(r) Marks(m)

T2 0 15 60

T3 6 15 60

T4 3 0 60

T5 3 31 60

T6 3 15 -1

T7 3 15 101

4. Strong Robust Equivalence Class Testing:

Test Case Options(i) Roll_No.(r) Marks(m)

T10 0 0 60

T11 6 31 60

T12 0 15 -1

T13 6 15 101

T14 3 0 -1

T15 3 31 101

Page 23: Software Verification, Validation and Testing

20

T16 0 0 -1

T17 6 31 101

5. Robust Mixed Equivalence Class Testing: Combine invalid values with other

valid values.

Test Cases= Max (1, 1, 1) + 6 = 7

[-∞, 1) (5, ∞] =2

[-∞, 1) (30, ∞)= 2

[-∞, 0) (100, ∞]= 2

Test Case Options(i) Roll_No.(r) Marks(m)

T1 3 15 60

T2 0 0 -1

T3 0 0 101

T4 0 31 -1

T5 0 31 101

T6 6 0 -1

T7 6 0 101

T8 6 31 -1

T9 6 31 101

B) Boundary Value Testing Methods:

6. Boundary Value Analysis:

Test Case Options(i) Roll_No.(r) Marks(m)

T1 3 15 0

T2 3 15 1

T3 3 15 60

T4 3 15 99

T5 3 15 100

T6 3 1 60

T7 3 2 60

T8 3 29 60

T9 3 30 60

T10 1 15 60

T11 2 15 60

T12 4 15 60

T13 5 15 60

Page 24: Software Verification, Validation and Testing

21

7. Robustness Testing:

It includes min-, min, min+, nom, max-, max, max+ for any one variable and for

other variables, it takes only nominal value. It adds four more test cases in

boundary value analysis.

Test Case Options(i) Roll_No.(r) Marks(m)

T1 3 15 -1

T2 3 15 0

T3 3 15 1

T4 3 15 60

T5 3 15 99

T6 3 15 100

T7 3 15 101

T8 3 0 60

T9 3 1 60

T10 3 2 60

T11 3 29 60

T12 3 30 60

T13 3 31 60

T14 0 15 60

T15 1 15 60

T16 2 15 60

T17 4 15 60

T18 5 15 60

T19 6 15 60

8. Worst Case Testing: In this testing the cases are generated by making the valid

combinations ( min, min+, nom, max-, max,) of options, roll_no and marks,

basically it is a Cartesian product of i, m and r.

{imin}{rmin, rmin+, rnom, rmax-, rmax}{mmin, mmin+, mnom, mmax-,

mmax}=25

{imin+}{rmin, rmin+, rnom, rmax-, rmax}{mmin, mmin+, mnom, mmax-,

mmax}=25

{inom}{rmin, rmin+, rnom, rmax-, rmax}{mmin, mmin+, mnom, mmax-,

mmax}=25

{imax-}{rmin, rmin+, rnom, rmax-, rmax}{mmin, mmin+, mnom, mmax-,

mmax}=25

{imax}{rmin, rmin+, rnom, rmax-, rmax}{mmin, mmin+, mnom, mmax-,

mmax}=25

Total Test Cases= 25+25+25+25+25= 125

9. Robust Worst Case Testing: In this testing the cases are generated by making

the valid and invalid combinations (min-, min, min+, nom, max-, max,max+) of

options, roll_no and marks, basically it is a Cartesian product of i, m and r.

Page 25: Software Verification, Validation and Testing

22

{imin-}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{imin}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{imin+}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{inom}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{imax-}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{imax}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

{imax+}{rmin-, rmin, rmin+, rnom, rmax-, rmax, rmax+}{mmin-, mmin, mmin+,

mnom, mmax-, mmax, mmax+}=49

Total Test Cases= 49*7= 343

10. Weak Diagonal In Boundary Value Testing:

Test Case Options(i) Roll_No.(r) Marks(m)

T1 1 1 0

T2 2 2 1

T3 3 15 60

T4 4 29 99

T5 5 30 100

11. Weak In Boundary Value Testing: (min, min+, nom, max-,max)

Test Case Options(i) Roll_No.(r) Marks(m)

T1 3 15 0

T2 3 15 1

T3 3 15 60

T4 3 15 99

T5 3 15 100

T6 3 1 60

T7 3 2 60

T8 3 29 60

T9 3 30 60

T10 1 15 60

T11 2 15 60

T12 4 15 60

T13 5 15 60

12. Weak Out Boundary Value Testing: (min-, min+, nom, max-,max+)

Test Case Options(i) Roll_No.(r) Marks(m)

Page 26: Software Verification, Validation and Testing

23

T1 3 15 -1

T2 3 15 1

T3 3 15 60

T4 3 15 99

T5 3 15 101

T6 3 0 60

T7 3 2 60

T8 3 29 60

T9 3 31 60

T10 0 15 60

T11 2 15 60

T12 4 15 60

T13 6 15 60

13. Weak Simple Out Boundary Value Testing: (min-, min+, max-,max+)

Test Case Options(i) Roll_No.(r) Marks(m)

T1 3 15 -1

T2 3 15 1

T3 3 15 99

T4 3 15 101

T5 3 0 60

T6 3 2 60

T7 3 29 60

T8 3 31 60

T9 0 15 60

T10 2 15 60

T11 4 15 60

T12 6 15 60

14. Weak Simple Out Boundary Value Testing:

Test Case Options(i) Roll_No.(r) Marks(m)

T1 1 1 0

T2 1 1 100

T3 1 30 0

T4 1 30 100

T5 5 1 0

T6 5 1 100

T7 5 30 0

T8 5 30 100

T9 2 2 1

T10 2 2 99

T11 2 29 10

T12 2 29 99

T13 4 2 1

T14 4 2 99

T15 4 29 1

Page 27: Software Verification, Validation and Testing

24

T16 4 29 99

T17 3 15 60

2. To generate the test cases by applying various testing methods to the insertion

sort program.

The Maximum number (M) user can enter = 50

The Range (R) of number that is entered by user = 1 to 1000

1<=M<=50 and 1<=R<=1000

A) Equivalence Class Testing Methods:

1. Weak Normal Equivalence Class Testing:

Test case Maximum number (M) Range (R)

T1 30 550

2. Strong Normal Equivalence Class Testing:

The test case of this class is same as weak normal equivalence class testing

because there are no any subintervals (No equivalence class).

3. Weak Robust Equivalence Class Testing:

Test case Maximum number (M) Range (R)

T2 0 550

T3 51 550

T4 25 0

T5 25 1001

4. Strong Robust Equivalence Class Testing:

Test case Maximum number (M) Range (R)

T6 0 0

T7 51 1001

5. Robust Mixed Equivalence Class Testing:

Max (1, 1) + 4= 5

[-∞, 1) (50, ∞] = 2 and [-∞, 1) (1000, ∞] = 2

Test case Maximum number (M) Range (R)

T1 25 550

T2 0 0

Page 28: Software Verification, Validation and Testing

25

T3 0 1001

T4 51 0

T5 51 1001

B) Boundary Value Testing Methods:

6. Boundary Value Analysis:

Test Case Maximum number (M) Range (R)

T1 1 550

T2 2 550

T3 30 550

T4 49 550

T5 50 550

T6 30 1

T7 30 2

T8 30 999

T9 30 1000

7. Robustness Testing:

It includes min-, min, min+, nom, max-, max, max+ for any one variable and for

other variables, it takes only nominal value. It adds four more test cases in

boundary value analysis.

Test Case Maximum number (M) Range (R)

T1 0 550

T2 1 550

T3 2 550

T4 30 550

T5 49 550

T6 50 550

T7 51 550

T8 30 0

T9 30 1

T10 30 2

T11 30 999

T12 30 1000

T13 30 1001

8. Worst Case Testing: In this testing the cases are generated by making the valid

combinations ( min, min+, nom, max-, max,) of Maximum number (M) and

Range (R), basically it is a Cartesian product of M and R.

Page 29: Software Verification, Validation and Testing

26

{Mmin}{Rmin, Rmin+, Rnom, Rmax-, Rmax}= 5

{Mmin+}{Rmin, Rmin+, Rnom, Rmax-, Rmax}= 5

{Mnom}{Rmin, Rmin+, Rnom, Rmax-, Rmax}= 5

{Mmax-}{Rmin, Rmin+, Rnom, Rmax-, Rmax}= 5

{Mmax}{Rmin, Rmin+, Rnom, Rmax-, Rmax}= 5

Total Test Cases= 5+5+5+5+5= 25

9. Robust Worst Case Testing: In this testing the cases are generated by making

the valid and invalid combinations (min-, min, min+, nom, max-, max, max+) of

Maximum number (M) and Range (R), basically it is a Cartesian product of of M

and R.

{Mmin-}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mmin}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mmin+}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mnom}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mmax-}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mmax}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

{Mmax+}{ Rmin-, Rmin, Rmin+, Rnom, Rmax-, Rmax, Rmax+}= 7

Total Test Cases= 7*7= 49

10. Weak Diagonal In Boundary Value Testing:

Test Case Maximum number (M) Range (R)

T1 1 1

T2 2 2

T3 30 550

T4 49 999

T5 50 1000

11. Weak In Boundary Value Testing: (min, min+, nom, max-,max)

Test Case Maximum number (M) Range (R)

T1 30 1

T2 30 2

T3 30 550

T4 30 999

T5 30 1000

T6 1 550

T7 2 550

T8 49 550

T9 50 550

Page 30: Software Verification, Validation and Testing

27

12. Weak Out Boundary Value Testing:

Test Case Maximum number (M) Range (R)

T1 30 0

T2 30 1

T3 30 550

T4 30 1000

T5 30 1001

T6 0 550

T7 1 550

T8 50 550

T9 51 550

13. Weak Out Boundary Value Testing: (No nominal case)

Test Case Maximum number (M) Range (R)

T1 30 0

T2 30 1

T3 30 1000

T4 30 1001

T5 0 550

T6 1 550

T7 50 550

T8 51 550

14. Robust Weak Boundary Value Testing:

Test Case Maximum number (M) Range (R)

T1 0 550

T2 1 550

T3 2 550

T4 30 550

T5 49 550

T6 50 550

T7 51 550

T8 30 0

T9 30 1

T10 30 2

T11 30 999

T12 30 1000

T13 30 1001

15. Robust Weak Simple Boundary Value Testing:

Test Case Maximum number (M) Range (R)

Page 31: Software Verification, Validation and Testing

28

T1 0 550

T2 1 550

T3 2 550

T4 49 550

T5 50 550

T6 51 550

T7 30 0

T8 30 1

T9 30 2

T10 30 999

T11 30 1000

T12 30 1001

16. Weak Corner In Boundary Value Testing:

Test Case Maximum number (M) Range (R)

T1 1 1

T2 2 2

T3 49 2

T4 50 1

T5 30 550

T6 1 1000

T7 2 999

T8 49 999

T9 50 1000

17. Robust Corner Out Boundary Value Testing:

Test Case Maximum number (M) Range (R)

T1 1 1

T2 50 1

T3 1 1000

T4 50 1000

T5 0 1

T6 1 0

T7 51 1

T8 50 0

T9 0 1000

T10 1 1001

T11 50 1001

T12 51 1000

Page 32: Software Verification, Validation and Testing

29

3. Decision Table Based Testing:

In a university, teacher assign grade on the basis of percentage and an attendance. If

absents are more than five then then original grades (based on only percentage) will

be shifted by one (ex: A to B). If any student have already F grade then it remains

same. Grades are basis on following criteria:

Percentage (P)

Grade (G)

P>=90 A

80<= P<90 B

70<= P<80 C

60<= P<70 D

33<= P<60 E

P<33 F

Conditions:

C1: Absent <=5

C2: P>=90

C3: 80<= P<90

C4: 70<= P<80

C5: 60<= P<70

C6: 33<= P<60

C7: P<33

R: Rules

Page 33: Software Verification, Validation and Testing

30

Rules R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12

Conditions:

C1 Y Y Y Y Y Y N N N N N N

C2 Y Y

C3 Y Y

C4 Y Y

C5 Y Y

C6 Y Y

C7 Y Y

Actions:

A √ B √ √ C √ √ D √ √ E √ √ F √ √ √