Skip to content

Commit 508abcc

Browse files
Output all functions table to json report. (#750)
This is needed for things such as comparing fuzz introspector runs and for creating scripts that gather overviews of a lot of fuzz introspector reports. Signed-off-by: David Korczynski <[email protected]> Signed-off-by: David Korczynski <[email protected]>
1 parent 52cd81a commit 508abcc

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/fuzz_introspector/analyses/optimal_targets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def get_consequential_section(
330330
"functions in the project will be:</p>"
331331
table_id = "all_functions_overview_table"
332332
tables.append(table_id)
333-
all_function_table, all_functions_json = html_report.create_all_function_table(
333+
all_function_table, all_functions_json, _ = html_report.create_all_function_table(
334334
tables, new_profile, coverage_url, basefolder, table_id)
335335
html_string += all_function_table
336336
html_string += "</div>" # close report-box

src/fuzz_introspector/html_report.py

+33-6
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def create_all_function_table(
185185
coverage_url: str,
186186
basefolder: str,
187187
table_id: Optional[str] = None
188-
) -> Tuple[str, List[typing.Dict[str, Any]]]:
188+
) -> Tuple[str, List[typing.Dict[str, Any]], List[typing.Dict[str, Any]]]:
189189
"""Table for all functions in the project. Contains many details about each
190190
function"""
191191
random_suffix = '_' + ''.join(
@@ -235,7 +235,8 @@ def create_all_function_table(
235235
# an array in development to replace html generation in python.
236236
# this will be stored as a json object and will be used to populate
237237
# the table in the frontend
238-
table_rows = []
238+
table_rows_json_html = []
239+
table_rows_json_report = []
239240

240241
for fd_k, fd in proj_profile.all_functions.items():
241242
demangled_func_name = utils.demangle_cpp_func(fd.function_name)
@@ -286,7 +287,7 @@ def create_all_function_table(
286287
else:
287288
args_row = "0"
288289

289-
table_rows.append({
290+
table_rows_json_html.append({
290291
"Func name": func_name_row,
291292
"func_url": func_cov_url,
292293
"Functions filename": fd.function_source_file,
@@ -304,8 +305,26 @@ def create_all_function_table(
304305
"Accumulated cyclomatic complexity": fd.total_cyclomatic_complexity,
305306
"Undiscovered complexity": fd.new_unreached_complexity
306307
})
308+
table_rows_json_report.append({
309+
"Func name": demangled_func_name,
310+
"func_url": func_cov_url,
311+
"Functions filename": fd.function_source_file,
312+
"Args": str(fd.arg_types),
313+
"Function call depth": fd.function_depth,
314+
"Reached by Fuzzers": reached_by_fuzzers_row,
315+
"collapsible_id": collapsible_id,
316+
"Fuzzers runtime hit": func_hit_at_runtime_row,
317+
"Func lines hit %": "%.5s" % (str(hit_percentage)) + "%",
318+
"I Count": fd.i_count,
319+
"BB Count": fd.bb_count,
320+
"Cyclomatic complexity": fd.cyclomatic_complexity,
321+
"Functions reached": len(fd.functions_reached),
322+
"Reached by functions": len(fd.incoming_references),
323+
"Accumulated cyclomatic complexity": fd.total_cyclomatic_complexity,
324+
"Undiscovered complexity": fd.new_unreached_complexity
325+
})
307326
html_string += ("</table>\n")
308-
return html_string, table_rows
327+
return html_string, table_rows_json_html, table_rows_json_report
309328

310329

311330
def create_collapsible_element(
@@ -959,12 +978,20 @@ def create_html_report(
959978

960979
table_id = "fuzzers_overview_table"
961980
tables.append(table_id)
962-
all_function_table, all_functions_json = create_all_function_table(
981+
(all_function_table,
982+
all_functions_json_html,
983+
all_functions_json_report) = create_all_function_table(
963984
tables, proj_profile, coverage_url, basefolder, table_id)
964985
html_report_core += all_function_table
965986
html_report_core += "</div>" # .collapsible
966987
html_report_core += "</div>" # report box
967988

989+
# Dump all functions in json report
990+
json_report.add_project_key_value_to_report(
991+
"all-functions",
992+
all_functions_json_report
993+
)
994+
968995
#############################################
969996
# Section with details about each fuzzer, including calltree.
970997
#############################################
@@ -1108,7 +1135,7 @@ def create_html_report(
11081135
# Write all functions to the .js file
11091136
with open(report_name, "a+") as all_funcs_json_file:
11101137
all_funcs_json_file.write("var all_functions_table_data = ")
1111-
all_funcs_json_file.write(json.dumps(all_functions_json))
1138+
all_funcs_json_file.write(json.dumps(all_functions_json_html))
11121139

11131140
# Remove existing fuzzer table data .js file
11141141
js_file = "fuzzer_table_data.js"

0 commit comments

Comments
 (0)