diff --git a/tests/bluechi_test/container.py b/tests/bluechi_test/container.py index 20c6cc6699..fa76355440 100644 --- a/tests/bluechi_test/container.py +++ b/tests/bluechi_test/container.py @@ -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) @@ -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() diff --git a/tests/scripts/create_coverage_report.py b/tests/scripts/create_coverage_report.py index cb2ac873c3..09fab4bf7f 100644 --- a/tests/scripts/create_coverage_report.py +++ b/tests/scripts/create_coverage_report.py @@ -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(