Skip to content

Commit 40045f2

Browse files
committed
Coverage
1 parent 4a8e7e8 commit 40045f2

File tree

74 files changed

+4286
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4286
-150
lines changed

.github/workflows/cmake-multi-platform.yml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ concurrency:
1010
group: ci-${{ github.ref }}
1111
cancel-in-progress: true
1212

13-
1413
##############################################################################
1514
# 1) Linux – Clang / Ninja
1615
##############################################################################
@@ -32,8 +31,8 @@ jobs:
3231
sudo apt-get install -y git build-essential cmake ninja-build \
3332
zip unzip curl pkg-config ca-certificates \
3433
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
35-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
36-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
34+
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
35+
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
3736
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
3837
- name: Linux (Clang) (x86-linux)
3938
triplet: x86-linux
@@ -56,8 +55,8 @@ jobs:
5655
# Install GCC 15 with multilib support
5756
sudo apt-get install -y gcc-15-multilib g++-15-multilib
5857
# Set up alternatives for Clang
59-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
60-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
58+
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
59+
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
6160
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
6261
# Set up alternatives for GCC
6362
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 100
@@ -73,8 +72,8 @@ jobs:
7372
sudo apt-get install -y git build-essential cmake ninja-build \
7473
zip unzip curl pkg-config ca-certificates \
7574
clang-21 lld-21 libc++-21-dev libc++abi-21-dev
76-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 100
77-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 100
75+
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
76+
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
7877
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
7978
fail-fast: false
8079
env:
@@ -84,16 +83,6 @@ jobs:
8483
shell: bash
8584
run: ${{ matrix.install_cmd }}
8685

87-
- name: Verify compiler versions
88-
shell: bash
89-
run: |
90-
echo "=== Clang ==="
91-
clang --version
92-
clang++ --version
93-
echo "=== GCC ==="
94-
gcc --version || true
95-
g++ --version || true
96-
9786
- name: Checkout repository (with sub-modules)
9887
uses: actions/checkout@v4
9988
with:
@@ -115,13 +104,28 @@ jobs:
115104
-DOMATH_BUILD_BENCHMARK=OFF \
116105
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"
117106
118-
- name: Build
107+
- name: Build and Run (non-coverage)
108+
if: ${{ matrix.triplet != 'x64-linux' }}
119109
shell: bash
120-
run: cmake --build cmake-build/build/${{ matrix.preset }} --target unit_tests omath
110+
run: |
111+
cmake --build cmake-build/build/${{ matrix.preset }} --target unit_tests omath
112+
./out/Release/unit_tests
121113
122-
- name: Run unit_tests
114+
- name: Run clang coverage (x64-linux)
115+
if: ${{ matrix.triplet == 'x64-linux' }}
123116
shell: bash
124-
run: ./out/Release/unit_tests
117+
run: |
118+
sudo apt-get update
119+
sudo apt-get install -y lcov llvm-21
120+
export PATH="/usr/lib/llvm-21/bin:$PATH"
121+
NO_AVX=1 ./scripts/run_clang_coverage.sh build/clang-coverage-lcov
122+
123+
- name: Run coveralls (x64-linux)
124+
if: ${{ matrix.triplet == 'x64-linux' }}
125+
uses: coverallsapp/github-action@master
126+
with:
127+
path-to-lcov: ./build/clang-coverage-lcov/coverage/coverage.fixed.lcov
128+
github-token: ${{ secrets.GITHUB_TOKEN }}
125129

126130
- name: Upload logs on failure
127131
if: ${{ failure() }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
/out
33
*.DS_Store
44
/extlibs/vcpkg
5-
.idea/workspace.xml
5+
.idea/workspace.xml
6+
/build/
7+
*.gcov

CMakeLists.txt

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ project(omath VERSION ${OMATH_VERSION} LANGUAGES CXX)
66
include(CMakePackageConfigHelpers)
77
include(CheckCXXCompilerFlag)
88

9+
include(cmake/Coverage.cmake)
10+
911
if (MSVC)
1012
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
1113
else ()
@@ -23,7 +25,7 @@ option(OMATH_STATIC_MSVC_RUNTIME_LIBRARY "Force Omath to link static runtime" OF
2325
option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build to improve general performance" ON)
2426
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
2527
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON)
26-
28+
option(OMATH_ENABLE_COVERAGE "Enable compiling tests with coverage. (Linux only)" ON)
2729

2830
if (VCPKG_MANIFEST_FEATURES)
2931
foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
@@ -60,6 +62,7 @@ if (${PROJECT_IS_TOP_LEVEL})
6062
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
6163
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
6264
message(STATUS "[${PROJECT_NAME}]: Building using vcpkg ${OMATH_BUILD_VIA_VCPKG}")
65+
message(STATUS "[${PROJECT_NAME}]: Coverage is ${OMATH_ENABLE_COVERAGE}")
6366
endif ()
6467

6568
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
@@ -76,6 +79,13 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
7679

7780
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")
7881

82+
# If forward_helpers.cpp is present, compile it with inlining disabled so that
83+
# emitted symbols/debug-info are produced in that TU (helpful for coverage attribution).
84+
# Delegate coverage-related configuration to cmake/Coverage.cmake
85+
if(OMATH_ENABLE_COVERAGE AND CMAKE_HOST_LINUX AND OMATH_BUILD_TESTS)
86+
omath_setup_coverage_for_root(${PROJECT_NAME})
87+
endif()
88+
7989
if (OMATH_IMGUI_INTEGRATION)
8090
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_IMGUI_INTEGRATION)
8191

@@ -135,6 +145,11 @@ if (OMATH_USE_AVX2)
135145
endif ()
136146
endif ()
137147

148+
if(EMSCRIPTEN)
149+
target_compile_options(${PROJECT_NAME} PRIVATE -fexceptions)
150+
target_link_options(${PROJECT_NAME} PRIVATE -fexceptions)
151+
endif()
152+
138153
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
139154

140155
if (OMATH_BUILD_TESTS)
@@ -150,6 +165,56 @@ if (OMATH_BUILD_EXAMPLES)
150165
add_subdirectory(examples)
151166
endif ()
152167

168+
if(OMATH_ENABLE_COVERAGE AND CMAKE_HOST_LINUX AND OMATH_BUILD_TESTS)
169+
# Configure coverage flags per-compiler:
170+
# - For Clang/AppleClang use LLVM's instrumentation flags so the build
171+
# produces .profraw files usable by llvm-profdata/llvm-cov.
172+
# - For GCC use the traditional gcov flags (-fprofile-arcs -ftest-coverage).
173+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
174+
target_compile_options(${PROJECT_NAME} PRIVATE
175+
$<$<CONFIG:Debug>:-g>
176+
$<$<CONFIG:Debug>:-fprofile-instr-generate>
177+
$<$<CONFIG:Debug>:-fcoverage-mapping>
178+
)
179+
# No special link flags needed for Clang llvm profile instrumentation.
180+
else()
181+
# Default to GCC-style gcov instrumentation for other compilers.
182+
target_compile_options(${PROJECT_NAME} PRIVATE
183+
$<$<CONFIG:Debug>:-g>
184+
$<$<CONFIG:Debug>:-fprofile-arcs>
185+
$<$<CONFIG:Debug>:-ftest-coverage>
186+
)
187+
# Link-time flags to ensure coverage support for gcov
188+
target_link_libraries(${PROJECT_NAME} PRIVATE
189+
$<$<CONFIG:Debug>:-fprofile-arcs>
190+
$<$<CONFIG:Debug>:-ftest-coverage>
191+
)
192+
endif()
193+
194+
# Normalize recorded source file paths in debug info and coverage by
195+
# rewriting build/source prefixes to a stable value. This helps tools
196+
# like geninfo/gcov map execution addresses to canonical header paths.
197+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
198+
# Map the absolute source and binary paths to a short placeholder
199+
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" OMATH_SRC_PATH)
200+
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}" OMATH_BUILD_PATH)
201+
string(REPLACE "/" "\\/" OMATH_SRC_PATH_ESCAPED "${OMATH_SRC_PATH}")
202+
string(REPLACE "/" "\\/" OMATH_BUILD_PATH_ESCAPED "${OMATH_BUILD_PATH}")
203+
204+
# Add compiler flags that rewrite recorded paths in debug info.
205+
# Map them to '.' so geninfo can find sources relative to the
206+
# build working directory used when collecting coverage.
207+
target_compile_options(${PROJECT_NAME} PRIVATE
208+
# Map source tree to one level up so geninfo running from the
209+
# binary directory can find ../include/... and ../source/...
210+
$<$<CONFIG:Debug>:-ffile-prefix-map=${OMATH_SRC_PATH}=..>
211+
$<$<CONFIG:Debug>:-ffile-prefix-map=${OMATH_BUILD_PATH}=.>
212+
$<$<CONFIG:Debug>:-fdebug-prefix-map=${OMATH_SRC_PATH}=..>
213+
$<$<CONFIG:Debug>:-fdebug-prefix-map=${OMATH_BUILD_PATH}=.>
214+
)
215+
endif()
216+
endif ()
217+
153218
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND OMATH_THREAT_WARNING_AS_ERROR)
154219
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
155220
elseif (OMATH_THREAT_WARNING_AS_ERROR)
@@ -167,6 +232,8 @@ target_include_directories(${PROJECT_NAME}
167232
$<INSTALL_INTERFACE:include> # Use this path when the project is installed
168233
)
169234

235+
# Coverage targets are configured by cmake/Coverage.cmake via
236+
# omath_setup_coverage_for_root().
170237

171238
# Installation rules
172239

@@ -188,7 +255,6 @@ install(EXPORT ${PROJECT_NAME}Targets
188255
DESTINATION lib/cmake/${PROJECT_NAME} COMPONENT ${PROJECT_NAME}
189256
)
190257

191-
192258
# Generate the omathConfigVersion.cmake file
193259
write_basic_package_version_file(
194260
"${CMAKE_CURRENT_BINARY_DIR}/omathConfigVersion.cmake"

CMakePresets.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@
134134
"name": "linux-base",
135135
"hidden": true,
136136
"inherits": "base",
137-
"cacheVariables": {
138-
"CMAKE_C_COMPILER": "clang-21",
139-
"CMAKE_CXX_COMPILER": "clang++-21"
140-
},
141137
"condition": {
142138
"type": "equals",
143139
"lhs": "${hostSystemName}",

0 commit comments

Comments
 (0)