mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-12 22:53:27 +00:00
Use LLVM coverage and LCOV genhtml on Windows OS (#131)
This commit is contained in:
58
.github/workflows/cmake-multi-platform.yml
vendored
58
.github/workflows/cmake-multi-platform.yml
vendored
@@ -753,3 +753,61 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
cmake-build/build/${{ matrix.preset }}/**/*.log
|
cmake-build/build/${{ matrix.preset }}/**/*.log
|
||||||
${{ env.VCPKG_ROOT }}/buildtrees/**/*.log
|
${{ env.VCPKG_ROOT }}/buildtrees/**/*.log
|
||||||
|
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# 9) Valgrind Memory Check
|
||||||
|
##############################################################################
|
||||||
|
valgrind-memory-check:
|
||||||
|
name: Valgrind Analysis (All Targets)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [linux-build-and-test]
|
||||||
|
env:
|
||||||
|
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
|
||||||
|
steps:
|
||||||
|
- name: Install toolchain
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
|
||||||
|
sudo add-apt-repository -y "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main"
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y git build-essential cmake ninja-build \
|
||||||
|
zip unzip curl pkg-config ca-certificates \
|
||||||
|
clang-21 lld-21 libc++-21-dev libc++abi-21-dev \
|
||||||
|
llvm-21 valgrind libxmu-dev libxi-dev libgl-dev libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev
|
||||||
|
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-21 100
|
||||||
|
sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-21 100
|
||||||
|
|
||||||
|
- name: Checkout repository (with sub-modules)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Set up vcpkg
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
git clone https://github.com/microsoft/vcpkg "$VCPKG_ROOT"
|
||||||
|
cd "$VCPKG_ROOT"
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
|
||||||
|
- name: Configure (cmake --preset)
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
cmake --preset linux-release-vcpkg \
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
|
-DOMATH_BUILD_EXAMPLES=OFF \
|
||||||
|
-DOMATH_BUILD_TESTS=ON \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=ON \
|
||||||
|
-DOMATH_ENABLE_VALGRIND=ON \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests;benchmark"
|
||||||
|
|
||||||
|
- name: Build All Targets
|
||||||
|
shell: bash
|
||||||
|
run: cmake --build cmake-build/build/linux-release-vcpkg
|
||||||
|
|
||||||
|
- name: Run Valgrind (All Registered Targets)
|
||||||
|
shell: bash
|
||||||
|
working-directory: cmake-build/build/linux-release-vcpkg
|
||||||
|
run: |
|
||||||
|
cmake --build . --target valgrind_all
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ project(omath VERSION ${OMATH_VERSION} LANGUAGES CXX)
|
|||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
include(cmake/Coverage.cmake)
|
include(cmake/Coverage.cmake)
|
||||||
|
include(cmake/Valgrind.cmake)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
|
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
|
||||||
@@ -61,6 +63,8 @@ if (${PROJECT_IS_TOP_LEVEL})
|
|||||||
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
message(STATUS "[${PROJECT_NAME}]: ImGUI integration feature status ${OMATH_IMGUI_INTEGRATION}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
message(STATUS "[${PROJECT_NAME}]: Legacy features support ${OMATH_ENABLE_LEGACY}")
|
||||||
message(STATUS "[${PROJECT_NAME}]: Building using vcpkg ${OMATH_BUILD_VIA_VCPKG}")
|
message(STATUS "[${PROJECT_NAME}]: Building using vcpkg ${OMATH_BUILD_VIA_VCPKG}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Coverage feature status ${OMATH_ENABLE_COVERAGE}")
|
||||||
|
message(STATUS "[${PROJECT_NAME}]: Valgrind feature status ${OMATH_ENABLE_VALGRIND}")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
file(GLOB_RECURSE OMATH_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
|
||||||
|
|||||||
@@ -17,3 +17,7 @@ else()
|
|||||||
find_package(benchmark CONFIG REQUIRED) # Benchmark is being linked as vcpkg package
|
find_package(benchmark CONFIG REQUIRED) # Benchmark is being linked as vcpkg package
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath)
|
target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark omath)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_VALGRIND)
|
||||||
|
omath_setup_valgrind(${PROJECT_NAME})
|
||||||
|
endif()
|
||||||
|
|||||||
45
cmake/Valgrind.cmake
Normal file
45
cmake/Valgrind.cmake
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# cmake/Valgrind.cmake
|
||||||
|
|
||||||
|
if(DEFINED __OMATH_VALGRIND_INCLUDED)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set(__OMATH_VALGRIND_INCLUDED TRUE)
|
||||||
|
|
||||||
|
find_program(VALGRIND_EXECUTABLE valgrind)
|
||||||
|
option(OMATH_ENABLE_VALGRIND "Enable Valgrind target for memory checking" ON)
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_VALGRIND AND NOT TARGET valgrind_all)
|
||||||
|
add_custom_target(valgrind_all)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(omath_setup_valgrind TARGET_NAME)
|
||||||
|
if(NOT OMATH_ENABLE_VALGRIND)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT VALGRIND_EXECUTABLE)
|
||||||
|
message(WARNING "OMATH_ENABLE_VALGRIND is ON, but 'valgrind' executable was not found.")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(VALGRIND_FLAGS
|
||||||
|
--leak-check=full
|
||||||
|
--show-leak-kinds=all
|
||||||
|
--track-origins=yes
|
||||||
|
--error-exitcode=99
|
||||||
|
)
|
||||||
|
|
||||||
|
set(VALGRIND_TARGET "valgrind_${TARGET_NAME}")
|
||||||
|
|
||||||
|
if(NOT TARGET ${VALGRIND_TARGET})
|
||||||
|
add_custom_target(${VALGRIND_TARGET}
|
||||||
|
DEPENDS ${TARGET_NAME}
|
||||||
|
COMMAND ${VALGRIND_EXECUTABLE} ${VALGRIND_FLAGS} $<TARGET_FILE:${TARGET_NAME}>
|
||||||
|
WORKING_DIRECTORY $<TARGET_FILE_DIR:${TARGET_NAME}>
|
||||||
|
COMMENT "Running Valgrind memory check on ${TARGET_NAME}..."
|
||||||
|
USES_TERMINAL
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(valgrind_all ${VALGRIND_TARGET})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
@@ -23,10 +23,15 @@ add_executable(example_glfw3 example_glfw3.cpp)
|
|||||||
set_target_properties(example_glfw3 PROPERTIES CXX_STANDARD 26
|
set_target_properties(example_glfw3 PROPERTIES CXX_STANDARD 26
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
|
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(GLEW REQUIRED)
|
find_package(GLEW REQUIRED)
|
||||||
find_package(glfw3 CONFIG REQUIRED)
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
target_link_libraries(example_glfw3 PRIVATE omath::omath GLEW::GLEW glfw)
|
target_link_libraries(example_glfw3 PRIVATE omath::omath GLEW::GLEW glfw)
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_VALGRIND)
|
||||||
|
omath_setup_valgrind(example_projection_matrix_builder)
|
||||||
|
omath_setup_valgrind(example_signature_scan)
|
||||||
|
omath_setup_valgrind(example_glfw3)
|
||||||
|
endif()
|
||||||
|
|||||||
77
scripts/valgrind.sh
Executable file
77
scripts/valgrind.sh
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Local Reproduction of "Valgrind Analysis" GitHub Action
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# Stop on error, undefined variables, or pipe failures
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# --- 1. Environment Setup ---
|
||||||
|
|
||||||
|
# Determine VCPKG_ROOT
|
||||||
|
# If VCPKG_ROOT is not set in your shell, we check if a local folder exists.
|
||||||
|
if [[ -z "${VCPKG_ROOT:-}" ]]; then
|
||||||
|
if [[ -d "./vcpkg" ]]; then
|
||||||
|
export VCPKG_ROOT="$(pwd)/vcpkg"
|
||||||
|
echo "Found local vcpkg at: $VCPKG_ROOT"
|
||||||
|
|
||||||
|
# Bootstrap vcpkg if the executable doesn't exist
|
||||||
|
if [[ ! -f "$VCPKG_ROOT/vcpkg" ]]; then
|
||||||
|
echo "Bootstrapping vcpkg..."
|
||||||
|
"$VCPKG_ROOT/bootstrap-vcpkg.sh"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: VCPKG_ROOT is not set and ./vcpkg directory not found."
|
||||||
|
echo "Please install vcpkg or set the VCPKG_ROOT environment variable."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Using existing VCPKG_ROOT: $VCPKG_ROOT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set the build directory matching the YAML's preset expectation
|
||||||
|
# Assuming the preset writes to: cmake-build/build/linux-release-vcpkg
|
||||||
|
BUILD_DIR="cmake-build/build/linux-release-vcpkg"
|
||||||
|
|
||||||
|
# Check if Valgrind is installed
|
||||||
|
if ! command -v valgrind &> /dev/null; then
|
||||||
|
echo "Error: valgrind is not installed. Please install it (e.g., sudo apt install valgrind)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
echo "Starting Configuration (Debug Build with Valgrind)..."
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
|
||||||
|
# --- 2. Configure (CMake) ---
|
||||||
|
# We force CMAKE_BUILD_TYPE=Debug even though the preset says 'release'
|
||||||
|
# to ensure Valgrind has access to debug symbols (line numbers).
|
||||||
|
|
||||||
|
cmake --preset linux-release-vcpkg \
|
||||||
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
|
-DOMATH_BUILD_EXAMPLES=OFF \
|
||||||
|
-DOMATH_BUILD_TESTS=ON \
|
||||||
|
-DOMATH_BUILD_BENCHMARK=ON \
|
||||||
|
-DOMATH_ENABLE_VALGRIND=ON \
|
||||||
|
-DVCPKG_MANIFEST_FEATURES="imgui;avx2;tests;benchmark"
|
||||||
|
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
echo "Building Targets..."
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
|
||||||
|
# --- 3. Build ---
|
||||||
|
# Using the specific build directory defined by the preset structure
|
||||||
|
cmake --build "$BUILD_DIR"
|
||||||
|
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
echo "Running Valgrind Analysis..."
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
|
||||||
|
# --- 4. Run Valgrind ---
|
||||||
|
# Runs the specific custom target defined in your CMakeLists.txt
|
||||||
|
cmake --build "$BUILD_DIR" --target valgrind_all
|
||||||
|
|
||||||
|
echo "----------------------------------------------------"
|
||||||
|
echo "Valgrind Analysis Complete."
|
||||||
|
echo "----------------------------------------------------"
|
||||||
@@ -26,6 +26,10 @@ if(OMATH_ENABLE_COVERAGE)
|
|||||||
omath_setup_coverage(${PROJECT_NAME})
|
omath_setup_coverage(${PROJECT_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(OMATH_ENABLE_VALGRIND)
|
||||||
|
omath_setup_valgrind(${PROJECT_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
# Skip test discovery for Android/iOS builds or when cross-compiling - binaries cannot run on host
|
# Skip test discovery for Android/iOS builds or when cross-compiling - binaries cannot run on host
|
||||||
if (NOT (ANDROID OR IOS OR EMSCRIPTEN))
|
if (NOT (ANDROID OR IOS OR EMSCRIPTEN))
|
||||||
gtest_discover_tests(${PROJECT_NAME})
|
gtest_discover_tests(${PROJECT_NAME})
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ namespace
|
|||||||
{
|
{
|
||||||
Ray ray;
|
Ray ray;
|
||||||
bool expected_clear; // true => segment does NOT hit the triangle
|
bool expected_clear; // true => segment does NOT hit the triangle
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const TraceCase& tc)
|
||||||
|
{
|
||||||
|
os << "{ RayStart: (" << tc.ray.start.x << ", " << tc.ray.start.y << ", " << tc.ray.start.z << "), "
|
||||||
|
<< "RayEnd: (" << tc.ray.end.x << ", " << tc.ray.end.y << ", " << tc.ray.end.z << "), "
|
||||||
|
<< "Expected: " << (tc.expected_clear ? "True" : "False") << " }";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CanTraceLineParam : public LineTracerFixture,
|
class CanTraceLineParam : public LineTracerFixture,
|
||||||
|
|||||||
Reference in New Issue
Block a user