Skip to content

Commit ddabe10

Browse files
authored
Merge branch 'master' into replace_PICS_from_TSTAT_test
2 parents 2835ae7 + 1c92162 commit ddabe10

11 files changed

+62
-27
lines changed

examples/chef/devices/rootnode_heatpump_87ivjRAECh.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ cluster GeneralDiagnostics = 51 {
12691269
/** Take a snapshot of system time and epoch time. */
12701270
command TimeSnapshot(): TimeSnapshotResponse = 1;
12711271
/** Request a variable length payload response. */
1272-
command PayloadTestRequest(PayloadTestRequestRequest): PayloadTestResponse = 3;
1272+
command access(invoke: manage) PayloadTestRequest(PayloadTestRequestRequest): PayloadTestResponse = 3;
12731273
}
12741274

12751275
/** Commands to trigger a Node to allow a new Administrator to commission it. */

src/app/server/Server.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <app/data-model-provider/Provider.h>
2828
#include <app/server/Dnssd.h>
2929
#include <app/server/EchoHandler.h>
30-
#include <app/util/DataModelHandler.h>
3130

3231
#if CONFIG_NETWORK_LAYER_BLE
3332
#include <ble/Ble.h>
@@ -170,17 +169,6 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
170169
SuccessOrExit(err = mAttributePersister.Init(mDeviceStorage));
171170
SetSafeAttributePersistenceProvider(&mAttributePersister);
172171

173-
// SetDataModelProvider() actually initializes/starts the provider. We need
174-
// to preserve the following ordering guarantees:
175-
//
176-
// 1) Provider initialization (under SetDataModelProvider) happens after
177-
// SetSafeAttributePersistenceProvider, since the provider can then use
178-
// the safe persistence provider to implement and initialize its own attribute persistence logic.
179-
// 2) For now, provider initialization happens before InitDataModelHandler(), which depends
180-
// on atttribute persistence being already set up before it runs. Longer-term, the logic from
181-
// InitDataModelHandler should just move into the codegen provider.
182-
app::InteractionModelEngine::GetInstance()->SetDataModelProvider(initParams.dataModelProvider);
183-
184172
{
185173
FabricTable::InitParams fabricTableInitParams;
186174
fabricTableInitParams.storage = mDeviceStorage;
@@ -302,8 +290,22 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
302290
}
303291
#endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT
304292

305-
// This initializes clusters, so should come after lower level initialization.
306-
InitDataModelHandler();
293+
// SetDataModelProvider() initializes and starts the provider, which in turn
294+
// triggers the initialization of cluster implementations. This callsite is
295+
// critical because it ensures that cluster-level initialization occurs only
296+
// after all necessary low-level dependencies have been set up.
297+
//
298+
// Ordering guarantees:
299+
// 1) Provider initialization (under SetDataModelProvider) must happen after
300+
// SetSafeAttributePersistenceProvider to ensure the provider can leverage
301+
// the safe persistence provider for attribute persistence logic.
302+
// 2) It must occur after all low-level components that cluster implementations
303+
// might depend on have been initialized, as they rely on these components
304+
// during their own initialization.
305+
//
306+
// This remains the single point of entry to ensure that all cluster-level
307+
// initialization is performed in the correct order.
308+
app::InteractionModelEngine::GetInstance()->SetDataModelProvider(initParams.dataModelProvider);
307309

308310
#if defined(CHIP_APP_USE_ECHO)
309311
err = InitEchoHandler(&mExchangeMgr);

src/app/tests/TestCommissioningWindowManager.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ using chip::CommissioningWindowAdvertisement;
4141
using chip::CommissioningWindowManager;
4242
using chip::Server;
4343

44-
// Mock function for linking
45-
void InitDataModelHandler() {}
46-
4744
namespace {
4845
bool sAdminFabricIndexDirty = false;
4946
bool sAdminVendorIdDirty = false;

src/app/tests/TestInteractionModelEngine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
#if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
4040
#include <app/SimpleSubscriptionResumptionStorage.h>
4141
#include <lib/support/TestPersistentStorageDelegate.h>
42-
4342
#endif // CHIP_CONFIG_PERSIST_SUBSCRIPTIONS
43+
4444
namespace {
4545

4646
class NullReadHandlerCallback : public chip::app::ReadHandler::ManagementCallback

src/app/tests/test-ember-api.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ uint16_t emberAfGetClusterServerEndpointIndex(chip::EndpointId endpoint, chip::C
3434
}
3535
return endpoint;
3636
}
37+
38+
// Mock function for linking
39+
void InitDataModelHandler() {}

src/controller/CHIPDeviceControllerFactory.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,10 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
252252

253253
chip::app::InteractionModelEngine * interactionModelEngine = chip::app::InteractionModelEngine::GetInstance();
254254

255-
// Note placement of this BEFORE `InitDataModelHandler` since InitDataModelHandler may
256-
// rely on ember (does emberAfInit() and configure which may load data from NVM).
257-
//
258-
// Expected forward path is that we will move move and more things inside datamodel
259-
// provider (e.g. storage settings) so we want datamodelprovider available before
260-
// `InitDataModelHandler`.
255+
// Initialize the data model now that everything cluster implementations might
256+
// depend on is initalized.
261257
interactionModelEngine->SetDataModelProvider(params.dataModelProvider);
262258

263-
InitDataModelHandler();
264-
265259
ReturnErrorOnFailure(Dnssd::Resolver::Instance().Init(stateParams.udpEndPointManager));
266260

267261
if (params.enableServerInteractions)

src/controller/tests/TestServerCommandDispatch.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ CHIP_ERROR TestClusterCommandHandler::EnumerateAcceptedCommands(const ConcreteCl
126126

127127
namespace {
128128

129+
// TODO:(#36837) implementing its own provider instead of using "CodegenDataModelProvider"
130+
// TestServerCommandDispatch should provide its own dedicated data model provider rather than using CodegenDataModelProvider
131+
// provider. This class exists solely for one specific test scenario, on a temporary basis.
129132
class DispatchTestDataModel : public CodegenDataModelProvider
130133
{
131134
public:
@@ -134,6 +137,20 @@ class DispatchTestDataModel : public CodegenDataModelProvider
134137
static DispatchTestDataModel instance;
135138
return instance;
136139
}
140+
141+
// The Startup method initializes the data model provider with a given context.
142+
// This approach ensures that the test relies on a more controlled and explicit data model provider
143+
// rather than depending on the code-generated one with undefined modifications.
144+
CHIP_ERROR Startup(DataModel::InteractionModelContext context) override
145+
{
146+
ReturnErrorOnFailure(CodegenDataModelProvider::Startup(context));
147+
return CHIP_NO_ERROR;
148+
}
149+
150+
protected:
151+
// Since the current unit tests do not involve any cluster implementations, we override InitDataModelForTesting
152+
// to do nothing, thereby preventing calls to the Ember-specific InitDataModelHandler.
153+
void InitDataModelForTesting() override {}
137154
};
138155

139156
class TestServerCommandDispatch : public chip::Test::AppContext
@@ -144,6 +161,7 @@ class TestServerCommandDispatch : public chip::Test::AppContext
144161
AppContext::SetUp();
145162
mOldProvider = InteractionModelEngine::GetInstance()->SetDataModelProvider(&DispatchTestDataModel::Instance());
146163
}
164+
147165
void TearDown()
148166
{
149167
InteractionModelEngine::GetInstance()->SetDataModelProvider(mOldProvider);

src/controller/tests/data_model/DataModelFixtures.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ using namespace chip::app::Clusters;
4040
using namespace chip::app::Clusters::UnitTesting;
4141
using namespace chip::Protocols;
4242

43+
// Mock function for linking
44+
void InitDataModelHandler() {}
45+
4346
namespace chip {
4447
namespace app {
4548

src/data-model-providers/codegen/CodegenDataModelProvider.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <app/RequiredPrivilege.h>
2727
#include <app/data-model-provider/MetadataTypes.h>
2828
#include <app/data-model-provider/Provider.h>
29+
#include <app/util/DataModelHandler.h>
2930
#include <app/util/IMClusterCommandHandler.h>
3031
#include <app/util/af-types.h>
3132
#include <app/util/attribute-storage.h>
@@ -417,6 +418,8 @@ CHIP_ERROR CodegenDataModelProvider::Startup(DataModel::InteractionModelContext
417418
}
418419
}
419420

421+
InitDataModelForTesting();
422+
420423
return CHIP_NO_ERROR;
421424
}
422425

@@ -859,6 +862,12 @@ ConcreteCommandPath CodegenDataModelProvider::NextGeneratedCommand(const Concret
859862
return ConcreteCommandPath(before.mEndpointId, before.mClusterId, commandId);
860863
}
861864

865+
void CodegenDataModelProvider::InitDataModelForTesting()
866+
{
867+
// Call the Ember-specific InitDataModelHandler
868+
InitDataModelHandler();
869+
}
870+
862871
std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceType(EndpointId endpoint)
863872
{
864873
// Use the `Index` version even though `emberAfDeviceTypeListFromEndpoint` would work because

src/data-model-providers/codegen/CodegenDataModelProvider.h

+6
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ class CodegenDataModelProvider : public DataModel::Provider
187187

188188
void Temporary_ReportAttributeChanged(const AttributePathParams & path) override;
189189

190+
protected:
191+
// Temporary hack for a test: Initializes the data model for testing purposes only.
192+
// This method serves as a placeholder and should NOT be used outside of specific tests.
193+
// It is expected to be removed or replaced with a proper implementation in the future.TODO:(#36837).
194+
virtual void InitDataModelForTesting();
195+
190196
private:
191197
// Iteration is often done in a tight loop going through all values.
192198
// To avoid N^2 iterations, cache a hint of where something is positioned

src/data-model-providers/codegen/tests/TestCodegenModelViaMocks.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ using namespace chip::app::Clusters::Globals::Attributes;
7575

7676
using chip::Protocols::InteractionModel::Status;
7777

78+
// Mock function for linking
79+
void InitDataModelHandler() {}
80+
7881
namespace {
7982

8083
constexpr AttributeId kAttributeIdReadOnly = 0x3001;

0 commit comments

Comments
 (0)