Code Coverage Visualization in GitLab

Continuous Integration (CI) / Continuous Development (CD) tools such as GitLab provide post-processing features for code coverage results. For example, with the help of GitLab CI/CD, you can collect the test coverage information of your favorite testing or coverage-analysis tool and visualize them inside the file diff view of your merge requests (MRs). This will allow you to see which lines are covered by tests, and which lines still require coverage before the MR is merged. GitLab requires Cobertura format as input to be able to generate code coverage analysis reports.

Cobertura report is an .xml file that contains information about the percentage of codes covered by test cases. It helps us find the parts of code that lacks the test coverage. This format was originally developed for Java, but most coverage analysis frameworks for other languages have plugins to add support for it, like:

simplecov-cobertura (Ruby)

gocover-cobertura (Golang)

Other coverage analysis frameworks support the format out of the box, for example:

Istanbul (JavaScript) (Python)

Riviera-PRO generates the ACDB file which stands for "Aldec Code Coverage Data Base". So, Riviera-PRO users need to convert the ACDB report to Cobertura xml format to be able to utilize GitLab's visual coverage analysis feature. We have prepared a Python script to convert ACDB to Cobertura. This app note is prepared to provide more information on how to convert ACDB to Cobertura format.

How to convert ACDB into Cobertura XML

To run this app note, you will need to create a new project in GitLab followed by a file. We have covered how to create a project using GitLab and Riviera-PRO in another app note that can be found here.

GitLab uses CI/CD's artifacts reports feature to collect the coverage information. You can specify one or more coverage report to collect, including wildcard paths. This change should be applied into the .yml file. For the coverage analysis to work, you have to provide a properly formatted Cobertura XML report to artifacts:reports:cobertura. Below you can find the the .yml file content for this project.

stages:         #List of stages for jobs, and their order of execution 
build-job:      # This job runs in the build stage, which runs first. 
  stage: build
  - ci
    cobertura: cobertura.xml
    - echo "Compiling the code..."
    - vsim -c -do sr c/
    - python3 -i ucdb.xml -o cobertura.xml
    - echo "Compile complete."

The "vsim" command is called using the host machine shell environment to run "" file. You can use your own file in this project. The code below shows the .do file used in this app note.

alib work
adel -all
alog -coverage sb -coverage_options count \
  src/verilog/board.v \
  src/verilog/tbscenario1.v src/verilog/tbscenario2.v \
  src/verilog/tbscenario3.v src/verilog/tbscenario4.v
asim -acdb scenario1
run -all 
acdb save -file cov/out1/out1.acdb
asim -acdb scenario2
run -all
acdb save -file cov/out2/out2.acdb
acdb merge -i cov/out1/out1.acdb -path /scenario1/UUT -i
cov/out2/out2.acdb -path /scenario2/UUT -o
asim -acdb scenario3
run -all 
acdb save -file cov/out3/out3.acdb

acdb merge -i cov/out3/out3.acdb -path /scenario3/UUT -i 
cov/aggregate/aggregate.acdb -path / -o cov/aggregate/aggregate.acdb
asim -acdb scenario4
run -all
acdb save -file cov/out4/out4.acdb
acdb merge -i cov/out4/out4.acdb -path /scenario4/UUT -i
cov/aggregate/aggregate.acdb -path / -o cov/aggregate/aggregate.acdb
acdb2xml -i cov/aggregate/aggregate.acdb -o ucdb.xml

After running the .do file, Riviera-PRO reads the project source files from the GitLab repository and does the compilation and simulation. The simulation runs four different scenarios and saves the .acdb reports. Then, the .acdb files are merged using "acdb merge" command. Then the acdb report is converted to .xml format using "acdb2xml" command that generates ucdb.xml format output that is going to be used in the python script.

Once the simulation is done, the script starts running using python3 tool installed on the host machine. It's important to have the python3 path setup correctly on both user and system variables so it can be called. If for some reason this command is not recognized, you need to use the path to the exe file inside the installation folder:

C:\path-to-python3-installation\python -i ucdb.xml -o cobertura.xml

How the Python converter works

The python script gets the ucdb.xml file as input, which is generated by Riviera-PRO. It parses the ucdb.xml file to generate the cobertura.xml format as an output. The image below shows a part of the script. This script is free and can be requested from Aldec's support team.

Aldec has made the Python source file public. You can download it from Aldec's Github.




Ask Us a Question
Ask Us a Question
Captcha ImageReload Captcha
Incorrect data entered.
Thank you! Your question has been submitted. Please allow 1-3 business days for someone to respond to your question.
Internal error occurred. Your question was not submitted. Please contact us using Feedback form.
We use cookies to ensure we give you the best user experience and to provide you with content we believe will be of relevance to you. If you continue to use our site, you consent to our use of cookies. A detailed overview on the use of cookies and other website information is located in our Privacy Policy.