feat: ActionHandler pause/resume + kCancelled status + ABI version guard
- ActionStatus::kCancelled (new, string "CANCELLED"): the missing "stopped on request" terminal status — previously a cancelled action only had Running/Succeeded/Failed to report through, so move_base2's state machine couldn't tell a cancelled action from a failed one. - ActionHandler::cancelNeedsTicks() (default false), pause(now) and resume(now) (default no-ops): lets a handler opt into "I need more ticks to actually stop" (device handshake) instead of being torn down immediately, and gives handlers a real pause/resume contract instead of move_base2 having to freeze/unfreeze them from outside. - action_abi.h (new) + ACTION_CORE_EXPORT_HANDLER macro, same pattern as recovery_core commit 254c7fc: exports a version symbol next to the factory alias; action_registry.cpp refuses a handler .so whose version doesn't match instead of dlsym+reinterpret_cast blindly onto a grown vtable. - frame_sampler / wait / noop handlers implement pause/resume via paused_at_ / started_at_ += (now - paused_at_) so their own internal timers don't count paused time; paused_ is reset on start() so a reused handler instance can't come up already paused. - test/plugins/stale_abi_action_handler.cpp (new) for the registry refusal test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -198,6 +198,24 @@ TEST(ActionRegistry, ReportsMissingLibraryPath)
|
||||
EXPECT_EQ(registry.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(ActionRegistry, RefusesAPluginBuiltForAnotherAbiVersion)
|
||||
{
|
||||
// 2026-09-11: header ActionHandler thêm virtual; plugin build với header cũ có vtable ngắn hơn và
|
||||
// sẽ crash ở lời gọi pause(). Registry tra `<Type>_abi` trước factory và từ chối khi lệch.
|
||||
robot::NodeHandle nh;
|
||||
ActionRegistry registry;
|
||||
EXPECT_FALSE(registry.loadFromConfig(nh, "actions_stale_abi"));
|
||||
EXPECT_EQ(registry.size(), 0u) << "a plugin with a mismatching _abi must not be registered";
|
||||
}
|
||||
|
||||
TEST(ActionRegistry, RefusesAPluginWithoutAnAbiSymbol)
|
||||
{
|
||||
robot::NodeHandle nh;
|
||||
ActionRegistry registry;
|
||||
EXPECT_FALSE(registry.loadFromConfig(nh, "actions_no_abi"));
|
||||
EXPECT_EQ(registry.size(), 0u) << "a plugin built before the ABI guard must not be registered";
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// Contract của registerHandler
|
||||
// ================================================================================================
|
||||
|
||||
@@ -49,6 +49,15 @@ actions_missing_library:
|
||||
actions_empty:
|
||||
something_else: 1
|
||||
|
||||
# ABI guard (2026-09-11): plugin giả export `_abi` = 1 (lệch) và một alias không có `_abi`.
|
||||
# Registry phải từ chối cả hai, log lỗi, không crash.
|
||||
actions_stale_abi:
|
||||
handlers:
|
||||
- {name: stale, type: StaleAbiActionHandler}
|
||||
actions_no_abi:
|
||||
handlers:
|
||||
- {name: ancient, type: NoAbiActionHandler}
|
||||
|
||||
# Bộ handler default, mỗi cái một namespace riêng để test nạp độc lập.
|
||||
actions_wait:
|
||||
handlers:
|
||||
@@ -193,6 +202,10 @@ actions_detect_simulated:
|
||||
|
||||
NoopActionHandler:
|
||||
library_path: libaction_core_noop_action_handler
|
||||
StaleAbiActionHandler:
|
||||
library_path: libaction_core_test_stale_abi_handler
|
||||
NoAbiActionHandler:
|
||||
library_path: libaction_core_test_stale_abi_handler
|
||||
|
||||
FrameSamplerActionHandler:
|
||||
library_path: libaction_core_frame_sampler_action_handler
|
||||
|
||||
72
test/plugins/stale_abi_action_handler.cpp
Normal file
72
test/plugins/stale_abi_action_handler.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* action_core — plugin GIẢ mô phỏng một handler build với header cũ: export `_abi` = 1 (và một
|
||||
* symbol không có `_abi` nào). Chỉ để test ABI guard của ActionRegistry; không cài đặt.
|
||||
*
|
||||
* Author: DuongTD
|
||||
*********************************************************************/
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/dll/alias.hpp>
|
||||
|
||||
#include <action_core/action_handler.h>
|
||||
|
||||
namespace action_core
|
||||
{
|
||||
namespace testing
|
||||
{
|
||||
|
||||
/// Handler tối thiểu, hợp lệ về mặt interface — registry phải từ chối nó CHỈ vì phiên bản ABI.
|
||||
class StaleAbiActionHandler final : public ActionHandler
|
||||
{
|
||||
public:
|
||||
static ActionHandler::Ptr create()
|
||||
{
|
||||
return std::make_shared<StaleAbiActionHandler>();
|
||||
}
|
||||
|
||||
bool configure(const std::string&, const ActionContext&, robot::NodeHandle&) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> supportedActionTypes() const override
|
||||
{
|
||||
return {"stale"};
|
||||
}
|
||||
|
||||
bool start(const robot_protocol_msgs::Action&, const robot::Time&) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ActionTick update(const robot::Time&) override
|
||||
{
|
||||
ActionTick tick;
|
||||
tick.status = ActionStatus::kSucceeded;
|
||||
return tick;
|
||||
}
|
||||
|
||||
void cancel() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/// Phiên bản ABI "cũ" — lệch với kActionAbiVersion của runtime.
|
||||
int staleAbiVersion()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace action_core
|
||||
|
||||
// Alias 1: có _abi nhưng lệch phiên bản.
|
||||
BOOST_DLL_ALIAS(action_core::testing::StaleAbiActionHandler::create, StaleAbiActionHandler)
|
||||
BOOST_DLL_ALIAS(action_core::testing::staleAbiVersion, StaleAbiActionHandler_abi)
|
||||
// Alias 2: không có _abi (plugin build trước 2026-09-11).
|
||||
BOOST_DLL_ALIAS(action_core::testing::StaleAbiActionHandler::create, NoAbiActionHandler)
|
||||
Reference in New Issue
Block a user