diff --git a/src/controller/python/ChipDeviceController-StorageDelegate.cpp b/src/controller/python/ChipDeviceController-StorageDelegate.cpp index 0c382e01c1a80d..9fb19efccdd2db 100644 --- a/src/controller/python/ChipDeviceController-StorageDelegate.cpp +++ b/src/controller/python/ChipDeviceController-StorageDelegate.cpp @@ -24,6 +24,7 @@ #include #include +#include #include namespace chip { @@ -39,7 +40,13 @@ CHIP_ERROR PythonPersistentStorageDelegate::SyncGetKeyValue(const char * key, vo return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; } - uint16_t neededSize = val->second.size(); + if (!CanCastTo(val->second.size())) + { + size = 0; + return CHIP_ERROR_BUFFER_TOO_SMALL; + } + + uint16_t neededSize = static_cast(val->second.size()); ReturnErrorCodeIf(size == 0 && neededSize == 0, CHIP_NO_ERROR); ReturnErrorCodeIf(value == nullptr, CHIP_ERROR_BUFFER_TOO_SMALL); diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index 240579071def38..5cad75c444a871 100644 --- a/src/controller/python/chip/clusters/Attribute.py +++ b/src/controller/python/chip/clusters/Attribute.py @@ -977,8 +977,8 @@ def WriteGroupAttributes(groupId: int, devCtrl: c_void_p, attributes: List[Attri # This struct matches the PyReadAttributeParams in attribute.cpp, for passing various params together. _ReadParams = construct.Struct( - "MinInterval" / construct.Int32ul, - "MaxInterval" / construct.Int32ul, + "MinInterval" / construct.Int16ul, + "MaxInterval" / construct.Int16ul, "IsSubscription" / construct.Flag, "IsFabricFiltered" / construct.Flag, "KeepSubscriptions" / construct.Flag, diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index 1ed6d7e1cb82c6..5e7ffcdc679008 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -238,8 +238,8 @@ extern "C" { struct __attribute__((packed)) PyReadAttributeParams { - uint32_t minInterval; // MinInterval in subscription request - uint32_t maxInterval; // MaxInterval in subscription request + uint16_t minInterval; // MinInterval in subscription request + uint16_t maxInterval; // MaxInterval in subscription request bool isSubscription; bool isFabricFiltered; bool keepSubscriptions; diff --git a/src/controller/tests/data_model/TestRead.cpp b/src/controller/tests/data_model/TestRead.cpp index 63983a9a5cb722..301febb1d3a895 100644 --- a/src/controller/tests/data_model/TestRead.cpp +++ b/src/controller/tests/data_model/TestRead.cpp @@ -2958,12 +2958,12 @@ class TestReadCallback : public app::ReadClient::Callback mLastError = CHIP_NO_ERROR; } - int32_t mAttributeCount = 0; - int32_t mOnReportEnd = 0; - int32_t mOnSubscriptionEstablishedCount = 0; - int32_t mOnDone = 0; - int32_t mOnError = 0; - CHIP_ERROR mLastError = CHIP_NO_ERROR; + uint32_t mAttributeCount = 0; + uint32_t mOnReportEnd = 0; + uint32_t mOnSubscriptionEstablishedCount = 0; + uint32_t mOnDone = 0; + uint32_t mOnError = 0; + CHIP_ERROR mLastError = CHIP_NO_ERROR; }; class TestPerpetualListReadCallback : public app::ReadClient::Callback @@ -2991,7 +2991,7 @@ class TestPerpetualListReadCallback : public app::ReadClient::Callback int32_t reportsReceived = 0; }; -void EstablishReadOrSubscriptions(nlTestSuite * apSuite, const SessionHandle & sessionHandle, int32_t numSubs, int32_t pathPerSub, +void EstablishReadOrSubscriptions(nlTestSuite * apSuite, const SessionHandle & sessionHandle, size_t numSubs, size_t pathPerSub, app::AttributePathParams path, app::ReadClient::InteractionType type, app::ReadClient::Callback * callback, std::vector> & readClients) { @@ -3006,7 +3006,7 @@ void EstablishReadOrSubscriptions(nlTestSuite * apSuite, const SessionHandle & s readParams.mKeepSubscriptions = true; } - for (int32_t i = 0; i < numSubs; i++) + for (uint32_t i = 0; i < numSubs; i++) { std::unique_ptr readClient = std::make_unique(app::InteractionModelEngine::GetInstance(), @@ -3066,9 +3066,9 @@ void TestReadInteraction::TestReadHandler_KillOverQuotaSubscriptions(nlTestSuite TestContext & ctx = *static_cast(apContext); auto sessionHandle = ctx.GetSessionBobToAlice(); - const int32_t kExpectedParallelSubs = + const auto kExpectedParallelSubs = app::InteractionModelEngine::kMinSupportedSubscriptionsPerFabric * ctx.GetFabricTable().FabricCount(); - const int32_t kExpectedParallelPaths = kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription; + const auto kExpectedParallelPaths = kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription; app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(&gTestReadInteraction); @@ -3117,14 +3117,14 @@ void TestReadInteraction::TestReadHandler_KillOverQuotaSubscriptions(nlTestSuite ctx.GetIOContext().DriveIOUntil(System::Clock::Seconds16(5), [&]() { return readCallback.mOnSubscriptionEstablishedCount == kExpectedParallelSubs + 1 && readCallback.mAttributeCount == - static_cast(kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription + - app::InteractionModelEngine::kMinSupportedPathsPerSubscription + 1); + kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription + + app::InteractionModelEngine::kMinSupportedPathsPerSubscription + 1; }); NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == - static_cast(kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription + - app::InteractionModelEngine::kMinSupportedPathsPerSubscription + 1)); + kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription + + app::InteractionModelEngine::kMinSupportedPathsPerSubscription + 1); NL_TEST_ASSERT(apSuite, readCallback.mOnSubscriptionEstablishedCount == kExpectedParallelSubs + 1); // We have set up the environment for testing the evicting logic. @@ -3132,8 +3132,8 @@ void TestReadInteraction::TestReadHandler_KillOverQuotaSubscriptions(nlTestSuite // subscriptions will require the eviction of existing subscriptions, OR potential rejection of the subscription if it exceeds // minimas. app::InteractionModelEngine::GetInstance()->SetForceHandlerQuota(true); - app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(kExpectedParallelSubs); - app::InteractionModelEngine::GetInstance()->SetPathPoolCapacityForSubscriptions(kExpectedParallelPaths); + app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(static_cast(kExpectedParallelSubs)); + app::InteractionModelEngine::GetInstance()->SetPathPoolCapacityForSubscriptions(static_cast(kExpectedParallelPaths)); // Part 1: Test per subscription minimas. // Rejection of the subscription that exceeds minimas. @@ -3291,9 +3291,9 @@ void TestReadInteraction::TestReadHandler_KillOldestSubscriptions(nlTestSuite * TestContext & ctx = *static_cast(apContext); auto sessionHandle = ctx.GetSessionBobToAlice(); - const int32_t kExpectedParallelSubs = + const auto kExpectedParallelSubs = app::InteractionModelEngine::kMinSupportedSubscriptionsPerFabric * ctx.GetFabricTable().FabricCount(); - const int32_t kExpectedParallelPaths = kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription; + const auto kExpectedParallelPaths = kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription; app::InteractionModelEngine::GetInstance()->RegisterReadHandlerAppCallback(&gTestReadInteraction); @@ -3301,8 +3301,8 @@ void TestReadInteraction::TestReadHandler_KillOldestSubscriptions(nlTestSuite * std::vector> readClients; app::InteractionModelEngine::GetInstance()->SetForceHandlerQuota(true); - app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(kExpectedParallelSubs); - app::InteractionModelEngine::GetInstance()->SetPathPoolCapacityForSubscriptions(kExpectedParallelPaths); + app::InteractionModelEngine::GetInstance()->SetHandlerCapacityForSubscriptions(static_cast(kExpectedParallelSubs)); + app::InteractionModelEngine::GetInstance()->SetPathPoolCapacityForSubscriptions(static_cast(kExpectedParallelPaths)); // This should just use all availbale resources. EstablishReadOrSubscriptions( @@ -3314,12 +3314,9 @@ void TestReadInteraction::TestReadHandler_KillOldestSubscriptions(nlTestSuite * NL_TEST_ASSERT(apSuite, readCallback.mAttributeCount == - kExpectedParallelSubs * - static_cast(app::InteractionModelEngine::kMinSupportedPathsPerSubscription)); + kExpectedParallelSubs * app::InteractionModelEngine::kMinSupportedPathsPerSubscription); NL_TEST_ASSERT(apSuite, readCallback.mOnSubscriptionEstablishedCount == kExpectedParallelSubs); - NL_TEST_ASSERT(apSuite, - app::InteractionModelEngine::GetInstance()->GetNumActiveReadHandlers() == - static_cast(kExpectedParallelSubs)); + NL_TEST_ASSERT(apSuite, app::InteractionModelEngine::GetInstance()->GetNumActiveReadHandlers() == kExpectedParallelSubs); // The following check will trigger the logic in im to kill the read handlers that uses more paths than the limit per fabric. {