CoverageScanner is a C++ program that—in effect—replaces the usual compiler. It uses the native compiler's preprocessor program to process the source code, then inserts instrumentation code into the preprocessed program, and at the end it compiles and links the project file, in the same way as in a normal build.
CoverageScanner's instrumentation process consists of:
- declaring a static table that contains the instrumentation results.
- generating a library which produces an execution report when the program terminates or receives a UNIX® signal or a Microsoft® Windows event.
- adding the instrumentation code itself for each relevant statement or Boolean expression.
The compiler, linker and preprocessor that are used are from the native environment (gcc, Visual Studio, etc.). The Coco tools are used transparently and the developer has only to prepend
cs to the name of the compiler executable to activate the code coverage. For example, using
csgcc instruments the source code and uses the
gcc compiler to generate objects.
Note: For Microsoft Visual Studio®, an additional wrapper is provided which directly uses the Microsoft
link (see Microsoft Visual Studio.)
Another way to achieve coverage is to add a wrapper directory to the search path. It contains compiler wrappers with the same name as the native tools. They are disabled by default but can be switched on with help of the
COVERAGESCANNER_ARGS environment variable.
CoverageScanner works like a preprocessor which calls the native compiler (Microsoft
g++, and so on) after instrumenting a source file.
Several invocation methods are possible:
- Using a dedicated CoverageScanner executable for a specific compiler: CoverageScanner executable for a specific compiler is named
cs-<native compiler name>or
<native compiler name-cs. For example,
cl.exeis the Microsoft C++ compiler and the corresponding CoverageScanner executable is
CoverageScanner aims to work like the native compiler with the difference that the code get instrumented.
csg++ source.cpp -o application.exe
- Using CoverageScanner compiler wrapper and activating the instrumentation using
--cs-onin the command line arguments:
Coco provides a replacement of the native compiler called wrapper which extends its command line arguments to support the code coverage feature. To use it, add to the first position of the PATH variable, the path of the CoverageScanner wrapper. The instrumentation gets activated when adding
--cs-onto the command line argument.
export PATH=/opt/SquishCoco/wrapper/bin:$PATH g++ --cs-on source.cpp -o application.exe
Or, without modifying globally the
PATH=/opt/SquishCoco/wrapper/bin:$PATH g++ --cs-on source.cpp -o application.exe
- Using CoverageScanner compiler wrapper and activating the instrumentation through the
It is also possible to set the command line arguments of the wrapper using the
COVERAGESCANNER_ARGSenvironment variable. In this case it is no longer necessary to modify the command line arguments.
export PATH=/opt/SquishCoco/wrapper/bin:$PATH export COVERAGESCANNER_ARGS='--cs-on' g++ source.cpp -o application.exe
Or, to instrument a complete project built using GNU
COVERAGESCANNER_ARGS='--cs-on' PATH=/opt/SquishCoco/wrapper/bin:$PATH make all
--cs-compilercommand line option of CoverageScanner:
--cs-compilerspecifies which native compiler should be used. All other command line arguments, except those specific to CoverageScanner, are passed through to the native compiler.
coveragescanner --cs-compiler=g++ source.cpp -o application.exe
Note: The native compiler path needs to appear in the
PATH variable, after the path to the compiler wrappers. This is necessary for finding the location of the native compiler after insertion of the instrumentation code.
Compiler support is done with the help of a profile. It contains declarations which make it possible to adapt CoverageScanner to C, C++ and C# preprocessors, compilers and linkers. For a description of the profile syntax see CoverageScanner adaptation to a tool suite.
Coco v7.0.0 ©2023 The Qt Company Ltd.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.