Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Dec 5, 2024
1 parent 3381978 commit 882cf24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion data_prep/introspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def query_introspector_public_classes(project: str) -> list[str]:
return _get_data(resp, 'classes', [])


def query_introspector_source_code(project: str, filepath: str,
def query_introspector_source_code(project: str,
filepath: str,
begin_line: int = 0,
end_line: int = 10000) -> str:
"""Queries FuzzIntrospector API for source code of a
Expand Down
11 changes: 6 additions & 5 deletions experiment/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def _fix_generated_fuzz_target(self, ai_binary: str,
dual_logger: _Logger, language: str):
"""Fixes the generated fuzz target."""
jvm_coverage_fix = False
error_desc, errors = '', []
if build_result.succeeded:
if language == 'jvm':
jvm_coverage_fix = True
Expand All @@ -293,7 +294,6 @@ def _fix_generated_fuzz_target(self, ai_binary: str,
else:
dual_logger.log(f'Warning: Build succeed but no run_result in '
f'{generated_oss_fuzz_project}.')
error_desc, errors = '', []
else:
error_desc, errors = None, build_result.errors

Expand Down Expand Up @@ -402,7 +402,7 @@ def check_target(self, ai_binary, target_path: str) -> Result:
# Gets line coverage (diff) details.
coverage_summary = self._load_existing_coverage_summary()

if self.benchmark.language in ['python', 'jvm']:
if self.benchmark.language in ['python', 'jvm'] and run_result.coverage:
# The Jacoco.xml coverage report used to generate summary.json on
# OSS-Fuzz for JVM projects does not trace the source file location.
# Thus the conversion may miss some classes because they are not
Expand All @@ -427,9 +427,10 @@ def check_target(self, ai_binary, target_path: str) -> Result:
coverage_percent = 0.0

existing_textcov = self.load_existing_textcov()
run_result.coverage.subtract_covered_lines(existing_textcov)
if run_result.coverage:
run_result.coverage.subtract_covered_lines(existing_textcov)

if total_lines:
if total_lines and run_result.coverage:
coverage_diff = run_result.coverage.covered_lines / total_lines
else:
dual_logger.log(
Expand All @@ -441,7 +442,7 @@ def check_target(self, ai_binary, target_path: str) -> Result:
# 1) Build success and run crashed (expected for exceptions)
# 2) Build success, run success and coverage diff > 0
gen_succ = build_result.succeeded and run_result
if gen_succ and run_result.succeeded:
if gen_succ and run_result and run_result.succeeded:
gen_succ = gen_succ and (coverage_diff > 0)
else:
gen_succ = build_result.succeeded and run_result and run_result.succeeded
Expand Down
14 changes: 8 additions & 6 deletions llm_toolkit/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,11 +1073,11 @@ def __init__(self,

# Load templates.
if self.jvm_cov_fix:
self.template_file = self._find_template(
template_dir, 'jvm_requirement_coverage_fixing.txt')
self.template_file = self._find_template(
template_dir, 'jvm_requirement_coverage_fixing.txt')
else:
self.template_file = self._find_template(
template_dir, 'jvm_requirement_error_fixing.txt')
self.template_file = self._find_template(
template_dir, 'jvm_requirement_error_fixing.txt')

def _find_template(self, template_dir: str, template_name: str) -> str:
"""Finds template file based on |template_dir|."""
Expand Down Expand Up @@ -1105,6 +1105,8 @@ def build(self,
with open(self.template_file, 'r') as f:
prompt_text = f.read()

proj = self.benchmark.project

# Format the repository
target_repository = oss_fuzz_checkout.get_project_repository(
self.benchmark.project)
Expand All @@ -1122,13 +1124,13 @@ def build(self,
harnesses = introspector.query_introspector_for_harness_intrinsics(proj)
for pair in harnesses:
path = pair.get('source', '')
if source_path:
if path:
source = introspector.query_introspector_source_code(proj, path)
if source:
source_list.append(source)

prompt_text = prompt_text.replace('{EXISTING_HARNESS}',
'\n---\n'.join(source_list))
'\n---\n'.join(source_list))

# Add all public candidates to prompt
methods = introspector.query_introspector_jvm_all_public_candidates(proj)
Expand Down

0 comments on commit 882cf24

Please sign in to comment.