Skip to content

Commit

Permalink
Generate coverage info files within containers
Browse files Browse the repository at this point in the history
Perform all processing around generating code coverage info file within
relevant container to improve performance.

Signed-off-by: Martin Perina <[email protected]>
  • Loading branch information
mwperina committed Dec 21, 2023
1 parent f54ba1c commit ccf1a64
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
4 changes: 4 additions & 0 deletions bluechi.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ will be used during integration tests when creating code coverage report.

%files coverage
%license LICENSE
%{_datadir}/bluechi-coverage/bin/*
%{_datadir}/bluechi-coverage/*.gcno
%dir %{_localstatedir}/tmp/bluechi-coverage/
%endif
Expand All @@ -256,6 +257,9 @@ popd
%meson_install

%if 0%{?with_coverage}
mkdir -p %{buildroot}/%{_datadir}/bluechi-coverage/bin
cp tests/scripts/gather-code-coverage.sh %{buildroot}/%{_datadir}/bluechi-coverage/bin

mkdir -p %{buildroot}/%{_localstatedir}/tmp/bluechi-coverage/
%endif

Expand Down
24 changes: 5 additions & 19 deletions tests/bluechi_test/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,14 @@ def gather_journal_logs(self, data_dir: str) -> None:
self.get_file(log_file, data_dir)

def gather_coverage(self, data_coverage_dir: str) -> None:
gcno_file_location = "/usr/share/bluechi-coverage/"
gcda_file_location = "/var/tmp/bluechi-coverage"
coverage_file = f"{gcda_file_location}/coverage-{self.container.name}.info"

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"
LOGGER.info("Generating info file started")
result, output = self.exec_run(f"/usr/share/bluechi-coverage/bin/gather-code-coverage.sh {coverage_file}")
LOGGER.info("Generating info file finished")

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

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.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)
self.get_file(f"{coverage_file}", data_coverage_dir)

def cleanup(self):
if self.container.status == 'running':
Expand Down
20 changes: 20 additions & 0 deletions tests/scripts/gather-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later

GCNO_DIR="/usr/share/bluechi-coverage"
GCDA_DIR="/var/tmp/bluechi-coverage"

# First parameter is the name of the generated info file
INFO_FILE=${1:-coverage.info}

BC_VRA="$(rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}' bluechi-agent 2>/dev/null)"
SRC_DIR="/usr/src/debug/bluechi-${BC_VRA}/src"

# Remove path prefix from GCDA files
(cd ${GCDA_DIR} && for file in *.gcda ; do mv ${file} ${file##*#} ; done)

# Copy .gcno files to code coverage temporary directory
cp -r ${GCNO_DIR}/. ${GCDA_DIR}

# Generate info file
geninfo ${GCDA_DIR} -b ${SRC_DIR} -o ${INFO_FILE}

0 comments on commit ccf1a64

Please sign in to comment.