- Introduction
- Prerequisites
- Documentation References
- Building the Coverage Variant
- Running Tests and Getting Raw Coverage Information
- Parsing Coverage Information and Generating a Report
- Viewing Results
maya-hydra has support for obtaining code coverage on Windows platforms.
The support uses two main tools: Clang for the compilation of maya-hydra and the LLVM toolset for the parsing of code coverage information and the generation of a code coverage report.
To install Clang and the LLVM toolset, you can install an optional module with Visual Studio. Refer to these instructions: Install Clang and LLVM Toolset
Note: On Windows, all commands must be executed in a
x64 Native Tools Command Prompt for VS 2022command line
The maya-hydra build has a Coverage variant that can be used with the following stages: clean,build,install,test (note that the test stage depends on the install stage). Clang is used with code coverage instrumentation flags enabled (-fprofile-instr-generate -fcoverage-mapping) so that when tests are run after a successful install stage, code coverage data files will be generated. Refer to the build documentation for more details.
Here is the command to build the Coverage variant:
python build.py
--build-coverage ^
--generator=Ninja ^
--stages=clean,configure,build,install ^
--maya-location <maya_location> ^
--mayausd-location <mayausd_location> ^
--pxrusd-location <pxrusd_location> ^
--devkit-location <devkit_location> ^
--build-args="-DPYTHON_INCLUDE_DIR=<python_include_dir>,-DPython_EXECUTABLE=<python_executable>,-DPYTHON_LIBRARIES=<python_libraries>,-DCMAKE_WANT_MATERIALX_BUILD=ON,-DCMAKE_PREFIX_PATH=<cmake_prefix_path>" ^
<workspace_location>
Note: Some tests might also require
--mtoa-locationor--lookdevx-locationto succeed.
The --build-coverage flag indicates that the variant to be built is the Coverage variant.
At time of writing (February 26th, 2024), only the Ninja code generator is supported. In particular, the Visual Studio generator is known not to output code coverage data.
To run tests and generate code coverage information using the Coverage build, run the same build.py command as in the previous section, but replace --stages=clean,configure,build,install with --stages=test.
After running tests, the raw coverage information files will be generated in <workspace_location>\build\Coverage\test\lib\mayaUsd\render\mayaToHydra\<test_subfolders>. These files have a .profraw file extension.
To parse the coverage information, two tools from the LLVM toolset are used: llvm-profdata merge and llvm-cov show.
llvm-profdata merge: Parses and merges all of the raw coverage information files (.profraw) into a single file with a.profdataextension.llvm-cov show: Generates an HTML report of the coverage of the maya-hydra plugin using the generated.profdatafile.
There is no build stage in maya-hydra that can automatically run this step of collecting coverage information and creating a report. Here are the steps to manually generate a coverage report:
- Generate a list of all the generated
.profrawfiles. Run this command from<workspace_location>\build:
dir /s /b *.profraw > "path\to\profraw_list.txt"
profraw_list.txt is a text file containing one path to a .profraw file per line.
- Run
llvm-profdatato combine all the coverage information into a single.profdatafile using the file list from the previous step:
llvm-profdata merge -sparse -o "path\to\profdata_file.profdata" --input-files="path\to\profraw_list.txt"
Note: The profdata file name must end with the file extension
.profdata
- Run
llvm-covto generate an HTML report containing code coverage information from the.profdatafile:
llvm-cov show ^
-instr-profile="path\to\profdata_file.profdata" ^
"<workspace_dir>\install\Coverage\lib\mayaHydraLib.dll" ^
-object="<workspace_dir>\install\Coverage\lib\maya\mayaHydra.mll" ^
-object="<workspace_dir>\install\Coverage\lib\flowViewport.dll" ^
-show-branches=count ^
-show-regions ^
-ignore-filename-regex="artifactory\\.*" ^
-format=html ^
-output-dir=<output_dir_name>
Notes:
-instr-profilerefers to the previously generated profdata file--ignore-filename-regex='artifactory\\.*'removes any files starting with "artifactory" from the report
Go to the output directory from the llvm-cov show command and open the index.html file in a web browser. When browsing individual source files, red highlights indicate lines or branches that were not covered in the tests.