From 1be7ed3f78f215e803f41aebb6b16165ed54e80c Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Mon, 10 Jan 2022 22:08:48 +0000 Subject: [PATCH] post-process: refactor HTML creation code --- post-processing/fuzz_html.py | 62 ++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/post-processing/fuzz_html.py b/post-processing/fuzz_html.py index cfcb03bd1..bd4d069de 100644 --- a/post-processing/fuzz_html.py +++ b/post-processing/fuzz_html.py @@ -496,43 +496,31 @@ def create_html_report( Logs a complete report. This is the current main place for looking at data produced by fuzz introspector. """ - tables = [] - - # Remove existing html report. - report_name = "fuzz_report.html" - if os.path.isfile(report_name): - os.remove(report_name) - + tables = list() toc_list = list() - l.info(" - Creating top section") - # Create html file and top bits. - # with open(report_name, "a+") as html_report: - html_header = html_get_header() + l.info(" - Creating HTML report") - # Now create the body of the html. The header will be prepended later. - html_string = "" + # Create html header, which will be used to assemble the doc at the + # end of this function. + html_header = html_get_header() - # Wrap the content - html_string += '
' + # Start creation of core html + html_string = '
' - # Add the content + # Project overview html_string += html_add_header_with_link("Project overview", 1, toc_list) + html_string += html_add_header_with_link"Project information", 2, toc_list) - # Project meta information - html_string += html_add_header_with_link( - "Project information", 2, toc_list) - - # 1) Display: - # - The amount of functions reached by existing fuzzers - html_string += html_add_header_with_link( - "Reachability overview", 3, toc_list) + ############################################# + # Reachability overview + ############################################# + l.info(" - Creating reachability overview table") + html_string += html_add_header_with_link("Reachability overview", 3, toc_list) tables.append("myTable%d" % (len(tables))) - html_string += "

This is the overview of reachability by the existing fuzzers in the project

" html_string += create_top_summary_info(tables, project_profile) - ############################################# # Table with overview of all fuzzers. ############################################# @@ -552,15 +540,11 @@ def create_html_report( tables, project_profile, coverage_url, git_repo_url, basefolder) ############################################# - # Section with details about each fuzzer. - # This includes calltree for each fuzzer. + # Section with details about each fuzzer, including calltree. ############################################# l.info(" - Creating section with details about each fuzzer") html_string += html_add_header_with_link("Fuzzer details", 1, toc_list) - - profile_idx = 0 - for profile in profiles: - profile_idx += 1 + for profile_idx in range(len(profiles)): html_string += create_fuzzer_detailed_section(profile, toc_list, tables, profile_idx, project_profile, coverage_url, git_repo_url, basefolder) ############################################# @@ -608,6 +592,7 @@ def create_html_report( html_string += "];\n" counter += 1 + # Closing tags html_string += ("\n") html_string += ("\n") html_string += ("\n") @@ -618,11 +603,18 @@ def create_html_report( html_toc_string = html_get_table_of_contents(toc_list) # Assemble the final HTML report and write it to a file. - html_string = html_header + html_toc_string + html_string + html_full_doc = html_header + html_toc_string + html_string - # pretty print the html code: - soup = bs(html_string, "lxml") + # Pretty print the html document + soup = bs(html_full_doc, "lxml") prettyHTML = soup.prettify() + + # Remove existing html report + report_name = "fuzz_report.html" + if os.path.isfile(report_name): + os.remove(report_name) + + # Write new html report with open(report_name, "a+") as html_report: html_report.write(prettyHTML)