Skip to content

Commit

Permalink
Update AttributePathExpandIterator to be able to use the IM/DM DataMo…
Browse files Browse the repository at this point in the history
…del split (#34288)

* Ember invoke implementation with unit tests inside DataModel

* Support ember/datamodel/dual(checked) attribute path expand iterators

* Code review comments

* Fix interactionmodel::status compilation in icd-management-server when ICD is on

* Do not include CodegeDataModelInstance if we do not use the codegen data model

* Fix linter

* Fix java controller linkage.

This is still broken: there should be no reason java should
want ember, yet here we are (with odd dependencies inside libCHIP)

* Fix Amebad compilation: OUT is defined in Ameba

* Update log formatting

* Review comment: use GlobalAttributesNotInMetadata directly

* Remove debug bits

* Code review update: we just need to match next logic in the ember code in the dm code.

* Restyle

* Do not check for differences if result is false ... this is what people expect even if we guarantee perfect overlap

* Fix typo

* Restyle

* Update src/app/AttributePathExpandIterator-DataModel.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
3 people authored Jul 19, 2024
1 parent 4762aaa commit 483af54
Show file tree
Hide file tree
Showing 33 changed files with 1,042 additions and 193 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ jobs:
':(exclude)src/app/util/attribute-table.cpp' \
':(exclude)src/app/util/attribute-table.h' \
':(exclude)src/app/util/ember-compatibility-functions.cpp' \
':(exclude)src/app/util/mock/CodegenEmberMocks.cpp' \
':(exclude)src/app/zap-templates/templates/app/attributes/Accessors-src.zapt' \
':(exclude)zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp' \
&& exit 1 || exit 0
Expand Down
4 changes: 4 additions & 0 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
if self.app == HostApp.SIMULATED_APP2:
self.extra_gn_options.append('chip_tests_zap_config="app2"')

if self.app in {HostApp.JAVA_MATTER_CONTROLLER, HostApp.KOTLIN_MATTER_CONTROLLER}:
# TODO: controllers depending on a datamodel is odd. For now fix compile dependencies on ember.
self.extra_gn_options.append('chip_use_data_model_interface="disabled"')

if self.app == HostApp.TESTS and fuzzing_type != HostFuzzingType.NONE:
self.build_command = 'fuzz_tests'

Expand Down
99 changes: 99 additions & 0 deletions src/app/AttributePathExpandIterator-Checked.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "lib/support/logging/TextOnlyLogging.h"
#include <app/AttributePathExpandIterator-Checked.h>

namespace chip {
namespace app {
AttributePathExpandIteratorChecked::AttributePathExpandIteratorChecked(InteractionModel::DataModel * dataModel,
SingleLinkedListNode<AttributePathParams> * attributePath) :
mDataModelIterator(dataModel, attributePath),
mEmberIterator(dataModel, attributePath)
{
CheckOutputsIdentical("Constructor");
}

bool AttributePathExpandIteratorChecked::Next()
{
bool dmResult = mDataModelIterator.Next();
bool emResult = mEmberIterator.Next();

CheckOutputsIdentical("Next");

VerifyOrDie(dmResult == emResult);

return emResult;
}

bool AttributePathExpandIteratorChecked::Get(ConcreteAttributePath & aPath)
{
CheckOutputsIdentical("Get");
return mEmberIterator.Get(aPath);
}

void AttributePathExpandIteratorChecked::ResetCurrentCluster()
{
mDataModelIterator.ResetCurrentCluster();
mEmberIterator.ResetCurrentCluster();

CheckOutputsIdentical("ResetCurrentCluster");
}

void AttributePathExpandIteratorChecked::ResetTo(SingleLinkedListNode<AttributePathParams> * paths)

{
mDataModelIterator.ResetTo(paths);
mEmberIterator.ResetTo(paths);
CheckOutputsIdentical("ResetTo");
}

void AttributePathExpandIteratorChecked::CheckOutputsIdentical(const char * msg)
{
ConcreteAttributePath dmPath;
ConcreteAttributePath emPath;

bool dmResult = mDataModelIterator.Get(dmPath);
bool emResult = mEmberIterator.Get(emPath);

if (dmResult == emResult)
{
// We check for:
// - either failed result (in which case path should not matter)
// - or exact match of paths on success
//
// NOTE: extra logic because mExpanded is NOT considered in operator== (ugly...)
if ((dmResult == false) || ((dmPath == emPath) && (dmPath.mExpanded == emPath.mExpanded)))
{
// outputs are identical. All is good
return;
}
}

ChipLogProgress(Test, "Different paths in DM vs EMBER (%d and %d) in %s", dmResult, emResult, msg);
ChipLogProgress(Test, " DM PATH: 0x%X/" ChipLogFormatMEI "/" ChipLogFormatMEI " (%s)", dmPath.mEndpointId,
ChipLogValueMEI(dmPath.mClusterId), ChipLogValueMEI(dmPath.mAttributeId),
dmPath.mExpanded ? "EXPANDED" : "NOT expanded");
ChipLogProgress(Test, " EMBER PATH: 0x%X/" ChipLogFormatMEI "/" ChipLogFormatMEI " (%s)", emPath.mEndpointId,
ChipLogValueMEI(emPath.mClusterId), ChipLogValueMEI(emPath.mAttributeId),
emPath.mExpanded ? "EXPANDED" : "NOT expanded");

chipDie();
}

} // namespace app
} // namespace chip
45 changes: 45 additions & 0 deletions src/app/AttributePathExpandIterator-Checked.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/AttributePathExpandIterator-DataModel.h>
#include <app/AttributePathExpandIterator-Ember.h>

namespace chip {
namespace app {

class AttributePathExpandIteratorChecked
{
public:
AttributePathExpandIteratorChecked(InteractionModel::DataModel * dataModel,
SingleLinkedListNode<AttributePathParams> * attributePath);

bool Next();
bool Get(ConcreteAttributePath & aPath);
void ResetCurrentCluster();
void ResetTo(SingleLinkedListNode<AttributePathParams> * paths);

private:
AttributePathExpandIteratorDataModel mDataModelIterator;
AttributePathExpandIteratorEmber mEmberIterator;

void CheckOutputsIdentical(const char * msg);
};

} // namespace app
} // namespace chip
Loading

0 comments on commit 483af54

Please sign in to comment.