Squish Coco

Code Coverage Measurement for Tcl, C# and C/C++

Squish Coco-Code Coverage Tool for Tcl, C# and C/C++

Squish Coco is a complete code coverage tool chain for Tcl, C# and C/C++ programs that runs on Apple® MacOSX, Linux and Microsoft® Windows. It analyzes the performance of an application being exercised (e.g., by a test suite), to reveal important information that can improve the testing of Tcl, C# and C/C++ applications. In particular, Squish Coco can:

  • Find untested code sections.
  • Find redundant tests which can then be eliminated.

    Squish Coco makes it possible to identify which portions of the source code are covered by a test, and to detect whether a new test covers source code lines that the existing tests don’t cover.

  • Find dead code by displaying code that is never executed.
  • Calculate the optimum test execution order so as to maximize test coverage for each run. This is particularly useful for manual testing.
  • Analyse two separate versions of an application and compare the differences.

    This feature makes it possible to see which tests are affected by source code modifications and also to get some measure of the test coverage of a patch or hot fix.

Squish Coco can be used at every stage of testing and for all testing methodologies (unit tests, automatic tests, manual white box tests, black box tests, etc…), and makes it possible to merge multiple execution reports into a single unified report.

The Squish Coco package provides two separate tools and an add-in:

  1. CoverageScanner—this analyzes, instruments and generates the Tcl, C# and C/C++ application.
  2. CoverageBrowser—this displays and manages the results of the coverage analysis.
  3. Microsoft® Visual Studio®Add-In—this is an optional add-in which makes it possible to generate code coverage configurations for every Tcl, C# and C/C++ project created by Microsoft® Visual Studio®.
Figure 1: Overview of Code Coverage Toolchain for Tcl, C# and C/C++

CoverageScanner—Instrumentation during the Generation

CoverageScanner instruments the source code seen by the compiler (leaving the original code untouched) and generates an instrumented executable, shared library, or plugin. The instrumentation keeps track of the code that is executed when the executable is run or when the library or plugin are used (e.g., how many times each line is executed, or simply whether a line was executed) and produces an execution report (.csexe file) upon program termination. In order to get the best quality of code coverage metrics, CoverageScanner instruments not only at the function and statement level, but also records statement coverage and decision coverage information. Optionally, it is also possible to insert the test name and its execution status (passed or failed) into the report using a batch script or directly in the application itself. This makes it possible to integrate CoverageScanner into a test framework (e.g., CppUnit or CxxTest), with the generation of the code coverage information for each test item.

CoverageScanner is a command line tool which substitutes itself for the the compiler that is normally used to build the executable, library, or plugin. Its main function is to insert instrumentation instructions into the preprocessed source code and then to compile this modified code in place of the original code using the normal compiler. CoverageScanner works with almost any standard compiler, including GNU gcc, GNU g++, Microsoft® Visual Studio® 6.0, .NET, Express, and Embedded C++, Intel® C++, etc. A database (.csmes file), which contains the list of instrumentations and a copy of the instrumented source code, is generated at the same time for later analysis. CoverageScanner’s ability to work with most compilers is because it can be configured to suit most compilers’ needs.

After the code generation, the instrumented executable can be run as usual (or the instrumented library or plugin used via the program that accesses them)—this will result in an execution report being produced (in a .csexe file) when the program terminates.

Info CoverageScanner has built-in support for QtLibrary which makes it possible to prevent the instrumentation of code generated by the moc.

CoverageBrowser—View, Analyse, and Manage, Code Coverage Results

The execution report (in the .csexe file) can be analyzed and managed using the CoverageBrowser tool. This tool has a GUI (graphical user interface) through which the user can browse and manage their execution reports. This makes it straightforward to locate untested code, dead code, and inefficient tests.

CoverageBrowser’s highlights:

  • Commenting instrumented source code lines.
  • Displaying the list of executions in a tree view.
  • Managing portions of code which cannot be tested by identifying them as “Manually Validated”.
  • Browsing through the instrumented code.
  • Switching between code coverage condition and code coverage branch analysis.
  • Displaying a detailed explanation of the state of the instrumentation. This includes:
    • User comments.
    • The state (executed, not executed, partially executed).
    • The code coverage count.
    • The list of tests executing the instrumentation.
  • Retrieving the execution status from an automated test suite.
  • Code coverage analysis of unit tests.
  • Exporting statistics to spreadsheets.
  • A test benefit analysis mode which makes it possible to see what additional code coverage a set of tests adds.
  • An API which makes it possible to control CoverageBrowser using an external Tcl, C# and C/C++application.
  • A source code and method browser which displays code coverage statistics per file, per class, per namespace, and per Tcl, C# and C/C++ function.
  • Generation of a report in HTML format, which includes statistics per source file, methods, executions, and a list of unexecuted code lines. Click here to see an example.
  • Black box testing support.
  • The ability to comparare coverage data for different versions of the software.
Figure 2: CoverageBrowser: Code Coverage Screenshot