Skip to content

Commit

Permalink
[JVM] Add harness sample code for JVM test-to-harness approach
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
  • Loading branch information
arthurscchan committed Nov 27, 2024
1 parent fd26d19 commit a67369f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions llm_toolkit/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,24 @@ def build(self,
language_text)

if self.benchmark.language == 'jvm':
prompt_text = prompt_text.replace('{HEADER_FILE_LANG}', '')
prompt_text = prompt_text.replace('{HARNESS_HEADERS}', '')

# Fuzz Introspector use JVM as it support other JVM languages in addition
# to Java. Currently, the logic in OSS-Fuzz-Gen is only working on Java.
prompt_text = prompt_text.replace('{PROG_LANG}', 'Java')
prompt_text = prompt_text.replace('{HEADER_FILE_LANG}', '')

# Provide list of public classes of this project
classes = introspector.query_introspector_public_classes(
self.benchmark.project)
prompt_text = prompt_text.replace('{PUBLIC_CLASSES}', ','.join(classes))
prompt_text = prompt_text.replace('{TARGET_SAMPLE_HARNESS}', '')

# Proivde sample harness code
harness_sample_text = ('There are already harnesses targeting this '
'project, and an example of this is:\n'
f'<code>\n{self.harness_source_code}\n</code>')
prompt_text = prompt_text.replace('{TARGET_SAMPLE_HARNESS}',
harness_sample_text)
else:
included_header_files = self.extract_header_files(test_source_code)
if included_header_files:
Expand Down
2 changes: 1 addition & 1 deletion prompts/template_xml/jvm_requirement_test_to_harness.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class {HARNESS_NAME} {
}
</code></item>
<item>
Here is a comma-separated list of all publicly accessible classes in this project. You can use any of these classes, as well as classes from the JVM library. Please AVOID using other classes in the project, even if it exists in the following test or sample code as they are not publicly accessible.
Here is a comma-separated list of all publicly accessible classes in this project. You can use any of these classes, as well as classes from the JVM library. Please AVOID using other classes in the project, even if it exists in the following test or sample code as they are not publicly accessible. Please import all necessary classes from this list.
{PUBLIC_CLASSES}
</item>
<item>
Expand Down

0 comments on commit a67369f

Please sign in to comment.