To print a coverage report while using libFuzzer with MSVC, you can follow these steps:
Install Clang: Ensure you have the Clang compiler installed. You can do this via the Visual Studio Installer by selecting the “C++ Clang Compiler for Windows” and “MSBuild support for LLVM (clang-cl)” components.
Set Up Your Project:
- Add the following flags to your compiler and linker settings:
Run Your Fuzz Tests:-fsanitize=fuzzer -fsanitize=address -fprofile-instr-generate -fcoverage-mapping
Set the environment variable LLVM_PROFILE_FILE
to specify the output file for the raw coverage data:
set LLVM_PROFILE_FILE=my_test.profraw
- Execute your fuzz tests as usual.
Generate the Coverage Report:
- Use
llvm-profdata
to merge the raw profile data:llvm-profdata merge -sparse my_test.profraw -o my_test.profdata
- Use
llvm-cov
to generate the coverage report:llvm-cov show ./your_fuzz_target_binary -instr-profile=my_test.profdata -format=html > coverage_report.html
- Use