Use the tca
command to analyze test coverage data. Code must be included when the application runs to be considered for coverage. If code is linked to an executable that is never executed, for example, then it is ignored by Insure++. Coverage data has several summary levels,but we'll introduce the following in this section:
Overall Summary
The overall summary (default) shows the percentage of coverage at the application level. It is summed over all program entities. To view the overall summary, execute the following command:
tca tca.log
The following top level summary is displayed.
COVERAGE SUMMARY ================ 1 block untested 12 blocks tested 92% covered
The overall coverage is high in this example, but one program block remains untested.
Function Summary
Use the -df
switch to access the function summary. This summary helps you find out which program block is untested by displaying the coverage of each individual function in the application. For example:
tca -df tca.log
This command displays the function level summary, including functions that are 100% tested.
COVERAGE SUMMARY - by function ================ blocks blocks %cov = functions untested tested %tested ------------------------------------------------- 0 4 100% bubble_sort [strsort.c, line 7-13] 1 8 88% main [strsort.c, line 26-45]
The summary shows that the bubble_sort
function is completely tested, but that one block in main
remains untested.
Source Code Summary
Use the -ds
switch to access the source code summary. For example:
tca -ds tca.log
This summary outputs the source code with each block marked with an execution status. Executed blocks are marked with a period (.
) Unexecuted blocks are marked with an exclamation point (!
).
UNTESTED BLOCKS - by file =============== FILE strsort.c 92% covered: 1 untested / 12 tested /* * File: strsort.c */ #include <stdio.h> #include <string.h> bubble_sort(a, n, dir) char **a; int n, dir; { int i, j; . -> for(i=0; i<n; i++) { . -> for(j=1; j<n-i; j++) { . -> if(dir * strcmp(a[j-1], a[j]) > 0) { char *temp; . -> temp = a[j-1]; a[j-1] = a[j]; a[j] = temp; } } } } main(argc, argv) int argc; char **argv; { int i, dir, length, start; . -> if (argc > 1 && argv[1][0] == '-') { . -> if (argv[1][1] == 'a') { . -> dir = 1; length = argc-2; start = 2; . -> } else if (argv[1][1] == 'd') { . -> dir = -1; length = argc-2; start = 2; } } else { ! -> dir = 1; length = argc; start = 1; } . -> bubble_sort(argv+start, length, dir); for (i = 2; i < argc; i++) . -> printf("%s ", argv[i]); . -> printf("\n"); return 0; }
This listing shows exactly which statements have been executed and which have not. The results show that the untested block corresponds to the case where strsort
is executed with neither the -a
nor -d
command line switches.