From 663c03abfed4e6f99c984a9ed3aebb0910ec0263 Mon Sep 17 00:00:00 2001 From: Li Cao Date: Thu, 5 Dec 2024 12:21:39 +0000 Subject: [PATCH] [thread host] add ThreadHost Error code --- src/dbus/server/dbus_thread_object_ncp.cpp | 28 +++- src/ncp/rcp_host.cpp | 2 +- src/ncp/rcp_host.hpp | 4 +- src/ncp/thread_host.hpp | 53 ++++++- tests/gtest/test_rcp_host_api.cpp | 167 +++++++++++---------- 5 files changed, 165 insertions(+), 89 deletions(-) diff --git a/src/dbus/server/dbus_thread_object_ncp.cpp b/src/dbus/server/dbus_thread_object_ncp.cpp index bd869f79b65..b2bc529208a 100644 --- a/src/dbus/server/dbus_thread_object_ncp.cpp +++ b/src/dbus/server/dbus_thread_object_ncp.cpp @@ -41,6 +41,22 @@ using std::placeholders::_2; namespace otbr { namespace DBus { +/* + * TODO: Update DBusRequest::ReplyOtResult so that it can return Host error code. + * This method is a workaround to cast Ncp::Error to otError and thus can be passed to DBusRequest::ReplyOtResult. + */ +static otError HostErrorToOtError(Ncp::Error aError) +{ + otError error = OT_ERROR_FAILED; + + if (aError >= Ncp::kErrorNone && aError <= Ncp::kErrorGeneric) + { + error = static_cast(aError); + } + + return error; +} + DBusThreadObjectNcp::DBusThreadObjectNcp(DBusConnection &aConnection, const std::string &aInterfaceName, otbr::Ncp::NcpHost &aHost) @@ -111,9 +127,9 @@ void DBusThreadObjectNcp::JoinHandler(DBusRequest &aRequest) std::copy(dataset.begin(), dataset.end(), activeOpDatasetTlvs.mTlvs); activeOpDatasetTlvs.mLength = dataset.size(); - mHost.Join(activeOpDatasetTlvs, [aRequest](otError aError, const std::string &aErrorInfo) mutable { + mHost.Join(activeOpDatasetTlvs, [aRequest](Ncp::Error aError, const std::string &aErrorInfo) mutable { OT_UNUSED_VARIABLE(aErrorInfo); - aRequest.ReplyOtResult(aError); + aRequest.ReplyOtResult(HostErrorToOtError(aError)); }); exit: @@ -125,9 +141,9 @@ void DBusThreadObjectNcp::JoinHandler(DBusRequest &aRequest) void DBusThreadObjectNcp::LeaveHandler(DBusRequest &aRequest) { - mHost.Leave(true /* aEraseDataset */, [aRequest](otError aError, const std::string &aErrorInfo) mutable { + mHost.Leave(true /* aEraseDataset */, [aRequest](Ncp::Error aError, const std::string &aErrorInfo) mutable { OT_UNUSED_VARIABLE(aErrorInfo); - aRequest.ReplyOtResult(aError); + aRequest.ReplyOtResult(HostErrorToOtError(aError)); }); } @@ -148,9 +164,9 @@ void DBusThreadObjectNcp::ScheduleMigrationHandler(DBusRequest &aRequest) SuccessOrExit(error = agent::ThreadHelper::ProcessDatasetForMigration(pendingOpDatasetTlvs, delayInMilli)); - mHost.ScheduleMigration(pendingOpDatasetTlvs, [aRequest](otError aError, const std::string &aErrorInfo) mutable { + mHost.ScheduleMigration(pendingOpDatasetTlvs, [aRequest](Ncp::Error aError, const std::string &aErrorInfo) mutable { OT_UNUSED_VARIABLE(aErrorInfo); - aRequest.ReplyOtResult(aError); + aRequest.ReplyOtResult(HostErrorToOtError(aError)); }); exit: diff --git a/src/ncp/rcp_host.cpp b/src/ncp/rcp_host.cpp index a6377f6cf82..cf2a58b510d 100644 --- a/src/ncp/rcp_host.cpp +++ b/src/ncp/rcp_host.cpp @@ -443,7 +443,7 @@ void RcpHost::Join(const otOperationalDatasetTlvs &aActiveOpDatasetTlvs, const A OT_UNUSED_VARIABLE(aActiveOpDatasetTlvs); // TODO: Implement Join under RCP mode. - mTaskRunner.Post([aReceiver](void) { aReceiver(OT_ERROR_NOT_IMPLEMENTED, "Not implemented!"); }); + mTaskRunner.Post([aReceiver](void) { aReceiver(kErrorNotImplemented, "Not implemented!"); }); } void RcpHost::Leave(bool aEraseDataset, const AsyncResultReceiver &aReceiver) diff --git a/src/ncp/rcp_host.hpp b/src/ncp/rcp_host.hpp index 8efdbf15895..395a97bd9f3 100644 --- a/src/ncp/rcp_host.hpp +++ b/src/ncp/rcp_host.hpp @@ -223,7 +223,7 @@ class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkPro } private: - static void SafeInvokeAndClear(AsyncResultReceiver &aReceiver, otError aError, const std::string &aErrorInfo = "") + static void SafeInvokeAndClear(AsyncResultReceiver &aReceiver, Error aError, const std::string &aErrorInfo = "") { if (aReceiver) { @@ -231,7 +231,7 @@ class RcpHost : public MainloopProcessor, public ThreadHost, public OtNetworkPro aReceiver = nullptr; } } - static void SafeInvoke(const AsyncResultReceiver &aReceiver, otError aError, const std::string &aErrorInfo = "") + static void SafeInvoke(const AsyncResultReceiver &aReceiver, Error aError, const std::string &aErrorInfo = "") { if (aReceiver) { diff --git a/src/ncp/thread_host.hpp b/src/ncp/thread_host.hpp index 5348c7c68d6..3f9eb8467a9 100644 --- a/src/ncp/thread_host.hpp +++ b/src/ncp/thread_host.hpp @@ -106,6 +106,56 @@ enum ThreadEnabledState kStateInvalid = 255, }; +/** + * Some cases in ThreadHost APIs cannot be denoted by otError. This enumeration is a superset of otErrors + * and contains some error code specific to ThreadHost APIs. + */ +typedef int16_t Error; + +// otErrors: 0 ~ 255 +constexpr Error kErrorNone = OT_ERROR_NONE; +constexpr Error kErrorFailed = OT_ERROR_FAILED; +constexpr Error kErrorDrop = OT_ERROR_DROP; +constexpr Error kErrorNoBufs = OT_ERROR_NO_BUFS; +constexpr Error kErrorNoRoute = OT_ERROR_NO_ROUTE; +constexpr Error kErrorBusy = OT_ERROR_BUSY; +constexpr Error kErrorParse = OT_ERROR_PARSE; +constexpr Error kErrorInvalidArgs = OT_ERROR_INVALID_ARGS; +constexpr Error kErrorSecurity = OT_ERROR_SECURITY; +constexpr Error kErrorAddressQuery = OT_ERROR_ADDRESS_QUERY; +constexpr Error kErrorNoAddress = OT_ERROR_NO_ADDRESS; +constexpr Error kErrorAbort = OT_ERROR_ABORT; +constexpr Error kErrorNotImplemented = OT_ERROR_NOT_IMPLEMENTED; +constexpr Error kErrorInvalidState = OT_ERROR_INVALID_STATE; +constexpr Error kErrorNoAck = OT_ERROR_NO_ACK; +constexpr Error kErrorChannelAccessFailure = OT_ERROR_CHANNEL_ACCESS_FAILURE; +constexpr Error kErrorDetached = OT_ERROR_DETACHED; +constexpr Error kErrorFcs = OT_ERROR_FCS; +constexpr Error kErrorNoFrameReceived = OT_ERROR_NO_FRAME_RECEIVED; +constexpr Error kErrorUnknownNeighbor = OT_ERROR_UNKNOWN_NEIGHBOR; +constexpr Error kErrorInvalidSourceAddress = OT_ERROR_INVALID_SOURCE_ADDRESS; +constexpr Error kErrorAddressFiltered = OT_ERROR_ADDRESS_FILTERED; +constexpr Error kErrorDestinationAddressFiltered = OT_ERROR_DESTINATION_ADDRESS_FILTERED; +constexpr Error kErrorNotFound = OT_ERROR_NOT_FOUND; +constexpr Error kErrorAlready = OT_ERROR_ALREADY; +constexpr Error kErrorIp6AddressCreationFailure = OT_ERROR_IP6_ADDRESS_CREATION_FAILURE; +constexpr Error kErrorNotCapable = OT_ERROR_NOT_CAPABLE; +constexpr Error kErrorResponseTimeout = OT_ERROR_RESPONSE_TIMEOUT; +constexpr Error kErrorDuplicated = OT_ERROR_DUPLICATED; +constexpr Error kErrorReassemblyTimeout = OT_ERROR_REASSEMBLY_TIMEOUT; +constexpr Error kErrorNotTmf = OT_ERROR_NOT_TMF; +constexpr Error kErrorNotLowpanDataFrame = OT_ERROR_NOT_LOWPAN_DATA_FRAME; +constexpr Error kErrorLinkMarginLow = OT_ERROR_LINK_MARGIN_LOW; +constexpr Error kErrorInvalidCommand = OT_ERROR_INVALID_COMMAND; +constexpr Error kErrorPending = OT_ERROR_PENDING; +constexpr Error kErrorRejected = OT_ERROR_REJECTED; +constexpr Error kErrorGeneric = OT_ERROR_GENERIC; + +// Proprietary errors: -256 ~ -1 +constexpr Error kErrorUnsupportedChannel = -1; // The channel provided is not supported. +constexpr Error kErrorDisabled = -2; // The action didn't succeed because Thread is in Disabled state. +constexpr Error kErrorFailedPrecondition = -3; // The action didn't succeed because some precondition isn't satisfied. + /** * This class is an interface which provides a set of async APIs to control the * Thread network. @@ -115,10 +165,9 @@ enum ThreadEnabledState class ThreadHost : virtual public NetworkProperties { public: - using AsyncResultReceiver = std::function; + using AsyncResultReceiver = std::function; using ChannelMasksReceiver = std::function; - using DeviceRoleHandler = std::function; using ThreadStateChangedCallback = std::function; using ThreadEnabledStateCallback = std::function; diff --git a/tests/gtest/test_rcp_host_api.cpp b/tests/gtest/test_rcp_host_api.cpp index 9ba5bd1eb9c..af99f5d394e 100644 --- a/tests/gtest/test_rcp_host_api.cpp +++ b/tests/gtest/test_rcp_host_api.cpp @@ -64,20 +64,23 @@ static void MainloopProcessUntil(otbr::MainloopContext &aMainloop, TEST(RcpHostApi, DeviceRoleChangesCorrectlyAfterSetThreadEnabled) { - otError error = OT_ERROR_FAILED; - bool resultReceived = false; - otbr::Ncp::ThreadEnabledState threadEnabledState = otbr::Ncp::ThreadEnabledState::kStateInvalid; - otbr::MainloopContext mainloop; - otbr::Ncp::ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error](otError aError, - const std::string &aErrorMsg) { + using namespace otbr; + using namespace otbr::Ncp; + + Error error = kErrorFailed; + bool resultReceived = false; + ThreadEnabledState threadEnabledState = ThreadEnabledState::kStateInvalid; + MainloopContext mainloop; + ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error](Error aError, const std::string &aErrorMsg) { OT_UNUSED_VARIABLE(aErrorMsg); resultReceived = true; error = aError; }; - otbr::Ncp::ThreadHost::ThreadEnabledStateCallback enabledStateCallback = - [&threadEnabledState](otbr::Ncp::ThreadEnabledState aState) { threadEnabledState = aState; }; - otbr::Ncp::RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, - /* aEnableAutoAttach */ false); + ThreadHost::ThreadEnabledStateCallback enabledStateCallback = [&threadEnabledState](ThreadEnabledState aState) { + threadEnabledState = aState; + }; + RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, + /* aEnableAutoAttach */ false); host.Init(); host.AddThreadEnabledStateChangedCallback(enabledStateCallback); @@ -85,9 +88,9 @@ TEST(RcpHostApi, DeviceRoleChangesCorrectlyAfterSetThreadEnabled) // 1. Active dataset hasn't been set, should succeed with device role still being disabled. host.SetThreadEnabled(true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 1, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); EXPECT_EQ(host.GetDeviceRole(), OT_DEVICE_ROLE_DISABLED); - EXPECT_EQ(threadEnabledState, otbr::Ncp::ThreadEnabledState::kStateEnabled); + EXPECT_EQ(threadEnabledState, ThreadEnabledState::kStateEnabled); // 2. Set active dataset and start it { @@ -105,88 +108,90 @@ TEST(RcpHostApi, DeviceRoleChangesCorrectlyAfterSetThreadEnabled) EXPECT_EQ(host.GetDeviceRole(), OT_DEVICE_ROLE_LEADER); // 3. Enable again, the enabled state should not change. - error = OT_ERROR_FAILED; + error = kErrorFailed; resultReceived = false; host.SetThreadEnabled(true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 1, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); - EXPECT_EQ(threadEnabledState, otbr::Ncp::ThreadEnabledState::kStateEnabled); + EXPECT_EQ(error, kErrorNone); + EXPECT_EQ(threadEnabledState, ThreadEnabledState::kStateEnabled); // 4. Disable it - error = OT_ERROR_FAILED; + error = kErrorFailed; resultReceived = false; host.SetThreadEnabled(false, receiver); - EXPECT_EQ(threadEnabledState, otbr::Ncp::ThreadEnabledState::kStateDisabling); + EXPECT_EQ(threadEnabledState, ThreadEnabledState::kStateDisabling); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 1, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); EXPECT_EQ(host.GetDeviceRole(), OT_DEVICE_ROLE_DISABLED); - EXPECT_EQ(threadEnabledState, otbr::Ncp::ThreadEnabledState::kStateDisabled); + EXPECT_EQ(threadEnabledState, ThreadEnabledState::kStateDisabled); - // 5. Duplicate call, should get OT_ERROR_BUSY - error = OT_ERROR_FAILED; - resultReceived = false; - otError error2 = OT_ERROR_FAILED; - bool resultReceived2 = false; + // 5. Duplicate call, should get kErrorBusy + error = kErrorFailed; + resultReceived = false; + Error error2 = kErrorFailed; + bool resultReceived2 = false; host.SetThreadEnabled(false, receiver); - host.SetThreadEnabled(false, [&resultReceived2, &error2](otError aError, const std::string &aErrorMsg) { + host.SetThreadEnabled(false, [&resultReceived2, &error2](Error aError, const std::string &aErrorMsg) { OT_UNUSED_VARIABLE(aErrorMsg); error2 = aError; resultReceived2 = true; }); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 1, [&resultReceived, &resultReceived2]() { return resultReceived && resultReceived2; }); - EXPECT_EQ(error, OT_ERROR_NONE); - EXPECT_EQ(error2, OT_ERROR_BUSY); - EXPECT_EQ(threadEnabledState, otbr::Ncp::ThreadEnabledState::kStateDisabled); + EXPECT_EQ(error, kErrorNone); + EXPECT_EQ(error2, kErrorBusy); + EXPECT_EQ(threadEnabledState, ThreadEnabledState::kStateDisabled); host.Deinit(); } TEST(RcpHostApi, SetCountryCodeWorkCorrectly) { - otError error = OT_ERROR_FAILED; - bool resultReceived = false; - otbr::MainloopContext mainloop; - otbr::Ncp::ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error](otError aError, - const std::string &aErrorMsg) { + using namespace otbr; + using namespace otbr::Ncp; + + Error error = kErrorFailed; + bool resultReceived = false; + MainloopContext mainloop; + ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error](Error aError, const std::string &aErrorMsg) { OT_UNUSED_VARIABLE(aErrorMsg); resultReceived = true; error = aError; }; - otbr::Ncp::RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, - /* aEnableAutoAttach */ false); + RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, + /* aEnableAutoAttach */ false); // 1. Call SetCountryCode when host hasn't been initialized. - otbr::MainloopManager::GetInstance().RemoveMainloopProcessor( + MainloopManager::GetInstance().RemoveMainloopProcessor( &host); // Temporarily remove RcpHost because it's not initialized yet. host.SetCountryCode("AF", receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_STATE); - otbr::MainloopManager::GetInstance().AddMainloopProcessor(&host); + EXPECT_EQ(error, kErrorInvalidState); + MainloopManager::GetInstance().AddMainloopProcessor(&host); host.Init(); // 2. Call SetCountryCode with invalid arguments resultReceived = false; - error = OT_ERROR_NONE; + error = kErrorNone; host.SetCountryCode("AFA", receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_ARGS); + EXPECT_EQ(error, kErrorInvalidArgs); resultReceived = false; - error = OT_ERROR_NONE; + error = kErrorNone; host.SetCountryCode("A", receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_ARGS); + EXPECT_EQ(error, kErrorInvalidArgs); resultReceived = false; - error = OT_ERROR_NONE; + error = kErrorNone; host.SetCountryCode("12", receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_ARGS); + EXPECT_EQ(error, kErrorInvalidArgs); // 3. Call SetCountryCode with valid argument resultReceived = false; - error = OT_ERROR_NONE; + error = kErrorNone; host.SetCountryCode("AF", receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); EXPECT_EQ(error, OT_ERROR_NOT_IMPLEMENTED); // The current platform weak implmentation returns 'NOT_IMPLEMENTED'. @@ -196,42 +201,45 @@ TEST(RcpHostApi, SetCountryCodeWorkCorrectly) TEST(RcpHostApi, StateChangesCorrectlyAfterLeave) { - otError error = OT_ERROR_NONE; - std::string errorMsg = ""; - bool resultReceived = false; - otbr::MainloopContext mainloop; - otbr::Ncp::ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error, - &errorMsg](otError aError, const std::string &aErrorMsg) { + using namespace otbr; + using namespace otbr::Ncp; + + Error error = kErrorNone; + std::string errorMsg = ""; + bool resultReceived = false; + MainloopContext mainloop; + ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error, &errorMsg](Error aError, + const std::string &aErrorMsg) { resultReceived = true; error = aError; errorMsg = aErrorMsg; }; - otbr::Ncp::RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, - /* aEnableAutoAttach */ false); + RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, + /* aEnableAutoAttach */ false); // 1. Call Leave when host hasn't been initialized. - otbr::MainloopManager::GetInstance().RemoveMainloopProcessor( + MainloopManager::GetInstance().RemoveMainloopProcessor( &host); // Temporarily remove RcpHost because it's not initialized yet. host.Leave(/* aEraseDataset */ true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_STATE); + EXPECT_EQ(error, kErrorInvalidState); EXPECT_STREQ(errorMsg.c_str(), "OT is not initialized"); - otbr::MainloopManager::GetInstance().AddMainloopProcessor(&host); + MainloopManager::GetInstance().AddMainloopProcessor(&host); host.Init(); // 2. Call Leave when disabling Thread. - error = OT_ERROR_NONE; + error = kErrorNone; resultReceived = false; host.SetThreadEnabled(false, nullptr); host.Leave(/* aEraseDataset */ true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_BUSY); + EXPECT_EQ(error, kErrorBusy); EXPECT_STREQ(errorMsg.c_str(), "Thread is disabling"); // 3. Call Leave when Thread is disabled. - error = OT_ERROR_NONE; + error = kErrorNone; resultReceived = false; otOperationalDataset dataset; otOperationalDatasetTlvs datasetTlvs; @@ -240,13 +248,13 @@ TEST(RcpHostApi, StateChangesCorrectlyAfterLeave) OT_UNUSED_VARIABLE(otDatasetSetActiveTlvs(ot::FakePlatform::CurrentInstance(), &datasetTlvs)); host.Leave(/* aEraseDataset */ true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); error = otDatasetGetActive(ot::FakePlatform::CurrentInstance(), &dataset); EXPECT_EQ(error, OT_ERROR_NOT_FOUND); // 4. Call Leave when Thread is enabled. - error = OT_ERROR_NONE; + error = kErrorNone; resultReceived = false; OT_UNUSED_VARIABLE(otDatasetSetActiveTlvs(ot::FakePlatform::CurrentInstance(), &datasetTlvs)); host.SetThreadEnabled(true, nullptr); @@ -255,56 +263,59 @@ TEST(RcpHostApi, StateChangesCorrectlyAfterLeave) EXPECT_EQ(host.GetDeviceRole(), OT_DEVICE_ROLE_LEADER); host.Leave(/* aEraseDataset */ false, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); error = otDatasetGetActive(ot::FakePlatform::CurrentInstance(), &dataset); // Dataset should still be there. - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); host.Deinit(); } TEST(RcpHostApi, StateChangesCorrectlyAfterScheduleMigration) { - otError error = OT_ERROR_NONE; - std::string errorMsg = ""; - bool resultReceived = false; - otbr::MainloopContext mainloop; - otbr::Ncp::ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error, - &errorMsg](otError aError, const std::string &aErrorMsg) { + using namespace otbr; + using namespace otbr::Ncp; + + Error error = kErrorNone; + std::string errorMsg = ""; + bool resultReceived = false; + MainloopContext mainloop; + ThreadHost::AsyncResultReceiver receiver = [&resultReceived, &error, &errorMsg](Error aError, + const std::string &aErrorMsg) { resultReceived = true; error = aError; errorMsg = aErrorMsg; }; - otbr::Ncp::RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, - /* aEnableAutoAttach */ false); + RcpHost host("wpan0", std::vector(), /* aBackboneInterfaceName */ "", /* aDryRun */ false, + /* aEnableAutoAttach */ false); otOperationalDataset dataset; otOperationalDatasetTlvs datasetTlvs; // 1. Call ScheduleMigration when host hasn't been initialized. - otbr::MainloopManager::GetInstance().RemoveMainloopProcessor( + MainloopManager::GetInstance().RemoveMainloopProcessor( &host); // Temporarily remove RcpHost because it's not initialized yet. host.ScheduleMigration(datasetTlvs, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_STATE); + EXPECT_EQ(error, kErrorInvalidState); EXPECT_STREQ(errorMsg.c_str(), "OT is not initialized"); - otbr::MainloopManager::GetInstance().AddMainloopProcessor(&host); + MainloopManager::GetInstance().AddMainloopProcessor(&host); host.Init(); // 2. Call ScheduleMigration when the Thread is not enabled. - error = OT_ERROR_NONE; + error = kErrorNone; resultReceived = false; host.ScheduleMigration(datasetTlvs, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_INVALID_STATE); + EXPECT_EQ(error, kErrorInvalidState); EXPECT_STREQ(errorMsg.c_str(), "Thread is disabled"); // 3. Schedule migration to another network. OT_UNUSED_VARIABLE(otDatasetCreateNewNetwork(ot::FakePlatform::CurrentInstance(), &dataset)); otDatasetConvertToTlvs(&dataset, &datasetTlvs); OT_UNUSED_VARIABLE(otDatasetSetActiveTlvs(ot::FakePlatform::CurrentInstance(), &datasetTlvs)); - error = OT_ERROR_NONE; + error = kErrorNone; resultReceived = false; host.SetThreadEnabled(true, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 1, @@ -313,7 +324,7 @@ TEST(RcpHostApi, StateChangesCorrectlyAfterScheduleMigration) host.ScheduleMigration(datasetTlvs, receiver); MainloopProcessUntil(mainloop, /* aTimeoutSec */ 0, [&resultReceived]() { return resultReceived; }); - EXPECT_EQ(error, OT_ERROR_NONE); + EXPECT_EQ(error, kErrorNone); host.Deinit(); }