Skip to content

Commit

Permalink
[infra] Fix jacoco_report_converter.py (#12026)
Browse files Browse the repository at this point in the history
There are 2 bugs in the jacoco_report_converter.py in which the src_file
and src_path are redefined and overwritten in the loop. These bugs cause
both of them to empty after the first iteration. This makes the
resulting JSON report summary only contain the first filename to
process. This has been mentioned in #11966.
This PR proposes a fix by changing the name of the needed variables.
Also, this PR adds in a filter to exclude fuzzer classes in the coverage
information as they are not part of the projects. The updated script
will include the coverage information for each class that existed in the
project source directory (`/out/src`) in the summary tag of the
resulting summary.json report.

Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan authored Jun 5, 2024
1 parent fac55fe commit 0406dd5
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions infra/base-images/base-runner/jacoco_report_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ def convert(xml):
src_files = list_src_files()

for class_element in report.findall('./package/class'):
class_name = class_element.attrib['name']
package_name = os.path.dirname(class_name)
# Skip fuzzer classes
if is_fuzzer_class(class_element):
continue

# Skip non class elements
if 'sourcefilename' not in class_element.attrib:
continue

class_name = class_element.attrib['name']
package_name = os.path.dirname(class_name)
basename = class_element.attrib['sourcefilename']
# This path is 'foo/Bar.java' for the class element
# <class name="foo/Bar" sourcefilename="Bar.java">.
canonical_path = os.path.join(package_name, basename)

class_summary = make_element_summary(class_element)
src_files = relative_to_src_path(src_files, canonical_path)
for src_file in src_files:
for src_file in relative_to_src_path(src_files, canonical_path):
summary['data'][0]['files'].append({
'filename': src_file,
'summary': class_summary,
Expand All @@ -77,11 +82,20 @@ def list_src_files():
for filename in filenames:
full_path = dirpath + '/' + filename
# Map /out//src/... to /src/...
src_path = full_path[len(out_path):]
filename_to_paths.setdefault(filename, []).append(src_path)
file_path = full_path[len(out_path):]
filename_to_paths.setdefault(filename, []).append(file_path)
return filename_to_paths


def is_fuzzer_class(class_element):
"""Check if the class is fuzzer class."""
method_elements = class_element.find('./method[@name=\"fuzzerTestOneInput\"]')
if method_elements:
return True

return False


def relative_to_src_path(src_files, canonical_path):
"""Returns all paths in src_files ending in canonical_path."""
basename = os.path.basename(canonical_path)
Expand Down

0 comments on commit 0406dd5

Please sign in to comment.