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++.
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.
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.
===============================
| 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.
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.