Coverage Statistics

Coverage tools

The Picker tool supports generating code line coverage reports, and the MLVP(https://github.com/XS-MLVP/mlvp)project supports generating functional coverage reports.

Code Line Coverage

Currently, the Picker tool supports generating code line coverage reports based on the Verilator simulator.

Verilator

The Verilator simulator provides coverage support.
The implementation is as follows:

  1. Use the verilator_coverage tool to process or merge coverage databases, ultimately generating a coverage.info file for multiple DUTs.
  2. Use the genhtml command of the lcov tool based on coverage.info and RTL code source files to generate a complete code coverage report.

The process is as follows:

  1. Enable the COVERAGE feature when generating the DUT with Picker (add the -c option).
  2. After the simulator runs, a coverage database file V{DUT_NAME}.dat will be generated after dut.finalize() is called.
  3. Use the write-info function of verilator_coverage to convert it to a .info file.
  4. Use the genhtml function of lcov to generate an HTML report using the .info file and the RTL source files specified in the file.

Note: The RTL source files specified in the file refer to the source file paths used when generating the DUT, and these paths need to be valid in the current environment. In simple terms, all .sv/.v files used for compilation need to exist in the current environment, and the directory remains unchanged.

verilator_coverage

The verilator_coverage tool is used to process coverage data generated by the DUT after running .dat files. The tool can process and merge multiple .dat files and has two main functions:

  1. Generate a .info file based on the .dat file for subsequent generation of a web page report.

    • -annotate <output_dir>:Present the coverage situation in the source file in annotated form, and save the result to output_dir. The format is as follows:

      100000  input logic a;   // Begins with whitespace, because
                              // number of hits (100000) is above the limit.
      %000000  input logic b;   // Begins with %, because
                              // number of hits (0) is below the limit.
      
    • -annotate-min <count>:Specify the limit as count for the above.

  2. Combine the .dat file with the source code file, and write the coverage data in annotated form into the specified directory.

    • -write <merged-datafile> -read <datafiles>:Merge several .dat (datafiles) files into one .dat file.
    • -write-info <merged-info> -read <datafiles>:Merge several .dat (datafiles) files into one .info file.

genhtml

The genhtml provided by the lcov package can export a more readable HTML report from the .info file. The command format is: genhtml [OPTIONS] <infofiles>. It is recommended to use the -o <outputdir> option to output the results to a specified directory.

For example, in theAddr project. adder.jpg

Usage Example

If you enable the -c option when using Picker, after the simulation ends, a V{DUT_NAME}.dat file will be generated. And there will be a Makefile in the top-level directory, which contains the command to generate the coverage report.

The command is as follows:

coverage:
    ...
    verilator_coverage -write-info coverage.info ./${TARGET}/V${PROJECT}_coverage.dat
    genhtml coverage.info --output-directory coverage
    ...

Enter make coverage in the shell, which will generate coverage.info based on the generated .dat file and then use genhtml to generate an html report in the coverage directory.

VCS

Documentation for VCS is currently being finalized.

Last modified September 12, 2024: Fix typo (4b0984f)