diff --git a/examples/chip-tool/commands/tests/Commands.h b/examples/chip-tool/commands/tests/Commands.h index 4f543f863b9602..ecd75e9c96cf12 100644 --- a/examples/chip-tool/commands/tests/Commands.h +++ b/examples/chip-tool/commands/tests/Commands.h @@ -3818,6 +3818,9 @@ class TestCluster : public TestCommand case 100: err = TestSendClusterTestClusterCommandWriteAttribute_100(); break; + case 101: + err = TestSendClusterTestClusterCommandTest_101(); + break; } if (CHIP_NO_ERROR != err) @@ -3829,7 +3832,7 @@ class TestCluster : public TestCommand private: std::atomic_uint16_t mTestIndex; - const uint16_t mTestCount = 101; + const uint16_t mTestCount = 102; // // Tests methods @@ -11301,6 +11304,75 @@ class TestCluster : public TestCommand runner->NextTest(); } + + // Test Send Test Command to unsupported endpoint + typedef void (*SuccessCallback_101)(void * context); + chip::Callback::Callback * mOnSuccessCallback_101 = nullptr; + chip::Callback::Callback * mOnFailureCallback_101 = nullptr; + bool mIsFailureExpected_101 = 1; + + CHIP_ERROR TestSendClusterTestClusterCommandTest_101() + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Sending command..."); + + mOnFailureCallback_101 = + new chip::Callback::Callback(OnTestSendClusterTestClusterCommandTest_101_FailureResponse, this); + mOnSuccessCallback_101 = + new chip::Callback::Callback(OnTestSendClusterTestClusterCommandTest_101_SuccessResponse, this); + + chip::Controller::TestClusterCluster cluster; + cluster.Associate(mDevice, 200); + + CHIP_ERROR err = CHIP_NO_ERROR; + + err = cluster.Test(mOnSuccessCallback_101->Cancel(), mOnFailureCallback_101->Cancel()); + + if (CHIP_NO_ERROR != err) + { + delete mOnFailureCallback_101; + delete mOnSuccessCallback_101; + } + + return err; + } + + static void OnTestSendClusterTestClusterCommandTest_101_FailureResponse(void * context, uint8_t status) + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Failure Response"); + + TestCluster * runner = reinterpret_cast(context); + + delete runner->mOnFailureCallback_101; + delete runner->mOnSuccessCallback_101; + + if (runner->mIsFailureExpected_101 == false) + { + ChipLogError(chipTool, "Error: The test was expecting a success callback. Got failure callback"); + runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL); + return; + } + + runner->NextTest(); + } + + static void OnTestSendClusterTestClusterCommandTest_101_SuccessResponse(void * context) + { + ChipLogProgress(chipTool, "Test Cluster - Send Test Command to unsupported endpoint: Success Response"); + + TestCluster * runner = reinterpret_cast(context); + + delete runner->mOnFailureCallback_101; + delete runner->mOnSuccessCallback_101; + + if (runner->mIsFailureExpected_101 == true) + { + ChipLogError(chipTool, "Error: The test was expecting a failure callback. Got success callback"); + runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL); + return; + } + + runner->NextTest(); + } }; class Test_TC_OO_1_1 : public TestCommand diff --git a/scripts/tests/test_suites.sh b/scripts/tests/test_suites.sh index bcf045b75dba90..8c152e3240711a 100755 --- a/scripts/tests/test_suites.sh +++ b/scripts/tests/test_suites.sh @@ -112,7 +112,7 @@ for j in "${iter_array[@]}"; do # Prevent cleanup trying to kill a process we already killed. temp_background_pid=$background_pid background_pid=0 - kill -9 "$temp_background_pid" || true + kill -9 "$temp_background_pid" echo " ===== Test complete: $i" done echo " ===== Iteration $j completed" diff --git a/src/app/tests/suites/TestCluster.yaml b/src/app/tests/suites/TestCluster.yaml index 7c15e81b210207..b0981e1b8929b5 100644 --- a/src/app/tests/suites/TestCluster.yaml +++ b/src/app/tests/suites/TestCluster.yaml @@ -671,3 +671,10 @@ tests: optional: true arguments: value: 0 + + - label: "Send Test Command to unsupported endpoint" + command: "test" + endpoint: 200 + response: + # No cluster on that endpoint, so expect an error. + error: 1 diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index ddb961903667ea..ce8fe6ebc0c4a0 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -2042,6 +2042,23 @@ - (void)testSendClusterTestCluster_000100_WriteAttribute [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; } +- (void)testSendClusterTestCluster_000101_Test +{ + XCTestExpectation * expectation = [self expectationWithDescription:@"Send Test Command to unsupported endpoint"]; + CHIPDevice * device = GetPairedDevice(kDeviceId); + dispatch_queue_t queue = dispatch_get_main_queue(); + CHIPTestCluster * cluster = [[CHIPTestCluster alloc] initWithDevice:device endpoint:200 queue:queue]; + XCTAssertNotNil(cluster); + + [cluster test:^(NSError * err, NSDictionary * values) { + NSLog(@"Send Test Command to unsupported endpoint Error: %@", err); + + XCTAssertEqual(err.code, 1); + [expectation fulfill]; + }]; + + [self waitForExpectationsWithTimeout:kTimeoutInSeconds handler:nil]; +} - (void)testSendClusterTest_TC_OO_1_1_000000_ReadAttribute {