Add the UME RobotArm and Damiao CAN-FD path, migrate the legacy UME controller, and introduce guarded cross-machine gRPC teleoperation with lifecycle, authority, configuration, and test coverage.
125 lines
3.1 KiB
C++
125 lines
3.1 KiB
C++
#include "manager/device_manager/include/device_manager.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace {
|
|
|
|
class LifecycleDevice final : public cmvr::device::AbstractDevice {
|
|
public:
|
|
explicit LifecycleDevice(const std::string& id)
|
|
: AbstractDevice(id)
|
|
{
|
|
}
|
|
|
|
cmvr::device::DeviceKind kind() const noexcept override
|
|
{
|
|
return cmvr::device::DeviceKind::Camera;
|
|
}
|
|
|
|
std::string typeName() const override { return "LifecycleDevice"; }
|
|
|
|
bool start() override
|
|
{
|
|
++start_calls;
|
|
if (throw_on_start) {
|
|
throw std::runtime_error("start failure");
|
|
}
|
|
return start_result;
|
|
}
|
|
|
|
bool stop() override
|
|
{
|
|
++stop_calls;
|
|
return true;
|
|
}
|
|
|
|
bool start_result{true};
|
|
bool throw_on_start{false};
|
|
int start_calls{0};
|
|
int stop_calls{0};
|
|
};
|
|
|
|
class DeviceManagerLifecycleTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
cmvr::device::DeviceManager::destroyInstance();
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
cmvr::device::DeviceManager::destroyInstance();
|
|
}
|
|
};
|
|
|
|
TEST_F(DeviceManagerLifecycleTest,
|
|
EnabledDeviceCreationFailureMarksInitializationFailed)
|
|
{
|
|
cmvr::config::DeviceManagerConfig config;
|
|
auto* entry = config.add_devices();
|
|
entry->set_id("unsupported");
|
|
entry->set_type(
|
|
cmvr::config::DeviceConfigEntry::DEVICE_TYPE_UNKNOWN);
|
|
entry->set_enable(true);
|
|
|
|
auto& manager =
|
|
cmvr::device::DeviceManager::getInstance(config);
|
|
EXPECT_FALSE(manager.initialized());
|
|
EXPECT_FALSE(manager.start());
|
|
}
|
|
|
|
TEST_F(DeviceManagerLifecycleTest, DisabledInvalidDeviceIsIgnored)
|
|
{
|
|
cmvr::config::DeviceManagerConfig config;
|
|
auto* entry = config.add_devices();
|
|
entry->set_id("disabled");
|
|
entry->set_type(
|
|
cmvr::config::DeviceConfigEntry::DEVICE_TYPE_UNKNOWN);
|
|
entry->set_enable(false);
|
|
|
|
auto& manager =
|
|
cmvr::device::DeviceManager::getInstance(config);
|
|
EXPECT_TRUE(manager.initialized());
|
|
EXPECT_TRUE(manager.start());
|
|
}
|
|
|
|
TEST_F(DeviceManagerLifecycleTest,
|
|
DeviceStartFailureIsReturnedAndTriggersStop)
|
|
{
|
|
cmvr::config::DeviceManagerConfig config;
|
|
auto& manager =
|
|
cmvr::device::DeviceManager::getInstance(config);
|
|
ASSERT_TRUE(manager.initialized());
|
|
|
|
auto device =
|
|
std::make_shared<LifecycleDevice>("start_failure");
|
|
device->start_result = false;
|
|
manager.registerDevice(device);
|
|
|
|
EXPECT_FALSE(manager.start());
|
|
EXPECT_EQ(device->start_calls, 1);
|
|
EXPECT_EQ(device->stop_calls, 1);
|
|
}
|
|
|
|
TEST_F(DeviceManagerLifecycleTest,
|
|
DeviceStartExceptionIsReturnedAndTriggersStop)
|
|
{
|
|
cmvr::config::DeviceManagerConfig config;
|
|
auto& manager =
|
|
cmvr::device::DeviceManager::getInstance(config);
|
|
ASSERT_TRUE(manager.initialized());
|
|
|
|
auto device =
|
|
std::make_shared<LifecycleDevice>("start_exception");
|
|
device->throw_on_start = true;
|
|
manager.registerDevice(device);
|
|
|
|
EXPECT_FALSE(manager.start());
|
|
EXPECT_EQ(device->start_calls, 1);
|
|
EXPECT_EQ(device->stop_calls, 1);
|
|
}
|
|
|
|
} // namespace
|