Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Jan 25, 2025
1 parent 3fcd304 commit b984328
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/fuzz_introspector/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@ def extract_all_sources(language):
to_avoid = [
'fuzztest', 'aflplusplus', 'libfuzzer', 'googletest', 'thirdparty',
'third_party', '/build/', '/usr/local/', '/fuzz-introspector/',
'/root/.cache/', 'honggfuzz', '/src/inspector/', '/src/.venv'
'/root/.cache/', 'honggfuzz', '/src/inspector/', '/src/.venv',
'/src/source-code/'
]

for file in all_files:
Expand All @@ -1071,20 +1072,20 @@ def extract_all_sources(language):
return interesting_source_files


def extract_test_information(report_dict=None, language='c-cpp'):
def extract_test_information(report_dict=None, language='c-cpp', out_dir='/'):
"""Extract test information for different project language."""
if not report_dict:
report_dict = {}
if language == 'c-cpp':
return _extract_test_information_cpp(report_dict)
return _extract_test_information_cpp(report_dict, out_dir)
elif language == 'jvm':
return _extract_test_information_jvm()
else:
# Currently only support c-cpp or jvm project
return set()


def _extract_test_information_cpp(report_dict):
def _extract_test_information_cpp(report_dict, out_dir):
"""Correlates function data collected by debug information to function
data collected by LLVMs module, and uses the correlated data to generate
function signatures for each function based on debug information."""
Expand All @@ -1103,10 +1104,10 @@ def _extract_test_information_cpp(report_dict):
if path.startswith('/tmp/inspector-saved/'):
continue
directories.add('/'.join(path.split('/')[:-1]))
return extract_tests_from_directories(directories, 'c-cpp')
return extract_tests_from_directories(directories, 'c-cpp', out_dir)


def extract_tests_from_directories(directories, language) -> Set[str]:
def extract_tests_from_directories(directories, language, out_dir) -> Set[str]:
"""Extracts test files from a given collection of directory paths and also
copies them to the `constants.SAVED_SOURCE_FOLDER` folder with the same
absolute path appended."""
Expand Down Expand Up @@ -1213,7 +1214,8 @@ def extract_tests_from_directories(directories, language) -> Set[str]:
logger.info("All test files")
for test_file in all_test_files:
logger.info(test_file)
dst = constants.SAVED_SOURCE_FOLDER + '/' + test_file
dst = os.path.join(out_dir,
constants.SAVED_SOURCE_FOLDER + '/' + test_file)
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy(test_file, dst)

Expand Down
3 changes: 2 additions & 1 deletion src/fuzz_introspector/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def light_analysis(args) -> int:
os.makedirs(light_dir, exist_ok=True)

all_tests = analysis.extract_tests_from_directories({src_dir},
args.language)
args.language,
inspector_dir)

with open(os.path.join(light_dir, 'all_tests.json'), 'w') as f:
f.write(json.dumps(list(all_tests)))
Expand Down
3 changes: 2 additions & 1 deletion src/fuzz_introspector/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ def create_html_report(introspection_proj: analysis.IntrospectionProject,

all_test_files = analysis.extract_test_information(
introspection_proj.debug_report,
introspection_proj.proj_profile.target_lang)
introspection_proj.proj_profile.target_lang,
out_dir)
with open(os.path.join(out_dir, constants.TEST_FILES_JSON),
'w') as test_file_fd:
test_file_fd.write(json.dumps(list(all_test_files)))
Expand Down

0 comments on commit b984328

Please sign in to comment.