NA-MIC-kit-curriculum/Testing-Based Programming/How to run Code Coverage

From NAMIC Wiki
Revision as of 15:52, 12 December 2009 by Ibanez (talk | contribs) (→‎Method 1)
Jump to: navigation, search
Home < NA-MIC-kit-curriculum < Testing-Based Programming < How to run Code Coverage

Introduction

Overview

This tutorial shows how to run Code Coverage in your project.

Code coverage is a mechanism for counting the number of lines of code that are exercised during the execution of your tests.

Prerequisite

You should read first the tutorial:

You should also have installed the package

 gcov

this is usually installed along with your gcc package

Configuring the Test

In the project that you built in the previous tutorial, do

 cd ${BINARY_DIR}
 make edit_cache

Enable Debug

Then search for the variable

 CMAKE_BUILD_TYPE

and set it to the word "Debug"


Set Coverage Options

  1. Pass to the advanced mode by hitting the "t" key
  2. Hit the "/" key in order to start a search
  3. Type CXX_FLAGS
  4. Hit the ENTER key to start editing the flags
  5. add the following test: -g -O0 -fprofile-arcs -ftest-coverage
  6. Hit the ENTER key to exit editing
  7. Hit the "/" key in order to start a search
  8. Type C_FLAGS
  9. Hit the ENTER key to start editing the flags
  10. add the following test: -g -O0 -fprofile-arcs -ftest-coverage
  11. Hit the ENTER key to exit editing
  12. Hit the "c" key to configure
  13. Hit the "g" key to generate and quit

Running the Test

Method 1

In order to run the tests that generate code coverage you can do the following

  cd ${BINARY_DIR}
  make ExperimentalStart
  make ExperimentalConfigure
  make ExperimentalBuild
  make ExperimentalTest
  make ExperimentalCoverage

The final output will look like:

  Site: macondo
  Build name: Linux-g++-4.4
  Performing coverage
  Processing coverage (each . represents one file):
  .
  Acumulating results (each . represents one file):
   .
       Covered LOC:         6
       Not covered LOC:     0
       Total LOC:           6
       Percentage Coverage: 100.00%
   Built target ExperimentalCoverage