Previous: , Up: Trace counts   [Contents][Index]


7.12.5 Coverage testing

Coverage testing is the process of finding out which parts of the code of a program are not executed during any test case, so that new test cases can be designed specifically to exercise those parts.


The first step in coverage testing a Mercury program is compiling that program with execution tracing enabled, either by using the ‘--trace deep’ option or by compiling the program in a debugging grade. The second step is to execute that program on all its test cases with coverage testing enabled. This can be done either by running the program with ‘mtc --coverage-test’, or by including one of the corresponding options (‘--coverage-test’ or ‘--coverage-test-if-exec=programname’) in the value of the ‘MERCURY_OPTIONS’ environment variable. These runs generate a set of trace counts files that can be given to the Mercury test coverage tool, the ‘mcov’ program. As usual, trace count files are named with the prefix ‘.mercury_trace_counts’ if the ‘mtc --output-file’ option is not given.


The ‘mcov’ tool is invoked with a command of the form:


mcov [-d] [-v] [-o output_file] tracecountfile1 ...

The arguments consist of one or more trace count files. The output will normally be a list of all the procedures in the program that were not executed in any of the runs that generated these trace count files. The output will go to standard output unless this is overridden by the ‘-o’ or ‘--output-file’ option.


If the ‘-d’ or ‘--detailed’ option is specified, then the output will list all the events in the program that were not executed in any of these runs. This option can thus show the unexecuted parts of the executed procedures.


If the ‘-v’ or ‘--verbose’ option is specified, then a progress message will be displayed as each file is read.


Previous: , Up: Trace counts   [Contents][Index]