Code Coverage¶
The script run_coverage.sh offers a way to test the code coverage
of the XGrammar library.
To run the coverage test, please follow these steps:
In
config.cmake, set the variableXGRAMMAR_ENABLE_COVERAGEtoON.Compile the XGrammar library with the configured settings.
Run the script
run_coverage.shin the root directory of the XGrammar library.
Note that the script invokes lcov with --gcov-tool /usr/bin/gcov-13, so it expects the
library to be compiled with GCC 13 and gcov-13 to be installed. If you use a different
compiler version, update the --gcov-tool path in the script accordingly.
After running the script, you will find the coverage report in the
coverage_report directory.
Please note that code coverage tools are merely aids to help identify which parts of the code have not been tested. However, pursuing 100% code coverage is not advisable. It can actually have negative consequences.