Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java-Integration]: Coverage report #612

Merged
merged 16 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/fuzz_introspector/code_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,32 @@ def load_python_json_coverage(
return cp


def load_jvm_coverage(
target_dir: str,
target_name: Optional[str] = None
) -> CoverageProfile:
arthurscchan marked this conversation as resolved.
Show resolved Hide resolved
"""
Scans a directory to read one or more coverage reports, and returns a CoverageProfile
arthurscchan marked this conversation as resolved.
Show resolved Hide resolved
Parses output from "llvm-cov show", e.g.
llvm-cov show -instr-profile=$profdata_file -object=$target \
-line-coverage-gt=0 $shared_libraries $LLVM_COV_COMMON_ARGS > \
${FUZZER_STATS_DIR}/$target.covreport
This is used to parse JVM coverage.
The function supports loading multiple and individual coverage reports.
This is needed because finding coverage on a per-fuzzer basis requires
correlating binary files to a specific introspection profile from compile time.
However, files could be moved around, renamed, and so on.
As such, this function accepts an arugment "target_name" which is used to
target specific coverage profiles. However, if no coverage profile matches
that given name then the function will find *all* coverage reports it can and
use all of them.
"""

cp = CoverageProfile()

return cp


if __name__ == "__main__":
logging.basicConfig()
logger.info("Starting coverage loader")
Expand Down
33 changes: 27 additions & 6 deletions src/fuzz_introspector/datatypes/fuzzer_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def identifier(self):
return os.path.basename(self.fuzzer_source_file).replace(".py", "")

elif self._target_lang == "jvm":
# TODO Handle jvm fuzzer source file
pass
# Class name is used for jvm identifier
return os.path.basename(self.fuzzer_source_file)

return self.fuzzer_source_file

Expand Down Expand Up @@ -150,8 +150,12 @@ def resolve_coverage_link(
function_name
)
elif self.target_lang == "jvm":
# TODO Add coverage report for JVM
pass
return self._resolve_jvm_coverage_link(
cov_url,
source_file,
lineno,
function_name
)
else:
logger.info("Could not find any html_status.json file")
return "#"
Expand Down Expand Up @@ -440,8 +444,7 @@ def _load_coverage(self, target_folder: str) -> None:
self.all_class_functions
)
elif self.target_lang == "jvm":
# TODO Add JVM coverage loading support
self.coverage = code_coverage.load_llvm_coverage(
self.coverage = code_coverage.load_jvm_coverage(
target_folder,
self.identifier
)
Expand Down Expand Up @@ -556,3 +559,21 @@ def _resolve_python_coverage_link(
else:
logger.info("Could not find any html_status.json file")
return "#"

def _resolve_jvm_coverage_link(
self,
cov_url: str,
source_file: str,
lineno: int,
function_name: str
) -> str:
"""Resolves link to HTML coverage report for JVM targets"""
# Handle source class for jvm
if ("." in source_file):
# Source file has package, change all . to path separator
source_file = source_file.replace(".", os.sep)
else:
# Source fil has no package, add in default package
source_file = os.path.join("default", source_file)

return cov_url + os.sep + source_file + ".html#L" + str(lineno)
23 changes: 11 additions & 12 deletions src/fuzz_introspector/datatypes/project_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,26 @@ def resolve_coverage_report_link(
func_name
):

if self.target_lang == "c-cpp":
return "%s%s.html#L%d" % (
if self.target_lang == "python":
return self.profiles[0].resolve_coverage_link(
coverage_url,
function_source_file,
lineno
lineno,
func_name
)
elif self.target_lang == "python":
elif self.target_lang == "jvm":
return self.profiles[0].resolve_coverage_link(
coverage_url,
function_source_file,
lineno,
func_name
)
elif self.target_lang == "jvm":
# TODO Add coverage details for jvm
pass
return "%s%s.html#L%d" % (
coverage_url,
function_source_file,
lineno
)
else:
arthurscchan marked this conversation as resolved.
Show resolved Hide resolved
return "%s%s.html#L%d" % (
coverage_url,
function_source_file,
lineno
)

@property
def target_lang(self):
Expand Down