diff --git a/data_prep/introspector.py b/data_prep/introspector.py index c088f2ff5..6d7a04285 100755 --- a/data_prep/introspector.py +++ b/data_prep/introspector.py @@ -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 diff --git a/experiment/evaluator.py b/experiment/evaluator.py index f07cf225a..5c1fb249b 100644 --- a/experiment/evaluator.py +++ b/experiment/evaluator.py @@ -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 @@ -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 @@ -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 @@ -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( @@ -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 diff --git a/llm_toolkit/prompt_builder.py b/llm_toolkit/prompt_builder.py index 3af1a41f5..a42aebb99 100644 --- a/llm_toolkit/prompt_builder.py +++ b/llm_toolkit/prompt_builder.py @@ -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|.""" @@ -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) @@ -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)