Skip to content

sonar.cxx.ctctxt.reportPaths

guwirth edited this page Mar 10, 2021 · 5 revisions

Overview

Sensor to read reports from the Testwell CTC++ coverage tool. Testwell CTC++ is a leading Code Coverage Tool for measuring Code Coverage on host and all embedded targets (even very small ones). The tool is compliant to Safety Standards. Testwell CTC++ is a good choice for companies which have to achieve and to proof high code coverage in aerospace, automotive, transportation, healthcare and other industries. Testwell CTC++ integrates with build and test infrastructure through a full command line interface.

Note: The cxx plugin itself does not run the tool, you have to do that yourself beforehand. The sensor only reads the report generated by the tool!

Supported versions

Create report

In order to run Testwell CTC++ and generate a fitting report, make sure:

  • to call it from the projects root directory, so that the paths in the report fit
  • that the parameter matches the sonar.sources list in sonar-project.properties

Suppose we have the following source files that form a complete program: src1.c src2.c. This program can be compiled and linked in many ways, two ways being the following resulting in the sample.exe:

cl –Fe"sample.exe" src1.c src2.c
gcc -o prime prime.c io.c calc.c

Now, we wish to apply Testwell CTC++ on our program, that is, we want to measure the files src1.c src2.c and find out how thoroughly they were exercised in our test runs. First we need to instrument the files we wish to measure. Assume we wish to measure multicondition coverage. This can be done as follows:

ctc -i m cl –Fe"sample.exe" src1.c src2.c
ctc -i m gcc -o sample src1.c src2.c

As a result we get the instrumented sample.exe program. Here ctc is the Testwell CTC++ Preprocessor utility, which makes the instrumentation on the given C and C++ source files and drives compiling/linking of the new instrumented target. The -i m command-line options to ctc mean "instrument for multicondition".

When ctc instruments source files, it maintains descriptions what the files contain (what interesting code there is to ctc, on what lines, etc.). This file is called symbolfile, and when it is not specified (like here) it will be MON.sym in current directory.

After a test run we notice that the file MON.dat has born in the current directory (same directory as the symbolfile MON.sym was created to). It is a datafile, containing the collected execution counters when the code in the instrumented files was executed.

Now we wish to see the results of our test, i.e. what parts of the program the above run has executed. We use the Testwell CTC++ Postprocessor utility ctcpost that takes the symbolfile MON.sym and the datafile MON.dat as input and produces an Execution Profile Listing to the file profile.txt.

ctcpost MON.sym MON.dat -p profile.txt

Example of a report file

If the tool was executed successfully, a report like the example below should be generated:

*****************************************************************************
*           CTC++, Test Coverage Analyzer for C/C++, Version 8.1            *
*                                                                           *
*                         EXECUTION PROFILE LISTING                         *
*                                                                           *
*                    Copyright (c) 1993-2013 Testwell Oy                    *
*             Copyright (c) 2013-2016 Verifysoft Technology GmbH            *
*****************************************************************************

Symbol file(s) used   : Sample\MON.sym (Wed Mar 15 11:11:37 2017)
Data file(s) used     : Sample\MON.dat (Wed Mar 15 11:11:48 2017)
Listing produced at   : Wed Mar 15 11:11:48 2017
Coverage view         : As instrumented

MONITORED SOURCE FILE : Sample.cpp
INSTRUMENTATION MODE  : multicondition

 HITS/TRUE      FALSE    LINE DESCRIPTION
=============================================================================

        10                 42 FUNCTION sample()
        10          0 -    50   if (success)
                           54   }+
         7          3      56   if (success)
         6          1      58     if (myDir . exists ( ))
                           62     }+
                           63     else
                           68     }+
                           69   }+
         3          7      71   if (! success)
                           75   }+
        10                 77   return success
                           78 }

***TER  90 % (  9/ 10) of FUNCTION sample()
       100 % ( 12/ 12) statement
-----------------------------------------------------------------------------


***TER  90 % (  9/ 10) of FILE Sample.cpp
       100 % ( 12/ 12) statement
-----------------------------------------------------------------------------

Configure cxx plugin

  1. First check if the file extensions read in by the cxx plugin are set (sonar.cxx.file.suffixes).
  2. Set the analysis parameter sonar.cxx.ctctxt.reportPaths in the configuration file sonar-project.properties of your project. The Report Paths link describes the configuration options.
  3. Normally the File Encoding is UTF-8. Use the parameter sonar.cxx.ctctxt.encoding to use another one.
  4. Execute the SonarScanner to transfer the project with the report to the SonarQube Server.

Sample for sonar-project.properties:

sonar.cxx.ctctxt.encoding=UTF-8
sonar.cxx.ctctxt.reportPaths=profile.txt

Troubleshooting

Clone this wiki locally