Skip to content

Commit

Permalink
analyser: Fix function dict to match webapp output
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Jan 22, 2025
1 parent 61fc40e commit 0139092
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FarReachLowCoverageAnalyser(analysis.AnalysisInterface):

name: str = 'FarReachLowCoverageAnalyser'

def __init__(self):
def __init__(self) -> None:
self.json_results: Dict[str, Any] = {}
self.json_string_result = ''

Expand Down Expand Up @@ -106,7 +106,7 @@ def analysis_func(self,
result_list: List[Dict[str, Any]] = []

# Get all functions from the profiles
all_functions = List(proj_profile.all_functions.values())
all_functions = list(proj_profile.all_functions.values())
all_functions.extend(proj_profile.all_constructors.values())

# Get cross reference function dict
Expand Down Expand Up @@ -139,7 +139,10 @@ def analysis_func(self,
# TODO No Debug information from the new frontend yet.
# Handle this later

result_list.append(function.to_dict())
result_list.append(
function.to_dict(
proj_profile.get_func_hit_percentage(
function.function_name)))

self.json_results['functions'] = result_list
result_json_path = os.path.join(out_dir, 'result.json')
Expand Down
7 changes: 5 additions & 2 deletions src/fuzz_introspector/analyses/source_code_line_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SourceCodeLineAnalyser(analysis.AnalysisInterface):

name: str = 'SourceCodeLineAnalyser'

def __init__(self):
def __init__(self) -> None:
self.json_results: Dict[str, Any] = {}
self.json_string_result = ''

Expand Down Expand Up @@ -120,7 +120,10 @@ def analysis_func(self,
logger.info('Found function %s from line %d in %s',
func.function_name, self.source_line,
self.source_file)
result_list.append(func.to_dict())
result_list.append(
func.to_dict(
proj_profile.get_func_hit_percentage(
func.function_name)))

if result_list:
self.json_results['functions'] = result_list
Expand Down
54 changes: 18 additions & 36 deletions src/fuzz_introspector/datatypes/function_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,25 @@ def __init__(self, elem: Dict[Any, Any]) -> None:
self.new_unreached_complexity: int = 0
self.total_cyclomatic_complexity: int = 0

def to_dict(self) -> Dict[str, Any]:
def to_dict(self, coverage: float = 0.0) -> Dict[str, Any]:
return {
"function_name": self.function_name,
"raw_function_name": self.raw_function_name,
"function_source_file": self.function_source_file,
"linkage_type": self.linkage_type,
"function_linenumber": self.function_linenumber,
"function_line_number_end": self.function_line_number_end,
"return_type": self.return_type,
"arg_count": self.arg_count,
"arg_types": self.arg_types,
"arg_names": self.arg_names,
"bb_count": self.bb_count,
"i_count": self.i_count,
"edge_count": self.edge_count,
"cyclomatic_complexity": self.cyclomatic_complexity,
"functions_reached": self.functions_reached,
"function_uses": self.function_uses,
"function_depth": self.function_depth,
"constants_touched": self.constants_touched,
"branch_profiles":
{k: str(v)
for k, v in self.branch_profiles.items()},
"signature": self.signature,
"functions_called": self.functions_called,
"is_accessible": self.is_accessible,
"is_jvm_library": self.is_jvm_library,
"is_enum": self.is_enum,
"is_static": self.is_static,
"exceptions": self.exceptions,
"need_close": self.need_close,
"callsite": self.callsite,
"hitcount": self.hitcount,
"reached_by_fuzzers": self.reached_by_fuzzers,
"incoming_references": self.incoming_references,
"new_unreached_complexity": self.new_unreached_complexity,
"total_cyclomatic_complexity": self.total_cyclomatic_complexity
'project': 'UnknownProject',
'function_name': self.function_name,
'function_filename': self.function_source_file,
'raw_function_name': self.raw_function_name,
'is_reached': bool(self.reached_by_fuzzers),
'is_enum_class': self.is_enum,
'accummulated_complexity': self.cyclomatic_complexity,
'function_argument_names': self.arg_names,
'function_arguments': self.arg_types,
'function_signature': self.signature,
'reached_by_fuzzers': self.reached_by_fuzzers,
'return_type': self.return_type,
'runtime_coverage_percent': coverage,
'source_line_begin': self.function_linenumber,
'source_line_endvv': self.function_line_number_end,
'debug_summary': '', # No debug summary from new frontend yet
'total_cyclomatic_complexity': self.total_cyclomatic_complexity
}

@property
Expand Down

0 comments on commit 0139092

Please sign in to comment.