Generate code coverage data

  1. Build a test target for coverage:

    ninja -C out/Coverage-iphonesimulator ios_chrome_unittests

    Targets that support code coverage need to call coverage_util::ConfigureCoverageReportPath(). If you don't use, you can set the gn argument ios_enable_coverage to true.

  2. Run the test target. If using Xcode, don‘t forget to set Coverage in the target’s scheme:

  3. Find the coverage.profraw in the Documents folder of the app. You can look in the console output of the instrumented target. For example:

    Coverage data at /Users/johndoe/Library/Developer/CoreSimulator/Devices/
  4. Create a coverage.profdata file out of the coverage.profraw file:

    xcrun llvm-profdata merge \
        -o out/Coverage-iphonesimulator/coverage.profdata \
  5. To see the line coverage for all the instrumented source files:

    xcrun llvm-cov show \
        out/Coverage-iphonesimulator/ \
        -instr-profile=out/Coverage-iphonesimulator/coverage.profdata \

    To see the line coverage for a specific instrumented source file/folder (e.g. ios/chrome/browser/ui/coordinators/

    xcrun llvm-cov show \
        out/Coverage-iphonesimulator/ \
        -instr-profile=out/Coverage-iphonesimulator/coverage.profdata \
        -arch=x86_64 ios/chrome/browser/ui/coordinators/