Skip to content

Commit

Permalink
Adds logging to gathering code coverage artifacts
Browse files Browse the repository at this point in the history
Related-to: eclipse-bluechi#397
Signed-off-by: Martin Perina <[email protected]>
  • Loading branch information
mwperina authored and engelmi committed Dec 14, 2023
1 parent 8e2d93e commit cfb7055
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
24 changes: 12 additions & 12 deletions tests/bluechi_test/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,23 @@ def gather_coverage(self, data_coverage_dir: str) -> None:
gcno_file_location = "/usr/share/bluechi-coverage/"
gcda_file_location = "/var/tmp/bluechi-coverage"

result, output = self.container.exec_run("rpm -q bluechi-controller")
bluechi_version = "bluechi" + str(output.decode()).split("-controller")[1].split("\n")[0]
result, output = self.exec_run("rpm -q bluechi-controller")
bluechi_version = "bluechi" + output.split("-controller")[1].split("\n")[0]
src_file_location = f"/usr/src/debug/{bluechi_version}/src"

self.container.exec_run(f"cp -r {gcno_file_location}/. {gcda_file_location}")
self.exec_run(f"cp -r {gcno_file_location}/. {gcda_file_location}")

result, output = self.container.exec_run(f"find {gcda_file_location} -name '*gcda'")
for file in output.split(b"\n"):
if b"gcda" in file:
file_name_without_hashes = file.split(b"#")[-1].decode()
file = gcda_file_location + file.split(b'/var/tmp/bluechi-coverage')[-1].decode()
result, output = self.container.exec_run(f"cp {file} {gcda_file_location}/{file_name_without_hashes}")
result, output = self.container.exec_run(f"rm {file}")
result, output = self.exec_run(f"find {gcda_file_location} -name '*gcda'")
for file in output.split("\n"):
if "gcda" in file:
file_name_without_hashes = file.split("#")[-1]
file = gcda_file_location + file.split('/var/tmp/bluechi-coverage')[-1]
result, output = self.exec_run(f"cp {file} {gcda_file_location}/{file_name_without_hashes}")
result, output = self.exec_run(f"rm {file}")

coverage_file_name = f"coverage-{self.container.name}.info"

result, output = self.container.exec_run(
f"geninfo {gcda_file_location} -b {src_file_location} -o {coverage_file_name}")
result, output = self.exec_run(f"geninfo {gcda_file_location} -b {src_file_location} -o {coverage_file_name}")

self.get_file(f"/{coverage_file_name}", data_coverage_dir)

Expand All @@ -98,6 +97,7 @@ def exec_run(self, command: (Union[str, list[str]]), raw_output: bool = False, t
Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]:

result, output = self.container.exec_run(command, tty=tty)
LOGGER.debug(f"Executed command '{command}' with result '{result}' and output '{output}'")

if not raw_output and output:
output = output.decode('utf-8').strip()
Expand Down
9 changes: 5 additions & 4 deletions tests/scripts/create_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
report_dir_name = "/report"

merge_all_info_files(path_to_info_files)
content = read_file(merge_file_name)
ctrl.create_file(merge_dir, merge_file_name, content)
ctrl.exec_run(f"genhtml {merge_dir}/{merge_file_name} --output-directory={report_dir_name}")
ctrl.get_file(report_dir_name, path_to_tests_results)
if os.path.exists(merge_file_name):
content = read_file(merge_file_name)
ctrl.create_file(merge_dir, merge_file_name, content)
ctrl.exec_run(f"genhtml {merge_dir}/{merge_file_name} --output-directory={report_dir_name}")
ctrl.get_file(report_dir_name, path_to_tests_results)


def test_create_coverag_report(
Expand Down

0 comments on commit cfb7055

Please sign in to comment.