Skip to content

Commit

Permalink
Merge branch 'master' into TC-SC-4.3-python-test
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa authored Oct 14, 2024
2 parents 58cb99d + ac9537d commit 675e799
Show file tree
Hide file tree
Showing 102 changed files with 51,128 additions and 4,722 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/darwin-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ jobs:
platform: darwin
bootstrap-log-name: bootstrap-logs-darwin-${{ matrix.build_variant }}

- name: Build iOS Darwin Framework Tool Build Debug
working-directory: src/darwin/Framework
run: xcodebuild -target "darwin-framework-tool" -sdk iphoneos -configuration Debug AD_HOC_CODE_SIGNING_ALLOWED=YES

- name: Run macOS Darwin Framework Tool Build Debug
working-directory: src/darwin/Framework
run: xcodebuild -target "darwin-framework-tool" -sdk macosx -configuration Debug
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ jobs:
src/app/zap-templates/zcl/data-model/chip/boolean-state-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/actions-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/bridged-device-basic-information.xml \
src/app/zap-templates/zcl/data-model/chip/camera-av-stream-management-cluster.xml \
src/app/zap-templates/zcl/data-model/chip/chip-ota.xml \
src/app/zap-templates/zcl/data-model/chip/chip-types.xml \
src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml \
Expand Down
1 change: 1 addition & 0 deletions docs/zap_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Generally regenerate using one of:
| 1295 | 0x50F | ContentControl |
| 1296 | 0x510 | ContentAppObserver |
| 1360 | 0x550 | ZoneManagement |
| 1361 | 0x551 | CameraAvStreamManagement |
| 1363 | 0x553 | WebRTCTransportProvider |
| 1364 | 0x554 | WebRTCTransportRequestor |
| 1366 | 0x556 | Chime |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ def run(self, specs, value, cluster_name: str, typename: str, array: bool):
del value[key_name]

elif isinstance(value, list) and array:
# Instead of using `False` for the last parameter (array), `isinstance(v, list)` is used.
# While the data model specification does not include lists of lists, the format returned
# by the Matter.framework for *ById APIs may contain them.
# For example, the command:
# darwin-framework-tool any read-by-id 29 0 0x12344321 65535
# returns value such as:
# [[{'DeviceType': 17, 'Revision': 1}, {'DeviceType': 22, 'Revision': 1}], ...]
value = [self.run(specs, v, cluster_name, typename, isinstance(v, list))
for v in value]

Expand Down
5 changes: 5 additions & 0 deletions examples/darwin-framework-tool/commands/memory/LeaksTool.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @implementation LeaksTool

- (BOOL)runWithArguments:(NSArray<NSString *> * _Nullable)arguments
{
#if TARGET_OS_OSX
pid_t pid = getpid();
__auto_type * pidString = [NSString stringWithFormat:@"%d", pid];

Expand Down Expand Up @@ -59,6 +60,10 @@ - (BOOL)runWithArguments:(NSArray<NSString *> * _Nullable)arguments
NSLog(@"%@", output);

return YES;
#else
NSLog(@"Running leaks as a task is supported on this platform.");
return NO;
#endif // TARGET_OS_OSX
}

@end
Expand Down
4 changes: 4 additions & 0 deletions examples/darwin-framework-tool/debug/LeakChecker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ @implementation LeakChecker

- (BOOL)hasMemoryLeaks
{
#if TARGET_OS_OSX
pid_t pid = getpid();
auto * pidString = [NSString stringWithFormat:@"%d", pid];

Expand All @@ -51,6 +52,9 @@ - (BOOL)hasMemoryLeaks
NSLog(@"%@", output);
return YES;
}
#else
NSLog(@"Running leaks as a task is supported on this platform.");
#endif // TARGET_OS_OSX

return NO;
}
Expand Down
1 change: 1 addition & 0 deletions scripts/rules.matterlint
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ load "../src/app/zap-templates/zcl/data-model/chip/binding-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/boolean-state-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/actions-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/bridged-device-basic-information.xml";
load "../src/app/zap-templates/zcl/data-model/chip/camera-av-stream-management-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/channel-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/chime-cluster.xml";
load "../src/app/zap-templates/zcl/data-model/chip/chip-ota.xml";
Expand Down
5 changes: 5 additions & 0 deletions src/app/icd/client/CheckInHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ CHIP_ERROR CheckInHandler::Init(Messaging::ExchangeManager * exchangeManager, IC
{
VerifyOrReturnError(exchangeManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(clientStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mpExchangeManager == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mpICDClientStorage == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mpCheckInDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mpImEngine == nullptr, CHIP_ERROR_INCORRECT_STATE);

mpExchangeManager = exchangeManager;
mpICDClientStorage = clientStorage;
Expand Down Expand Up @@ -113,6 +117,7 @@ CHIP_ERROR CheckInHandler::OnMessageReceived(Messaging::ExchangeContext * ec, co

if (refreshKey)
{
ChipLogProgress(ICD, "Key Refresh is required");
RefreshKeySender * refreshKeySender = mpCheckInDelegate->OnKeyRefreshNeeded(clientInfo, mpICDClientStorage);
if (refreshKeySender == nullptr)
{
Expand Down
51 changes: 44 additions & 7 deletions src/app/icd/client/DefaultICDClientStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ CHIP_ERROR DefaultICDClientStorage::UpdateFabricList(FabricIndex fabricIndex)

mFabricList.push_back(fabricIndex);

return StoreFabricList();
}

CHIP_ERROR DefaultICDClientStorage::StoreFabricList()
{
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
size_t counter = mFabricList.size();
size_t total = kFabricIndexTlvSize * counter + kArrayOverHead;
Expand All @@ -68,7 +73,7 @@ CHIP_ERROR DefaultICDClientStorage::UpdateFabricList(FabricIndex fabricIndex)
const auto len = writer.GetLengthWritten();
VerifyOrReturnError(CanCastTo<uint16_t>(len), CHIP_ERROR_BUFFER_TOO_SMALL);

writer.Finalize(backingBuffer);
ReturnErrorOnFailure(writer.Finalize(backingBuffer));
return mpClientInfoStore->SyncSetKeyValue(DefaultStorageKeyAllocator::ICDFabricList().KeyName(), backingBuffer.Get(),
static_cast<uint16_t>(len));
}
Expand Down Expand Up @@ -211,6 +216,7 @@ CHIP_ERROR DefaultICDClientStorage::Load(FabricIndex fabricIndex, std::vector<IC
{
size_t count = 0;
ReturnErrorOnFailure(LoadCounter(fabricIndex, count, clientInfoSize));
VerifyOrReturnError(count > 0, CHIP_NO_ERROR);
size_t len = clientInfoSize * count + kArrayOverHead;
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
VerifyOrReturnError(CanCastTo<uint16_t>(len), CHIP_ERROR_BUFFER_TOO_SMALL);
Expand Down Expand Up @@ -344,8 +350,21 @@ CHIP_ERROR DefaultICDClientStorage::SerializeToTlv(TLV::TLVWriter & writer, cons
return writer.EndContainer(arrayType);
}

bool DefaultICDClientStorage::FabricExists(FabricIndex fabricIndex)
{
for (auto & fabric_idx : mFabricList)
{
if (fabric_idx == fabricIndex)
{
return true;
}
}
return false;
}

CHIP_ERROR DefaultICDClientStorage::StoreEntry(const ICDClientInfo & clientInfo)
{
VerifyOrReturnError(FabricExists(clientInfo.peer_node.GetFabricIndex()), CHIP_ERROR_INVALID_FABRIC_INDEX);
std::vector<ICDClientInfo> clientInfoVector;
size_t clientInfoSize = MaxICDClientInfoSize();
ReturnErrorOnFailure(Load(clientInfo.peer_node.GetFabricIndex(), clientInfoVector, clientInfoSize));
Expand All @@ -359,7 +378,6 @@ CHIP_ERROR DefaultICDClientStorage::StoreEntry(const ICDClientInfo & clientInfo)
break;
}
}

clientInfoVector.push_back(clientInfo);
size_t total = clientInfoSize * clientInfoVector.size() + kArrayOverHead;
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
Expand All @@ -371,7 +389,7 @@ CHIP_ERROR DefaultICDClientStorage::StoreEntry(const ICDClientInfo & clientInfo)
const auto len = writer.GetLengthWritten();
VerifyOrReturnError(CanCastTo<uint16_t>(len), CHIP_ERROR_BUFFER_TOO_SMALL);

writer.Finalize(backingBuffer);
ReturnErrorOnFailure(writer.Finalize(backingBuffer));
ReturnErrorOnFailure(mpClientInfoStore->SyncSetKeyValue(
DefaultStorageKeyAllocator::ICDClientInfoKey(clientInfo.peer_node.GetFabricIndex()).KeyName(), backingBuffer.Get(),
static_cast<uint16_t>(len)));
Expand Down Expand Up @@ -416,17 +434,19 @@ CHIP_ERROR DefaultICDClientStorage::UpdateEntryCountForFabric(FabricIndex fabric

const auto len = writer.GetLengthWritten();
VerifyOrReturnError(CanCastTo<uint16_t>(len), CHIP_ERROR_BUFFER_TOO_SMALL);
writer.Finalize(backingBuffer);
ReturnErrorOnFailure(writer.Finalize(backingBuffer));

return mpClientInfoStore->SyncSetKeyValue(DefaultStorageKeyAllocator::FabricICDClientInfoCounter(fabricIndex).KeyName(),
backingBuffer.Get(), static_cast<uint16_t>(len));
}

CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode)
{
VerifyOrReturnError(FabricExists(peerNode.GetFabricIndex()), CHIP_NO_ERROR);
size_t clientInfoSize = 0;
std::vector<ICDClientInfo> clientInfoVector;
ReturnErrorOnFailure(Load(peerNode.GetFabricIndex(), clientInfoVector, clientInfoSize));
VerifyOrReturnError(clientInfoVector.size() > 0, CHIP_NO_ERROR);

for (auto it = clientInfoVector.begin(); it != clientInfoVector.end(); it++)
{
Expand All @@ -440,7 +460,6 @@ CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode)

ReturnErrorOnFailure(
mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::ICDClientInfoKey(peerNode.GetFabricIndex()).KeyName()));

size_t total = clientInfoSize * clientInfoVector.size() + kArrayOverHead;
Platform::ScopedMemoryBuffer<uint8_t> backingBuffer;
ReturnErrorCodeIf(!backingBuffer.Calloc(total), CHIP_ERROR_NO_MEMORY);
Expand All @@ -451,7 +470,7 @@ CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode)
const auto len = writer.GetLengthWritten();
VerifyOrReturnError(CanCastTo<uint16_t>(len), CHIP_ERROR_BUFFER_TOO_SMALL);

writer.Finalize(backingBuffer);
ReturnErrorOnFailure(writer.Finalize(backingBuffer));
ReturnErrorOnFailure(
mpClientInfoStore->SyncSetKeyValue(DefaultStorageKeyAllocator::ICDClientInfoKey(peerNode.GetFabricIndex()).KeyName(),
backingBuffer.Get(), static_cast<uint16_t>(len)));
Expand All @@ -461,6 +480,8 @@ CHIP_ERROR DefaultICDClientStorage::DeleteEntry(const ScopedNodeId & peerNode)

CHIP_ERROR DefaultICDClientStorage::DeleteAllEntries(FabricIndex fabricIndex)
{
VerifyOrReturnError(FabricExists(fabricIndex), CHIP_NO_ERROR);

size_t clientInfoSize = 0;
std::vector<ICDClientInfo> clientInfoVector;
ReturnErrorOnFailure(Load(fabricIndex, clientInfoVector, clientInfoSize));
Expand All @@ -471,7 +492,23 @@ CHIP_ERROR DefaultICDClientStorage::DeleteAllEntries(FabricIndex fabricIndex)
}
ReturnErrorOnFailure(
mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::ICDClientInfoKey(fabricIndex).KeyName()));
return mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::FabricICDClientInfoCounter(fabricIndex).KeyName());
ReturnErrorOnFailure(
mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::FabricICDClientInfoCounter(fabricIndex).KeyName()));

for (auto fabric = mFabricList.begin(); fabric != mFabricList.end(); fabric++)
{
if (*fabric == fabricIndex)
{
mFabricList.erase(fabric);
break;
}
}

if (mFabricList.size() == 0)
{
return mpClientInfoStore->SyncDeleteKeyValue(DefaultStorageKeyAllocator::ICDFabricList().KeyName());
}
return StoreFabricList();
}

CHIP_ERROR DefaultICDClientStorage::ProcessCheckInPayload(const ByteSpan & payload, ICDClientInfo & clientInfo,
Expand Down
9 changes: 9 additions & 0 deletions src/app/icd/client/DefaultICDClientStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class DefaultICDClientStorage : public ICDClientStorage
CHIP_ERROR ProcessCheckInPayload(const ByteSpan & payload, ICDClientInfo & clientInfo,
Protocols::SecureChannel::CounterType & counter) override;

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
size_t GetFabricListSize() { return mFabricList.size(); }

PersistentStorageDelegate * GetClientInfoStore() { return mpClientInfoStore; }
#endif // CONFIG_BUILD_FOR_HOST_UNIT_TEST

protected:
enum class ClientInfoTag : uint8_t
{
Expand Down Expand Up @@ -173,9 +179,12 @@ class DefaultICDClientStorage : public ICDClientStorage

private:
friend class ICDClientInfoIteratorImpl;
CHIP_ERROR StoreFabricList();
CHIP_ERROR LoadFabricList();
CHIP_ERROR LoadCounter(FabricIndex fabricIndex, size_t & count, size_t & clientInfoSize);

bool FabricExists(FabricIndex fabricIndex);

CHIP_ERROR IncreaseEntryCountForFabric(FabricIndex fabricIndex);
CHIP_ERROR DecreaseEntryCountForFabric(FabricIndex fabricIndex);
CHIP_ERROR UpdateEntryCountForFabric(FabricIndex fabricIndex, bool increase);
Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ chip_test_suite("tests") {
"TestBasicCommandPathRegistry.cpp",
"TestBindingTable.cpp",
"TestBuilderParser.cpp",
"TestCheckInHandler.cpp",
"TestCommandHandlerInterfaceRegistry.cpp",
"TestCommandInteraction.cpp",
"TestCommandPathParams.cpp",
Expand Down Expand Up @@ -251,6 +252,7 @@ chip_test_suite("tests") {
"${chip_root}/src/app/codegen-data-model-provider:instance-header",
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/app/data-model-provider/tests:encode-decode",
"${chip_root}/src/app/icd/client:handler",
"${chip_root}/src/app/icd/client:manager",
"${chip_root}/src/app/tests:helpers",
"${chip_root}/src/app/util/mock:mock_codegen_data_model",
Expand Down
Loading

0 comments on commit 675e799

Please sign in to comment.