GroveEngine/CMakeLists.txt
StillHammer d8c5f93429 feat: Add comprehensive hot-reload test suite with 3 integration scenarios
This commit implements a complete test infrastructure for validating
hot-reload stability and robustness across multiple scenarios.

## New Test Infrastructure

### Test Helpers (tests/helpers/)
- TestMetrics: FPS, memory, reload time tracking with statistics
- TestReporter: Assertion tracking and formatted test reports
- SystemUtils: Memory usage monitoring via /proc/self/status
- TestAssertions: Macro-based assertion framework

### Test Modules
- TankModule: Realistic module with 50 tanks for production testing
- ChaosModule: Crash-injection module for robustness validation
- StressModule: Lightweight module for long-duration stability tests

## Integration Test Scenarios

### Scenario 1: Production Hot-Reload (test_01_production_hotreload.cpp)
 PASSED - End-to-end hot-reload validation
- 30 seconds simulation (1800 frames @ 60 FPS)
- TankModule with 50 tanks, realistic state
- Source modification (v1.0 → v2.0), recompilation, reload
- State preservation: positions, velocities, frameCount
- Metrics: ~163ms reload time, 0.88MB memory growth

### Scenario 2: Chaos Monkey (test_02_chaos_monkey.cpp)
 PASSED - Extreme robustness testing
- 150+ random crashes per run (5% crash probability per frame)
- 5 crash types: runtime_error, logic_error, out_of_range, domain_error, state corruption
- 100% recovery rate via automatic hot-reload
- Corrupted state detection and rejection
- Random seed for unpredictable crash patterns
- Proof of real reload: temporary files in /tmp/grove_module_*.so

### Scenario 3: Stress Test (test_03_stress_test.cpp)
 PASSED - Long-duration stability validation
- 10 minutes simulation (36000 frames @ 60 FPS)
- 120 hot-reloads (every 5 seconds)
- 100% reload success rate (120/120)
- Memory growth: 2 MB (threshold: 50 MB)
- Avg reload time: 160ms (threshold: 500ms)
- No memory leaks, no file descriptor leaks

## Core Engine Enhancements

### ModuleLoader (src/ModuleLoader.cpp)
- Temporary file copy to /tmp/ for Linux dlopen cache bypass
- Robust reload() method: getState() → unload() → load() → setState()
- Automatic cleanup of temporary files
- Comprehensive error handling and logging

### DebugEngine (src/DebugEngine.cpp)
- Automatic recovery in processModuleSystems()
- Exception catching → logging → module reload → continue
- Module state dump utilities for debugging

### SequentialModuleSystem (src/SequentialModuleSystem.cpp)
- extractModule() for safe module extraction
- registerModule() for module re-registration
- Enhanced processModules() with error handling

## Build System
- CMake configuration for test infrastructure
- Shared library compilation for test modules (.so)
- CTest integration for all scenarios
- PIC flag management for spdlog compatibility

## Documentation (planTI/)
- Complete test architecture documentation
- Detailed scenario specifications with success criteria
- Global test plan and validation thresholds

## Validation Results
All 3 integration scenarios pass successfully:
- Production hot-reload: State preservation validated
- Chaos Monkey: 100% recovery from 150+ crashes
- Stress Test: Stable over 120 reloads, minimal memory growth

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-13 22:13:07 +08:00

101 lines
2.9 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(GroveEngine VERSION 1.0.0 LANGUAGES CXX)
# C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Dependencies
include(FetchContent)
# nlohmann_json for JSON handling
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(nlohmann_json)
# spdlog for logging
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Force PIC for all targets
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.12.0
)
FetchContent_MakeAvailable(spdlog)
# Core library (INTERFACE - header-only pour les interfaces)
add_library(grove_core INTERFACE)
target_include_directories(grove_core INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(grove_core INTERFACE
nlohmann_json::nlohmann_json
)
# Alias for consistent naming
add_library(GroveEngine::core ALIAS grove_core)
# Optional: Build implementations
option(GROVE_BUILD_IMPLEMENTATIONS "Build GroveEngine implementations" ON)
if(GROVE_BUILD_IMPLEMENTATIONS)
# Find OpenSSL for SHA256 hashing
find_package(OpenSSL REQUIRED)
add_library(grove_impl STATIC
# --- Working files (IDataNode-based) ---
src/ResourceRegistry.cpp
src/JsonDataValue.cpp
src/JsonDataNode.cpp
src/JsonDataTree.cpp
src/DataTreeFactory.cpp
src/IntraIO.cpp # ✅ Fixed for IDataNode
src/IntraIOManager.cpp # ✅ Fixed for IDataNode
src/SequentialModuleSystem.cpp # ✅ Fixed for IDataNode
src/IOFactory.cpp # ✅ Fixed for IDataNode
src/ModuleFactory.cpp # ✅ Should work (no json in main API)
src/ModuleSystemFactory.cpp # ✅ Needs check
src/EngineFactory.cpp # ✅ Needs check
src/DebugEngine.cpp # ✅ Needs migration
src/ModuleLoader.cpp # ✅ Hot-reload support
# --- TODO: Fix API mismatch (json vs IDataNode) ---
# src/ImGuiUI.cpp # Requires imgui dependency
)
target_link_libraries(grove_impl PUBLIC
GroveEngine::core
OpenSSL::Crypto
spdlog::spdlog
${CMAKE_DL_LIBS}
)
# Enable position-independent code for static library (needed for .so modules)
set_target_properties(grove_impl PROPERTIES POSITION_INDEPENDENT_CODE ON)
# If imgui is available from parent project, link it
if(TARGET imgui_backends)
target_link_libraries(grove_impl PUBLIC imgui_backends)
endif()
add_library(GroveEngine::impl ALIAS grove_impl)
endif()
# Testing
option(GROVE_BUILD_TESTS "Build GroveEngine tests" ON)
if(GROVE_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# Installation
install(DIRECTORY include/grove
DESTINATION include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)