From 01a273b438a0db18d1997a82c785a7bf89f55f5c Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 7 Mar 2022 20:38:31 +0100 Subject: [PATCH] [YAML] Add TestMultiAdmin.yaml (#15106) * Add TestMultiAdmin * Update generated code --- examples/chip-tool/templates/tests/tests.js | 5 + src/app/tests/suites/TestMultiAdmin.yaml | 141 +++++++ .../chip-tool/zap-generated/test/Commands.h | 363 ++++++++++++++++++ 3 files changed, 509 insertions(+) create mode 100644 src/app/tests/suites/TestMultiAdmin.yaml diff --git a/examples/chip-tool/templates/tests/tests.js b/examples/chip-tool/templates/tests/tests.js index d3cf270b8..420313fc4 100644 --- a/examples/chip-tool/templates/tests/tests.js +++ b/examples/chip-tool/templates/tests/tests.js @@ -480,6 +480,10 @@ function getTests() 'TestBinding', ]; + const MultiAdmin = [ + 'TestMultiAdmin', + ]; + const SoftwareDiagnostics = [ 'Test_TC_SWDIAG_1_1', 'Test_TC_SWDIAG_2_1', @@ -531,6 +535,7 @@ function getTests() WindowCovering, // TV, // Others, // + MultiAdmin, // SoftwareDiagnostics, // Subscriptions, // DoorLock, // diff --git a/src/app/tests/suites/TestMultiAdmin.yaml b/src/app/tests/suites/TestMultiAdmin.yaml new file mode 100644 index 000000000..be4c9ba14 --- /dev/null +++ b/src/app/tests/suites/TestMultiAdmin.yaml @@ -0,0 +1,141 @@ +# Copyright (c) 2022 Project CHIP Authors +# +# 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. + +name: Test Multi Admin + +config: + nodeId: 0x12344321 + nodeId2: + type: NODE_ID + defaultValue: 0xCAFE + nodeId3: + type: NODE_ID + defaultValue: 0xC00FEE + endpoint: 0 + discriminator: + type: INT16U + defaultValue: 3840 + payload: + type: CHAR_STRING + defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically + +tests: + - label: "Reboot target device" + cluster: "SystemCommands" + command: "Reboot" + arguments: + values: + - name: "discriminator" + value: discriminator + + - label: "Wait for the commissioned device to be retrieved for alpha" + cluster: "DelayCommands" + command: "WaitForCommissionee" + arguments: + values: + - name: "nodeId" + value: nodeId + + - label: "Open Commissioning Window from alpha" + cluster: "AdministratorCommissioning" + command: "OpenBasicCommissioningWindow" + timedInteractionTimeoutMs: 10000 + arguments: + values: + - name: "CommissioningTimeout" + value: 120 + + - label: "Commission from beta" + identity: "beta" + cluster: "CommissionerCommands" + command: "PairWithQRCode" + arguments: + values: + - name: "nodeId" + value: nodeId2 + - name: "payload" + value: payload + + - label: "Wait for the commissioned device to be retrieved for beta" + identity: "beta" + cluster: "DelayCommands" + command: "WaitForCommissionee" + arguments: + values: + - name: "nodeId" + value: nodeId2 + + - label: "Open Commissioning Window from beta" + identity: "beta" + cluster: "AdministratorCommissioning" + command: "OpenBasicCommissioningWindow" + timedInteractionTimeoutMs: 10000 + arguments: + values: + - name: "CommissioningTimeout" + value: 120 + + - label: "Commission from gamma" + identity: "gamma" + cluster: "CommissionerCommands" + command: "PairWithQRCode" + arguments: + values: + - name: "nodeId" + value: nodeId3 + - name: "payload" + value: payload + + - label: "Wait for the commissioned device to be retrieved for gamma" + identity: "gamma" + cluster: "DelayCommands" + command: "WaitForCommissionee" + arguments: + values: + - name: "nodeId" + value: nodeId3 + + - label: "read the mandatory attribute: NodeLabel from alpha" + identity: "alpha" + cluster: "Basic" + command: "readAttribute" + attribute: "NodeLabel" + response: + value: "" + saveAs: readFromAlpha + + - label: "write the mandatory attribute NodeLabel from beta" + identity: "beta" + cluster: "Basic" + command: "writeAttribute" + attribute: "NodeLabel" + arguments: + value: "written from beta" + + - label: "read the mandatory attribute: NodeLabel from gamma" + identity: "gamma" + cluster: "Basic" + command: "readAttribute" + attribute: "NodeLabel" + response: + constraints: + notValue: readFromAlpha + + - label: "write the mandatory attribute NodeLabel back to default" + identity: "alpha" + cluster: "Basic" + command: "writeAttribute" + attribute: "NodeLabel" + arguments: + value: readFromAlpha diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index c494fa4ee..8cdd54216 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -192,6 +192,7 @@ class TestList : public Command printf("TestModeSelectCluster\n"); printf("TestSystemCommands\n"); printf("TestBinding\n"); + printf("TestMultiAdmin\n"); printf("Test_TC_SWDIAG_1_1\n"); printf("Test_TC_SWDIAG_2_1\n"); printf("Test_TC_SWDIAG_3_1\n"); @@ -89790,6 +89791,367 @@ class TestBindingSuite : public TestCommand } }; +class TestMultiAdminSuite : public TestCommand +{ +public: + TestMultiAdminSuite(CredentialIssuerCommands * credsIssuerConfig) : + TestCommand("TestMultiAdmin", credsIssuerConfig), mTestIndex(0) + { + AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); + AddArgument("nodeId2", 0, UINT64_MAX, &mNodeId2); + AddArgument("nodeId3", 0, UINT64_MAX, &mNodeId3); + AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); + AddArgument("discriminator", 0, UINT16_MAX, &mDiscriminator); + AddArgument("payload", &mPayload); + } + + ~TestMultiAdminSuite() + { + if (readFromAlphaBuffer != nullptr) + { + chip::Platform::MemoryFree(readFromAlphaBuffer); + readFromAlphaBuffer = nullptr; + } + } + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Start: TestMultiAdmin\n"); + } + + if (mTestCount == mTestIndex) + { + ChipLogProgress(chipTool, " **** Test Complete: TestMultiAdmin\n"); + SetCommandExitStatus(CHIP_NO_ERROR); + return; + } + + Wait(); + + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) + { + case 0: + ChipLogProgress(chipTool, " ***** Test Step 0 : Reboot target device\n"); + err = TestRebootTargetDevice_0(); + break; + case 1: + ChipLogProgress(chipTool, " ***** Test Step 1 : Wait for the commissioned device to be retrieved for alpha\n"); + err = TestWaitForTheCommissionedDeviceToBeRetrievedForAlpha_1(); + break; + case 2: + ChipLogProgress(chipTool, " ***** Test Step 2 : Open Commissioning Window from alpha\n"); + err = TestOpenCommissioningWindowFromAlpha_2(); + break; + case 3: + ChipLogProgress(chipTool, " ***** Test Step 3 : Commission from beta\n"); + err = TestCommissionFromBeta_3(); + break; + case 4: + ChipLogProgress(chipTool, " ***** Test Step 4 : Wait for the commissioned device to be retrieved for beta\n"); + err = TestWaitForTheCommissionedDeviceToBeRetrievedForBeta_4(); + break; + case 5: + ChipLogProgress(chipTool, " ***** Test Step 5 : Open Commissioning Window from beta\n"); + err = TestOpenCommissioningWindowFromBeta_5(); + break; + case 6: + ChipLogProgress(chipTool, " ***** Test Step 6 : Commission from gamma\n"); + err = TestCommissionFromGamma_6(); + break; + case 7: + ChipLogProgress(chipTool, " ***** Test Step 7 : Wait for the commissioned device to be retrieved for gamma\n"); + err = TestWaitForTheCommissionedDeviceToBeRetrievedForGamma_7(); + break; + case 8: + ChipLogProgress(chipTool, " ***** Test Step 8 : read the mandatory attribute: NodeLabel from alpha\n"); + err = TestReadTheMandatoryAttributeNodeLabelFromAlpha_8(); + break; + case 9: + ChipLogProgress(chipTool, " ***** Test Step 9 : write the mandatory attribute NodeLabel from beta\n"); + err = TestWriteTheMandatoryAttributeNodeLabelFromBeta_9(); + break; + case 10: + ChipLogProgress(chipTool, " ***** Test Step 10 : read the mandatory attribute: NodeLabel from gamma\n"); + err = TestReadTheMandatoryAttributeNodeLabelFromGamma_10(); + break; + case 11: + ChipLogProgress(chipTool, " ***** Test Step 11 : write the mandatory attribute NodeLabel back to default\n"); + err = TestWriteTheMandatoryAttributeNodeLabelBackToDefault_11(); + break; + } + + if (CHIP_NO_ERROR != err) + { + ChipLogError(chipTool, " ***** Test Failure: %s\n", chip::ErrorStr(err)); + SetCommandExitStatus(err); + } + } + +private: + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = 12; + + chip::Optional mNodeId; + chip::Optional mNodeId2; + chip::Optional mNodeId3; + chip::Optional mEndpoint; + chip::Optional mDiscriminator; + chip::Optional mPayload; + + char * readFromAlphaBuffer = nullptr; + chip::CharSpan readFromAlpha; + + void OnDiscoveryCommandsResults(const DiscoveryCommandResult & value) override + { + bool isExpectedDnssdResult = false; + + VerifyOrReturn(isExpectedDnssdResult, Exit("An unexpected dnssd result has been received")); + NextTest(); + } + + static void OnFailureCallback_8(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_8(error); + } + + static void OnSuccessCallback_8(void * context, chip::CharSpan nodeLabel) + { + (static_cast(context))->OnSuccessResponse_8(nodeLabel); + } + + static void OnFailureCallback_9(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_9(error); + } + + static void OnSuccessCallback_9(void * context) { (static_cast(context))->OnSuccessResponse_9(); } + + static void OnFailureCallback_10(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_10(error); + } + + static void OnSuccessCallback_10(void * context, chip::CharSpan nodeLabel) + { + (static_cast(context))->OnSuccessResponse_10(nodeLabel); + } + + static void OnFailureCallback_11(void * context, CHIP_ERROR error) + { + (static_cast(context))->OnFailureResponse_11(error); + } + + static void OnSuccessCallback_11(void * context) { (static_cast(context))->OnSuccessResponse_11(); } + + // + // Tests methods + // + + CHIP_ERROR TestRebootTargetDevice_0() + { + SetIdentity(kIdentityAlpha); + return Reboot(mDiscriminator.HasValue() ? mDiscriminator.Value() : 3840U); + } + + CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrievedForAlpha_1() + { + SetIdentity(kIdentityAlpha); + return WaitForCommissionee(mNodeId.HasValue() ? mNodeId.Value() : 305414945ULL); + } + + CHIP_ERROR TestOpenCommissioningWindowFromAlpha_2() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + using RequestType = chip::app::Clusters::AdministratorCommissioning::Commands::OpenBasicCommissioningWindow::Type; + + RequestType request; + request.commissioningTimeout = 120U; + + auto success = [](void * context, const typename RequestType::ResponseType & data) { + (static_cast(context))->OnSuccessResponse_2(); + }; + + auto failure = [](void * context, CHIP_ERROR error) { + (static_cast(context))->OnFailureResponse_2(error); + }; + + ReturnErrorOnFailure( + chip::Controller::InvokeCommand(mDevices[kIdentityAlpha], this, success, failure, endpoint, request, 10000)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_2(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_2() { NextTest(); } + + CHIP_ERROR TestCommissionFromBeta_3() + { + SetIdentity(kIdentityBeta); + return PairWithQRCode(mNodeId2.HasValue() ? mNodeId2.Value() : 51966ULL, + mPayload.HasValue() ? mPayload.Value() : chip::CharSpan::fromCharString("MT:-24J0AFN00KA0648G00")); + } + + CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrievedForBeta_4() + { + SetIdentity(kIdentityBeta); + return WaitForCommissionee(mNodeId2.HasValue() ? mNodeId2.Value() : 51966ULL); + } + + CHIP_ERROR TestOpenCommissioningWindowFromBeta_5() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + using RequestType = chip::app::Clusters::AdministratorCommissioning::Commands::OpenBasicCommissioningWindow::Type; + + RequestType request; + request.commissioningTimeout = 120U; + + auto success = [](void * context, const typename RequestType::ResponseType & data) { + (static_cast(context))->OnSuccessResponse_5(); + }; + + auto failure = [](void * context, CHIP_ERROR error) { + (static_cast(context))->OnFailureResponse_5(error); + }; + + ReturnErrorOnFailure( + chip::Controller::InvokeCommand(mDevices[kIdentityBeta], this, success, failure, endpoint, request, 10000)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_5(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_5() { NextTest(); } + + CHIP_ERROR TestCommissionFromGamma_6() + { + SetIdentity(kIdentityGamma); + return PairWithQRCode(mNodeId3.HasValue() ? mNodeId3.Value() : 12586990ULL, + mPayload.HasValue() ? mPayload.Value() : chip::CharSpan::fromCharString("MT:-24J0AFN00KA0648G00")); + } + + CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrievedForGamma_7() + { + SetIdentity(kIdentityGamma); + return WaitForCommissionee(mNodeId3.HasValue() ? mNodeId3.Value() : 12586990ULL); + } + + CHIP_ERROR TestReadTheMandatoryAttributeNodeLabelFromAlpha_8() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::BasicClusterTest cluster; + cluster.Associate(mDevices[kIdentityAlpha], endpoint); + + ReturnErrorOnFailure(cluster.ReadAttribute( + this, OnSuccessCallback_8, OnFailureCallback_8, true)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_8(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_8(chip::CharSpan nodeLabel) + { + VerifyOrReturn(CheckValueAsString("nodeLabel", nodeLabel, chip::CharSpan("", 0))); + + if (readFromAlphaBuffer != nullptr) + { + chip::Platform::MemoryFree(readFromAlphaBuffer); + } + readFromAlphaBuffer = static_cast(chip::Platform::MemoryAlloc(nodeLabel.size())); + memcpy(readFromAlphaBuffer, nodeLabel.data(), nodeLabel.size()); + readFromAlpha = chip::CharSpan(readFromAlphaBuffer, nodeLabel.size()); + NextTest(); + } + + CHIP_ERROR TestWriteTheMandatoryAttributeNodeLabelFromBeta_9() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::BasicClusterTest cluster; + cluster.Associate(mDevices[kIdentityBeta], endpoint); + + chip::CharSpan nodeLabelArgument; + nodeLabelArgument = chip::Span("written from betagarbage: not in length on purpose", 17); + + ReturnErrorOnFailure(cluster.WriteAttribute( + nodeLabelArgument, this, OnSuccessCallback_9, OnFailureCallback_9)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_9(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_9() { NextTest(); } + + CHIP_ERROR TestReadTheMandatoryAttributeNodeLabelFromGamma_10() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::BasicClusterTest cluster; + cluster.Associate(mDevices[kIdentityGamma], endpoint); + + ReturnErrorOnFailure(cluster.ReadAttribute( + this, OnSuccessCallback_10, OnFailureCallback_10, true)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_10(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_10(chip::CharSpan nodeLabel) + { + VerifyOrReturn(CheckConstraintNotValue("nodeLabel", nodeLabel, readFromAlpha)); + + NextTest(); + } + + CHIP_ERROR TestWriteTheMandatoryAttributeNodeLabelBackToDefault_11() + { + const chip::EndpointId endpoint = mEndpoint.HasValue() ? mEndpoint.Value() : 0; + chip::Controller::BasicClusterTest cluster; + cluster.Associate(mDevices[kIdentityAlpha], endpoint); + + chip::CharSpan nodeLabelArgument; + nodeLabelArgument = readFromAlpha; + + ReturnErrorOnFailure(cluster.WriteAttribute( + nodeLabelArgument, this, OnSuccessCallback_11, OnFailureCallback_11)); + return CHIP_NO_ERROR; + } + + void OnFailureResponse_11(CHIP_ERROR error) + { + chip::app::StatusIB status(error); + ThrowFailureResponse(); + } + + void OnSuccessResponse_11() { NextTest(); } +}; + class Test_TC_SWDIAG_1_1Suite : public TestCommand { public: @@ -111434,6 +111796,7 @@ void registerCommandsTests(Commands & commands, CredentialIssuerCommands * creds make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), + make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig),