Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect binary names #722

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark-sets/all/hermes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
"signature": "Value facebook::jsi::RuntimeDecorator<facebook::hermes::HermesRuntimeImpl, facebook::jsi::ThreadSafeRuntime>::evaluatePreparedJavaScript(RuntimeDecorator<facebook::hermes::HermesRuntimeImpl, facebook::jsi::ThreadSafeRuntime> *, const shared_ptr<const facebook::jsi::PreparedJavaScript> &)"
"language": "c++"
"project": "hermes"
"target_name": "/src/hermes/tools/fuzzers/libfuzzer/fuzzer-jsi-entry.cpp"
"target_name": "fuzzer-jsi-entry"
"target_path": "/src/hermes/tools/fuzzers/libfuzzer/fuzzer-jsi-entry.cpp"
2 changes: 1 addition & 1 deletion benchmark-sets/all/sleuthkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
"signature": "TSK_RETVAL_ENUM ffs_dir_open_meta(TSK_FS_INFO *, TSK_FS_DIR **, TSK_INUM_T, int)"
"language": "c++"
"project": "sleuthkit"
"target_name": "sleuthkit_mmls_sun_fuzzer"
"target_name": "mmls_sun_fuzzer"
"target_path": "/src/sleuthkit_mmls_fuzzer.cc"
2 changes: 1 addition & 1 deletion benchmark-sets/all/stb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
"signature": "int stbi_is_16_bit_from_file(FILE *)"
"language": "c++"
"project": "stb"
"target_name": "stb_png_read_fuzzer"
"target_name": "stbi_read_fuzzer"
"target_path": "/src/stb/tests/stbi_read_fuzzer.c"
71 changes: 71 additions & 0 deletions helper/diff_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Replace the fuzz target binary name (`target_name`) in all benchmark YAMLs of a
dir with the target name of the corresponding YAMLs of another dir. Target will
only be replaced if they share the same fuzz target source code path
(`target_path`).
Usage: python3 diff_target.py <dest-dir> <source-dir>
"""
import argparse
import os

import yaml


def load_yaml(file_path):
"""Load a YAML file and return its contents."""
try:
with open(file_path, 'r') as f:
return yaml.safe_load(f)
except Exception as e:
print(f"Error loading YAML file {file_path}: {e}")
return None


def save_yaml(file_path, data):
"""Save a dictionary to a YAML file."""
try:
with open(file_path, 'w') as f:
yaml.safe_dump(data, f)
except Exception as e:
print(f"Error saving YAML file {file_path}: {e}")


def overwrite_target_name(dir_a, dir_b):
"""Overwrite target_name in A if target_path is the same and target_name differs."""
common_files = set(os.listdir(dir_a)) & set(os.listdir(dir_b))
updated_files = []

for file_name in common_files:
if not file_name.endswith('.yaml'):
continue

file_a = os.path.join(dir_a, file_name)
file_b = os.path.join(dir_b, file_name)

data_a = load_yaml(file_a)
data_b = load_yaml(file_b)

if data_a and data_b:
if data_a.get('target_path') == data_b.get('target_path'):
if data_a.get('target_name') != data_b.get('target_name'):
data_a['target_name'] = data_b['target_name']
save_yaml(file_a, data_a)
updated_files.append(file_name)

return updated_files


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Update target_name in A if target_path matches B.")
parser.add_argument("dir_a", help="Path to directory A (to be updated)")
parser.add_argument("dir_b", help="Path to directory B (source of updates)")
args = parser.parse_args()

updated_files = overwrite_target_name(args.dir_a, args.dir_b)
if updated_files:
print("The following files in A had target_name updated from B:")
for file_name in updated_files:
print(file_name)
else:
print("No updates were necessary.")