|
| 1 | +# |
| 2 | +# Copyright (c) 2025 Project CHIP Authors |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +# === BEGIN CI TEST ARGUMENTS === |
| 19 | +# test-runner-runs: |
| 20 | +# run1: |
| 21 | +# app: ${TERMS_AND_CONDITIONS_APP} |
| 22 | +# app-args: > |
| 23 | +# --tc-min-required-version 1 |
| 24 | +# --tc-required-acknowledgements 1 |
| 25 | +# --custom-flow 2 |
| 26 | +# --capabilities 6 |
| 27 | +# script-args: |
| 28 | +# --PICS src/app/tests/suites/certification/ci-pics-values |
| 29 | +# --in-test-commissioning-method on-network |
| 30 | +# --tc-version-to-simulate 1 |
| 31 | +# --tc-user-response-to-simulate 1 |
| 32 | +# --qr-code MT:-24J0AFN00KA0648G00 |
| 33 | +# --trace-to json:log |
| 34 | +# factoryreset: True |
| 35 | +# quiet: True |
| 36 | +# === END CI TEST ARGUMENTS === |
| 37 | + |
| 38 | +import chip.clusters as Clusters |
| 39 | +from chip import ChipDeviceCtrl |
| 40 | +from chip.commissioning import ROOT_ENDPOINT_ID |
| 41 | +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main |
| 42 | +from mobly import asserts |
| 43 | + |
| 44 | + |
| 45 | +class TC_CGEN_2_10(MatterBaseTest): |
| 46 | + def desc_TC_CGEN_2_10(self) -> str: |
| 47 | + return "[TC-CGEN-2.10] Verification that required terms can't be unset from TCAcknowledgements with SetTCAcknowledgements [DUT as Server]" |
| 48 | + |
| 49 | + def pics_TC_CGEN_2_10(self) -> list[str]: |
| 50 | + """ This function returns a list of PICS for this test case that must be True for the test to be run""" |
| 51 | + return ["CGEN.S", "CGEN.S.F00"] |
| 52 | + |
| 53 | + def steps_TC_CGEN_2_10(self) -> list[TestStep]: |
| 54 | + return [ |
| 55 | + TestStep(0, description="", expectation="", is_commissioning=False), |
| 56 | + TestStep(1, "TH reads from the DUT the attribute TCAcceptedVersion. Store the value as acceptedVersion."), |
| 57 | + TestStep(2, "TH reads from the DUT the attribute TCAcknowledgements. Store the value as userAcknowledgements."), |
| 58 | + TestStep(3, "TH Sends the SetTCAcknowledgements command to the DUT with the fields set as follows:\n* TCVersion: 0\n* TCUserResponse: 65535"), |
| 59 | + TestStep(4, "TH reads from the DUT the attribute TCAcceptedVersion."), |
| 60 | + TestStep(5, "TH reads from the DUT the attribute TCAcknowledgements."), |
| 61 | + TestStep(6, "TH Sends the SetTCAcknowledgements command to the DUT with the fields set as follows:\n* TCVersion: acceptedVersion + 1\n* TCUserResponse: 0"), |
| 62 | + TestStep(7, "TH reads from the DUT the attribute TCAcceptedVersion."), |
| 63 | + TestStep(8, "TH reads from the DUT the attribute TCAcknowledgements."), |
| 64 | + ] |
| 65 | + |
| 66 | + @async_test_body |
| 67 | + async def test_TC_CGEN_2_10(self): |
| 68 | + commissioner: ChipDeviceCtrl.ChipDeviceController = self.default_controller |
| 69 | + |
| 70 | + self.step(0) |
| 71 | + if not self.check_pics("CGEN.S.F00"): |
| 72 | + asserts.skip('Root endpoint does not support the [commissioning] feature under test') |
| 73 | + return |
| 74 | + |
| 75 | + # Step 1: Begin commissioning with PASE and failsafe |
| 76 | + commissioner.SetSkipCommissioningComplete(True) |
| 77 | + self.matter_test_config.commissioning_method = self.matter_test_config.in_test_commissioning_method |
| 78 | + self.matter_test_config.tc_version_to_simulate = None |
| 79 | + self.matter_test_config.tc_user_response_to_simulate = None |
| 80 | + await self.commission_devices() |
| 81 | + |
| 82 | + # Step 1: Read TCAcceptedVersion |
| 83 | + self.step(1) |
| 84 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion)]) |
| 85 | + accepted_version = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion] |
| 86 | + |
| 87 | + # Step 2: Read TCAcknowledgements |
| 88 | + self.step(2) |
| 89 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcknowledgements)]) |
| 90 | + user_acknowledgements = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcknowledgements] |
| 91 | + |
| 92 | + # Step 3: Send SetTCAcknowledgements with invalid version |
| 93 | + self.step(3) |
| 94 | + response = await commissioner.SendCommand( |
| 95 | + nodeid=self.dut_node_id, |
| 96 | + endpoint=ROOT_ENDPOINT_ID, |
| 97 | + payload=Clusters.GeneralCommissioning.Commands.SetTCAcknowledgements(TCVersion=0, TCUserResponse=65535), |
| 98 | + ) |
| 99 | + |
| 100 | + # Verify TCMinVersionNotMet error |
| 101 | + asserts.assert_equal( |
| 102 | + response.errorCode, |
| 103 | + Clusters.GeneralCommissioning.Enums.CommissioningErrorEnum.kTCMinVersionNotMet, |
| 104 | + "Expected TCMinVersionNotMet error", |
| 105 | + ) |
| 106 | + |
| 107 | + # Step 4: Verify TCAcceptedVersion unchanged |
| 108 | + self.step(4) |
| 109 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion)]) |
| 110 | + current_version = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion] |
| 111 | + asserts.assert_equal(current_version, accepted_version, "TCAcceptedVersion changed unexpectedly") |
| 112 | + |
| 113 | + # Step 5: Verify TCAcknowledgements unchanged |
| 114 | + self.step(5) |
| 115 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcknowledgements)]) |
| 116 | + current_acknowledgements = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcknowledgements] |
| 117 | + asserts.assert_equal(current_acknowledgements, user_acknowledgements, "TCAcknowledgements changed unexpectedly") |
| 118 | + |
| 119 | + # Step 6: Send SetTCAcknowledgements with invalid response |
| 120 | + self.step(6) |
| 121 | + response = await commissioner.SendCommand( |
| 122 | + nodeid=self.dut_node_id, |
| 123 | + endpoint=ROOT_ENDPOINT_ID, |
| 124 | + payload=Clusters.GeneralCommissioning.Commands.SetTCAcknowledgements( |
| 125 | + TCVersion=accepted_version + 1, TCUserResponse=0 |
| 126 | + ), |
| 127 | + ) |
| 128 | + |
| 129 | + # Verify RequiredTCNotAccepted error |
| 130 | + asserts.assert_equal( |
| 131 | + response.errorCode, |
| 132 | + Clusters.GeneralCommissioning.Enums.CommissioningErrorEnum.kRequiredTCNotAccepted, |
| 133 | + "Expected RequiredTCNotAccepted error", |
| 134 | + ) |
| 135 | + |
| 136 | + # Step 7: Verify TCAcceptedVersion still unchanged |
| 137 | + self.step(7) |
| 138 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion)]) |
| 139 | + current_version = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcceptedVersion] |
| 140 | + asserts.assert_equal(current_version, accepted_version, "TCAcceptedVersion changed unexpectedly after second attempt") |
| 141 | + |
| 142 | + # Step 8: Verify TCAcknowledgements still unchanged |
| 143 | + self.step(8) |
| 144 | + response = await commissioner.ReadAttribute(nodeid=self.dut_node_id, attributes=[(ROOT_ENDPOINT_ID, Clusters.GeneralCommissioning.Attributes.TCAcknowledgements)]) |
| 145 | + current_acknowledgements = response[ROOT_ENDPOINT_ID][Clusters.GeneralCommissioning][Clusters.GeneralCommissioning.Attributes.TCAcknowledgements] |
| 146 | + asserts.assert_equal( |
| 147 | + current_acknowledgements, |
| 148 | + user_acknowledgements, |
| 149 | + "TCAcknowledgements changed unexpectedly after second attempt", |
| 150 | + ) |
| 151 | + |
| 152 | + |
| 153 | +if __name__ == "__main__": |
| 154 | + default_matter_test_main() |
0 commit comments