diff --git a/docs/code_coverage.md b/docs/code_coverage.md index b37f03a78..232f07f7b 100644 --- a/docs/code_coverage.md +++ b/docs/code_coverage.md @@ -72,6 +72,17 @@ via `--corpus-dir` to be used instead of the corpus downloaded from OSS-Fuzz: python infra/helper.py profile --fuzz-target= --corpus-dir= $project_name ``` +### Additional arguments for `llvm-cov` + +You may want to use some of the options of [llvm-cov tool], for example, +`-ignore-filename-regex=` or `-tab-size=`. You can pass those to the helper +script after `--`: + +```bash +python infra/helper.py profile $project_name -- -ignore-filename-regex='.*code/to/be/ignored/.*' -tab-size=2 +``` + [Clang Source-based Code Coverage]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html [gsutil tool]: https://cloud.google.com/storage/docs/gsutil_install +[llvm-cov tool]: https://llvm.org/docs/CommandGuide/llvm-cov.html diff --git a/infra/base-images/base-runner/coverage b/infra/base-images/base-runner/coverage index 935f07e9e..b7783d888 100755 --- a/infra/base-images/base-runner/coverage +++ b/infra/base-images/base-runner/coverage @@ -23,7 +23,10 @@ else fi LOGS_DIR="$OUT/logs" -mkdir -p $LOGS_DIR +rm -rf $LOGS_DIR && mkdir -p $LOGS_DIR + +REPORT_DIR="$OUT/report" +rm -rf $REPORT_DIR # This will be used by llvm-cov command to generate the actual report. objects="" @@ -75,10 +78,10 @@ rm *.profraw # TODO(mmoroz): add script from Chromium for rendering directory view reports. # Generate HTML report. -llvm-cov show -format=html -output-dir=report -path-equivalence="/,$OUT" \ - -instr-profile merged.profdata $objects +llvm-cov show -format=html -output-dir=$REPORT_DIR -path-equivalence="/,$OUT" \ + $COVERAGE_EXTRA_ARGS -instr-profile merged.profdata $objects # Serve the report locally. echo "Serving the report on http://127.0.0.1:$HTTP_PORT/" -cd report +cd $REPORT_DIR python3 -m http.server $HTTP_PORT diff --git a/infra/base-images/base-runner/llvm-cov b/infra/base-images/base-runner/llvm-cov index c38e6809f..ec9aa94da 100755 Binary files a/infra/base-images/base-runner/llvm-cov and b/infra/base-images/base-runner/llvm-cov differ diff --git a/infra/base-images/base-runner/llvm-profdata b/infra/base-images/base-runner/llvm-profdata index 747a09cab..b82aabcde 100755 Binary files a/infra/base-images/base-runner/llvm-profdata and b/infra/base-images/base-runner/llvm-profdata differ diff --git a/infra/helper.py b/infra/helper.py index e4042e184..6a7173464 100755 --- a/infra/helper.py +++ b/infra/helper.py @@ -122,7 +122,6 @@ def main(): profile_parser = subparsers.add_parser( 'profile', help='Generate code coverage report for the project.') - profile_parser.add_argument('project_name', help='name of the project') profile_parser.add_argument('--no-corpus-download', action='store_true', help='do not download corpus backup from OSS-Fuzz; ' 'use corpus located in build/corpus///') @@ -132,6 +131,9 @@ def main(): 'target to be run for generating coverage report') profile_parser.add_argument('--corpus-dir', help='specify location of corpus ' 'to be used (requires --fuzz-target argument)') + profile_parser.add_argument('project_name', help='name of the project') + profile_parser.add_argument('extra_args', help='additional arguments to ' + 'pass to llvm-cov utility.', nargs='*') reproduce_parser = subparsers.add_parser( 'reproduce', help='Reproduce a crash.') @@ -621,6 +623,7 @@ def profile(args): 'PROJECT=%s' % args.project_name, 'SANITIZER=profile', 'HTTP_PORT=%s' % args.port, + 'COVERAGE_EXTRA_ARGS=%s' % ' '.join(args.extra_args), ] run_args = _env_to_docker_args(env)