Tutorial Example

The following example shows how to use Testwell CTC++ in a simplified case. It works completely on command-line.

We use a program to role a dice. The file dice.c contains everything. You find this example also in the \Examples directory of Testwell CTC++.

Note: You need a console and an environment allowing calls to a C compiler. In this tutorial, Microsoft's Visual Studio compiler cl is used with the developer command prompt.
Without coverage measurement,
cl dice.c
results in a program dice.exe.

To measure code coverage for dice, you need to instrument the source file during compilation. On this basic level, this is done with the tool ctc.

Pass the compiler command to ctc:
ctc -i m cl dice.c

The option -i m sets the instrumentation mode to multicondition coverage.

The program dice is built again in an instrumented version. A symbol file MON.sym is generated by ctc, containing a description of the instrumentation probes ctc adds to the source code.

Every execution of dice rolls a virtual dice twice, leading to an output like:
| Coverage by Dicing - Hello! |
  | o     |
  |   o   |
  |     o |
  | o   o |
  | o   o |
  | o   o |

With the first execution, a data file called MON.dat is created. It containins the coverage counters collected during execution. If this file already exists, it is updated.

Now you can generate the first coverage report with ctcreport:
ctcreport -html S

By default, MON.sym and MON.dat are used as input. The source code is also used. With option -html S, a layout suitable for this small project in one folder is chosen for the HTML report.

The report is opened in your standard browser and written to the default folder CTC-HTML-REPORT. The overview page looks like

MC/DC and statement coverage are displayed by default for multicondition instrumentation. You can drill down to the source code view on the file and on each function line.

If you execute dice again and generate the report again, the coverage increases - in this example, only by chance.