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?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,147 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,743 questions
Windows 10 Security
Windows 10 Security
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
2,919 questions
{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.