Skip to content

Commit

Permalink
make it possible to run projects not in OSS-Fuzz upstream
Browse files Browse the repository at this point in the history
This makes it possible to run OSS-Fuzz-gen on projects that are in a
local OSS-Fuzz folder, but that are not in upstream OSS-Fuzz. This needs
to use a local deployment of Fuzz Introspector.

Will follow-up with PRs for experimental that merges the two with
scripts.

Ref: #498

Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Aug 20, 2024
1 parent 5da97e1 commit c2ca109
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 9 additions & 3 deletions experiment/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def load_existing_textcov(project: str) -> textcov.Textcov:

if not blobs.prefixes: # type: ignore
# No existing coverage reports.
raise RuntimeError(f'No existing coverage reports for {project}')
logger.info('No existing coverage report. Using empty.')
return textcov.Textcov()

# Find the latest generated textcov date.
latest_dir = sorted(blobs.prefixes)[-1] # type: ignore
Expand Down Expand Up @@ -137,7 +138,8 @@ def load_existing_coverage_summary(project: str) -> dict:

if not blobs.prefixes: # type: ignore
# No existing coverage reports.
raise RuntimeError(f'No existing coverage reports for {project}')
logger.info('No existing coverage reports, using empty one.')
return {}

latest_dir = sorted(blobs.prefixes)[-1] # type: ignore
blob = bucket.blob(f'{latest_dir}linux/summary.json')
Expand Down Expand Up @@ -418,8 +420,12 @@ def check_target(self, ai_binary, target_path: str) -> Result:
# Gets line coverage (diff) details.
coverage_summary = self._load_existing_coverage_summary()

total_lines = _compute_total_lines_without_fuzz_targets(
if coverage_summary:
total_lines = _compute_total_lines_without_fuzz_targets(
coverage_summary, generated_target_name)
else:
total_lines = 0

if self.benchmark.language == 'jvm':
# The Jacoco.xml coverage report used to generate
# summary.json on OSS-Fuzz for JVM projects does
Expand Down
16 changes: 9 additions & 7 deletions experiment/oss_fuzz_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# This will change if temp_dir is used.
OSS_FUZZ_DIR: str = os.path.join(
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'oss-fuzz')
CLEAN_UP_OSS_FUZZ = bool(int(os.getenv('OFG_CLEAN_UP_OSS_FUZZ', '1')))

VENV_DIR: str = 'venv'

Expand Down Expand Up @@ -90,13 +91,14 @@ def clone_oss_fuzz(oss_fuzz_dir: str = ''):

if not os.path.exists(OSS_FUZZ_DIR):
_clone_oss_fuzz_repo()
# Remove existing targets.
clean_command = ['git', 'clean', '-fxd', '-e', VENV_DIR, '-e', BUILD_DIR]
sp.run(clean_command,
capture_output=True,
stdin=sp.DEVNULL,
check=True,
cwd=OSS_FUZZ_DIR)

if CLEAN_UP_OSS_FUZZ:
clean_command = ['git', 'clean', '-fxd', '-e', VENV_DIR, '-e', BUILD_DIR]
sp.run(clean_command,
capture_output=True,
stdin=sp.DEVNULL,
check=True,
cwd=OSS_FUZZ_DIR)


def postprocess_oss_fuzz() -> None:
Expand Down

0 comments on commit c2ca109

Please sign in to comment.