From 906d6443520cad3333e92d6b5521b51c8f825bcf Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 12 Nov 2026 17:32:54 +0300 Subject: [PATCH 1/2] ci: report unit test coverage in the job summary --- .github/workflows/tests.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f2d5590..a38552e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -311,3 +311,40 @@ jobs: assert not missing, f"dangling bom-refs: {missing}" print(f"ok: {path} with {len(doc['components'])} components") EOF + + # Line, function and branch coverage of the test suite, written to the job summary. + coverage: + name: Coverage + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - name: Checkout code + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + submodules: "recursive" + + - name: Install dependencies + run: | + sudo apt-get $APT_OPTS update + sudo apt-get $APT_OPTS install -y --no-install-recommends libcurl4-openssl-dev libssl-dev gcovr + + - name: Build the tests with coverage + run: | + cmake -DCOUNTLY_BUILD_TESTS=1 -DCOUNTLY_USE_SQLITE=ON -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage \ + -DCMAKE_EXE_LINKER_FLAGS=--coverage -DCMAKE_SHARED_LINKER_FLAGS=--coverage -B build . + cmake --build build -j 4 + + - name: Run the tests + run: ./build/countly-tests + + - name: Write the coverage summary + run: | + gcovr --root . --filter 'src/' --filter 'include/' --print-summary > "$RUNNER_TEMP/coverage.txt" + { + echo "### Unit test coverage" + echo + echo "| Metric | Covered | Count |" + echo "|---|---|---|" + awk '/^(lines|functions|branches):/ { gsub(/[():]/, ""); printf "| %s | %s | %s/%s |\n", $1, $2, $3, $6 }' "$RUNNER_TEMP/coverage.txt" + } >> "$GITHUB_STEP_SUMMARY" From 793bea6da96952bd8e64b7255965057e33f588de Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 12 Nov 2026 19:53:59 +0300 Subject: [PATCH 2/2] ci: use atomic coverage counters --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a38552e..5b1163c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -328,10 +328,11 @@ jobs: sudo apt-get $APT_OPTS update sudo apt-get $APT_OPTS install -y --no-install-recommends libcurl4-openssl-dev libssl-dev gcovr + # Atomic counters: the SDK's request thread runs beside the tests, and racing plain counters yield negative branch counts that gcovr rejects. - name: Build the tests with coverage run: | cmake -DCOUNTLY_BUILD_TESTS=1 -DCOUNTLY_USE_SQLITE=ON -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage \ + -DCMAKE_C_FLAGS="--coverage -fprofile-update=atomic" -DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic" \ -DCMAKE_EXE_LINKER_FLAGS=--coverage -DCMAKE_SHARED_LINKER_FLAGS=--coverage -B build . cmake --build build -j 4