From 4194c8d4bbd5bc48c2f50a7377c616f147385016 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 10:22:15 +0100 Subject: feat(tooling): Implement code coverage reporting (Task #44) Added CMake support for coverage builds and a script to generate HTML reports using lcov on macOS. Also cleaned up .gitignore. --- .gitignore | 3 ++- CMakeLists.txt | 9 +++++++ PROJECT_CONTEXT.md | 1 + TODO.md | 12 +++++---- doc/HOWTO.md | 15 +++++++++++ scripts/gen_coverage_report.sh | 56 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100755 scripts/gen_coverage_report.sh diff --git a/.gitignore b/.gitignore index d58ca56..9408588 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,5 @@ compile_commands.json *.spec BASS_SYNTH_1.wav *.aif -*.wavsrc/generated/ +*.wav +src/generated/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e96bea..0029adf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(DEMO_SIZE_OPT "Enable size optimization flags" OFF) option(DEMO_STRIP_ALL "Strip all unnecessary code for final build" OFF) option(DEMO_BUILD_TESTS "Build tests" OFF) option(DEMO_BUILD_TOOLS "Build tools" OFF) +option(DEMO_ENABLE_COVERAGE "Enable code coverage generation (macOS only)" OFF) option(DEMO_ALL_OPTIONS "Activate all options at once" OFF) if (DEMO_ALL_OPTIONS) @@ -23,6 +24,14 @@ if (DEMO_STRIP_ALL) set(DEMO_SIZE_OPT ON) endif() +if (DEMO_ENABLE_COVERAGE AND APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + # Coverage requires debug info + set(CMAKE_BUILD_TYPE Debug) +endif() + #-- - Platform Detection and Core Setup -- - if(APPLE) add_definitions(-DGLFW_EXPOSE_NATIVE_COCOA) diff --git a/PROJECT_CONTEXT.md b/PROJECT_CONTEXT.md index af87827..15b5090 100644 --- a/PROJECT_CONTEXT.md +++ b/PROJECT_CONTEXT.md @@ -28,6 +28,7 @@ Style: ## Project Roadmap ### Recently Completed +- **Task #44: Developer Tooling (Coverage)**: Added `DEMO_ENABLE_COVERAGE` CMake option and created `scripts/gen_coverage_report.sh` to generate HTML coverage reports using `lcov` on macOS. - **Skybox & Two-pass Rendering Stability**: Resolved "black screen" and validation errors by implementing a robust two-pass rendering architecture (Pass 1: Skybox/Clear, Pass 2: Scene Objects). Implemented a rotating skybox using world-space ray unprojection (`inv_view_proj`) and a multi-octave procedural noise generator. - **Task #20: Platform & Code Hygiene**: Consolidated platform-specific shims and WebGPU headers into `platform.h`. Refactored `platform_init` and `platform_poll` for better abstraction. Removed STL containers from initial hot paths (`AssetManager`, `procedural`). Full STL removal for CRT replacement is deferred to the final optimization phase. - **Task #26: Shader Asset Testing & Validation**: Developed comprehensive tests for `ShaderComposer` and WGSL asset loading/composition. Added a shader validation test to ensure production assets are valid. diff --git a/TODO.md b/TODO.md index db93578..2d7eb90 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,9 @@ This file tracks prioritized tasks with detailed attack plans. ## Recently Completed (February 4, 2026) +- [x] **Task #44: Developer Tooling (Coverage)**: + - [x] **Implement Code Coverage:** Added `DEMO_ENABLE_COVERAGE` CMake option and created `scripts/gen_coverage_report.sh` to generate HTML coverage reports using `lcov` on macOS. + - [x] **Documentation:** Updated `doc/HOWTO.md` with usage instructions. - [x] **Skybox & Two-pass Rendering Stability**: - [x] **Fixed Two-pass Rendering:** Implemented mandatory clear operations for color and depth when the skybox is absent, preventing black screens and depth validation errors. - [x] **Implemented Rotating Skybox:** Added `inv_view_proj` to `GlobalUniforms` and updated the skybox shader to perform world-space ray unprojection, enabling correct rotation with the camera. @@ -46,6 +49,10 @@ This file tracks prioritized tasks with detailed attack plans. - [ ] **Task #37: Asset Ingestion:** Update `asset_packer` to handle the new 3D binary format. - [ ] **Task #38: Runtime Loader:** Implement a minimal C++ parser to load the scene data into the ECS/Renderer. +## Priority 2: Developer Tooling & CI +**Goal**: Improve developer workflows, code quality, and release processes. +*(No active tasks)* + ## Phase 2: Size Optimization (Final Goal) - [ ] **Task #34: Full STL Removal**: Replace all remaining `std::vector`, `std::map`, and `std::string` usage with custom minimal containers or C-style arrays to allow for CRT replacement. (Minimal Priority - deferred to end). @@ -56,9 +63,4 @@ This file tracks prioritized tasks with detailed attack plans. - [ ] **Task #35: CRT Replacement**: investigation and implementation of CRT-free entry point. -## Priority Low: Codebase hygiene -- [ ] ** Task #?: implement an easy-to-use coverage script on MacOS (only). Coverage Report in HTML format would be nice. - - - ## Future Goals diff --git a/doc/HOWTO.md b/doc/HOWTO.md index d402453..29492d5 100644 --- a/doc/HOWTO.md +++ b/doc/HOWTO.md @@ -117,6 +117,21 @@ ctest cd .. ``` +### Code Coverage (macOS only) + +To generate an HTML code coverage report for the project: + +1. **Install lcov:** + ```bash + brew install lcov + ``` + +2. **Run the coverage script:** + ```bash + ./scripts/gen_coverage_report.sh + ``` + This script will configure the build with `-DDEMO_ENABLE_COVERAGE=ON`, run the tests, and generate a report in `build_coverage/coverage_report/`. It will then attempt to open the report in your browser. + ## Tools ### Updating Submodules diff --git a/scripts/gen_coverage_report.sh b/scripts/gen_coverage_report.sh new file mode 100755 index 0000000..bae2141 --- /dev/null +++ b/scripts/gen_coverage_report.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Exit on error +set -e + +# Project root +PROJECT_ROOT=$(cd "$(dirname "$0")/.." && pwd) +BUILD_DIR="${PROJECT_ROOT}/build_coverage" +REPORT_DIR="${PROJECT_ROOT}/build_coverage/coverage_report" + +# Common lcov options to handle AppleClang quirks +LCOV_OPTS="--ignore-errors mismatch,inconsistent,gcov,format,unsupported,category" + +echo "=== Code Coverage Report Generator ===" +echo "Project Root: ${PROJECT_ROOT}" + +# Check for lcov +if ! command -v lcov &> /dev/null; then + echo "Error: lcov is not installed." + echo "Please install it using: brew install lcov" + exit 1 +fi + +# Cleanup previous build if requested (optional, but safer for coverage) +# rm -rf "${BUILD_DIR}" + +mkdir -p "${BUILD_DIR}" +cd "${BUILD_DIR}" + +echo "--- Configuring CMake with Coverage ---" +cmake "${PROJECT_ROOT}" -DDEMO_ENABLE_COVERAGE=ON -DDEMO_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug + +echo "--- Building Tests ---" +# Build only the test targets to save time, or all if needed. +# Building 'all' ensures everything is compiled with coverage flags. +cmake --build . -j $(sysctl -n hw.ncpu) + +echo "--- Running Tests ---" +# Run tests and ignore failures so we still get a report? +# Ideally tests should pass. Let's allow failures for now so we see what's covered. +ctest --output-on-failure || true + +echo "--- Capturing Coverage Data ---" +# Capture initial coverage data +lcov --capture --directory . --output-file coverage.info $LCOV_OPTS + +echo "--- Filtering Coverage Data ---" +# Remove system headers and third-party libraries +lcov --remove coverage.info '/usr/*' "${PROJECT_ROOT}/third_party/*" "${PROJECT_ROOT}/build_coverage/*" '*/test_*' --output-file coverage_filtered.info $LCOV_OPTS + +echo "--- Generating HTML Report ---" +genhtml coverage_filtered.info --output-directory "${REPORT_DIR}" $LCOV_OPTS + +echo "=== Coverage Report Generated ===" +echo "Open the report with:" +echo "open ${REPORT_DIR}/index.html" -- cgit v1.2.3