Re-expresses the old FSM-plugin hot-plug through the service layer, reusing the unchanged Plugin module (PluginManager, v2 serialize/ deserialize ABI, FileWatcher, atomic-rename install). Service/PluginService.hpp: PluginServiceBinding<I> resolves a plugin's exported service (extern "C" void_plugin_service(instance) -> IService*) via PluginManager::raw_symbol and registers it under interface I. The registry entry pins the plugin instance (and its mapped .so) so in-flight callers never see a freed object. enable_hot_reload() re-binds on each reload; the FSMs resolve I through their context, so a running FSM picks up the new implementation on its next service<I>() call with no code patched. I must derive IService (single inheritance) so the host recovers it from IService* by static_cast — no dynamic_cast across RTLD_LOCAL. Tests: ServicePluginV1/V2 (the plugin object is the service: IPlugin + ICalc : IService; v2 migrates v1 state via Json::MigrationChain). FsmServiceHotReload.cpp: an Orchestrator-launched FSM accumulates through the plugin service while a reloader thread flips v1<->v2 under load — state survives every migration, the FSM runs to completion, no crash; and a deterministic reload test proving the implementation swaps (version 1->2) with the running total migrated. Docs: CLAUDE.md/README updated for the new Fsm, Service, and Orchestrator (StateMachine row removed). 965 tests green, ASan+UBSan clean, stable across runs, -Werror clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
141 lines
6.2 KiB
CMake
141 lines
6.2 KiB
CMake
include(${CMAKE_SOURCE_DIR}/cmake/VoidTesting.cmake)
|
|
|
|
get_property(ACTIVE_MODULES GLOBAL PROPERTY VOID_MODULES)
|
|
|
|
set(_gen_dir "${CMAKE_CURRENT_BINARY_DIR}/void_testing_generated")
|
|
file(MAKE_DIRECTORY "${_gen_dir}")
|
|
|
|
set(_all_generated "")
|
|
|
|
# ── Standalone tests ──────────────────────────────────────────────────────────
|
|
# Each .cpp under tests/standalone/<Module>/ is scanned for Void::Testing tests.
|
|
# All generated shims are compiled into ONE VoidTests executable that links
|
|
# every active module. This avoids N separate test binaries while preserving
|
|
# per-module suite names in the runner output.
|
|
#
|
|
# Generated file naming: <Module>_<stem>.void_tests.cpp
|
|
# SUITE_NAME passed to scanner: <stem> (shown in the runner as the suite label)
|
|
|
|
foreach(mod ${ACTIVE_MODULES})
|
|
set(_mod_dir "${CMAKE_CURRENT_SOURCE_DIR}/standalone/${mod}")
|
|
if(NOT IS_DIRECTORY "${_mod_dir}")
|
|
continue()
|
|
endif()
|
|
|
|
file(GLOB _test_files CONFIGURE_DEPENDS "${_mod_dir}/*.cpp")
|
|
foreach(_src ${_test_files})
|
|
get_filename_component(_stem "${_src}" NAME_WE)
|
|
set(_gen "${_gen_dir}/${mod}_${_stem}.void_tests.cpp")
|
|
|
|
add_custom_command(
|
|
OUTPUT "${_gen}"
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DINPUT_FILE=${_src}
|
|
-DOUTPUT_FILE=${_gen}
|
|
-DSUITE_NAME=${_stem}
|
|
-P "${VOID_TESTING_SCANNER}"
|
|
DEPENDS "${_src}" "${VOID_TESTING_SCANNER}"
|
|
COMMENT "Scanning ${_src} for Void::Testing tests"
|
|
)
|
|
set_source_files_properties("${_src}" PROPERTIES HEADER_FILE_ONLY TRUE)
|
|
set_source_files_properties("${_gen}" PROPERTIES GENERATED TRUE)
|
|
list(APPEND _all_generated "${_gen}")
|
|
endforeach()
|
|
endforeach()
|
|
|
|
# ── Internal tests (kitchen-sink, links everything) ───────────────────────────
|
|
|
|
file(GLOB_RECURSE _internal_sources CONFIGURE_DEPENDS "internal/*.cpp")
|
|
foreach(_src ${_internal_sources})
|
|
get_filename_component(_stem "${_src}" NAME_WE)
|
|
set(_gen "${_gen_dir}/internal_${_stem}.void_tests.cpp")
|
|
|
|
add_custom_command(
|
|
OUTPUT "${_gen}"
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DINPUT_FILE=${_src}
|
|
-DOUTPUT_FILE=${_gen}
|
|
-DSUITE_NAME=internal_${_stem}
|
|
-P "${VOID_TESTING_SCANNER}"
|
|
DEPENDS "${_src}" "${VOID_TESTING_SCANNER}"
|
|
COMMENT "Scanning ${_src} for Void::Testing tests"
|
|
)
|
|
set_source_files_properties("${_src}" PROPERTIES HEADER_FILE_ONLY TRUE)
|
|
set_source_files_properties("${_gen}" PROPERTIES GENERATED TRUE)
|
|
list(APPEND _all_generated "${_gen}")
|
|
endforeach()
|
|
|
|
# ── VoidTests — the single test executable ────────────────────────────────────
|
|
|
|
if(_all_generated)
|
|
add_executable(VoidTests ${_all_generated})
|
|
|
|
# Disable auto-sweep: we already applied the scanner manually above.
|
|
set_target_properties(VoidTests PROPERTIES VOID_TESTING_NO_AUTO_SCAN TRUE)
|
|
|
|
target_link_libraries(VoidTests PRIVATE Void::Testing)
|
|
foreach(mod ${ACTIVE_MODULES})
|
|
if(NOT mod STREQUAL "Testing" AND TARGET Void::${mod})
|
|
target_link_libraries(VoidTests PRIVATE Void::${mod})
|
|
endif()
|
|
endforeach()
|
|
|
|
add_test(NAME VoidTests COMMAND VoidTests)
|
|
endif()
|
|
|
|
# ── Test-support libraries ────────────────────────────────────────────────────
|
|
# These are NOT test files; they are helper shared libs referenced by tests.
|
|
|
|
if(TARGET Void::Plugin)
|
|
set(_test_plugin_src "${CMAKE_CURRENT_SOURCE_DIR}/plugins/TestPlugin.cpp")
|
|
if(EXISTS "${_test_plugin_src}")
|
|
add_library(VoidTestPlugin SHARED "${_test_plugin_src}")
|
|
target_link_libraries(VoidTestPlugin PRIVATE Void::Plugin)
|
|
# Give VoidTests the absolute path to VoidTestPlugin.so via a define.
|
|
target_compile_definitions(VoidTests PRIVATE
|
|
"VOID_TEST_PLUGIN_PATH=\"$<TARGET_FILE:VoidTestPlugin>\""
|
|
)
|
|
add_dependencies(VoidTests VoidTestPlugin)
|
|
endif()
|
|
|
|
# Stateful plugins (schema v1 + v2) for hot-reload/state-migration
|
|
# tests. Same plugin name; v2 adds a field and migrates v1 JSON.
|
|
add_library(VoidStatefulPluginV1 SHARED
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/StatefulPluginV1.cpp")
|
|
add_library(VoidStatefulPluginV2 SHARED
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/StatefulPluginV2.cpp")
|
|
foreach(_sp VoidStatefulPluginV1 VoidStatefulPluginV2)
|
|
target_link_libraries(${_sp} PRIVATE Void::Plugin Void::Data)
|
|
target_include_directories(${_sp} PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins")
|
|
endforeach()
|
|
target_compile_definitions(VoidTests PRIVATE
|
|
"VOID_STATEFUL_V1_PATH=\"$<TARGET_FILE:VoidStatefulPluginV1>\""
|
|
"VOID_STATEFUL_V2_PATH=\"$<TARGET_FILE:VoidStatefulPluginV2>\""
|
|
)
|
|
target_include_directories(VoidTests PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins")
|
|
add_dependencies(VoidTests VoidStatefulPluginV1 VoidStatefulPluginV2)
|
|
|
|
# Service plugins (a plugin provides an IService-derived interface) for
|
|
# the FSM x Service hot-reload integration test. Same plugin name; v2
|
|
# migrates v1 state.
|
|
if(TARGET Void::Service AND TARGET Void::Data)
|
|
add_library(VoidServicePluginV1 SHARED
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/ServicePluginV1.cpp")
|
|
add_library(VoidServicePluginV2 SHARED
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins/ServicePluginV2.cpp")
|
|
foreach(_sp VoidServicePluginV1 VoidServicePluginV2)
|
|
target_link_libraries(${_sp}
|
|
PRIVATE Void::Plugin Void::Service Void::Data)
|
|
target_include_directories(${_sp} PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/plugins")
|
|
endforeach()
|
|
target_compile_definitions(VoidTests PRIVATE
|
|
"VOID_SERVICE_V1_PATH=\"$<TARGET_FILE:VoidServicePluginV1>\""
|
|
"VOID_SERVICE_V2_PATH=\"$<TARGET_FILE:VoidServicePluginV2>\""
|
|
)
|
|
add_dependencies(VoidTests VoidServicePluginV1 VoidServicePluginV2)
|
|
endif()
|
|
endif()
|