Skip to content

Commit

Permalink
pylint: Fix pylint error
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 Jan 22, 2025
1 parent a8c12d8 commit e23ebe2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
25 changes: 12 additions & 13 deletions src/fuzz_introspector/cfg_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ def __init__(
def extract_all_callsites_recursive(
calltree: CalltreeCallsite,
callsite_nodes: List[CalltreeCallsite]) -> None:
"""
Given a node, will assemble all callsites in the children. Recursive function.
"""
"""Given a node, will assemble all callsites in the children.
Recursive function."""
callsite_nodes.append(calltree)
for c in calltree.children:
extract_all_callsites_recursive(c, callsite_nodes)
Expand Down Expand Up @@ -129,34 +128,34 @@ def data_file_read_calltree(filename: str) -> Optional[CalltreeCallsite]:
ctcs = CalltreeCallsite(target_func, filename, depth,
linenumber, curr_ctcs_node)

# Check if this node is still a child of the current parent node and handle if not.
# Check if this node is still a child of the current parent node
# and handle if not.
if curr_depth == -1:
# First node
curr_ctcs_node = ctcs
elif depth > curr_depth and curr_ctcs_node is not None:
# We are going one calldepth deeper
# Special case in the root parent case, where we have no parent in the current
# node
# and also no children.
if (curr_ctcs_node.parent_calltree_callsite is None
and len(curr_ctcs_node.children) == 0):
None
else:
# Special case in the root parent case, where we have no
# parent in the current node and also no children.
if (curr_ctcs_node.parent_calltree_callsite
or len(curr_ctcs_node.children) == 0):
curr_ctcs_node = curr_ctcs_node.children[-1]

elif depth < curr_depth and curr_ctcs_node is not None:
# We are going up, find out how much
depth_diff = int(curr_depth - depth)
tmp_node = curr_ctcs_node
idx = 0
while idx < depth_diff and tmp_node.parent_calltree_callsite is not None:
while (idx < depth_diff
and tmp_node.parent_calltree_callsite is not None):
tmp_node = tmp_node.parent_calltree_callsite
idx += 1
curr_ctcs_node = tmp_node
# Add the node to the current parent
if curr_depth != -1 and curr_ctcs_node is not None:
ctcs.parent_calltree_callsite = curr_ctcs_node
ctcs.src_function_name = ctcs.parent_calltree_callsite.dst_function_name
ctcs.src_function_name = (
ctcs.parent_calltree_callsite.dst_function_name)
curr_ctcs_node.children.append(ctcs)
curr_depth = depth

Expand Down
22 changes: 11 additions & 11 deletions src/fuzz_introspector/diff_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,25 @@ def _compare_numericals(num1, num2, title="", to_print=True) -> int:
0 if num1 == num2
1 if num1 > num2
"""
msg = ''
ret_val = -1
if num1 < num2:
msg = "Report 2 has a larger %s than report 1" % (title)
msg = f"Report 2 has a larger {title} than report 1"
ret_val = -1
if num1 == num2:
msg = "Report 2 has similar %s to report 1" % (title)
msg = f"Report 2 has similar {title} to report 1"
ret_val = 0
if num1 > num2:
msg = "Report 2 has less %s than report 1" % (title)
msg = f"Report 2 has less {title} than report 1"
ret_val = 1
if to_print:
print("%s - {report 1: %s / report 2: %s})" %
(msg, str(num1), str(num2)))
print(f"{msg} - {{report 1: {num1} / report 2: {num2}}}")

return ret_val


def _compare_summary_of_all_functions(first_report, second_report):
"""Internal helper to compare summary of all functions."""
all_funcs1 = first_report['MergedProjectProfile']['all-functions']
all_funcs2 = second_report['MergedProjectProfile']['all-functions']

Expand Down Expand Up @@ -138,19 +140,17 @@ def _compare_summary_of_all_functions(first_report, second_report):
for func_name in report1_reached_only:
print(func_name)
else:
print(
"- All functions reachable in report 1 are reachable in report 2"
)
print("- All functions reachable in report 1 are reachable"
" in report 2")

print("")
print("The following functions are only reachable in report 2:")
if len(report2_reached_only) > 0:
for func_name in report2_reached_only:
print(func_name)
else:
print(
"- All functions reachable in report 2 are reachable in report 1"
)
print("- All functions reachable in report 2 are reachable"
" in report 1")


def _compare_report_dictionaries(first_report, second_report):
Expand Down

0 comments on commit e23ebe2

Please sign in to comment.