Skip to content
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
58 changes: 58 additions & 0 deletions .github/actions/gcovr/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Gcovr
description: Generate code coverage reports with gcovr and llvm-cov

inputs:
build-directory:
description: Build directory containing coverage data (.gcda / .gcno)
required: false
default: build
source-root:
description: Source root for gcovr --root
required: false
default: ${{ github.workspace }}
gcov-executable:
description: gcov executable passed to gcovr (e.g. llvm-cov-16 gcov for Clang)
required: false
default: llvm-cov-16 gcov
gcovr-version:
description: gcovr PyPI version to install
required: false
default: "8.4"
output-directory:
description: Directory for generated coverage reports
required: false
default: build/coverage
fail-under-line:
description: Fail if line coverage is below this percent (0 disables the gate)
required: false
default: "0"

runs:
using: composite
steps:
- name: Install gcovr
shell: bash
run: |
python3 -m pip install --user "gcovr==${{ inputs.gcovr-version }}"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"

- name: Verify llvm-cov
shell: bash
run: |
llvm_cov="${{ inputs.gcov-executable }}"
llvm_cov_bin="${llvm_cov%% *}"
if ! command -v "${llvm_cov_bin}" >/dev/null 2>&1; then
echo "::error::${llvm_cov_bin} not found; install LLVM or adjust gcov-executable"
exit 1
fi

- name: Generate coverage report
shell: bash
run: |
chmod +x "${{ github.action_path }}/run_gcovr.sh"
SOURCE_ROOT="${{ inputs.source-root }}" \
BUILD_DIR="${{ github.workspace }}/${{ inputs.build-directory }}" \
OUTPUT_DIR="${{ github.workspace }}/${{ inputs.output-directory }}" \
GCOV_EXECUTABLE="${{ inputs.gcov-executable }}" \
FAIL_UNDER_LINE="${{ inputs.fail-under-line }}" \
"${{ github.action_path }}/run_gcovr.sh"
32 changes: 32 additions & 0 deletions .github/actions/gcovr/run_gcovr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

: "${SOURCE_ROOT:?SOURCE_ROOT is required}"
: "${BUILD_DIR:?BUILD_DIR is required}"
: "${OUTPUT_DIR:?OUTPUT_DIR is required}"
: "${GCOV_EXECUTABLE:=llvm-cov-16 gcov}"

mkdir -p "${OUTPUT_DIR}"

gcovr_args=(
--root "${SOURCE_ROOT}"
--object-directory "${BUILD_DIR}"
--gcov-executable "${GCOV_EXECUTABLE}"
--print-summary
--json-summary "${OUTPUT_DIR}/summary.json"
--html --html-details
-o "${OUTPUT_DIR}/index.html"
--cobertura "${OUTPUT_DIR}/cobertura.xml"
--exclude '.*contrib/.*'
--exclude '.*tests/.*'
--exclude '.*/_deps/.*'
--filter 'src/'
--filter 'include/ydb-cpp-sdk/'
--filter 'plugins/'
)

if [[ -n "${FAIL_UNDER_LINE:-}" && "${FAIL_UNDER_LINE}" != "0" ]]; then
gcovr_args+=(--fail-under-line "${FAIL_UNDER_LINE}")
fi

gcovr "${gcovr_args[@]}"
89 changes: 89 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Coverage

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main

concurrency:
group: coverage-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
coverage:
runs-on: ubuntu-22.04
permissions:
contents: read
id-token: write
services:
ydb:
image: ydbplatform/local-ydb:24.4
ports:
- 2135:2135
- 2136:2136
- 8765:8765
volumes:
- /tmp/ydb_certs:/ydb_certs
env:
YDB_LOCAL_SURVIVE_RESTART: true
YDB_USE_IN_MEMORY_PDISKS: true
YDB_TABLE_ENABLE_PREPARED_DDL: true
options: '-h localhost'
steps:
- name: Checkout PR
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}

- name: Checkout
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true

- name: Install dependencies
uses: ./.github/actions/prepare_vm

- name: Configure and build with coverage
shell: bash
run: |
mkdir -p build
rm -rf build/*
cmake --preset coverage-test-gcc
cmake --build build -j"$(nproc)"

- name: Test
shell: bash
run: |
ctest -j1 --preset coverage-all --output-on-failure

- name: Generate coverage report
uses: ./.github/actions/gcovr
with:
build-directory: build
source-root: ${{ github.workspace }}
gcov-executable: gcov-13

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
use_oidc: true
files: build/coverage/cobertura.xml
disable_search: true
flags: sdk
name: ydb-cpp-sdk
fail_ci_if_error: true
verbose: true

- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/coverage/
retention-days: 14
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ include(CMakePackageConfigHelpers)
list(APPEND CMAKE_MODULE_PATH ${YDB_SDK_SOURCE_DIR}/cmake)

include(cmake/global_flags.cmake)
include(cmake/coverage.cmake)
include(cmake/global_vars.cmake)
include(cmake/install.cmake)
include(cmake/common.cmake)
Expand Down
34 changes: 34 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@
"name": "debug-test-gcc",
"inherits": ["debug-base", "gcc-toolchain", "test"],
"displayName": "Default Debug Test Config (GCC)"
},
{
"name": "coverage-base",
"inherits": ["release-base", "test"],
"hidden": true,
"cacheVariables": {
"YDB_SDK_COVERAGE": "ON",
"ARCADIA_ROOT": "${sourceDir}",
"ARCADIA_BUILD_ROOT": "${sourceDir}/build"
}
},
{
"name": "coverage-test-gcc",
"inherits": ["coverage-base", "gcc-toolchain"],
"displayName": "Coverage Test Config (GCC)"
}
],
"buildPresets": [
Expand Down Expand Up @@ -173,6 +188,25 @@
"YDB_ENDPOINT": "localhost:2136",
"YDB_DATABASE": "/local"
}
},
{
"name": "coverage-all",
"inherits": "all",
"displayName": "Run All Tests (coverage CI)",
"configurePreset": "coverage-test-gcc",
"execution": {
"timeout": 1800
},
"filter": {
"exclude": {
"name": "(ManyMessages|DiscoveryHang|DescribeHang)"
}
},
"environment": {
"YDB_ENDPOINT": "localhost:2136",
"YDB_DATABASE": "/local",
"YDB_VERSION": "24.4"
}
}
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# YDB C++ SDK: driver for [YDB](https://github.com/ydb-platform/ydb)

[![Codecov](https://codecov.io/gh/ydb-platform/ydb-cpp-sdk/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ydb-platform/ydb-cpp-sdk)

## Building YDB C++ SDK from sources

### Prerequisites
Expand Down
4 changes: 3 additions & 1 deletion cmake/ccache.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
find_program(CCACHE_PATH ccache)
if (NOT CCACHE_PATH)
if (YDB_SDK_COVERAGE)
message(STATUS "YDB_SDK_COVERAGE is ON: ccache compiler launchers disabled")
elseif (NOT CCACHE_PATH)
message(AUTHOR_WARNING
"Ccache is not found, that will increase the re-compilation time; "
"pass -DCCACHE_PATH=path/to/bin to specify the path to the `ccache` binary file."
Expand Down
2 changes: 1 addition & 1 deletion cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function(_ydb_sdk_add_library Tgt)
target_compile_definitions(${Tgt} ${includeMode}
YDB_SDK_OSS
)
_ydb_sdk_apply_coverage(${Tgt})

endfunction()

Expand Down Expand Up @@ -462,4 +463,3 @@ function(_ydb_sdk_validate_public_headers)
)
target_include_directories(validate_public_interface PUBLIC ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include)
endfunction()
21 changes: 21 additions & 0 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
option(YDB_SDK_COVERAGE "Instrument SDK and tests for gcov/llvm-cov coverage" OFF)

if (YDB_SDK_COVERAGE)
add_link_options(--coverage)
endif()

function(_ydb_sdk_apply_coverage target)
if (NOT YDB_SDK_COVERAGE)
return()
endif()
get_target_property(is_iface ${target} TYPE)
if (is_iface STREQUAL "INTERFACE_LIBRARY")
return()
endif()
# Do not use -fprofile-abs-path: it expands __FILE__/__LOCATION__ to absolute paths
# and breaks util/system/src_location_ut and src_root_ut (and similar assertions).
# gcovr --root maps profile data to the source tree without it.
set(_coverage_compile_flags --coverage -O0 -g -fno-inline)
target_compile_options(${target} PRIVATE ${_coverage_compile_flags})
target_link_options(${target} PRIVATE --coverage)
endfunction()
1 change: 1 addition & 0 deletions cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function(add_ydb_test)
endif()

add_executable(${YDB_TEST_NAME})
_ydb_sdk_apply_coverage(${YDB_TEST_NAME})
target_include_directories(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_INCLUDE_DIRS})
target_link_libraries(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_LINK_LIBRARIES})
target_sources(${YDB_TEST_NAME} PRIVATE ${YDB_TEST_SOURCES})
Expand Down
Loading