Skip to content

Commit

Permalink
make coverage reports available in local UI (#573)
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski authored Sep 4, 2024
1 parent d7d2b2a commit 931da89
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
7 changes: 7 additions & 0 deletions experiment/builder_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,13 @@ def get_coverage_local(
re.compile(r'^' + re.escape(target_basename) + ':')
])

coverage_report = os.path.join(oss_fuzz_checkout.OSS_FUZZ_DIR, 'build',
'out', generated_project, 'report')
destination_coverage = self.work_dirs.code_coverage_report(
benchmark_target_name)

shutil.copytree(coverage_report, destination_coverage, dirs_exist_ok=True)

coverage_summary = os.path.join(oss_fuzz_checkout.OSS_FUZZ_DIR, 'build',
'out', generated_project, 'report', 'linux',
'summary.json')
Expand Down
7 changes: 7 additions & 0 deletions experiment/workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def corpus(self, sample_id):
os.makedirs(corpus_dir, exist_ok=True)
return corpus_dir

def code_coverage_report(self, benchmark):
coverage_dir = os.path.join(self._base_dir, 'code-coverage-reports')
os.makedirs(coverage_dir, exist_ok=True)

benchmark_coverage = os.path.join(coverage_dir, benchmark)
return benchmark_coverage

@property
def status(self):
return os.path.join(self._base_dir, 'status')
Expand Down
37 changes: 34 additions & 3 deletions report/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import logging
import os
import shutil
import threading
import time
import urllib.parse
Expand Down Expand Up @@ -46,16 +47,21 @@ def _percent(num: float):

@staticmethod
def _cov_report_link(link: str):
"""Get URL to coverage report"""
if not link:
return '#'

path = link.removeprefix('gs://oss-fuzz-gcb-experiment-run-logs/')
link_path = f'https://llm-exp.oss-fuzz.com/{path}/report/linux/'
if 'gcb-experiment' not in link:
# In local rusn we don't overwrite the path
link_path = link
else:
path = link.removeprefix('gs://oss-fuzz-gcb-experiment-run-logs/')
link_path = f'https://llm-exp.oss-fuzz.com/{path}/report/linux/'

# Check if this is a java benchmark, which will always have a period in
# the path, where C/C++ wont.
# TODO(David) refactor to have paths for links more controlled.
if '.' in path:
if '.' in link_path:
return link_path + 'index.html'
return link_path + 'report.html'

Expand Down Expand Up @@ -103,6 +109,27 @@ def read_timings(self):
timings_dict = json.loads(f.read())
return timings_dict

def _copy_and_set_coverage_report(self, benchmark, sample):
"""Prepares coverage reports in local runs."""
coverage_path = os.path.join(self.results_dir, benchmark.id,
'code-coverage-reports')
if not os.path.isdir(coverage_path):
return

coverage_report = ''
for l in os.listdir(coverage_path):
if l.split('.')[0] == sample.id:
coverage_report = os.path.join(coverage_path, l)
if coverage_report:
# Copy coverage to reports out
dst = os.path.join(self._output_dir, 'sample', benchmark.id, 'coverage')
os.makedirs(dst, exist_ok=True)
dst = os.path.join(dst, sample.id)

shutil.copytree(coverage_report, dst, dirs_exist_ok=True)
sample.result.coverage_report_path = \
f'/sample/{benchmark.id}/coverage/{sample.id}/linux/'

def generate(self):
"""Generate and write every report file."""
benchmarks = []
Expand All @@ -113,6 +140,10 @@ def generate(self):
samples = self._results.get_samples(results, targets)
prompt = self._results.get_prompt(benchmark.id)

for sample in samples:
# If this is a local run then we need to set up coverage reports.
self._copy_and_set_coverage_report(benchmark, sample)

self._write_benchmark_index(benchmark, samples, prompt)
self._write_benchmark_crash(benchmark, samples)

Expand Down

0 comments on commit 931da89

Please sign in to comment.