Remove the two old FSMs ahead of the inheritance-based rewrite
Deletes the compile-time Void::StateMachine and the builder-based runtime Void::Fsm (Definition/Machine/Event/PluginBehavior + their standalone tests, the FSM behaviour plugins, and the FSM x Plugin integration test and its CMake wiring). The general-purpose Plugin module and its stateful hot-reload tests are untouched. Both are being replaced by a single inheritance + coroutine workflow FSM (next phase). 936 tests green (51 old FSM/StateMachine tests removed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b5f61f00a
commit
04cf1998bd
20 files changed
+3
-3793
No files matched your search
@@ -1,158 +0,0 @@
|
||||
#include <Void/Fsm/Machine.hpp>
|
||||
#include <Void/Fsm/PluginBehavior.hpp>
|
||||
#include <Void/Plugin/Manager.hpp>
|
||||
#include <Void/System/TempDir.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#if defined(VOID_FSM_PLUGIN_V1_PATH) && defined(VOID_FSM_PLUGIN_V2_PATH) && \
|
||||
__has_include(<dlfcn.h>)
|
||||
|
||||
using namespace Void::Fsm;
|
||||
using Void::Plugin::PluginManager;
|
||||
|
||||
namespace
|
||||
{
|
||||
void install(const std::filesystem::path& src,
|
||||
const std::filesystem::path& dst)
|
||||
{
|
||||
auto staging = dst;
|
||||
staging += ".incoming";
|
||||
std::filesystem::copy_file(
|
||||
src, staging, std::filesystem::copy_options::overwrite_existing);
|
||||
std::filesystem::rename(staging, dst);
|
||||
}
|
||||
|
||||
// Build a machine definition from the plugin's behaviour pack.
|
||||
std::shared_ptr<const MachineDef> def_from(const PluginManager& mgr)
|
||||
{
|
||||
auto* sym = reinterpret_cast<fsm_behaviors_fn>(
|
||||
mgr.raw_symbol("FsmPlugin", kFsmBehaviorsSymbol));
|
||||
Void::Testing::expect(sym != nullptr);
|
||||
if (sym == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
auto built = build_machine_def(*sym());
|
||||
Void::Testing::expect(built.has_value());
|
||||
return built.value_or(nullptr);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// A machine whose states and actions come entirely from a plugin keeps
|
||||
// running across a plugin reload: the new definition is built from the
|
||||
// reloaded behaviour pack and swapped in between run-to-completion steps.
|
||||
Void::Testing::Test internal_fsm_plugin_definition_swap()
|
||||
{
|
||||
Void::FileSystem::TempDir tmp{"void_fsmplugin"};
|
||||
const auto so = tmp.path() / "fsm.so";
|
||||
std::filesystem::copy_file(VOID_FSM_PLUGIN_V1_PATH, so);
|
||||
|
||||
PluginManager mgr;
|
||||
Void::Testing::expect(mgr.load(so).has_value());
|
||||
|
||||
auto def = def_from(mgr);
|
||||
Void::Testing::expect(def != nullptr);
|
||||
|
||||
Machine machine{def, MachineOptions{.own_worker = false}};
|
||||
machine.start();
|
||||
machine.post(Event{*def->event_id("start"), {}});
|
||||
machine.run_pending();
|
||||
Void::Testing::expect(machine.is_in("busy"));
|
||||
|
||||
// Reload to v2 (adds a "skip" transition; same state names) and swap
|
||||
// the definition in. The machine keeps its active "busy" leaf.
|
||||
install(VOID_FSM_PLUGIN_V2_PATH, so);
|
||||
Void::Testing::expect(mgr.reload("FsmPlugin").has_value());
|
||||
auto def2 = def_from(mgr);
|
||||
Void::Testing::expect(def2 != nullptr);
|
||||
machine.swap_definition(def2);
|
||||
machine.run_pending();
|
||||
Void::Testing::expect(machine.is_in("busy")); // configuration survived
|
||||
|
||||
// Finish the v1 cycle, then exercise the v2-only "skip" transition.
|
||||
machine.post(Event{*def2->event_id("finish"), {}});
|
||||
machine.run_pending();
|
||||
Void::Testing::expect(machine.is_in("done"));
|
||||
machine.post(Event{*def2->event_id("reset"), {}});
|
||||
machine.run_pending();
|
||||
Void::Testing::expect(machine.is_in("idle"));
|
||||
machine.post(Event{*def2->event_id("skip"), {}}); // new in v2
|
||||
machine.run_pending();
|
||||
Void::Testing::expect(machine.is_in("done"));
|
||||
}
|
||||
|
||||
// @tag stress, concurrency
|
||||
Void::Testing::Test internal_fsm_plugin_hot_reload_under_load()
|
||||
{
|
||||
Void::FileSystem::TempDir tmp{"void_fsmplugin"};
|
||||
const auto so = tmp.path() / "fsm.so";
|
||||
std::filesystem::copy_file(VOID_FSM_PLUGIN_V1_PATH, so);
|
||||
|
||||
PluginManager mgr;
|
||||
Void::Testing::expect(mgr.load(so).has_value());
|
||||
auto def = def_from(mgr);
|
||||
|
||||
// Worker-driven machine; the plugin's .so stays mapped (the manager's
|
||||
// dlclose_on_swap=false) so its action code remains valid for frames
|
||||
// in flight. Pin a handle for the machine's lifetime as belt-and-
|
||||
// suspenders against the .so unmapping.
|
||||
auto pin = mgr.acquire("FsmPlugin");
|
||||
Void::Testing::expect(static_cast<bool>(pin));
|
||||
|
||||
Machine machine{def};
|
||||
machine.start();
|
||||
|
||||
const auto start = *def->event_id("start");
|
||||
const auto finish = *def->event_id("finish");
|
||||
const auto reset = *def->event_id("reset");
|
||||
|
||||
std::atomic<bool> stop{false};
|
||||
std::atomic<long long> posts{0};
|
||||
std::vector<std::thread> producers;
|
||||
producers.reserve(4);
|
||||
for (int p = 0; p < 4; ++p) {
|
||||
producers.emplace_back([&] {
|
||||
while (!stop.load(std::memory_order_relaxed)) {
|
||||
machine.post(Event{start, {}});
|
||||
machine.post(Event{finish, {}});
|
||||
machine.post(Event{reset, {}});
|
||||
posts.fetch_add(3, std::memory_order_relaxed);
|
||||
std::this_thread::yield();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Rebuild + swap the definition repeatedly while events flow.
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const char* src =
|
||||
(i % 2 == 0) ? VOID_FSM_PLUGIN_V2_PATH : VOID_FSM_PLUGIN_V1_PATH;
|
||||
install(src, so);
|
||||
Void::Testing::expect(mgr.reload("FsmPlugin").has_value());
|
||||
machine.swap_definition(def_from(mgr));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{3});
|
||||
}
|
||||
|
||||
stop.store(true);
|
||||
for (auto& t : producers) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
// Drain and confirm the machine is still coherent: exactly one of the
|
||||
// three leaves is active.
|
||||
(void)machine.send_wait(Event{reset, {}});
|
||||
const int active = static_cast<int>(machine.is_in("idle")) +
|
||||
static_cast<int>(machine.is_in("busy")) +
|
||||
static_cast<int>(machine.is_in("done"));
|
||||
Void::Testing::expect_eq(active, 1);
|
||||
Void::Testing::expect(posts.load() > 0);
|
||||
machine.stop();
|
||||
}
|
||||
|
||||
#endif // FSM plugins available
|
||||
Reference in new issue
Block a user