From 8bcc9b8a965ac4a9346ccc359484e3f2fb29adac Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Mon, 16 Sep 2024 16:36:27 -0700 Subject: [PATCH 01/16] [Test] Creating CADMIN 1.19 test module: - Test module created following steps in PR: https://github.com/CHIP-Specifications/chip-test-plans/pull/4669 --- src/python_testing/TC_CADMIN_1_19.py | 195 +++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/python_testing/TC_CADMIN_1_19.py diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py new file mode 100644 index 00000000000000..c134717df74a9a --- /dev/null +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -0,0 +1,195 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --PICS src/app/tests/suites/certification/ci-pics-values +# === END CI TEST ARGUMENTS === + +import logging +import random +from time import sleep + +import chip.clusters as Clusters +from chip import ChipDeviceCtrl +from chip.ChipDeviceCtrl import CommissioningParameters +from chip.exceptions import ChipStackError +from chip.native import PyChipError +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts + +class TC_CADMIN_1_19(MatterBaseTest): + async def OpenCommissioningWindow(self) -> CommissioningParameters: + try: + params = await self.th1.OpenCommissioningWindow( + nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=10000, discriminator=self.discriminator, option=1) + return params + + except Exception as e: + logging.exception('Error running OpenCommissioningWindow %s', e) + asserts.assert_true(False, 'Failed to open commissioning window') + + def generate_unique_random_value(self, value): + while True: + random_value = random.randint(10000000, 99999999) + if random_value != value: + return random_value + + async def CommissionAttempt( + self, setupPinCode: int, thnum: int, th: str, fail: bool): + + logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") + if fail == True: + ctx = asserts.assert_raises(ChipStackError) + self.print_step(0, ctx) + with ctx: + await th.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setup_code, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) + errcode = PyChipError.from_code(ctx.exception.err) + logging.info('Commissioning complete done. Successful? {}, errorcode = {}, cycle={}'.format( + errcode.is_success, errcode, (cycle+1))) + asserts.assert_false(errcode.is_success, 'Commissioning complete did not error as expected') + asserts.assert_true(errcode.sdk_code == 0x0000000B, + 'Unexpected error code returned from CommissioningComplete') + + elif fail == False: + await th.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) + + async def get_fabrics(self, th: ChipDeviceCtrl) -> int: + OC_cluster = Clusters.OperationalCredentials + fabrics = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + return fabrics + + def steps_TC_CADMIN_1_19(self) -> list[TestStep]: + return [ + TestStep(1, "Commissioning, already done", is_commissioning=True), + TestStep( + 2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), + TestStep(3, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), + TestStep(4, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"), + TestStep(5, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), + TestStep("5a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep("5b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Commissioning is successful"), + TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to max_fabrics"), + TestStep(7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), + TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), + TestStep("9a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."), + TestStep("9b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"), + TestStep(10, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to initial_number_of_fabrics."), + ] + + def pics_TC_CADMIN_1_19(self) -> list[str]: + return ["CADMIN.S"] + + @async_test_body + async def test_TC_CADMIN_1_19(self): + self.step(1) + + # Establishing TH1 and TH2 + self.th1 = self.default_controller + self.discriminator = random.randint(0, 4095) + th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() + th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) + self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) + + self.step(2) + GC_cluster = Clusters.GeneralCommissioning + attribute = GC_cluster.Attributes.BasicCommissioningInfo + duration = await self.read_single_attribute_check_success(endpoint=0, cluster=GC_cluster, attribute=attribute) + self.max_window_duration = duration.maxCumulativeFailsafeSeconds + + self.step(3) + fabrics = await self.get_fabrics(th=self.th1) + initial_number_of_fabrics = len(fabrics) + + self.step(4) + OC_cluster = Clusters.OperationalCredentials + max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) + + self.print_step(0, (max_fabrics - initial_number_of_fabrics)) + + self.step(5) + fids_ca_dir = {} + fids_fa_dir = {} + fids = {} + for fid in range(1, max_fabrics - initial_number_of_fabrics): + # Make sure that current test step is 5, resets here after each loop + self.current_step_index = 5 + + self.step("5a") + params = await self.OpenCommissioningWindow() + setupPinCode = params.setupPinCode + + self.step("5b") + fids_ca_dir['thca' + str(fid)] = self.certificate_authority_manager.NewCertificateAuthority() + fids_fa_dir['thfa' + str(fid)] = fids_ca_dir['thca' + str(fid)].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) + fids['th' + str(fid)] = fids_fa_dir['thfa' + str(fid)].NewController(nodeId=fid, useTestCommissioner=True) + await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(fid)], fail=False) + + self.step(6) + #TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster + current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) + if current_fabrics != max_fabrics: + asserts.fail(f"Expected number of fabrics not correct, instead was {str(current_fabrics)}") + + self.step(7) + params = await self.OpenCommissioningWindow() + setupPinCode = params.setupPinCode + + self.step(8) + #TH creates a controller on a new fabric and commissions DUT_CE using that controller + fids_ca_dir['thca' + str(current_fabrics + 1)] = self.certificate_authority_manager.NewCertificateAuthority() + fids_fa_dir['thfa' + str(current_fabrics + 1)] = fids_ca_dir['thca' + str(current_fabrics + 1)].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) + try: + fids['th' + str(current_fabrics + 1)] = fids_fa_dir['thfa' + str(current_fabrics + 1)].NewController(nodeId=current_fabrics + 1, useTestCommissioner=True) + await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(current_fabrics + 1)], fail=True) + asserts.fail("Expected exception not thrown") + + except ChipStackError as e: + # When attempting to create a new controller we are expected to get the following response: + # src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory + # Since the FabricTable is full and unable to create any new fabrics + asserts.assert_equal(e.err, 0x0000000B, + "Expected to return table is full since max number of fabrics has been created already") + + self.step(9) + for thc in fids.keys(): + # Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop + self.current_step_index = 11 + + self.step("9a") + fabric_index = await self.read_single_attribute_check_success(dev_ctrl=fids[thc], endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CurrentFabricIndex) + + self.step("9b") + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(fabric_index) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + + self.step(10) + #TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster. + current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics) + if current_fabrics != initial_number_of_fabrics: + asserts.fail(f"Found more than expected fabrics: {str(current_fabrics)}") + +if __name__ == "__main__": + default_matter_test_main() From 76142a6ca36af89ee16dfe17923d316623a08002 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 00:01:43 +0000 Subject: [PATCH 02/16] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_19.py | 40 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index c134717df74a9a..b3037aac8f813c 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -35,6 +35,7 @@ from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts + class TC_CADMIN_1_19(MatterBaseTest): async def OpenCommissioningWindow(self) -> CommissioningParameters: try: @@ -88,15 +89,21 @@ def steps_TC_CADMIN_1_19(self) -> list[TestStep]: TestStep(3, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), TestStep(4, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"), TestStep(5, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), - TestStep("5a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), - TestStep("5b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Commissioning is successful"), - TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to max_fabrics"), - TestStep(7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), - TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), + TestStep( + "5a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep("5b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller", + "Commissioning is successful"), + TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", + "Verify this is equal to max_fabrics"), + TestStep( + 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", + "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), TestStep("9a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."), TestStep("9b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"), - TestStep(10, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to initial_number_of_fabrics."), + TestStep(10, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", + "Verify this is equal to initial_number_of_fabrics."), ] def pics_TC_CADMIN_1_19(self) -> list[str]: @@ -122,7 +129,7 @@ async def test_TC_CADMIN_1_19(self): self.step(3) fabrics = await self.get_fabrics(th=self.th1) initial_number_of_fabrics = len(fabrics) - + self.step(4) OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) @@ -143,29 +150,31 @@ async def test_TC_CADMIN_1_19(self): self.step("5b") fids_ca_dir['thca' + str(fid)] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir['thfa' + str(fid)] = fids_ca_dir['thca' + str(fid)].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) + fids_fa_dir['thfa' + str(fid)] = fids_ca_dir['thca' + str(fid)].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) fids['th' + str(fid)] = fids_fa_dir['thfa' + str(fid)].NewController(nodeId=fid, useTestCommissioner=True) await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(fid)], fail=False) self.step(6) - #TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster + # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) if current_fabrics != max_fabrics: asserts.fail(f"Expected number of fabrics not correct, instead was {str(current_fabrics)}") - + self.step(7) params = await self.OpenCommissioningWindow() setupPinCode = params.setupPinCode self.step(8) - #TH creates a controller on a new fabric and commissions DUT_CE using that controller + # TH creates a controller on a new fabric and commissions DUT_CE using that controller fids_ca_dir['thca' + str(current_fabrics + 1)] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir['thfa' + str(current_fabrics + 1)] = fids_ca_dir['thca' + str(current_fabrics + 1)].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) + fids_fa_dir['thfa' + str(current_fabrics + 1)] = fids_ca_dir['thca' + str(current_fabrics + 1) + ].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) try: - fids['th' + str(current_fabrics + 1)] = fids_fa_dir['thfa' + str(current_fabrics + 1)].NewController(nodeId=current_fabrics + 1, useTestCommissioner=True) + fids['th' + str(current_fabrics + 1)] = fids_fa_dir['thfa' + str(current_fabrics + 1) + ].NewController(nodeId=current_fabrics + 1, useTestCommissioner=True) await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(current_fabrics + 1)], fail=True) asserts.fail("Expected exception not thrown") - + except ChipStackError as e: # When attempting to create a new controller we are expected to get the following response: # src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory @@ -186,10 +195,11 @@ async def test_TC_CADMIN_1_19(self): await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) self.step(10) - #TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster. + # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster. current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics) if current_fabrics != initial_number_of_fabrics: asserts.fail(f"Found more than expected fabrics: {str(current_fabrics)}") + if __name__ == "__main__": default_matter_test_main() From e42c43610d50221e8c7f7367ec1c1950e94e5f91 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 17 Sep 2024 00:04:33 -0700 Subject: [PATCH 03/16] Update TC_CADMIN_1_19 test module: - Resolving linting issues --- src/python_testing/TC_CADMIN_1_19.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index b3037aac8f813c..0f75b262ddde6c 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -25,7 +25,6 @@ import logging import random -from time import sleep import chip.clusters as Clusters from chip import ChipDeviceCtrl @@ -57,21 +56,21 @@ async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") - if fail == True: + if fail: ctx = asserts.assert_raises(ChipStackError) self.print_step(0, ctx) with ctx: await th.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setup_code, + nodeId=self.dut_node_id, setupPinCode=setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) errcode = PyChipError.from_code(ctx.exception.err) - logging.info('Commissioning complete done. Successful? {}, errorcode = {}, cycle={}'.format( - errcode.is_success, errcode, (cycle+1))) + logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format( + errcode.is_success, errcode)) asserts.assert_false(errcode.is_success, 'Commissioning complete did not error as expected') asserts.assert_true(errcode.sdk_code == 0x0000000B, 'Unexpected error code returned from CommissioningComplete') - elif fail == False: + elif not fail: await th.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) From 4c04d291bd72b1a170b4bf834edd344c55eef9e2 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 17 Sep 2024 00:13:08 -0700 Subject: [PATCH 04/16] Removing yaml test module for TC_CADMIN_1_19: - Removed yaml test as we have created python test module in its place --- .../certification/Test_TC_CADMIN_1_19.yaml | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml diff --git a/src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml b/src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml deleted file mode 100644 index 892ae3c627623b..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml +++ /dev/null @@ -1,127 +0,0 @@ -# Copyright (c) 2021 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. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: - 4.1.19. [TC-CADMIN-1.19] max number of Commissioned Fabrics and - SupportedFabrics rollover using ECM [DUT - Commissionee] -PICS: - - CADMIN.S - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Precondition" - verification: | - Reset Devices to factory defaults - disabled: true - - - label: "Step 1: TH_CR1 starts a commissioning process with DUT_CE" - PICS: CADMIN.S - verification: | - "1. Provision the device using TH_CR1 -chip tool(use above instructions) , - " - disabled: true - - - label: - "Step 2: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - PICS: CADMIN.S.C00.Rsp - verification: | - On TH_CR1 (chip tool), open commissioning window using ECM - - ./chip-tool pairing open-commissioning-window 1 1 300 1000 3840 - - Verify Manual pairing code on TH_CR1 (chip-tool) Log - - [1635925713.966786][9695:9700] CHIP:SC: Success status report received. Session was established - [1635925713.966839][9695:9700] CHIP:IN: New secure session created for device 0x0000000000000001, key 33!! - [1635925713.966938][9695:9700] CHIP:CTL: OpenCommissioningWindow for device ID 1 - [1635925713.972601][9695:9700] CHIP:DMG: ICR moving to [AddingComm] - [1635925713.972705][9695:9700] CHIP:DMG: ICR moving to [AddedComma] - [1635925713.972815][9695:9700] CHIP:IN: Prepared encrypted message 0xaaaad9b57d10 to 0x0000000000000001 of type 0x8 and protocolId (0, 1) on exchange 31056i with MessageCounter:0. - [1635925713.972876][9695:9700] CHIP:IN: Sending encrypted msg 0xaaaad9b57d10 with MessageCounter:0 to 0x0000000000000001 at monotonic time: 13449459 msec - [1635925713.973006][9695:9700] CHIP:DMG: ICR moving to [CommandSen] - [1635925713.973061][9695:9700] CHIP:CTL: Manual pairing code: [36217551633] - [1635925713.973120][9695:9700] CHIP:CTL: SetupQRCode: [MT:00000CQM00A7F87ZT10] - [1635925713.973178][9695:9700] CHIP:EM: Sending Standalone Ack for MessageCounter:1964916542 on exchange 31055i - disabled: true - - - label: "Step 3: THn starts a commissioning process with DUT_CE" - PICS: CADMIN.S - verification: | - On TH_CR1+1 controller using chip tool connect to the accessory - - - ./chip-tool pairing code 2 36217551633 --commissioner-name beta - - Verify you got below message on TH_CR1+1(chip-tool) log - Device commissioning completed with success - disabled: true - - - label: - "Step 4: Repeat Step 3 and Step 4 an additional (SupportedFabrics - 2) - times to reach an index value of SupportedFabrics on DUT_CE" - PICS: CADMIN.S.C00.Rsp - verification: | - Repeat step 3 until CommissionedFabrics=SupportedFabrics (Supported fabrics value obtained in the precondition) - - Use the following command to verify the currentcommissioned fabric (Output number may vary depends on the number successful commissioning ) - - ./chip-tool operationalcredentials read commissioned-fabrics 1 0 - - [1660907933.677983][33780:33785] CHIP:TOO: CommissionedFabrics: 16 - disabled: true - - - label: - "Step 5: THn_1 starts a commissioning process and opens a - commissioning window with DUT_CE" - PICS: CADMIN.S - verification: | - On THnth controller using chip tool connect to the accessory - - ./chip-tool pairing code 6 36217551633 --commissioner-name 4 - - Verify DUT_CE responds with NOCResponse with a StatusCode of 0x05 on THn (chip-tool) log - - CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008 - [1649756670.402192][10794:10799] CHIP:CTL: Device returned status 5 on receiving the NOC - [1649756670.402221][10794:10799] CHIP:CTL: Add NOC failed with error ../../third_party/connectedhomeip/src/controller/CHIPDeviceController.cpp:1110: CHIP Error 0x0000000B: No memory - [1649756670.402241][10794:10799] CHIP:CTL: Failed to perform commissioning step 13 - disabled: true - - - label: "Step 6: TH_CR1 removes FabricIndex1" - PICS: OPCREDS.S.C0a.Rsp - verification: | - on TH_CR1 using chip tool, remove fabric with FabricIndex=1 - - ./chip-tool operationalcredentials remove-fabric 1 1 0 - - CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008 - CHIP:TOO: Endpoint: 0 Cluster: 0x0000_003E Command 0x0000_0008 - CHIP:TOO: NOCResponse: { - CHIP:TOO: statusCode: 0 - CHIP:TOO: fabricIndex: 1 - CHIP:TOO: } - CHIP:DMG: ICR moving to [AwaitingDe] - - Verify CommissionedFabrics=SupportedFabrics-1 on TH_CR1(chip-tool) log - - ./chip-tool operationalcredentials read commissioned-fabrics 2 0 --commissioner-name beta - - [1660907933.677983][33780:33785] CHIP:TOO: CommissionedFabrics: 15 - disabled: true From 9ef5882418ee0de9541a3db81d894485f3c0b535 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 17 Sep 2024 01:11:12 -0700 Subject: [PATCH 05/16] Update TC_CADMIN_1_19.py - Removed debugging print statements as no longer needed in test code --- src/python_testing/TC_CADMIN_1_19.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 0f75b262ddde6c..e532de86d06d06 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -58,7 +58,6 @@ async def CommissionAttempt( logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") if fail: ctx = asserts.assert_raises(ChipStackError) - self.print_step(0, ctx) with ctx: await th.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setupPinCode, @@ -133,8 +132,6 @@ async def test_TC_CADMIN_1_19(self): OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) - self.print_step(0, (max_fabrics - initial_number_of_fabrics)) - self.step(5) fids_ca_dir = {} fids_fa_dir = {} From c7814abdaf132a301ca11ffa0efb4fe594e6ba1b Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 22 Oct 2024 11:18:21 -0700 Subject: [PATCH 06/16] Update src/python_testing/TC_CADMIN_1_19.py Co-authored-by: C Freeman --- src/python_testing/TC_CADMIN_1_19.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index e532de86d06d06..b35338f229df46 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -55,7 +55,7 @@ def generate_unique_random_value(self, value): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): - logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") + logging.info(f"-----------------Commissioning with TH_CR{thnum}-------------------------") if fail: ctx = asserts.assert_raises(ChipStackError) with ctx: From 32f1236fcd74a733eb04687fb4e61b40ab8eb9bb Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 22 Oct 2024 11:19:02 -0700 Subject: [PATCH 07/16] Update src/python_testing/TC_CADMIN_1_19.py Co-authored-by: C Freeman --- src/python_testing/TC_CADMIN_1_19.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index b35338f229df46..40dc829753eb86 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -154,7 +154,7 @@ async def test_TC_CADMIN_1_19(self): # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) if current_fabrics != max_fabrics: - asserts.fail(f"Expected number of fabrics not correct, instead was {str(current_fabrics)}") + asserts.fail(f"Expected number of fabrics not correct, instead was {current_fabrics}") self.step(7) params = await self.OpenCommissioningWindow() From 2bc7233070b69cd3edabace71180614bc50a7ab8 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 22 Oct 2024 17:56:19 -0700 Subject: [PATCH 08/16] Updating TC_CADMIN_1_19 and matter_testing scripts: - Updated CI Arguments - Updated dependency location for matter_testing_support - Removed local OpenCommissioningWindow function, updated to using MatterBaseTest version - Removed local CommissioningAttempt function, moved to using function call directly in test - Removed initialization of TH2 controller as not needed - Removed additional dictionary names and delimited it down to just using numbers instead. - Updated matter_testing support script to include setting timeout value dynamically in openCommissioningWindow function --- src/python_testing/TC_CADMIN_1_19.py | 96 +++++++------------ .../chip/testing/matter_testing.py | 4 +- 2 files changed, 38 insertions(+), 62 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 40dc829753eb86..7aceaecde0ac75 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -15,12 +15,20 @@ # limitations under the License. # # === BEGIN CI TEST ARGUMENTS === -# test-runner-runs: run1 -# test-runner-run/run1/app: ${ALL_CLUSTERS_APP} -# test-runner-run/run1/factoryreset: True -# test-runner-run/run1/quiet: True -# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json -# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto --PICS src/app/tests/suites/certification/ci-pics-values +# test-runner-runs: +# run1: +# app: ${ALL_CLUSTERS_APP} +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# script-args: > +# --storage-path admin_storage.json +# --commissioning-method on-network +# --discriminator 1234 +# --passcode 20202021 +# --trace-to json:${TRACE_TEST_JSON}.json +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# --PICS src/app/tests/suites/certification/ci-pics-values +# factory-reset: true +# quiet: true # === END CI TEST ARGUMENTS === import logging @@ -31,49 +39,16 @@ from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError from chip.native import PyChipError -from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts - class TC_CADMIN_1_19(MatterBaseTest): - async def OpenCommissioningWindow(self) -> CommissioningParameters: - try: - params = await self.th1.OpenCommissioningWindow( - nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=10000, discriminator=self.discriminator, option=1) - return params - - except Exception as e: - logging.exception('Error running OpenCommissioningWindow %s', e) - asserts.assert_true(False, 'Failed to open commissioning window') - def generate_unique_random_value(self, value): while True: random_value = random.randint(10000000, 99999999) if random_value != value: return random_value - async def CommissionAttempt( - self, setupPinCode: int, thnum: int, th: str, fail: bool): - - logging.info(f"-----------------Commissioning with TH_CR{thnum}-------------------------") - if fail: - ctx = asserts.assert_raises(ChipStackError) - with ctx: - await th.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) - errcode = PyChipError.from_code(ctx.exception.err) - logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format( - errcode.is_success, errcode)) - asserts.assert_false(errcode.is_success, 'Commissioning complete did not error as expected') - asserts.assert_true(errcode.sdk_code == 0x0000000B, - 'Unexpected error code returned from CommissioningComplete') - - elif not fail: - await th.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) - async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials fabrics = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) @@ -94,7 +69,7 @@ def steps_TC_CADMIN_1_19(self) -> list[TestStep]: TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to max_fabrics"), TestStep( - 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), @@ -113,10 +88,6 @@ async def test_TC_CADMIN_1_19(self): # Establishing TH1 and TH2 self.th1 = self.default_controller - self.discriminator = random.randint(0, 4095) - th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() - th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) - self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) self.step(2) GC_cluster = Clusters.GeneralCommissioning @@ -136,19 +107,24 @@ async def test_TC_CADMIN_1_19(self): fids_ca_dir = {} fids_fa_dir = {} fids = {} + self.print_step("total fabrics", max_fabrics - initial_number_of_fabrics) for fid in range(1, max_fabrics - initial_number_of_fabrics): # Make sure that current test step is 5, resets here after each loop self.current_step_index = 5 self.step("5a") - params = await self.OpenCommissioningWindow() - setupPinCode = params.setupPinCode + params = await self.openCommissioningWindow(dev_ctrl=self.th1, timeout=self.max_window_duration, node_id=self.dut_node_id) self.step("5b") - fids_ca_dir['thca' + str(fid)] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir['thfa' + str(fid)] = fids_ca_dir['thca' + str(fid)].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) - fids['th' + str(fid)] = fids_fa_dir['thfa' + str(fid)].NewController(nodeId=fid, useTestCommissioner=True) - await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(fid)], fail=False) + fids_ca_dir[fid] = self.certificate_authority_manager.NewCertificateAuthority() + fids_fa_dir[fid] = fids_ca_dir[fid].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) + fids[fid] = fids_fa_dir[fid].NewController(nodeId=fid) + + await fids[fid].CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) + + self.print_step("commissioning iteration", fid) self.step(6) # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster @@ -157,27 +133,27 @@ async def test_TC_CADMIN_1_19(self): asserts.fail(f"Expected number of fabrics not correct, instead was {current_fabrics}") self.step(7) - params = await self.OpenCommissioningWindow() - setupPinCode = params.setupPinCode + params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) self.step(8) # TH creates a controller on a new fabric and commissions DUT_CE using that controller - fids_ca_dir['thca' + str(current_fabrics + 1)] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir['thfa' + str(current_fabrics + 1)] = fids_ca_dir['thca' + str(current_fabrics + 1) - ].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) + fids_ca_dir[current_fabrics + 1] = self.certificate_authority_manager.NewCertificateAuthority() + fids_fa_dir[current_fabrics + 1] = fids_ca_dir[current_fabrics + 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) try: - fids['th' + str(current_fabrics + 1)] = fids_fa_dir['thfa' + str(current_fabrics + 1) - ].NewController(nodeId=current_fabrics + 1, useTestCommissioner=True) - await self.CommissionAttempt(setupPinCode, thnum=fid, th=fids['th' + str(current_fabrics + 1)], fail=True) - asserts.fail("Expected exception not thrown") + fids[current_fabrics + 1] = fids_fa_dir[current_fabrics + 1].NewController(nodeId=current_fabrics + 1) + await fids[current_fabrics + 1].CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) except ChipStackError as e: + self.print_step("err", e.err) # When attempting to create a new controller we are expected to get the following response: # src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory # Since the FabricTable is full and unable to create any new fabrics asserts.assert_equal(e.err, 0x0000000B, "Expected to return table is full since max number of fabrics has been created already") + self.step(9) for thc in fids.keys(): # Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop diff --git a/src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py b/src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py index b16d1b42a08b45..c2427fe1a8b39e 100644 --- a/src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py +++ b/src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py @@ -1136,10 +1136,10 @@ def check_pics(self, pics_key: str) -> bool: def is_pics_sdk_ci_only(self) -> bool: return self.check_pics('PICS_SDK_CI_ONLY') - async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int) -> CustomCommissioningParameters: + async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int, timeout: int = 900) -> CustomCommissioningParameters: rnd_discriminator = random.randint(0, 4095) try: - commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=900, iteration=1000, + commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=timeout, iteration=1000, discriminator=rnd_discriminator, option=1) params = CustomCommissioningParameters(commissioning_params, rnd_discriminator) return params From 971cf6f2efe4c6ac7a4c80b64d73ffbd34c6e8f0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 23 Oct 2024 00:58:14 +0000 Subject: [PATCH 09/16] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_19.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 7aceaecde0ac75..027eea0b1318eb 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -42,6 +42,7 @@ from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts + class TC_CADMIN_1_19(MatterBaseTest): def generate_unique_random_value(self, value): while True: @@ -69,7 +70,7 @@ def steps_TC_CADMIN_1_19(self) -> list[TestStep]: TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to max_fabrics"), TestStep( - 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), @@ -138,7 +139,8 @@ async def test_TC_CADMIN_1_19(self): self.step(8) # TH creates a controller on a new fabric and commissions DUT_CE using that controller fids_ca_dir[current_fabrics + 1] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir[current_fabrics + 1] = fids_ca_dir[current_fabrics + 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) + fids_fa_dir[current_fabrics + 1] = fids_ca_dir[current_fabrics + + 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) try: fids[current_fabrics + 1] = fids_fa_dir[current_fabrics + 1].NewController(nodeId=current_fabrics + 1) await fids[current_fabrics + 1].CommissionOnNetwork( @@ -153,7 +155,6 @@ async def test_TC_CADMIN_1_19(self): asserts.assert_equal(e.err, 0x0000000B, "Expected to return table is full since max number of fabrics has been created already") - self.step(9) for thc in fids.keys(): # Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop From a9f265058f47a9680f43403b879a9c07ce637830 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 23 Oct 2024 00:52:15 -0700 Subject: [PATCH 10/16] Update TC_CADMIN_1_19.py Resolving Linting errors --- src/python_testing/TC_CADMIN_1_19.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 027eea0b1318eb..90e9c7375592a4 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -31,14 +31,11 @@ # quiet: true # === END CI TEST ARGUMENTS === -import logging import random import chip.clusters as Clusters from chip import ChipDeviceCtrl -from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError -from chip.native import PyChipError from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mobly import asserts From b2e6dd5fb7bd620fa717c2fc8e3a61c6a8b970b7 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 29 Oct 2024 13:39:04 -0700 Subject: [PATCH 11/16] Update TC_CADMIN_1_19.py - Moved location of print_step to top of for range for creating virtual fragments - Removed unnecessary print_step for catching error --- src/python_testing/TC_CADMIN_1_19.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 90e9c7375592a4..d9502db95383a9 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -107,6 +107,7 @@ async def test_TC_CADMIN_1_19(self): fids = {} self.print_step("total fabrics", max_fabrics - initial_number_of_fabrics) for fid in range(1, max_fabrics - initial_number_of_fabrics): + self.print_step("commissioning iteration", fid) # Make sure that current test step is 5, resets here after each loop self.current_step_index = 5 @@ -122,8 +123,6 @@ async def test_TC_CADMIN_1_19(self): nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) - self.print_step("commissioning iteration", fid) - self.step(6) # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) @@ -145,7 +144,6 @@ async def test_TC_CADMIN_1_19(self): filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) except ChipStackError as e: - self.print_step("err", e.err) # When attempting to create a new controller we are expected to get the following response: # src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory # Since the FabricTable is full and unable to create any new fabrics From ee5b154da36effcf7ddbe52f8d08fc1522392c4b Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 31 Oct 2024 16:48:33 -0700 Subject: [PATCH 12/16] Updated TC_CADMIN_1_19 test module: - Created new variable for current_fabric + 1 - Replaced if statements with asserts.assert_equal() - Changed start of range from 1 to 0 - Changed test steps to match test plan better, removed test step 1 --- src/python_testing/TC_CADMIN_1_19.py | 93 +++++++++++++--------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index d9502db95383a9..e4afd3af56df38 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -44,8 +44,8 @@ class TC_CADMIN_1_19(MatterBaseTest): def generate_unique_random_value(self, value): while True: random_value = random.randint(10000000, 99999999) - if random_value != value: - return random_value + asserts.assert_equal(random_value, value) + return random_value async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -54,26 +54,25 @@ async def get_fabrics(self, th: ChipDeviceCtrl) -> int: def steps_TC_CADMIN_1_19(self) -> list[TestStep]: return [ - TestStep(1, "Commissioning, already done", is_commissioning=True), TestStep( - 2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), - TestStep(3, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), - TestStep(4, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"), - TestStep(5, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), + 1, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), + TestStep(2, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), + TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"), + TestStep(4, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), TestStep( - "5a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), - TestStep("5b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller", + "4a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep("4b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Commissioning is successful"), - TestStep(6, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", + TestStep(5, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to max_fabrics"), TestStep( - 7, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), - TestStep(8, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", + 6, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), + TestStep(7, "TH creates a controller on a new fabric and commissions DUT_CE using that controller", "Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"), - TestStep(9, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), - TestStep("9a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."), - TestStep("9b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"), - TestStep(10, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", + TestStep(8, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"), + TestStep("8a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."), + TestStep("8b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"), + TestStep(9, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.", "Verify this is equal to initial_number_of_fabrics."), ] @@ -83,63 +82,60 @@ def pics_TC_CADMIN_1_19(self) -> list[str]: @async_test_body async def test_TC_CADMIN_1_19(self): self.step(1) - - # Establishing TH1 and TH2 + # Establishing TH1 self.th1 = self.default_controller - self.step(2) GC_cluster = Clusters.GeneralCommissioning attribute = GC_cluster.Attributes.BasicCommissioningInfo duration = await self.read_single_attribute_check_success(endpoint=0, cluster=GC_cluster, attribute=attribute) self.max_window_duration = duration.maxCumulativeFailsafeSeconds - self.step(3) + self.step(2) fabrics = await self.get_fabrics(th=self.th1) initial_number_of_fabrics = len(fabrics) - self.step(4) + self.step(3) OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) - self.step(5) + self.step(4) fids_ca_dir = {} fids_fa_dir = {} fids = {} - self.print_step("total fabrics", max_fabrics - initial_number_of_fabrics) - for fid in range(1, max_fabrics - initial_number_of_fabrics): - self.print_step("commissioning iteration", fid) + for fid in range(0, max_fabrics - initial_number_of_fabrics): + self.print_step("commissioning iteration", fid + 1) # Make sure that current test step is 5, resets here after each loop - self.current_step_index = 5 + self.current_step_index = 4 - self.step("5a") + self.step("4a") params = await self.openCommissioningWindow(dev_ctrl=self.th1, timeout=self.max_window_duration, node_id=self.dut_node_id) - self.step("5b") + self.step("4b") fids_ca_dir[fid] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir[fid] = fids_ca_dir[fid].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid) - fids[fid] = fids_fa_dir[fid].NewController(nodeId=fid) + fids_fa_dir[fid] = fids_ca_dir[fid].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid + 1) + fids[fid] = fids_fa_dir[fid].NewController(nodeId=fid + 1) await fids[fid].CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) - self.step(6) + self.step(5) # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) - if current_fabrics != max_fabrics: - asserts.fail(f"Expected number of fabrics not correct, instead was {current_fabrics}") + asserts.assert_equal(current_fabrics, max_fabrics, "Expected number of fabrics not correct") - self.step(7) + self.step(6) params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) - self.step(8) - # TH creates a controller on a new fabric and commissions DUT_CE using that controller - fids_ca_dir[current_fabrics + 1] = self.certificate_authority_manager.NewCertificateAuthority() - fids_fa_dir[current_fabrics + 1] = fids_ca_dir[current_fabrics + - 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=current_fabrics + 1) + self.step(7) + # TH creates a controller on a new fabric and attempts to commission DUT_CE using that controller + next_fabric = current_fabrics + 1 + fids_ca_dir[next_fabric] = self.certificate_authority_manager.NewCertificateAuthority() + fids_fa_dir[next_fabric] = fids_ca_dir[current_fabrics + + 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=next_fabric) try: - fids[current_fabrics + 1] = fids_fa_dir[current_fabrics + 1].NewController(nodeId=current_fabrics + 1) - await fids[current_fabrics + 1].CommissionOnNetwork( + fids[next_fabric] = fids_fa_dir[next_fabric].NewController(nodeId=next_fabric) + await fids[next_fabric].CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) @@ -147,27 +143,26 @@ async def test_TC_CADMIN_1_19(self): # When attempting to create a new controller we are expected to get the following response: # src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory # Since the FabricTable is full and unable to create any new fabrics + self.print_step("Max number of fabrics", "reached") asserts.assert_equal(e.err, 0x0000000B, "Expected to return table is full since max number of fabrics has been created already") - self.step(9) + self.step(8) for thc in fids.keys(): # Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop - self.current_step_index = 11 + self.current_step_index = 10 - self.step("9a") + self.step("8a") fabric_index = await self.read_single_attribute_check_success(dev_ctrl=fids[thc], endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CurrentFabricIndex) - self.step("9b") + self.step("8b") removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(fabric_index) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - self.step(10) + self.step(9) # TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster. current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics) - if current_fabrics != initial_number_of_fabrics: - asserts.fail(f"Found more than expected fabrics: {str(current_fabrics)}") - + asserts.assert_equal(current_fabrics, initial_number_of_fabrics, "Expected number of fabrics not correct") if __name__ == "__main__": default_matter_test_main() From 71ef17af83e190bd3c0e62227c257e6ee509af7e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 31 Oct 2024 23:50:22 +0000 Subject: [PATCH 13/16] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_19.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index e4afd3af56df38..29bff427458731 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -132,7 +132,7 @@ async def test_TC_CADMIN_1_19(self): next_fabric = current_fabrics + 1 fids_ca_dir[next_fabric] = self.certificate_authority_manager.NewCertificateAuthority() fids_fa_dir[next_fabric] = fids_ca_dir[current_fabrics + - 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=next_fabric) + 1].NewFabricAdmin(vendorId=0xFFF1, fabricId=next_fabric) try: fids[next_fabric] = fids_fa_dir[next_fabric].NewController(nodeId=next_fabric) await fids[next_fabric].CommissionOnNetwork( @@ -164,5 +164,6 @@ async def test_TC_CADMIN_1_19(self): current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics) asserts.assert_equal(current_fabrics, initial_number_of_fabrics, "Expected number of fabrics not correct") + if __name__ == "__main__": default_matter_test_main() From 4be58208b2455ee79d07a129dede7459b3de1d5a Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Mon, 18 Nov 2024 14:18:36 -0800 Subject: [PATCH 14/16] Updated TC_CADMIN_1_19 test module: - Added new criteria to test step 3 where max_fabrics is checked to make sure it is greater than initial_fabrics count --- src/python_testing/TC_CADMIN_1_19.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 29bff427458731..37468648aa0641 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -57,7 +57,8 @@ def steps_TC_CADMIN_1_19(self) -> list[TestStep]: TestStep( 1, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep(2, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), - TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics"), + TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics", + "Verify that max_fabrics is larger than initial_number_of_fabrics. If not, instruct the tester to remove one non-test-harness fabric and re-start the test."), TestStep(4, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), TestStep( "4a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), @@ -97,6 +98,9 @@ async def test_TC_CADMIN_1_19(self): self.step(3) OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) + self.print_step("asserts", dir(asserts)) + asserts.assert_greater(max_fabrics, initial_number_of_fabrics, + "max fabrics must be greater than initial fabrics, please remove one non-test-harness fabric and try test again") self.step(4) fids_ca_dir = {} From 1cea908ae85a427eab962b77ee54754b3cca87a5 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Mon, 18 Nov 2024 14:36:17 -0800 Subject: [PATCH 15/16] Updated TC_CADMIN_1_19 test module: - Removed print statement from debugging session --- src/python_testing/TC_CADMIN_1_19.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 37468648aa0641..453f2d3212776c 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -98,7 +98,6 @@ async def test_TC_CADMIN_1_19(self): self.step(3) OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) - self.print_step("asserts", dir(asserts)) asserts.assert_greater(max_fabrics, initial_number_of_fabrics, "max fabrics must be greater than initial fabrics, please remove one non-test-harness fabric and try test again") From c06b84a37e2ba0f3cfac32cab17858d2c95d2bcf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 18 Nov 2024 22:37:24 +0000 Subject: [PATCH 16/16] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_19.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_19.py b/src/python_testing/TC_CADMIN_1_19.py index 453f2d3212776c..5ec3da867da6f1 100644 --- a/src/python_testing/TC_CADMIN_1_19.py +++ b/src/python_testing/TC_CADMIN_1_19.py @@ -57,8 +57,8 @@ def steps_TC_CADMIN_1_19(self) -> list[TestStep]: TestStep( 1, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep(2, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"), - TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics", - "Verify that max_fabrics is larger than initial_number_of_fabrics. If not, instruct the tester to remove one non-test-harness fabric and re-start the test."), + TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics", + "Verify that max_fabrics is larger than initial_number_of_fabrics. If not, instruct the tester to remove one non-test-harness fabric and re-start the test."), TestStep(4, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"), TestStep( "4a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"), @@ -98,8 +98,8 @@ async def test_TC_CADMIN_1_19(self): self.step(3) OC_cluster = Clusters.OperationalCredentials max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics) - asserts.assert_greater(max_fabrics, initial_number_of_fabrics, - "max fabrics must be greater than initial fabrics, please remove one non-test-harness fabric and try test again") + asserts.assert_greater(max_fabrics, initial_number_of_fabrics, + "max fabrics must be greater than initial fabrics, please remove one non-test-harness fabric and try test again") self.step(4) fids_ca_dir = {}