Skip to content

Commit

Permalink
Merge branch 'master' into silabs/add_air_quality_app
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak-Shaha authored Sep 12, 2024
2 parents a4305a5 + 0adae42 commit 0cb134e
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 107 deletions.
10 changes: 9 additions & 1 deletion build/config/linux/pkg-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def main():
dest='dridriverdir')
parser.add_option('--version-as-components', action='store_true',
dest='version_as_components')
parser.add_option('--static', action='store_true',
dest='static')
(options, args) = parser.parse_args()

# Make a list of regular expressions to strip out.
Expand Down Expand Up @@ -203,7 +205,13 @@ def main():
sys.stdout.write(dridriverdir.strip())
return

cmd = [options.pkg_config, "--cflags", "--libs"] + args
cmd = [options.pkg_config, "--cflags", "--libs"]

if options.static:
cmd.append("--static")

cmd.extend(args)

if options.debug:
sys.stderr.write('Running: %s\n' % ' '.join(cmd))

Expand Down
13 changes: 11 additions & 2 deletions build/config/linux/pkg_config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ template("pkg_config") {

# Link libraries statically for OSS-Fuzz fuzzer build
if (oss_fuzz) {
# Output libs needed for static linking (direct + transitive/non-direct libs), we will re-execute the script to get those libs
args += [ "--static" ]
pkgresult_static = exec_script(pkg_config_script, args, "value")
libs = []
ldflags = [ "-Wl,-Bstatic" ]
foreach(lib, pkgresult[3]) {
ldflags += [ "-l$lib" ]
foreach(lib, pkgresult_static[3]) {
# dl(dynamic loading) lib is not needed for linking statically and its presence triggers errors.
# example of errors:
# ld.lld: error: undefined symbol: __dlsym
# >>> referenced by dlsym.o:(dlsym) in archive /lib/x86_64-linux-gnu/libdl.a
if (lib != "dl") {
ldflags += [ "-l$lib" ]
}
}
ldflags += [ "-Wl,-Bdynamic" ]
lib_dirs = pkgresult[4]
Expand Down
6 changes: 4 additions & 2 deletions examples/chef/dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM debian:bullseye
FROM debian:trixie

ARG DEVICE_NAME

RUN apt-get update && \
apt-get install -y \
libglib2.0-0 && \
libglib2.0-0 \
libc6 \
libssl3 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand Down
3 changes: 1 addition & 2 deletions examples/ota-provider-app/esp32/main/BdxOtaSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
{
ChipLogError(BDX, "onTransferComplete Callback not set");
}
mStopPolling = true; // Stop polling the TransferSession only after receiving BlockAckEOF
Reset();
break;
case TransferSession::OutputEventType::kStatusReceived:
Expand Down Expand Up @@ -228,7 +227,7 @@ void BdxOtaSender::Reset()
{
mFabricIndex.ClearValue();
mNodeId.ClearValue();
mTransfer.Reset();
ResetTransfer();
if (mExchangeCtx != nullptr)
{
mExchangeCtx->Close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
break;
case TransferSession::OutputEventType::kAckEOFReceived:
ChipLogDetail(BDX, "Transfer completed, got AckEOF");
mStopPolling = true; // Stop polling the TransferSession only after receiving BlockAckEOF
Reset();
break;
case TransferSession::OutputEventType::kStatusReceived:
Expand Down Expand Up @@ -212,7 +211,7 @@ void BdxOtaSender::Reset()
{
mFabricIndex.ClearValue();
mNodeId.ClearValue();
Responder::ResetTransfer();
ResetTransfer();
if (mExchangeCtx != nullptr)
{
mExchangeCtx->Close();
Expand Down
18 changes: 9 additions & 9 deletions src/app/tests/suites/certification/Test_TC_OO_2_7.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ tests:
}

- label:
"Step 0b: TH binds GroupIds 0x0001 and 0x0002 with GroupKeySetID
0x01a1 in the GroupKeyMap attribute list on GroupKeyManagement cluster
by writing the GroupKeyMap attribute with two entries as follows:"
"Step 0b: TH binds GroupIds 0x0001 with GroupKeySetID 0x01a1 in the
GroupKeyMap attribute list on GroupKeyManagement cluster by writing
the GroupKeyMap attribute with two entries as follows:"
cluster: "Group Key Management"
endpoint: 0
command: "writeAttribute"
Expand Down Expand Up @@ -142,7 +142,7 @@ tests:
value: 0

- label:
"Step 2b: TH sends a StoreScene command to DUT with the GroupID field
"Step 3: TH sends a StoreScene command to DUT with the GroupID field
set to G1 and the SceneID field set to 0x01."
command: "StoreScene"
arguments:
Expand All @@ -160,7 +160,7 @@ tests:
- name: "SceneID"
value: 0x01

- label: "Step 3: TH sends a AddScene command to DUT with the GroupID field
- label: "Step 4: TH sends a AddScene command to DUT with the GroupID field
set to G1, the SceneID field set to 0x02, the TransitionTime field set
to 1000 (1s) and the ExtensionFieldSets set to: '[{ ClusterID: 0x0006,
AttributeValueList: [{ AttributeID: 0x0000, ValueUnsigned8: 0x01 }]}]'
Expand Down Expand Up @@ -195,7 +195,7 @@ tests:
value: 0x02

- label:
"Step 4a: TH sends a RecallScene command to DUT with the GroupID field
"Step 5a: TH sends a RecallScene command to DUT with the GroupID field
set to G1 and the SceneID field set to 0x02."
PICS: S.S.C05.Rsp
command: "RecallScene"
Expand All @@ -214,15 +214,15 @@ tests:
- name: "ms"
value: 2000

- label: "Step 4b: after a few seconds, TH reads OnOff attribute from DUT"
- label: "Step 5b: after a few seconds, TH reads OnOff attribute from DUT"
cluster: "On/Off"
command: "readAttribute"
attribute: "OnOff"
response:
value: 1

- label:
"Step 5a: TH sends a RecallScene command to DUT with the GroupID field
"Step 6a: TH sends a RecallScene command to DUT with the GroupID field
set to G1 and the SceneID field set to 0x01."
PICS: S.S.C05.Rsp
command: "RecallScene"
Expand All @@ -241,7 +241,7 @@ tests:
- name: "ms"
value: 1000

- label: "Step 5b: after a few seconds, TH reads OnOff attribute from DUT"
- label: "Step 6b: after a few seconds, TH reads OnOff attribute from DUT"
cluster: "On/Off"
command: "readAttribute"
attribute: "OnOff"
Expand Down
4 changes: 1 addition & 3 deletions src/darwin/Framework/CHIP/MTRDefines_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,4 @@ typedef struct {} variable_hidden_by_mtr_hide;
}
#endif

#ifndef YES_NO
#define YES_NO(x) ((x) ? @"YES" : @"NO")
#endif
#define MTR_YES_NO(x) ((x) ? @"YES" : @"NO")
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ - (nullable MTRDeviceClusterData *)_clusterDataForPath:(MTRClusterPath *)cluster

// Page in the stored value for the data.
MTRDeviceClusterData * data = [_deviceController.controllerDataStore getStoredClusterDataForNodeID:_nodeID endpointID:clusterPath.endpoint clusterID:clusterPath.cluster];
MTR_LOG("%@ cluster path %@ cache miss - load from storage success %@", self, clusterPath, YES_NO(data));
MTR_LOG("%@ cluster path %@ cache miss - load from storage success %@", self, clusterPath, MTR_YES_NO(data));
if (data != nil) {
[_persistedClusterData setObject:data forKey:clusterPath];
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1))
/**
* Adds a Delegate to the device controller as well as the Queue on which the Delegate callbacks will be triggered
*
* Multiple delegates can be added to monitor MTRDeviceController state changes. Note that there should only
* be one delegate that responds to pairing related callbacks.
*
* If a delegate is added a second time, the call would be ignored.
*
* All delegates are held by weak references, and so if a delegate object goes away, it will be automatically removed.
*
* @param[in] delegate The delegate the commissioning process should use
*
* @param[in] queue The queue on which the callbacks will be delivered
Expand Down
26 changes: 17 additions & 9 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ @implementation MTRDeviceController {
BOOL _shutdownPending;
os_unfair_lock _assertionLock;

NSMutableSet<MTRDeviceControllerDelegateInfo *> * _delegates;
NSMutableArray<MTRDeviceControllerDelegateInfo *> * _delegates;
id<MTRDeviceControllerDelegate> _strongDelegateForSetDelegateAPI;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ - (instancetype)initForSubclasses:(BOOL)startSuspended

_nodeIDToDeviceMap = [NSMapTable strongToWeakObjectsMapTable];

_delegates = [NSMutableSet set];
_delegates = [NSMutableArray array];

return self;
}
Expand Down Expand Up @@ -1793,7 +1793,7 @@ + (void)forceLocalhostAdvertisingOnly

#pragma mark - MTRDeviceControllerDelegate management

// Note these are implemented in the base class so that XPC subclass can use it as well when it
// Note these are implemented in the base class so that XPC subclass can use it as well
- (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
@synchronized(self) {
Expand All @@ -1814,6 +1814,17 @@ - (void)setDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate qu
- (void)addDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate queue:(dispatch_queue_t)queue
{
@synchronized(self) {
__block BOOL delegateAlreadyAdded = NO;
[self _iterateDelegateInfoWithBlock:^(MTRDeviceControllerDelegateInfo * delegateInfo) {
if (delegateInfo.delegate == delegate) {
delegateAlreadyAdded = YES;
}
}];
if (delegateAlreadyAdded) {
MTR_LOG("%@ addDeviceControllerDelegate: delegate already added", self);
return;
}

MTRDeviceControllerDelegateInfo * newDelegateInfo = [[MTRDeviceControllerDelegateInfo alloc] initWithDelegate:delegate queue:queue];
[_delegates addObject:newDelegateInfo];
MTR_LOG("%@ addDeviceControllerDelegate: added %p total %lu", self, delegate, static_cast<unsigned long>(_delegates.count));
Expand All @@ -1836,9 +1847,6 @@ - (void)removeDeviceControllerDelegate:(id<MTRDeviceControllerDelegate>)delegate

if (delegateInfoToRemove) {
[_delegates removeObject:delegateInfoToRemove];
if (_strongDelegateForSetDelegateAPI == delegate) {
_strongDelegateForSetDelegateAPI = nil;
}
MTR_LOG("%@ removeDeviceControllerDelegate: removed %p remaining %lu", self, delegate, static_cast<unsigned long>(_delegates.count));
} else {
MTR_LOG("%@ removeDeviceControllerDelegate: delegate %p not found in %lu", self, delegate, static_cast<unsigned long>(_delegates.count));
Expand All @@ -1857,7 +1865,7 @@ - (NSUInteger)_iterateDelegateInfoWithBlock:(void (^_Nullable)(MTRDeviceControll
}

// Opportunistically remove defunct delegate references on every iteration
NSMutableSet * delegatesToRemove = nil;
NSMutableArray * delegatesToRemove = nil;
for (MTRDeviceControllerDelegateInfo * delegateInfo in _delegates) {
id<MTRDeviceControllerDelegate> strongDelegate = delegateInfo.delegate;
if (strongDelegate) {
Expand All @@ -1866,14 +1874,14 @@ - (NSUInteger)_iterateDelegateInfoWithBlock:(void (^_Nullable)(MTRDeviceControll
}
} else {
if (!delegatesToRemove) {
delegatesToRemove = [NSMutableSet set];
delegatesToRemove = [NSMutableArray array];
}
[delegatesToRemove addObject:delegateInfo];
}
}

if (delegatesToRemove.count) {
[_delegates minusSet:delegatesToRemove];
[_delegates removeObjectsInArray:delegatesToRemove];
MTR_LOG("%@ _iterateDelegatesWithBlock: removed %lu remaining %lu", self, static_cast<unsigned long>(delegatesToRemove.count), static_cast<unsigned long>(_delegates.count));
}

Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ - (NSString *)description
wifi = @"NO";
thread = @"NO";
} else {
wifi = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
thread = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
wifi = MTR_YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
thread = MTR_YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
}

NSString * reportAge;
Expand Down Expand Up @@ -2103,7 +2103,7 @@ - (nullable MTRDeviceClusterData *)_clusterDataForPath:(MTRClusterPath *)cluster

// Page in the stored value for the data.
MTRDeviceClusterData * data = [_deviceController.controllerDataStore getStoredClusterDataForNodeID:_nodeID endpointID:clusterPath.endpoint clusterID:clusterPath.cluster];
MTR_LOG("%@ cluster path %@ cache miss - load from storage success %@", self, clusterPath, YES_NO(data));
MTR_LOG("%@ cluster path %@ cache miss - load from storage success %@", self, clusterPath, MTR_YES_NO(data));
if (data != nil) {
[_persistedClusterData setObject:data forKey:clusterPath];
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ - (NSString *)description
wifi = @"NO";
thread = @"NO";
} else {
wifi = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
thread = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
wifi = MTR_YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
thread = MTR_YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
}

// TODO: Add these to the description
Expand Down
22 changes: 20 additions & 2 deletions src/darwin/Framework/CHIPTests/MTRPairingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,35 @@ @interface MTRPairingTestMonitoringControllerDelegate : NSObject <MTRDeviceContr
@property (atomic, readwrite) BOOL commissioningSessionEstablishmentDoneCalled;
@property (atomic, readwrite) BOOL commissioningCompleteCalled;
@property (atomic, readwrite) BOOL readCommissioningInfoCalled;
@property (atomic, readwrite, strong) XCTestExpectation * allCallbacksCalledExpectation;
@end

@implementation MTRPairingTestMonitoringControllerDelegate
- (NSString *)description
{
return [NSString stringWithFormat:@"<MTRPairingTestMonitoringControllerDelegate: %p statusUpdateCalled %@ commissioningSessionEstablishmentDoneCalled %@ commissioningCompleteCalled %@ readCommissioningInfoCalled %@>", self, YES_NO(_statusUpdateCalled), YES_NO(_commissioningSessionEstablishmentDoneCalled), YES_NO(_commissioningCompleteCalled), YES_NO(_readCommissioningInfoCalled)];
return [NSString stringWithFormat:@"<MTRPairingTestMonitoringControllerDelegate: %p statusUpdateCalled %@ commissioningSessionEstablishmentDoneCalled %@ commissioningCompleteCalled %@ readCommissioningInfoCalled %@>", self, MTR_YES_NO(_statusUpdateCalled), MTR_YES_NO(_commissioningSessionEstablishmentDoneCalled), MTR_YES_NO(_commissioningCompleteCalled), MTR_YES_NO(_readCommissioningInfoCalled)];
}

- (void)_checkIfAllCallbacksCalled
{
if (self.allCallbacksCalledExpectation) {
if (self.statusUpdateCalled && self.commissioningSessionEstablishmentDoneCalled && self.commissioningCompleteCalled && self.readCommissioningInfoCalled) {
[self.allCallbacksCalledExpectation fulfill];
self.allCallbacksCalledExpectation = nil;
}
}
}

- (void)controller:(MTRDeviceController *)controller statusUpdate:(MTRCommissioningStatus)status
{
self.statusUpdateCalled = YES;
[self _checkIfAllCallbacksCalled];
}

- (void)controller:(MTRDeviceController *)controller commissioningSessionEstablishmentDone:(NSError * _Nullable)error
{
self.commissioningSessionEstablishmentDoneCalled = YES;
[self _checkIfAllCallbacksCalled];
}

- (void)controller:(MTRDeviceController *)controller
Expand All @@ -161,11 +175,13 @@ - (void)controller:(MTRDeviceController *)controller
metrics:(MTRMetrics *)metrics
{
self.commissioningCompleteCalled = YES;
[self _checkIfAllCallbacksCalled];
}

- (void)controller:(MTRDeviceController *)controller readCommissioningInfo:(MTRProductIdentity *)info
{
self.readCommissioningInfoCalled = YES;
[self _checkIfAllCallbacksCalled];
}
@end

Expand Down Expand Up @@ -259,6 +275,8 @@ - (void)doPairingTestWithAttestationDelegate:(id<MTRDeviceAttestationDelegate>)a

// Test that a monitoring delegate works
__auto_type * monitoringControllerDelegate = [[MTRPairingTestMonitoringControllerDelegate alloc] init];
XCTestExpectation * allCallbacksCalledExpectation = [self expectationWithDescription:@"All callbacks called on monitoring delegate"];
monitoringControllerDelegate.allCallbacksCalledExpectation = allCallbacksCalledExpectation;
[sController addDeviceControllerDelegate:monitoringControllerDelegate queue:callbackQueue];
XCTAssertEqual([sController unitTestDelegateCount], 2);

Expand All @@ -278,7 +296,7 @@ - (void)doPairingTestWithAttestationDelegate:(id<MTRDeviceAttestationDelegate>)a
XCTAssertTrue([sController setupCommissioningSessionWithPayload:payload newNodeID:@(sDeviceId) error:&error]);
XCTAssertNil(error);

[self waitForExpectations:@[ expectation ] timeout:kPairingTimeoutInSeconds];
[self waitForExpectations:@[ expectation, allCallbacksCalledExpectation ] timeout:kPairingTimeoutInSeconds];
XCTAssertNil(controllerDelegate.commissioningCompleteError);

// Test that the monitoring delegate got all the callbacks
Expand Down
Loading

0 comments on commit 0cb134e

Please sign in to comment.