How to print the coverage report while using libfuzzer with MSVC?

Vishnu Gopalakrishnan 126 Reputation points
2024-10-08T06:08:05.8933333+00:00

While using libfuzzer with MSVC the coverage section is empty. Is there a way to print the coverage report with libfuzzer & MSVC?

Windows for business Windows Client for IT Pros Devices and deployment Configure application groups
Developer technologies C++
Developer technologies Visual Studio Other
{count} votes

1 answer

Sort by: Most helpful
  1. Sergei Kozlov 300 Reputation points
    2024-10-09T06:23:08.85+00:00

    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:
         -fsanitize=fuzzer -fsanitize=address -fprofile-instr-generate -fcoverage-mapping
      
      Run Your Fuzz Tests:

    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
        

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.