Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get peer's node ID from session instead of packet header for response handling #9287

Merged
merged 2 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,9 @@ CHIP_ERROR DeviceController::OnMessageReceived(Messaging::ExchangeContext * ec,
uint16_t index;

VerifyOrExit(mState == State::Initialized, ChipLogError(Controller, "OnMessageReceived was called in incorrect state"));
VerifyOrExit(ec != nullptr, ChipLogError(Controller, "OnMessageReceived was called with null exchange"));

VerifyOrExit(packetHeader.GetSourceNodeId().HasValue(),
ChipLogError(Controller, "OnMessageReceived was called for unknown source node"));

index = FindDeviceIndex(packetHeader.GetSourceNodeId().Value());
index = FindDeviceIndex(ec->GetSecureSession().GetPeerNodeId());
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrExit(index < kNumMaxActiveDevices, ChipLogError(Controller, "OnMessageReceived was called for unknown device object"));

mActiveDevices[index].OnMessageReceived(ec, packetHeader, payloadHeader, std::move(msgBuf));
Expand Down
73 changes: 73 additions & 0 deletions src/darwin/Framework/CHIP/templates/clusters-tests.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,79 @@ CHIPDevice * GetPairedDevice(uint64_t deviceId)
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0000_BindOnOff_Test
woody-apple marked this conversation as resolved.
Show resolved Hide resolved
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Binding to OnOff Cluster complete"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPBinding * bindingCluster = [[CHIPBinding alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(bindingCluster);
[bindingCluster bind:kDeviceId groupId:0
endpointId:1
clusterId:6
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Binding status : %@", err);
XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0001_ConfigureOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Reporting OnOff configured"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster configureAttributeOnOffWithMinInterval:0
maxInterval:1
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Configure status: %@", err);

XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0002_ReportOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"First report received"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster reportAttributeOnOffWithResponseHandler:^(NSError * err, NSDictionary * values)
{
NSLog(@"Reporting Test Report first report: %@", err);
[expectation fulfill];
XCTAssertEqual(err.code, 0);
}];

[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

- (void)testSendClusterTestCluster_Reporting_0003_StopReportOnOff_Test
{
XCTestExpectation * expectation = [self expectationWithDescription:@"Reporting OnOff cancelled"];
CHIPDevice * device = GetPairedDevice(kDeviceId);
dispatch_queue_t queue = dispatch_get_main_queue();
CHIPOnOff * onOffCluster = [[CHIPOnOff alloc] initWithDevice:device endpoint:1 queue:queue];
XCTAssertNotNil(onOffCluster);
[onOffCluster configureAttributeOnOffWithMinInterval:0
maxInterval:0xffff
responseHandler:^(NSError * err, NSDictionary * values) {
NSLog(@"Reporting Test Cancel Reports status: %@", err);

XCTAssertEqual(err.code, 0);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil];
}

{{>test_cluster tests="TestCluster, Test_TC_OO_1_1, Test_TC_OO_2_1, Test_TC_OO_2_2, Test_TC_DM_1_1, Test_TC_DM_3_1, Test_TC_CC_3_4, Test_TC_CC_5, Test_TC_CC_6, Test_TC_CC_7, Test_TC_CC_8, Test_TC_WNCV_1_1, Test_TC_WNCV_2_1, Test_TC_BI_1_1, Test_TC_FLW_1_1, Test_TC_TM_1_1, Test_TC_OCC_1_1"}}

{{#chip_client_clusters}}
Expand Down
73 changes: 73 additions & 0 deletions src/darwin/Framework/CHIPTests/CHIPClustersTests.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.