0% found this document useful (0 votes)
82 views3 pages

Exercise 1 Software Engineering Virtual Lab - IIT Kharagpur

Ex1 Software Engineering Virtual Lab — IIT Kharagpur

Uploaded by

Tasneem khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views3 pages

Exercise 1 Software Engineering Virtual Lab - IIT Kharagpur

Ex1 Software Engineering Virtual Lab — IIT Kharagpur

Uploaded by

Tasneem khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Home Credits Feedback Advanced Network Technologies Virtual Lab Virtual Labs

Estimation of Test Coverage Metrics and Structural


Complexity

Introduction Theory Simulation Case Study Self-evaluation Procedure Exercises References

Select 1

Identification of basic blocks from a program and determining it's cyclomatic complexity

Consider the following simple C program.

01 // Sum of first n natural numbers (not in the best possible way though)
02
03 #include <stdio.h>
04
05 int
06 main(int argc, char **argv)
07 {
08 int i;
09 int sum;
10 int n = 10;
11
12 sum = 0;
13 for (i = 1; i <= n; i++)
14 sum += i;
15
16 printf("Sum of first %d natural numbers is: %d\n", n, sum);
17
18 return 0;
19 }

Any sequence of instructions in a program could be represented in terms of basic blocks, and a CFG could be drawn using those
basic blocks. For the given C program:

1. Identify the basic blocks and verify whether your representation matches with the output produced after compiling your
program
2. Draw a Control Flow Graph (CFG) using these basic blocks. Again, verify how the CFG generated after compilation relates to
the basic blocks identified by the compiler
3. Calculate McCabe's complexity from the CFG so obtained

Note that gcc translates the high-level program into an intermediate representation using GIMPLE. So, the CFG generated from your
code would not show the actual instructions.

Learning Objectives:

Identify the basic basic blocks for a given program


Draw a CFG using the basic blocks
Determination of McCabe's complexity from a CFG

Limitations: The current workspace can generate CFGs only for the main function. In other words, this would not work with user-
defined functions. However, in real life a program would contain several modules. All such modules have to be taken into account
while determining the complexity.

Submit

Write the C program below


10 pt

1 #include <stdio.h>
2
3 int
4
5 main(int argc, char **argv) {
6
7 int i;
8
9 int sum;
10
Position: Ln 21, Ch 11 Total: Ln 21, Ch 183 resize

Compile program (gcc -c -fdump-tree-vcg -fdump-tree-cfg test.c)

Compilation error (if any)

Program representation in terms of Basic Blocks

;; Function main (main)

Merging blocks 5 and 6


main (int argc, char * * argv)
{
int n;
int sum;
int i;
int D.2055;
const char * restrict D.2054;

<bb 2>:

Control Flow Graph of the program


Result

Sponsored by MHRD (NME-ICT) | Licensing Terms | Disclaimer Except otherwise noted, content on
this site is licensed under the CC-BY-
Copyright © 2010-2016 IIT Kharagpur NC-SA-3.0 License. See details.

You might also like