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

Unify unit and integration tests coverage report #711

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 0 additions & 17 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
run: |
meson setup builddir
meson configure \
-Db_coverage=true \
-Dwith_analyzer=true \
builddir
meson compile -C builddir
Expand All @@ -41,25 +40,9 @@ jobs:
run: |
meson test --wrap='valgrind --leak-check=full --error-exitcode=1 --track-origins=yes' -C builddir

- name: Generating coverage report
run: |
ninja coverage-html -C builddir

- name: Upload unit test logs
if: always()
uses: actions/upload-artifact@v3
with:
name: unit-test-logs
path: ./builddir/meson-logs/testlog-valgrind.txt

- name: Upload coverage HTML artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: builddir/meson-logs/coveragereport
if-no-files-found: error

- name: Report coverage results
run: |
cd builddir/meson-logs/coveragereport/
html2text --ignore-images --ignore-links -b 0 --bypass-tables index.html >> $GITHUB_STEP_SUMMARY
7 changes: 7 additions & 0 deletions bluechi.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ popd
%if 0%{?with_coverage}
mkdir -p %{buildroot}/%{_datadir}/bluechi-coverage/bin
cp tests/scripts/gather-code-coverage.sh %{buildroot}/%{_datadir}/bluechi-coverage/bin
cp tests/scripts/setup-src-dir-for-coverage.sh %{buildroot}/%{_datadir}/bluechi-coverage/bin

mkdir -p %{buildroot}/%{_localstatedir}/tmp/bluechi-coverage/
%endif
Expand All @@ -283,6 +284,12 @@ popd
%check
%meson_test

%if 0%{?with_coverage}
# Install gcda files from unit test execution so they could be packages into bluechi-coverage RPM.
# Those files cannot be installed inside install section, because unit tests are executed later.
# Files need to be moved to clean up as using clean section in spec is not recommended by Fedora Packaging Guidelines.
mv /var/tmp/bluechi-coverage/*.gcda %{buildroot}/%{_datadir}/bluechi-coverage
%endif

%changelog
* Mon Jan 17 2024 Michael Engel <mengel@redhat.com> - 0.7.0-1
Expand Down
16 changes: 8 additions & 8 deletions build-scripts/install-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

# This script should be executed only from meson as a part of install flow!
#
COVERAGE_ROOT="${MESON_INSTALL_DESTDIR_PREFIX}/share/bluechi-coverage"

# Install all created `*.gcno` files so they could be packaged into bluechi-coverage RPM.
mkdir -p ${COVERAGE_ROOT}
( cd $MESON_BUILD_ROOT ; find . -name "*.gcno" -exec cp -v --parents {} ${COVERAGE_ROOT} \; )

for f in $MESON_BUILD_ROOT/src/*; do
if [ -d "$f" ]; then
COV_DIR="${MESON_INSTALL_DESTDIR_PREFIX}/share/bluechi-coverage"
COV_DIR="${COV_DIR}/${f##*/}"
mkdir -p "${COV_DIR}"
find "${f}" -name '*.gcno' -exec cp "{}" "${COV_DIR}" \;
fi
done
# Unit test source files are not included in debugsource RPM, add them to bluechi-coverage RPM
engelmi marked this conversation as resolved.
Show resolved Hide resolved
TEST_SUBDIR="src/libbluechi/test"
mkdir -p ${COVERAGE_ROOT}/${TEST_SUBDIR}
( cd $MESON_SOURCE_ROOT/${TEST_SUBDIR} ; find . -name "*.c" -exec cp -v --parents {} ${COVERAGE_ROOT}/${TEST_SUBDIR} \; )
9 changes: 8 additions & 1 deletion tests/scripts/create_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
merge_dir = "/tmp"
report_dir_name = "/report"

LOGGER.debug("Setting up source code directory for generating coverage report")
ctrl.exec_run("/usr/share/bluechi-coverage/bin/setup-src-dir-for-coverage.sh")

# Copy info files to the ctrl container and run lcov command
LOGGER.debug(f"Merging info files from integration tests to '{merge_dir}/{merge_file_name}'")
root = pathlib.Path(path_to_info_files)
lcov_list = list()
lcov_list.append("lcov")
Expand All @@ -33,8 +37,11 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer

lcov_list.append("-o")
lcov_list.append(f"{merge_dir}/{merge_file_name}")
result, output = ctrl.exec_run(" ".join(lcov_list))
if result != 0:
raise Exception(f"Error merging info files from each integration test: {output}")

ctrl.exec_run(" ".join(lcov_list))
LOGGER.debug(f"Generating report for merged info file '{merge_dir}/{merge_file_name}'")
result, output = ctrl.exec_run(f"genhtml {merge_dir}/{merge_file_name} --output-directory={report_dir_name}")
if result != 0:
raise Exception(f"Failed to do run genthtml inside the container: {output}")
Expand Down
21 changes: 8 additions & 13 deletions tests/scripts/gather-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,25 +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"
source $(dirname "$(readlink -f "$0")")/setup-src-dir-for-coverage.sh

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

# move each .gcda file into the respective project directory containing the .gcno
# Move each .gcda file into the respective project directory containing the .gcno
for file in ${GCDA_DIR}/*.gcda ; do
# project directory, e.g. libbluechi, is at position 3 (hence -f-3)
project_dir=$(echo $file | rev | cut -d'#' -f-3 | rev | cut -d'#' -f-1)
filename=$(echo $file | rev | cut -d'#' -f-1 | rev)
mv $file ${GCDA_DIR}/$project_dir/$filename
# Remove encoded directories up to src
tmp_f="src${file##*src}"
# Convert encoded directory to proper path
tmp_f="${tmp_f//\#/\/}"
mv -v $file ${GCDA_DIR}/${tmp_f}
done

# Generate info file
geninfo ${GCDA_DIR} -b ${SRC_DIR} -o ${INFO_FILE}
geninfo ${GCDA_DIR} -b ${GCDA_DIR}/src -o ${INFO_FILE}
15 changes: 15 additions & 0 deletions tests/scripts/setup-src-dir-for-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later

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

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

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

# Copy source files from bluechi-debugsource package into GCDA_DIR, because unit test source files are not included
# in debugsource package, so we needed to add them to bluechi-coverage package
( cd $SRC_DIR ; cp -r src ${GCDA_DIR} )
Loading