mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Use LLVM coverage and LCOV genhtml on Windows OS (#129)
This commit is contained in:
109
.github/workflows/cmake-multi-platform.yml
vendored
109
.github/workflows/cmake-multi-platform.yml
vendored
@@ -188,7 +188,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Configure (cmake --preset)
|
- name: Configure (cmake --preset)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: cmake --preset ${{ matrix.preset }} -DOMATH_BUILD_TESTS=ON -DOMATH_BUILD_BENCHMARK=OFF -DOMATH_ENABLE_COVERAGE=OFF -DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"
|
run: |
|
||||||
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DOMATH_BUILD_TESTS=ON \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
|
-DOMATH_ENABLE_COVERAGE=OFF \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -198,35 +203,121 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: ./out/Release/unit_tests.exe
|
run: ./out/Release/unit_tests.exe
|
||||||
|
|
||||||
- name: Install OpenCppCoverage with Chocolatey
|
##########################################################################
|
||||||
|
# Coverage (x64-windows only)
|
||||||
|
##########################################################################
|
||||||
|
- name: Install LLVM
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
run: choco install opencppcoverage -y
|
run: |
|
||||||
|
choco install llvm -y
|
||||||
|
|
||||||
|
- name: Clean Build Directory for Coverage
|
||||||
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$buildDir = "cmake-build/build/${{ matrix.preset }}"
|
||||||
|
if (Test-Path $buildDir) {
|
||||||
|
Write-Host "Cleaning build directory to prevent compiler conflict: $buildDir"
|
||||||
|
Remove-Item -Path $buildDir -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
- name: Build Debug for Coverage
|
- name: Build Debug for Coverage
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cmake --preset ${{ matrix.preset }} \
|
cmake --preset ${{ matrix.preset }} \
|
||||||
|
-DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" \
|
||||||
|
-DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" \
|
||||||
|
-DCMAKE_LINKER="C:/Program Files/LLVM/bin/lld-link.exe" \
|
||||||
-DOMATH_BUILD_TESTS=ON \
|
-DOMATH_BUILD_TESTS=ON \
|
||||||
-DOMATH_BUILD_BENCHMARK=OFF \
|
-DOMATH_BUILD_BENCHMARK=OFF \
|
||||||
-DOMATH_ENABLE_COVERAGE=ON \
|
-DOMATH_ENABLE_COVERAGE=ON \
|
||||||
|
-DOMATH_THREAT_WARNING_AS_ERROR=OFF \
|
||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests"
|
||||||
cmake --build cmake-build/build/${{ matrix.preset }} --config Debug --target unit_tests omath
|
cmake --build cmake-build/build/${{ matrix.preset }} --config Debug --target unit_tests omath
|
||||||
|
|
||||||
- name: Run Coverage
|
- name: Run Tests (Generates .profraw)
|
||||||
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
|
shell: pwsh
|
||||||
|
env:
|
||||||
|
LLVM_PROFILE_FILE: "cmake-build/build/${{ matrix.preset }}/unit_tests.profraw"
|
||||||
|
run: |
|
||||||
|
./out/Debug/unit_tests.exe
|
||||||
|
|
||||||
|
- name: Process Coverage (llvm-profdata & llvm-cov)
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$env:Path = "C:\Program Files\OpenCppCoverage;$env:Path"
|
$BUILD_DIR = "cmake-build/build/${{ matrix.preset }}"
|
||||||
cmake --build cmake-build/build/${{ matrix.preset }} --target coverage --config Debug
|
$EXE_PATH = "./out/Debug/unit_tests.exe"
|
||||||
|
|
||||||
- name: Upload Coverage
|
# 1. Merge raw profile data (essential step)
|
||||||
|
& "C:/Program Files/LLVM/bin/llvm-profdata.exe" merge `
|
||||||
|
-sparse "$BUILD_DIR/unit_tests.profraw" `
|
||||||
|
-o "$BUILD_DIR/unit_tests.profdata"
|
||||||
|
|
||||||
|
# 2. Export to LCOV format
|
||||||
|
# NOTE: We explicitly ignore vcpkg_installed and system headers
|
||||||
|
& "C:/Program Files/LLVM/bin/llvm-cov.exe" export "$EXE_PATH" `
|
||||||
|
-instr-profile="$BUILD_DIR/unit_tests.profdata" `
|
||||||
|
-format=lcov `
|
||||||
|
-ignore-filename-regex="vcpkg_installed|external|tests" `
|
||||||
|
> "$BUILD_DIR/lcov.info"
|
||||||
|
|
||||||
|
if (Test-Path "$BUILD_DIR/lcov.info") {
|
||||||
|
Write-Host "✅ LCOV info created at $BUILD_DIR/lcov.info"
|
||||||
|
} else {
|
||||||
|
Write-Error "Failed to create LCOV info"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Install LCOV (for genhtml)
|
||||||
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
|
run: choco install lcov -y
|
||||||
|
|
||||||
|
- name: Generate HTML Report
|
||||||
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
BUILD_DIR="cmake-build/build/${{ matrix.preset }}"
|
||||||
|
LCOV_INFO="${BUILD_DIR}/lcov.info"
|
||||||
|
HTML_DIR="${BUILD_DIR}/coverage-html"
|
||||||
|
|
||||||
|
# Fix paths for genhtml (Perl hates backslashes)
|
||||||
|
sed -i 's|\\|/|g' "${LCOV_INFO}"
|
||||||
|
|
||||||
|
# Locate genhtml provided by 'choco install lcov'
|
||||||
|
# It is typically in ProgramData/chocolatey/lib/lcov/tools/bin
|
||||||
|
GENHTML=$(find /c/ProgramData/chocolatey -name genhtml -print -quit)
|
||||||
|
|
||||||
|
if [ -z "$GENHTML" ]; then
|
||||||
|
echo "Error: genhtml executable not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using genhtml: $GENHTML"
|
||||||
|
mkdir -p "$HTML_DIR"
|
||||||
|
|
||||||
|
# Run genhtml
|
||||||
|
# Added --demangle-cpp if your version supports it, otherwise remove it
|
||||||
|
perl "$GENHTML" \
|
||||||
|
"${LCOV_INFO}" \
|
||||||
|
--output-directory "$HTML_DIR" \
|
||||||
|
--title "OMath Coverage Report" \
|
||||||
|
--legend \
|
||||||
|
--show-details \
|
||||||
|
--branch-coverage \
|
||||||
|
--ignore-errors source
|
||||||
|
|
||||||
|
echo "✅ LCOV HTML report generated at $HTML_DIR"
|
||||||
|
|
||||||
|
- name: Upload Coverage (HTML Report)
|
||||||
if: ${{ matrix.triplet == 'x64-windows' }}
|
if: ${{ matrix.triplet == 'x64-windows' }}
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: coverage-report-windows
|
name: coverage-html-windows
|
||||||
path: cmake-build/build/${{ matrix.preset }}/coverage/
|
path: cmake-build/build/${{ matrix.preset }}/coverage-html/
|
||||||
|
|
||||||
- name: Upload logs on failure
|
- name: Upload logs on failure
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ endif()
|
|||||||
|
|
||||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_23)
|
||||||
|
|
||||||
|
|
||||||
if (OMATH_BUILD_TESTS)
|
if (OMATH_BUILD_TESTS)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_BUILD_TESTS)
|
||||||
|
|||||||
@@ -6,8 +6,20 @@ function(omath_setup_coverage TARGET_NAME)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC)
|
||||||
# Apply to ALL configs when coverage is enabled (not just Debug)
|
target_compile_options(${TARGET_NAME} PRIVATE
|
||||||
|
-fprofile-instr-generate
|
||||||
|
-fcoverage-mapping
|
||||||
|
/Zi
|
||||||
|
)
|
||||||
|
target_link_options(${TARGET_NAME} PRIVATE
|
||||||
|
-fprofile-instr-generate
|
||||||
|
-fcoverage-mapping
|
||||||
|
/DEBUG:FULL
|
||||||
|
/INCREMENTAL:NO
|
||||||
|
/PROFILE
|
||||||
|
)
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE
|
target_compile_options(${TARGET_NAME} PRIVATE
|
||||||
-fprofile-instr-generate
|
-fprofile-instr-generate
|
||||||
-fcoverage-mapping
|
-fcoverage-mapping
|
||||||
@@ -18,7 +30,6 @@ function(omath_setup_coverage TARGET_NAME)
|
|||||||
-fprofile-instr-generate
|
-fprofile-instr-generate
|
||||||
-fcoverage-mapping
|
-fcoverage-mapping
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE
|
target_compile_options(${TARGET_NAME} PRIVATE
|
||||||
--coverage
|
--coverage
|
||||||
@@ -28,68 +39,22 @@ function(omath_setup_coverage TARGET_NAME)
|
|||||||
target_link_options(${TARGET_NAME} PRIVATE
|
target_link_options(${TARGET_NAME} PRIVATE
|
||||||
--coverage
|
--coverage
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif(MSVC)
|
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE
|
|
||||||
/Zi
|
|
||||||
/Od
|
|
||||||
/Ob0
|
|
||||||
)
|
|
||||||
target_link_options(${TARGET_NAME} PRIVATE
|
|
||||||
/DEBUG:FULL
|
|
||||||
/INCREMENTAL:NO
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Create coverage target only once
|
|
||||||
if(TARGET coverage)
|
if(TARGET coverage)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC OR MINGW)
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC)
|
||||||
# Windows: OpenCppCoverage
|
message(STATUS "MSVC detected: Use VS Code Coverage from CI workflow")
|
||||||
find_program(OPENCPPCOVERAGE_EXECUTABLE
|
|
||||||
NAMES OpenCppCoverage OpenCppCoverage.exe
|
|
||||||
PATHS
|
|
||||||
"$ENV{ProgramFiles}/OpenCppCoverage"
|
|
||||||
"$ENV{ProgramW6432}/OpenCppCoverage"
|
|
||||||
"C:/Program Files/OpenCppCoverage"
|
|
||||||
DOC "Path to OpenCppCoverage executable"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT OPENCPPCOVERAGE_EXECUTABLE)
|
|
||||||
message(WARNING "OpenCppCoverage not found. Install with: choco install opencppcoverage")
|
|
||||||
set(OPENCPPCOVERAGE_EXECUTABLE "C:/Program Files/OpenCppCoverage/OpenCppCoverage.exe")
|
|
||||||
else()
|
|
||||||
message(STATUS "Found OpenCppCoverage: ${OPENCPPCOVERAGE_EXECUTABLE}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
file(TO_NATIVE_PATH "${CMAKE_SOURCE_DIR}" COVERAGE_ROOT_PATH)
|
|
||||||
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/coverage" COVERAGE_OUTPUT_PATH)
|
|
||||||
file(TO_NATIVE_PATH "${CMAKE_BINARY_DIR}/coverage.xml" COVERAGE_XML_PATH)
|
|
||||||
file(TO_NATIVE_PATH "${OPENCPPCOVERAGE_EXECUTABLE}" OPENCPPCOVERAGE_NATIVE)
|
|
||||||
|
|
||||||
add_custom_target(coverage
|
add_custom_target(coverage
|
||||||
DEPENDS unit_tests
|
DEPENDS unit_tests
|
||||||
COMMAND "${OPENCPPCOVERAGE_NATIVE}"
|
COMMAND $<TARGET_FILE:unit_tests>
|
||||||
--verbose
|
|
||||||
--sources "${COVERAGE_ROOT_PATH}"
|
|
||||||
--modules "${COVERAGE_ROOT_PATH}"
|
|
||||||
--excluded_sources "*\\tests\\*"
|
|
||||||
--excluded_sources "*\\gtest\\*"
|
|
||||||
--excluded_sources "*\\googletest\\*"
|
|
||||||
--excluded_sources "*\\_deps\\*"
|
|
||||||
--excluded_sources "*\\vcpkg_installed\\*"
|
|
||||||
--export_type "html:${COVERAGE_OUTPUT_PATH}"
|
|
||||||
--export_type "cobertura:${COVERAGE_XML_PATH}"
|
|
||||||
--cover_children
|
|
||||||
-- "$<TARGET_FILE:unit_tests>"
|
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
COMMENT "Running OpenCppCoverage"
|
COMMENT "Running tests for coverage (use VS Code Coverage from CI)"
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
|
||||||
# Linux/macOS: LLVM coverage via script
|
|
||||||
add_custom_target(coverage
|
add_custom_target(coverage
|
||||||
DEPENDS unit_tests
|
DEPENDS unit_tests
|
||||||
COMMAND bash "${CMAKE_SOURCE_DIR}/scripts/coverage-llvm.sh"
|
COMMAND bash "${CMAKE_SOURCE_DIR}/scripts/coverage-llvm.sh"
|
||||||
@@ -102,7 +67,6 @@ function(omath_setup_coverage TARGET_NAME)
|
|||||||
)
|
)
|
||||||
|
|
||||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
# GCC: lcov/gcov
|
|
||||||
add_custom_target(coverage
|
add_custom_target(coverage
|
||||||
DEPENDS unit_tests
|
DEPENDS unit_tests
|
||||||
COMMAND $<TARGET_FILE:unit_tests> || true
|
COMMAND $<TARGET_FILE:unit_tests> || true
|
||||||
|
|||||||
Reference in New Issue
Block a user