Developer(s) | Oracle Corporation |
---|---|
Operating system | Solaris |
Type | Code Coverage |
License | Free for download and use as described in the Sun Studio product license. |
Website | developers.sun.com |
Tcov is a source code coverage analysis and statement-by-statement profiling tool for software written in Fortran, C and C++. Tcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. It is a standard utility, provided free of cost with Sun Studio software under Sun Studio product license.
The tcov utility gives information on how often a program executes segments of code. It produces a copy of the source file, annotated with execution frequencies. The code can be annotated at the basic block level or the source line level. As the statements in a basic block are executed the same number of times, a count of basic block executions equals number of times each statement in the block is executed. The tcov utility does not produce any time-based data.
tcov produces a test coverage analysis of a compiled program. tcov takes source files as arguments and produces an annotated source listing. Each basic block of code (or each line if the particular option to tcov is specified) is prefixed with the number of times it has been executed; lines that have not been executed are prefixed with "#####".
The tcov utility also places a summary at the end of the annotated program listing. The statistics for the most frequently executed basic blocks are listed in order of execution frequency. The line number is the number of the first line in the block.
There are two implementations of tcov:
Enhanced coverage analysis overcomes some of the shortcomings of the original analysis tool, such as:
To generate annotated source code, following three steps are required:
Each subsequent run accumulates more coverage data into the profile data file. Data for each object file is zeroed out the first time the program is executed after recompilation. Data for the entire program is zeroed by removing the tcovd file.
The above steps are explained for both original and enhanced tcov below:
Source code is compiled with -xa option for C program and -a option for Fortran and C++ programs. The compiler creates a coverage data file with the suffix .d for each object file. The coverage data file is created in the directory specified by the environment variable TCOVDIR. If TCOVDIR is not set, the coverage data file is created in the current directory. The above instrumented build is run and at program completion, the .d files are updated. Finally, tcov command is run to generate the annotated source files. The syntax of the tcov command is as follows: