Skip to content

[CONFIG] [Docker] [tools] gcovr tool (coverage) replaced by lcov. #32

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

Merged
merged 3 commits into from
Sep 16, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/cpp-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:

- name: Install Tools
run: |
pip install gcovr
sudo apt-get install lcov

- name: Check Tools
run: |
make --version
cmake --version
vcpkg --version
gcovr --version
lcov --version

- name: Install dependencies
run: |
Expand All @@ -54,6 +54,6 @@ jobs:
uses: codecov/codecov-action@v4
with:
directory: ./coverage
files: coverage.lcov
files: coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }} # required
verbose: true # optional (default = false)
10 changes: 4 additions & 6 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ jobs:
fetch-depth: 0
- name: Install Tools
run: |
sudo apt-get install lcov
pip install gcovr

- name: Check Tools
run: |
make --version
cmake --version
vcpkg --version
lcov --version
gcovr --version

- name: Install dependencies
Expand All @@ -43,17 +45,13 @@ jobs:
- name: Run build-wrapper
run: |
export VCPKG_ROOT=/usr/local/share/vcpkg
cmake --preset debug -B build
cmake --preset debug \
-DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
build
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build --verbose
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make build
# yamllint enable rule:line-length

- name: Run tests to generate coverage statistics
run: |
make coverage

- name: Collect coverage into one XML report
run: |
gcovr -e "src/tests/*" --sonarqube > coverage.xml
Expand Down
84 changes: 84 additions & 0 deletions .lcovrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Example LCOV configuration file
#
# External style sheet file
#genhtml_css_file = gcov.css

# Coverage rate limits for line coverage
genhtml_hi_limit = 80
genhtml_med_limit = 50

# Coverage rate limits for function coverage
genhtml_function_hi_limit = 90
genhtml_function_med_limit = 75

# Width of overview image
genhtml_overview_width = 80

# Resolution of overview navigation
genhtml_nav_resolution = 4

# Offset for source code navigation
genhtml_nav_offset = 10

# Do not remove unused test descriptions if non-zero
genhtml_keep_descriptions = 0

# Do not remove prefix from directory names if non-zero
genhtml_no_prefix = 0

# Do not create source code view if non-zero
genhtml_no_source = 0

# Specify size of tabs
genhtml_num_spaces = 8

# Highlight lines with converted-only data if non-zero
genhtml_highlight = 0

# Include color legend in HTML output if non-zero
genhtml_legend = 0

# Include HTML file at start of HTML output
#genhtml_html_prolog = prolog.html

# Include HTML file at end of HTML output
#genhtml_html_epilog = epilog.html

# Use custom HTML file extension
#genhtml_html_extension = html

# Compress all generated html files with gzip.
#genhtml_html_gzip = 1

# Include sorted overview pages
genhtml_sort = 1

# Include function coverage data display
genhtml_function_coverage = 1

# Location of the gcov tool
#geninfo_gcov_tool = gcov

# Adjust test names if non-zero
#geninfo_adjust_testname = 0

# Calculate a checksum for each line if non-zero
geninfo_checksum = 0

# Enable libtool compatibility mode if non-zero
geninfo_compat_libtool = 0

# Directory containing gcov kernel files
lcov_gcov_dir = /proc/gcov

# Location of the insmod tool
lcov_insmod_tool = /sbin/insmod

# Location of the modprobe tool
lcov_modprobe_tool = /sbin/modprobe

# Location of the rmmod tool
lcov_rmmod_tool = /sbin/rmmod

# Location for temporary directories
lcov_tmp_dir = /tmp
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ADD https://deb.nodesource.com/setup_22.x nodesource_setup.sh
RUN bash nodesource_setup.sh && \
apt-get -y install --no-install-recommends --no-install-suggests nodejs && \
npm install -g --ignore-scripts markdownlint-cli && \
apt-get -y install --no-install-recommends --no-install-suggests python3 python3-pip && \
apt-get -y install --no-install-recommends --no-install-suggests python3-minimal python3-pip && \
rm /usr/lib/python3.*/EXTERNALLY-MANAGED && \
pip install --no-cache-dir yamllint && \
apt-get -y install --no-install-recommends --no-install-suggests cppcheck && \
Expand All @@ -98,7 +98,7 @@ CMD ["make", "lint"]
FROM development AS testing

RUN apt-get -y update && \
apt-get -y install --no-install-recommends --no-install-suggests gcovr && \
apt-get -y install --no-install-recommends --no-install-suggests lcov && \
rm -rf /var/lib/apt/lists/*

COPY --from=builder ${WORKDIR}/build ${WORKDIR}/
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BUILDKIT_PROGRESS=plain
DOCKER_COMPOSE=docker compose

# TOOLS
COVERAGE_TOOL=gcovr -e "src/tests/*" -e "build/*" --exclude-throw-branches --exclude-unreachable-branches --exclude-noncode-lines --print-summary
COVERAGE_TOOL_OPTS=--config-file .lcovrc --rc branch_coverage=1

# C++ specific
SRC_DIR = src
Expand Down Expand Up @@ -94,11 +94,10 @@ test: env dependencies
cd build && make test

coverage: test
${COVERAGE_TOOL}
${COVERAGE_TOOL} --lcov coverage/coverage.lcov
lcov ${COVERAGE_TOOL_OPTS} -o coverage/lcov.info --no-external -c --exclude "build/vcpkg_installed" --exclude "test.cpp" -d .

coverage/html:
${COVERAGE_TOOL} --html-details coverage/index.html
coverage/html: coverage
genhtml ${COVERAGE_TOOL_OPTS} -o coverage/ -s --legend coverage/lcov.info
open coverage/index.html

outdated:
Expand Down
3 changes: 2 additions & 1 deletion src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("aVeryBigSum JSON Test Cases", "[warmup]") {
TEST_CASE("aVeryBigSum JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("birthdayCakeCandles JSON Test Cases", "[warmup]") {
TEST_CASE("birthdayCakeCandles JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("compareTriplets JSON Test Cases", "[warmup]") {
TEST_CASE("compareTriplets JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand All @@ -27,7 +28,7 @@ TEST_CASE("compareTriplets JSON Test Cases", "[warmup]") {
}
}

TEST_CASE("compareTriplets EDGE CASE empty input", "[warmup]") {
TEST_CASE("compareTriplets EDGE CASE empty input", "[hackerrank] [warmup]") {
std::vector<int> a;
std::vector<int> b;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("diagonalDifference JSON Test Cases", "[warmup]") {
TEST_CASE("diagonalDifference JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand Down
5 changes: 3 additions & 2 deletions src/tests/unit/lib/hackerrank/warmup/mini_max_sum.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("miniMaxSum JSON Test Cases", "[warmup]") {
TEST_CASE("miniMaxSum JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() + "/unit/lib/hackerrank/warmup/mini_max_sum.testcases.json";
Expand All @@ -30,7 +31,7 @@ TEST_CASE("miniMaxSum JSON Test Cases", "[warmup]") {
}
}

TEST_CASE("miniMaxSum Edge Cases", "[warmup]") {
TEST_CASE("miniMaxSum Edge Cases", "[hackerrank] [warmup]") {
std::vector<int> empty;
CHECK_THROWS_AS(hackerrank::warmup::miniMaxSumCalculate(empty),
std::invalid_argument);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/unit/lib/hackerrank/warmup/plus_minus.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <nlohmann/json.hpp>
using json = nlohmann::json;

TEST_CASE("plusMinus JSON Test Cases", "[warmup]") {
TEST_CASE("plusMinus JSON Test Cases", "[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() + "/unit/lib/hackerrank/warmup/plus_minus.testcases.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

using json = nlohmann::json;

TEST_CASE("simpleArraySum", "[warmup]") {
TEST_CASE("simpleArraySum JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand Down
3 changes: 2 additions & 1 deletion src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

using json = nlohmann::json;

TEST_CASE("solveMeFirst", "[warmup]") {
TEST_CASE("solveMeFirst JSON Test Cases",
"[hackerrank] [jsontestcase] [warmup]") {
std::filesystem::path cwd = std::filesystem::current_path();
std::string path =
cwd.string() +
Expand Down