From ae671bbcbfe15a254b3d83be0c28898e0c422f69 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 27 Sep 2024 05:20:19 -0700 Subject: [PATCH 001/104] [Test] Creating TC_CADMIN_1_3 python test module: - Current WIP script creation following test steps in PR: https://github.com/CHIP-Specifications/chip-test-plans/pull/4689 --- src/python_testing/TC_CADMIN_1_3.py | 246 ++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 src/python_testing/TC_CADMIN_1_3.py diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py new file mode 100644 index 00000000000000..3eff27ba1b4180 --- /dev/null +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -0,0 +1,246 @@ +# +# 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 pathlib import Path + +import chip.clusters as Clusters +from chip.tlv import TLVReader +from chip import ChipDeviceCtrl +from chip.ChipDeviceCtrl import CommissioningParameters +from chip.exceptions import ChipStackError +from chip.interaction_model import Status +from chip.native import PyChipError +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main, MatterStackState +from mdns_discovery import mdns_discovery +from mobly import asserts +from time import sleep + +opcreds = Clusters.OperationalCredentials +nonce = random.randbytes(32) + +class TC_CADMIN_1_3(MatterBaseTest): + async def CommissionAttempt( + self, setupPinCode: int, thnum: int, th: str, fail: bool): + + 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, + 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 + fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + return fabric_info + + async def get_rcac_decoded(self, th: str) -> int: + csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) + TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) + th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] + return th_rcac_decoded + + async def get_txt_record(self): + discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) + comm_service = await discovery.get_commissionable_service( + discovery_timeout_sec = 240, + log_output = False, + ) + return comm_service + + async def get_window_status(self) -> int: + AC_cluster = Clusters.AdministratorCommissioning + window_status = await self.read_single_attribute_check_success(dev_ctrl=self.th2, fabric_filtered=True, cluster=AC_cluster, attribute=AC_cluster.Attributes.WindowStatus) + return window_status + + async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int): + self.discriminator = random.randint(0, 4095) + try: + params = await th.OpenCommissioningWindow( + nodeid=self.dut_node_id, timeout=duration, iteration=10000, discriminator=self.discriminator, option=1) + return params + + except Exception as e: + logging.exception('Error running OpenCommissioningWindow %s', e) + if str(Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy) in e.msg: + asserts.assert_true(False, 'Failed to open commissioning window') + else: + asserts.assert_true(False, 'Failed to verify') + + async def write_nl_attr(self, th: str, attr_val: object): + result = await th.WriteAttribute(self.dut_node_id, [(0, attr_val)]) + asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") + + async def read_nl_attr(self, th: str, attr_val: object): + try: + result = await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + except Exception as e: + asserts.assert_equal(e.err, "Received error message from read attribute attempt") + + def pics_TC_CADMIN_1_3(self) -> list[str]: + return ["CADMIN.S"] + + def steps_TC_CADMIN_1_3(self) -> list[TestStep]: + return [ + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using ECM", + "DUT_CE opens its Commissioning window to allow a second commissioning."), + TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=2"), + TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify DUT_CE responds to both write/read with a success"), + TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", + "Commissioning is successful"), + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), + TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), + TestStep(7, "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify DUT_CE responds to both write/read with a success"), + TestStep(8, "TH_CR2 reads, writes and then reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify the initial read reflect the value written in the above step. Verify DUT_CE responds to both write/read with a success"), + TestStep(9, "TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM"), + TestStep(10, "Wait for the commissioning window in step 9 to timeout"), + TestStep(11, "TH_CR2 reads the window status to verify the DUT_CE window is closed", "DUT_CE windows status shows the window is closed"), + TestStep(12, "TH_CR2 opens a commissioning window on DUT_CE using ECM", + "DUT_CE opens its Commissioning window to allow a new commissioning"), + TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", + "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), + ] + + @async_test_body + async def test_TC_CADMIN_1_3(self): + self.step(1) + + # 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("3a") + params = await self.OpenCommissioningWindow(th=self.th1, duration=self.max_window_duration) + setupPinCode = params.setupPinCode + + self.step("3b") + services = await self.get_txt_record() + if services.txt_record['CM'] != "2": + asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + + self.step("3c") + BI_cluster = Clusters.BasicInformation + nl_attribute = BI_cluster.Attributes.NodeLabel + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + + self.step(4) + # Establishing TH2 + 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) + await self.CommissionAttempt(setupPinCode, th=self.th2, fail=False, thnum=2) + + self.step(5) + #TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th1_fabric_info = await self.get_fabrics(th=self.th1) + + #Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) + if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + asserts.fail(f"public keys from fabric and certs for TH1 are not the same") + if th1_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail(f"DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") + + # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. + await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(6) + #TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th2_fabric_info = await self.get_fabrics(th=self.th2) + + #Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + asserts.fail(f"public keys from fabric and certs for TH2 are not the same") + if th2_fabric_info[0].nodeID != self.dut_node_id : + asserts.fail(f"DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + + await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(7) + #TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + + self.step(8) + #TH_CR2 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE + await self.write_nl_attr(th=self.th2, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th2, attr_val=nl_attribute) + sleep(1) + + self.step(9) + #TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM + await self.OpenCommissioningWindow(th=self.th2, duration=180) + + self.step(10) + #Wait for the commissioning window in step 9 to timeout + sleep(180) + + self.step(11) + #TH_CR2 reads the window status to verify the DUT_CE window is closed + await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + window_status = await self.get_window_status() + #window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) + self.print_step(0, dir(AC_cluster.Enums)) + self.print_step(1, window_status) + + self.step(12) + # TH_CR2 opens a commissioning window on DUT_CE using ECM + + self.step(13) + # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 + +if __name__ == "__main__": + default_matter_test_main() From 71119b52e6bed715d6835efa9ceb390bd2fc024c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 27 Sep 2024 12:35:48 +0000 Subject: [PATCH 002/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3.py | 67 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py index 3eff27ba1b4180..bcc4444c9c671c 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -41,7 +41,8 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - + + class TC_CADMIN_1_3(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -65,7 +66,7 @@ async def CommissionAttempt( 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 fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) @@ -80,8 +81,8 @@ async def get_rcac_decoded(self, th: str) -> int: async def get_txt_record(self): discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) comm_service = await discovery.get_commissionable_service( - discovery_timeout_sec = 240, - log_output = False, + discovery_timeout_sec=240, + log_output=False, ) return comm_service @@ -121,28 +122,29 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: return [ TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using ECM", - "DUT_CE opens its Commissioning window to allow a second commissioning."), + TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using ECM", + "DUT_CE opens its Commissioning window to allow a second commissioning."), TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=2"), TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", - "Verify DUT_CE responds to both write/read with a success"), + "Verify DUT_CE responds to both write/read with a success"), TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", - "Commissioning is successful"), - TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), - TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), + "Commissioning is successful"), + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), + TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), TestStep(7, "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", - "Verify DUT_CE responds to both write/read with a success"), + "Verify DUT_CE responds to both write/read with a success"), TestStep(8, "TH_CR2 reads, writes and then reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", - "Verify the initial read reflect the value written in the above step. Verify DUT_CE responds to both write/read with a success"), + "Verify the initial read reflect the value written in the above step. Verify DUT_CE responds to both write/read with a success"), TestStep(9, "TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM"), TestStep(10, "Wait for the commissioning window in step 9 to timeout"), - TestStep(11, "TH_CR2 reads the window status to verify the DUT_CE window is closed", "DUT_CE windows status shows the window is closed"), - TestStep(12, "TH_CR2 opens a commissioning window on DUT_CE using ECM", - "DUT_CE opens its Commissioning window to allow a new commissioning"), - TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", - "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), + TestStep(11, "TH_CR2 reads the window status to verify the DUT_CE window is closed", + "DUT_CE windows status shows the window is closed"), + TestStep(12, "TH_CR2 opens a commissioning window on DUT_CE using ECM", + "DUT_CE opens its Commissioning window to allow a new commissioning"), + TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", + "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), ] @async_test_body @@ -151,7 +153,7 @@ async def test_TC_CADMIN_1_3(self): # Establishing TH1 self.th1 = self.default_controller - + self.step(2) GC_cluster = Clusters.GeneralCommissioning attribute = GC_cluster.Attributes.BasicCommissioningInfo @@ -181,10 +183,10 @@ async def test_TC_CADMIN_1_3(self): await self.CommissionAttempt(setupPinCode, th=self.th2, fail=False, thnum=2) self.step(5) - #TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th1_fabric_info = await self.get_fabrics(th=self.th1) - #Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. + # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: @@ -196,43 +198,43 @@ async def test_TC_CADMIN_1_3(self): await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(6) - #TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th2_fabric_info = await self.get_fabrics(th=self.th2) - #Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. + # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: asserts.fail(f"public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info[0].nodeID != self.dut_node_id : + if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail(f"DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) - #TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE + # TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) self.step(8) - #TH_CR2 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE + # TH_CR2 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE await self.write_nl_attr(th=self.th2, attr_val=nl_attribute) await self.read_nl_attr(th=self.th2, attr_val=nl_attribute) sleep(1) self.step(9) - #TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM + # TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM await self.OpenCommissioningWindow(th=self.th2, duration=180) self.step(10) - #Wait for the commissioning window in step 9 to timeout + # Wait for the commissioning window in step 9 to timeout sleep(180) - + self.step(11) - #TH_CR2 reads the window status to verify the DUT_CE window is closed + # TH_CR2 reads the window status to verify the DUT_CE window is closed await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) window_status = await self.get_window_status() - #window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) + # window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) self.print_step(0, dir(AC_cluster.Enums)) self.print_step(1, window_status) @@ -242,5 +244,6 @@ async def test_TC_CADMIN_1_3(self): self.step(13) # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 + if __name__ == "__main__": default_matter_test_main() From 5a48f129e461175ae715938f2623d8e29a92115e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 27 Sep 2024 12:35:49 +0000 Subject: [PATCH 003/104] Restyled by isort --- src/python_testing/TC_CADMIN_1_3.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py index bcc4444c9c671c..7388086212d0b4 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -26,18 +26,18 @@ import logging import random from pathlib import Path +from time import sleep import chip.clusters as Clusters -from chip.tlv import TLVReader from chip import ChipDeviceCtrl from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.native import PyChipError -from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main, MatterStackState +from chip.tlv import TLVReader +from matter_testing_support import MatterBaseTest, MatterStackState, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery from mobly import asserts -from time import sleep opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) From 28ba101daa13e671dea5d21ffff054685e8ffe5b Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 27 Sep 2024 07:11:46 -0700 Subject: [PATCH 004/104] Update TC_CADMIN_1_3: - Updated TC_CADMIN_1_3 to latest CI format --- src/python_testing/TC_CADMIN_1_3.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py index 7388086212d0b4..9630bc345d04cb 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -15,12 +15,19 @@ # 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} +# factoryreset: true +# quiet: true +# 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 # === END CI TEST ARGUMENTS === import logging From 6ed06831ef2523f631f2061c8fa918c79aee2a69 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 27 Sep 2024 14:22:06 -0700 Subject: [PATCH 005/104] Updated TC_CADMIN_1_3: - Resolving linting errors --- src/python_testing/TC_CADMIN_1_3.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py index 9630bc345d04cb..3fec2012d21284 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -32,7 +32,6 @@ import logging import random -from pathlib import Path from time import sleep import chip.clusters as Clusters @@ -42,14 +41,13 @@ from chip.interaction_model import Status from chip.native import PyChipError from chip.tlv import TLVReader -from matter_testing_support import MatterBaseTest, MatterStackState, TestStep, async_test_body, default_matter_test_main +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery from mobly import asserts opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - class TC_CADMIN_1_3(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -98,7 +96,7 @@ async def get_window_status(self) -> int: window_status = await self.read_single_attribute_check_success(dev_ctrl=self.th2, fabric_filtered=True, cluster=AC_cluster, attribute=AC_cluster.Attributes.WindowStatus) return window_status - async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int): + async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int) -> CommissioningParameters: self.discriminator = random.randint(0, 4095) try: params = await th.OpenCommissioningWindow( @@ -118,7 +116,7 @@ async def write_nl_attr(self, th: str, attr_val: object): async def read_nl_attr(self, th: str, attr_val: object): try: - result = await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) except Exception as e: asserts.assert_equal(e.err, "Received error message from read attribute attempt") @@ -197,9 +195,9 @@ async def test_TC_CADMIN_1_3(self): await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: - asserts.fail(f"public keys from fabric and certs for TH1 are not the same") + asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: - asserts.fail(f"DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) @@ -212,9 +210,9 @@ async def test_TC_CADMIN_1_3(self): await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: - asserts.fail(f"public keys from fabric and certs for TH2 are not the same") + asserts.fail("public keys from fabric and certs for TH2 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: - asserts.fail(f"DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) @@ -239,9 +237,9 @@ async def test_TC_CADMIN_1_3(self): self.step(11) # TH_CR2 reads the window status to verify the DUT_CE window is closed - await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) window_status = await self.get_window_status() # window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) + AC_cluster = Clusters.AdministratorCommissioning self.print_step(0, dir(AC_cluster.Enums)) self.print_step(1, window_status) From 75e368cecda411b8ebc048f93e23bfdea102b828 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 27 Sep 2024 21:23:29 +0000 Subject: [PATCH 006/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3.py index 3fec2012d21284..16f70b1590e884 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3.py @@ -48,6 +48,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_3(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): From 66a1e951e0663dc06c953c723ff4b3917ad36625 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 8 Oct 2024 17:02:08 -0700 Subject: [PATCH 007/104] Renamed TC_CADMIN_1_3 to TC_CADMIN_1_3_4 test module: - Appended WIP CADMIN_1_4 test script to TC_CADMIN_1_3 test module - Renamed TC_CADMIN_1_3 to TC_CADMIN_1_3_4 - Added issue in a TODO comment since current workaround in place to make CADMIN_1_3 pass --- .../{TC_CADMIN_1_3.py => TC_CADMIN_1_3_4.py} | 196 ++++++++++++++---- 1 file changed, 160 insertions(+), 36 deletions(-) rename src/python_testing/{TC_CADMIN_1_3.py => TC_CADMIN_1_3_4.py} (51%) diff --git a/src/python_testing/TC_CADMIN_1_3.py b/src/python_testing/TC_CADMIN_1_3_4.py similarity index 51% rename from src/python_testing/TC_CADMIN_1_3.py rename to src/python_testing/TC_CADMIN_1_3_4.py index 16f70b1590e884..c69824e715908c 100644 --- a/src/python_testing/TC_CADMIN_1_3.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -30,6 +30,7 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === +import asyncio import logging import random from time import sleep @@ -48,25 +49,19 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - -class TC_CADMIN_1_3(MatterBaseTest): +class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): - logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") if fail: - ctx = asserts.assert_raises(ChipStackError) - self.print_step(0, ctx) - with ctx: + logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") + try: 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') + except ChipStackError as e: + asserts.assert_equal(e.err, 0x0000007E, + "Expected to return Trying to add NOC for fabric that already exists") elif not fail: await th.CommissionOnNetwork( @@ -75,7 +70,14 @@ async def CommissionAttempt( async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials - fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + if th == self.th2: + th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0,OC_cluster.Attributes.Fabrics)]) + th2_fabric_data = list(th2_fabric_info.values())[0] + th2_fabric_data = list(th2_fabric_data.values())[0] + fabric_info = vars(list(th2_fabric_data.values())[1][0]) + + else: + fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) return fabric_info async def get_rcac_decoded(self, th: str) -> int: @@ -92,11 +94,6 @@ async def get_txt_record(self): ) return comm_service - async def get_window_status(self) -> int: - AC_cluster = Clusters.AdministratorCommissioning - window_status = await self.read_single_attribute_check_success(dev_ctrl=self.th2, fabric_filtered=True, cluster=AC_cluster, attribute=AC_cluster.Attributes.WindowStatus) - return window_status - async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int) -> CommissioningParameters: self.discriminator = random.randint(0, 4095) try: @@ -111,15 +108,22 @@ async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int) -> Co else: asserts.assert_true(False, 'Failed to verify') - async def write_nl_attr(self, th: str, attr_val: object): - result = await th.WriteAttribute(self.dut_node_id, [(0, attr_val)]) - asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") - - async def read_nl_attr(self, th: str, attr_val: object): + async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): + result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") + + async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): try: await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) except Exception as e: asserts.assert_equal(e.err, "Received error message from read attribute attempt") + self.print_step(0, e) + + async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: + cluster = Clusters.OperationalCredentials + attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex + current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) + return current_fabric_index def pics_TC_CADMIN_1_3(self) -> list[str]: return ["CADMIN.S"] @@ -151,6 +155,7 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: "DUT_CE opens its Commissioning window to allow a new commissioning"), TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), + TestStep(14, "", "") ] @async_test_body @@ -185,7 +190,7 @@ async def test_TC_CADMIN_1_3(self): # Establishing TH2 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.th2 = th2_fabric_admin.NewController(nodeId=2) await self.CommissionAttempt(setupPinCode, th=self.th2, fail=False, thnum=2) self.step(5) @@ -205,17 +210,18 @@ async def test_TC_CADMIN_1_3(self): self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_info = await self.get_fabrics(th=self.th2) + th2_fabric_data = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + if th2_fabric_data["rootPublicKey"] != th2_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info[0].nodeID != self.dut_node_id: + if th2_fabric_data["nodeID"] != self.dut_node_id: asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE @@ -230,26 +236,144 @@ async def test_TC_CADMIN_1_3(self): self.step(9) # TH_CR2 opens a commissioning window on DUT_CE for 180 seconds using ECM - await self.OpenCommissioningWindow(th=self.th2, duration=180) + await self.th2.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=180, iteration=1000, discriminator=0, option=1) self.step(10) - # Wait for the commissioning window in step 9 to timeout - sleep(180) + sleep(181) self.step(11) # TH_CR2 reads the window status to verify the DUT_CE window is closed - window_status = await self.get_window_status() - # window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) - AC_cluster = Clusters.AdministratorCommissioning - self.print_step(0, dir(AC_cluster.Enums)) - self.print_step(1, window_status) + #TODO: Issue noticed when initially attempting to check window status, issue is detailed here: https://github.com/project-chip/connectedhomeip/issues/35983 + # Workaround in place until above issue resolved + try: + window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) + except: + window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) + + window_status = window_status[0] + outer_key = list(window_status.keys())[0] + inner_key = list(window_status[outer_key].keys())[1] + if window_status[outer_key][inner_key] != Clusters.AdministratorCommissioning.Enums.CommissioningWindowStatusEnum.kWindowNotOpen: + asserts.fail("Commissioning window is expected to be closed, but was found to be open") self.step(12) # TH_CR2 opens a commissioning window on DUT_CE using ECM + self.discriminator = random.randint(0, 4095) + params2 = await self.th2.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=180, iteration=1000, discriminator=self.discriminator, option=1) + setupPinCode2 = params2.setupPinCode self.step(13) # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 + await self.CommissionAttempt(setupPinCode2, th=self.th1, fail=True, thnum=1) + ''' + expected error: + [2024-10-08 11:57:43.144125][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Device returned status 9 on receiving the NOC + [2024-10-08 11:57:43.144365][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Add NOC failed with error src/controller/CHIPDeviceController.cpp:1712: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists + ''' + + self.step(14) + # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx + th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] + attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + + def pics_TC_CADMIN_1_4(self) -> list[str]: + return ["CADMIN.S"] + def steps_TC_CADMIN_1_4(self) -> list[TestStep]: + return [ + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", + "DUT_CE opens its Commissioning window to allow a second commissioning."), + TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=2"), + TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify DUT_CE responds to both write/read with a success"), + TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", + "Commissioning is successful"), + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), + TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), + TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + "TH_CR1 removes TH_CR2 fabric using th2_idx") + ] + + @async_test_body + async def test_TC_CADMIN_1_4(self): + self.step(1) + + # 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("3a") + obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) + obc = await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) + + self.step("3b") + services = await self.get_txt_record() + if services.txt_record['CM'] != "2": + asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + + self.step("3c") + BI_cluster = Clusters.BasicInformation + nl_attribute = BI_cluster.Attributes.NodeLabel + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + + self.step(4) + # Establishing TH2 + 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) + #TODO: Find a way to commission the endpoint with BCM method + + self.step(5) + # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th1_fabric_info = await self.get_fabrics(th=self.th1) + + # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) + if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH1 are not the same") + if th1_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") + + # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. + await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(6) + # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th2_fabric_info = await self.get_fabrics(th=self.th2) + + # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH2 are not the same") + if th2_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + + await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(7) + # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx + th2_idx = await self.th2.ReadAttribute(nodeid=2, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] + attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) if __name__ == "__main__": default_matter_test_main() From cab902dc6ba5cf34bcadcbdcf0d8c282d3ae26b3 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 8 Oct 2024 17:11:32 -0700 Subject: [PATCH 008/104] Update TC_CADMIN_1_3_4.py - Updated test step 14 for TC_CADMIN_1_3 to contain correct information --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index c69824e715908c..cdf009f0dbe752 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -155,7 +155,8 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: "DUT_CE opens its Commissioning window to allow a new commissioning"), TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), - TestStep(14, "", "") + TestStep(14, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + "TH_CR1 removes TH_CR2 fabric using th2_idx") ] @async_test_body From 510f4f1caed0a1bb3ffb37cd66b967cb2f940b49 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 8 Oct 2024 17:18:10 -0700 Subject: [PATCH 009/104] Updating TC_CADMIN_1_3_4 test module: - Minor change to attempt resolving restylizer issue --- src/python_testing/TC_CADMIN_1_3_4.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index cdf009f0dbe752..67e13bdc602914 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -49,6 +49,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): From 7a74ef3a2e57c6325b024f3bb9d648886f706e6d Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 9 Oct 2024 10:24:58 -0700 Subject: [PATCH 010/104] Updated TC_CADMIN_1_3_4 test module: - Updating to resolve some linting issues --- src/python_testing/TC_CADMIN_1_3_4.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 67e13bdc602914..9dd37c2798b41c 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -30,7 +30,6 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === -import asyncio import logging import random from time import sleep @@ -40,7 +39,6 @@ from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError from chip.interaction_model import Status -from chip.native import PyChipError from chip.tlv import TLVReader from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery @@ -49,7 +47,6 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -319,7 +316,7 @@ async def test_TC_CADMIN_1_4(self): self.step("3a") obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) - obc = await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) self.step("3b") services = await self.get_txt_record() From dabe8b76bd9bd79b8816dde9c150b01fb25dd6f7 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 9 Oct 2024 10:52:50 -0700 Subject: [PATCH 011/104] Update src/python_testing/TC_CADMIN_1_3_4.py Updating to reflect change in master for "factory-reset", thank you @arkq Co-authored-by: Arkadiusz Bokowy --- src/python_testing/TC_CADMIN_1_3_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 9dd37c2798b41c..0c530c7d7af6e1 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -18,7 +18,7 @@ # test-runner-runs: # run1: # app: ${ALL_CLUSTERS_APP} -# factoryreset: true +# factory-reset: true # quiet: true # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > From 404c43656d027654a251c9f3cb59fe6f34fab810 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 10 Oct 2024 10:24:38 -0700 Subject: [PATCH 012/104] Updated TC_CADMIN_1_3_4 test module: - Now using get_setup_payload_info() to gather discriminator and passcode for BCM commissioning in TC_CADMIN_1_4 --- src/python_testing/TC_CADMIN_1_3_4.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 0c530c7d7af6e1..8858aa04547180 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -264,11 +264,11 @@ async def test_TC_CADMIN_1_3(self): self.step(13) # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 await self.CommissionAttempt(setupPinCode2, th=self.th1, fail=True, thnum=1) - ''' + """ expected error: [2024-10-08 11:57:43.144125][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Device returned status 9 on receiving the NOC [2024-10-08 11:57:43.144365][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Add NOC failed with error src/controller/CHIPDeviceController.cpp:1712: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists - ''' + """ self.step(14) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx @@ -288,7 +288,7 @@ def steps_TC_CADMIN_1_4(self) -> list[TestStep]: TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), - TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=2"), + TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=1"), TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", "Verify DUT_CE responds to both write/read with a success"), TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", @@ -320,7 +320,7 @@ async def test_TC_CADMIN_1_4(self): self.step("3b") services = await self.get_txt_record() - if services.txt_record['CM'] != "2": + if services.txt_record['CM'] != "1": asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") self.step("3c") @@ -334,7 +334,10 @@ async def test_TC_CADMIN_1_4(self): 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) - #TODO: Find a way to commission the endpoint with BCM method + setupPayloadInfo = self.get_setup_payload_info() + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read @@ -358,16 +361,16 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info[0].nodeID != self.dut_node_id: + if th2_fabric_info['nodeID'] != self.dut_node_id: asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx - th2_idx = await self.th2.ReadAttribute(nodeid=2, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) + th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) outer_key = list(th2_idx.keys())[0] inner_key = list(th2_idx[outer_key].keys())[0] attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] From 70169f3dcaf3d21c7db31577f8dccbe670ef26cf Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 10 Oct 2024 21:32:25 +0000 Subject: [PATCH 013/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 40 ++++++++++++++------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 8858aa04547180..f3f28f776f7750 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -47,6 +47,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -59,7 +60,7 @@ async def CommissionAttempt( filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) except ChipStackError as e: asserts.assert_equal(e.err, 0x0000007E, - "Expected to return Trying to add NOC for fabric that already exists") + "Expected to return Trying to add NOC for fabric that already exists") elif not fail: await th.CommissionOnNetwork( @@ -69,7 +70,7 @@ async def CommissionAttempt( async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials if th == self.th2: - th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0,OC_cluster.Attributes.Fabrics)]) + th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) th2_fabric_data = list(th2_fabric_info.values())[0] th2_fabric_data = list(th2_fabric_data.values())[0] fabric_info = vars(list(th2_fabric_data.values())[1][0]) @@ -107,9 +108,9 @@ async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int) -> Co asserts.assert_true(False, 'Failed to verify') async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): - result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) - asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") - + result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") + async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): try: await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) @@ -153,7 +154,7 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: "DUT_CE opens its Commissioning window to allow a new commissioning"), TestStep(13, "TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12", "Since DUT_CE was already commissioned by TH_CR1 in step 1, AddNOC fails with NOCResponse with StatusCode field set to FabricConflict (9)"), - TestStep(14, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + TestStep(14, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", "TH_CR1 removes TH_CR2 fabric using th2_idx") ] @@ -242,13 +243,13 @@ async def test_TC_CADMIN_1_3(self): self.step(11) # TH_CR2 reads the window status to verify the DUT_CE window is closed - #TODO: Issue noticed when initially attempting to check window status, issue is detailed here: https://github.com/project-chip/connectedhomeip/issues/35983 - # Workaround in place until above issue resolved + # TODO: Issue noticed when initially attempting to check window status, issue is detailed here: https://github.com/project-chip/connectedhomeip/issues/35983 + # Workaround in place until above issue resolved try: window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) except: window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) - + window_status = window_status[0] outer_key = list(window_status.keys())[0] inner_key = list(window_status[outer_key].keys())[1] @@ -270,11 +271,11 @@ async def test_TC_CADMIN_1_3(self): [2024-10-08 11:57:43.144365][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Add NOC failed with error src/controller/CHIPDeviceController.cpp:1712: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists """ - self.step(14) + self.step(14) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) - outer_key = list(th2_idx.keys())[0] - inner_key = list(th2_idx[outer_key].keys())[0] + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) @@ -297,7 +298,7 @@ def steps_TC_CADMIN_1_4(self) -> list[TestStep]: "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), - TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", "TH_CR1 removes TH_CR2 fabric using th2_idx") ] @@ -336,8 +337,8 @@ async def test_TC_CADMIN_1_4(self): self.th2 = th2_fabric_admin.NewController(nodeId=2) setupPayloadInfo = self.get_setup_payload_info() await self.th2.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) + nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read @@ -367,15 +368,16 @@ async def test_TC_CADMIN_1_4(self): asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - - self.step(7) + + self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) - outer_key = list(th2_idx.keys())[0] - inner_key = list(th2_idx[outer_key].keys())[0] + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From 26de65a6395c9caeb9c7602768ef9beecc6eda30 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 10 Oct 2024 16:19:45 -0700 Subject: [PATCH 014/104] Updating TC_CADMIN_1_3_4 test module: - Resolved linting issue --- src/python_testing/TC_CADMIN_1_3_4.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index f3f28f776f7750..8a81eec52e422d 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -30,6 +30,7 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === +import asyncio import logging import random from time import sleep @@ -247,9 +248,9 @@ async def test_TC_CADMIN_1_3(self): # Workaround in place until above issue resolved try: window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) - except: + except asyncio.CancelledError: window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) - + window_status = window_status[0] outer_key = list(window_status.keys())[0] inner_key = list(window_status[outer_key].keys())[1] @@ -378,6 +379,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() From 2610f4564c4ee37326cfc0fe7e17aede79fea761 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 10 Oct 2024 23:21:26 +0000 Subject: [PATCH 015/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 8a81eec52e422d..d6f804063e5e98 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -250,7 +250,7 @@ async def test_TC_CADMIN_1_3(self): window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) except asyncio.CancelledError: window_status = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.AdministratorCommissioning.Attributes.WindowStatus)]) - + window_status = window_status[0] outer_key = list(window_status.keys())[0] inner_key = list(window_status[outer_key].keys())[1] @@ -379,5 +379,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From 1b4d94d16aa45f3e4fcfc3317c80909a25c763af Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Sun, 13 Oct 2024 23:42:43 -0700 Subject: [PATCH 016/104] Updating TC_CADMIN_1_3_4 and matter_testing modules: - Updating TC_CADMIN_1_3_4 due to change to matter_testing_support module - Updating matter_testing module to resolve missing dependencies not found in chip library. --- src/python_testing/TC_CADMIN_1_3_4.py | 6 ++---- .../chip/testing/matter_testing.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index d6f804063e5e98..a0ad57d9e10254 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -41,14 +41,13 @@ from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader -from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_infrastructure.chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery from mobly import asserts opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -286,7 +285,7 @@ def pics_TC_CADMIN_1_4(self) -> list[str]: def steps_TC_CADMIN_1_4(self) -> list[TestStep]: return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=True), + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE"), TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), @@ -379,6 +378,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() 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 2d23a9f84b0192..cc90281ae42aa3 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 @@ -65,8 +65,8 @@ from chip.interaction_model import InteractionModelError, Status from chip.setup_payload import SetupPayload from chip.storage import PersistentStorage -from chip.testing.global_attribute_ids import GlobalAttributeIds -from chip.testing.pics import read_pics_from_file +from .global_attribute_ids import GlobalAttributeIds +from .pics import read_pics_from_file from chip.tracing import TracingContext from mobly import asserts, base_test, signals, utils from mobly.config_parser import ENV_MOBLY_LOGPATH, TestRunConfig From bb3da6eb25b8ccdbb0bf86fbff7438e516a30a7e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 14 Oct 2024 06:46:38 +0000 Subject: [PATCH 017/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index a0ad57d9e10254..8cb058c2c7739b 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -48,6 +48,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_3_4(MatterBaseTest): async def CommissionAttempt( self, setupPinCode: int, thnum: int, th: str, fail: bool): @@ -378,5 +379,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From 35d08e69d6d9d90bf1a4eb147ef6d1a9318fb235 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 14 Oct 2024 06:46:41 +0000 Subject: [PATCH 018/104] Restyled by isort --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- .../chip/testing/matter_testing.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 8cb058c2c7739b..3ad771698b556a 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -41,7 +41,8 @@ from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader -from matter_testing_infrastructure.chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, + default_matter_test_main) from mdns_discovery import mdns_discovery from mobly import asserts 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 cc90281ae42aa3..7c88f23ab97b61 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 @@ -65,13 +65,14 @@ from chip.interaction_model import InteractionModelError, Status from chip.setup_payload import SetupPayload from chip.storage import PersistentStorage -from .global_attribute_ids import GlobalAttributeIds -from .pics import read_pics_from_file from chip.tracing import TracingContext from mobly import asserts, base_test, signals, utils from mobly.config_parser import ENV_MOBLY_LOGPATH, TestRunConfig from mobly.test_runner import TestRunner +from .global_attribute_ids import GlobalAttributeIds +from .pics import read_pics_from_file + try: from matter_yamltests.hooks import TestRunnerHooks except ImportError: From 428ca9e604216a812a5b751e48993877af294040 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 09:16:59 -0700 Subject: [PATCH 019/104] Update matter_testing.py Reverting changes back as just needed to rebuild the python environment to get this working. --- .../chip/testing/matter_testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7c88f23ab97b61..a23a75bb20e687 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 @@ -70,8 +70,8 @@ from mobly.config_parser import ENV_MOBLY_LOGPATH, TestRunConfig from mobly.test_runner import TestRunner -from .global_attribute_ids import GlobalAttributeIds -from .pics import read_pics_from_file +from chip.testing.global_attribute_ids import GlobalAttributeIds +from chip.testing.pics import read_pics_from_file try: from matter_yamltests.hooks import TestRunnerHooks From 9966c284b8d7191b2f72350e512b95e168467123 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 09:19:06 -0700 Subject: [PATCH 020/104] Update matter_testing.py Updating location of imported new modules for chip.testing to match with master --- .../chip/testing/matter_testing.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 a23a75bb20e687..2d23a9f84b0192 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 @@ -65,14 +65,13 @@ from chip.interaction_model import InteractionModelError, Status from chip.setup_payload import SetupPayload from chip.storage import PersistentStorage +from chip.testing.global_attribute_ids import GlobalAttributeIds +from chip.testing.pics import read_pics_from_file from chip.tracing import TracingContext from mobly import asserts, base_test, signals, utils from mobly.config_parser import ENV_MOBLY_LOGPATH, TestRunConfig from mobly.test_runner import TestRunner -from chip.testing.global_attribute_ids import GlobalAttributeIds -from chip.testing.pics import read_pics_from_file - try: from matter_yamltests.hooks import TestRunnerHooks except ImportError: From deb11fcf1ab77c23af91fff3b8c9c7ff82401ba0 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 10:03:24 -0700 Subject: [PATCH 021/104] Updated TC_CADMIN_1_3_4 test module: - Added revoke commissioning after test step 13 to revoke commissioning window. --- src/python_testing/TC_CADMIN_1_3_4.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 3ad771698b556a..fdc36c601f0642 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -272,6 +272,10 @@ async def test_TC_CADMIN_1_3(self): [2024-10-08 11:57:43.144125][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Device returned status 9 on receiving the NOC [2024-10-08 11:57:43.144365][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Add NOC failed with error src/controller/CHIPDeviceController.cpp:1712: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists """ + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + # The failsafe cleanup is scheduled after the command completes, so give it a bit of time to do that + sleep(1) self.step(14) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx @@ -287,7 +291,7 @@ def pics_TC_CADMIN_1_4(self) -> list[str]: def steps_TC_CADMIN_1_4(self) -> list[TestStep]: return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE"), + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), From 1d5433f7ad15e91b42af6c3755b5015a648b6040 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 10:55:28 -0700 Subject: [PATCH 022/104] Updated TC_CADMIN_1_3_4 test module: - Enabled verbose output to identify issue noticed in CI/CD pipeline Linux REPL tests --- src/python_testing/TC_CADMIN_1_3_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index fdc36c601f0642..9b7e4f695f87b6 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -19,7 +19,7 @@ # run1: # app: ${ALL_CLUSTERS_APP} # factory-reset: true -# quiet: true +# quiet: false # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > # --storage-path admin_storage.json From e2cf410af0c84b41113d68c5e808a8453eca9f95 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 17:24:19 -0700 Subject: [PATCH 023/104] Updating TC_CADMIN_1_3_4 test module: - Removed local OpenCommissiongWindow and CommissionAttempt functions - Started using openCommissioningWindow function from matter_testing support module --- src/python_testing/TC_CADMIN_1_3_4.py | 52 +++++++-------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 9b7e4f695f87b6..45883ecfb71c70 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -51,24 +51,6 @@ class TC_CADMIN_1_3_4(MatterBaseTest): - async def CommissionAttempt( - self, setupPinCode: int, thnum: int, th: str, fail: bool): - - if fail: - logging.info(f"-----------------Commissioning with TH_CR{str(thnum)}-------------------------") - try: - await th.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) - except ChipStackError as e: - asserts.assert_equal(e.err, 0x0000007E, - "Expected to return Trying to add NOC for fabric that already exists") - - 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 if th == self.th2: @@ -95,20 +77,6 @@ async def get_txt_record(self): ) return comm_service - async def OpenCommissioningWindow(self, th: ChipDeviceCtrl, duration: int) -> CommissioningParameters: - self.discriminator = random.randint(0, 4095) - try: - params = await th.OpenCommissioningWindow( - nodeid=self.dut_node_id, timeout=duration, iteration=10000, discriminator=self.discriminator, option=1) - return params - - except Exception as e: - logging.exception('Error running OpenCommissioningWindow %s', e) - if str(Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy) in e.msg: - asserts.assert_true(False, 'Failed to open commissioning window') - else: - asserts.assert_true(False, 'Failed to verify') - async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") @@ -174,8 +142,7 @@ async def test_TC_CADMIN_1_3(self): self.max_window_duration = duration.maxCumulativeFailsafeSeconds self.step("3a") - params = await self.OpenCommissioningWindow(th=self.th1, duration=self.max_window_duration) - setupPinCode = params.setupPinCode + params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) self.step("3b") services = await self.get_txt_record() @@ -193,7 +160,9 @@ async def test_TC_CADMIN_1_3(self): 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) - await self.CommissionAttempt(setupPinCode, th=self.th2, fail=False, thnum=2) + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read @@ -261,17 +230,23 @@ async def test_TC_CADMIN_1_3(self): self.step(12) # TH_CR2 opens a commissioning window on DUT_CE using ECM self.discriminator = random.randint(0, 4095) - params2 = await self.th2.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=180, iteration=1000, discriminator=self.discriminator, option=1) - setupPinCode2 = params2.setupPinCode + params2 = await self.openCommissioningWindow(dev_ctrl=self.th2, node_id=self.dut_node_id) self.step(13) # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 - await self.CommissionAttempt(setupPinCode2, th=self.th1, fail=True, thnum=1) + try: + await self.th1.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=params2.commissioningParameters.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params2.randomDiscriminator) + except ChipStackError as e: + asserts.assert_equal(e.err, 0x0000007E, + "Expected to return Trying to add NOC for fabric that already exists") """ expected error: [2024-10-08 11:57:43.144125][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Device returned status 9 on receiving the NOC [2024-10-08 11:57:43.144365][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Add NOC failed with error src/controller/CHIPDeviceController.cpp:1712: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists """ + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) # The failsafe cleanup is scheduled after the command completes, so give it a bit of time to do that @@ -384,6 +359,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() From 85b9d6181d4702559a51ddba79e37ddd70199db5 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 16 Oct 2024 00:28:16 +0000 Subject: [PATCH 024/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 45883ecfb71c70..b196b1549fb16f 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -240,7 +240,7 @@ async def test_TC_CADMIN_1_3(self): filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params2.randomDiscriminator) except ChipStackError as e: asserts.assert_equal(e.err, 0x0000007E, - "Expected to return Trying to add NOC for fabric that already exists") + "Expected to return Trying to add NOC for fabric that already exists") """ expected error: [2024-10-08 11:57:43.144125][TEST][STDOUT][MatterTest] 10-08 11:57:42.777 INFO Device returned status 9 on receiving the NOC @@ -359,5 +359,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From c0414f20c596771c0724d637f5fd8e1e7b201746 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 15 Oct 2024 18:13:33 -0700 Subject: [PATCH 025/104] Updating TC_CADMIN_1_3_4 test module: - Resolving lint errors --- src/python_testing/TC_CADMIN_1_3_4.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index b196b1549fb16f..8830a310cda9d4 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -31,13 +31,11 @@ # === END CI TEST ARGUMENTS === import asyncio -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.interaction_model import Status from chip.tlv import TLVReader From 427397d4233f2ddd448e08fc08f9cba1769913a6 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 10:02:42 -0700 Subject: [PATCH 026/104] Added TC_CADMIN_1_4_nofreset test module: - Added new test module to verify that if no factory reset occurs between TC_CADMIN_1_3_4 test modules and TC_CADMIN_1_4_nofreset, how to handle that situation for BCM. --- src/python_testing/TC_CADMIN_1_4_nofreset.py | 199 +++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 src/python_testing/TC_CADMIN_1_4_nofreset.py diff --git a/src/python_testing/TC_CADMIN_1_4_nofreset.py b/src/python_testing/TC_CADMIN_1_4_nofreset.py new file mode 100644 index 00000000000000..84d145f5c42d49 --- /dev/null +++ b/src/python_testing/TC_CADMIN_1_4_nofreset.py @@ -0,0 +1,199 @@ +# +# 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: +# app: ${ALL_CLUSTERS_APP} +# factory-reset: false +# quiet: false +# 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 +# === END CI TEST ARGUMENTS === + +import asyncio +import random +from time import sleep + +import chip.clusters as Clusters +from chip import ChipDeviceCtrl +from chip.exceptions import ChipStackError +from chip.interaction_model import Status +from chip.tlv import TLVReader +from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, + default_matter_test_main) +from mdns_discovery import mdns_discovery +from mobly import asserts + +opcreds = Clusters.OperationalCredentials +nonce = random.randbytes(32) + +class TC_CADMIN_1_4_nofreset(MatterBaseTest): + async def get_fabrics(self, th: ChipDeviceCtrl) -> int: + OC_cluster = Clusters.OperationalCredentials + if th == self.th2: + th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) + th2_fabric_data = list(th2_fabric_info.values())[0] + th2_fabric_data = list(th2_fabric_data.values())[0] + fabric_info = vars(list(th2_fabric_data.values())[1][0]) + + else: + fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + return fabric_info + + async def get_rcac_decoded(self, th: str) -> int: + csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) + TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) + th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] + return th_rcac_decoded + + async def get_txt_record(self): + discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) + comm_service = await discovery.get_commissionable_service( + discovery_timeout_sec=240, + log_output=False, + ) + return comm_service + + async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): + result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") + + async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): + try: + await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + except Exception as e: + asserts.assert_equal(e.err, "Received error message from read attribute attempt") + self.print_step(0, e) + + async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: + cluster = Clusters.OperationalCredentials + attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex + current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) + return current_fabric_index + + def pics_TC_CADMIN_1_4_noreset(self) -> list[str]: + return ["CADMIN.S"] + + def steps_TC_CADMIN_1_4_noreset(self) -> list[TestStep]: + return [ + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", + "DUT_CE opens its Commissioning window to allow a second commissioning."), + TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=1"), + TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify DUT_CE responds to both write/read with a success"), + TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", + "Commissioning is successful"), + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), + TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), + TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + "TH_CR1 removes TH_CR2 fabric using th2_idx") + ] + + @async_test_body + async def test_TC_CADMIN_1_4_noreset(self): + setupPayloadInfo = self.get_setup_payload_info() + self.print_step("Setup payload info", setupPayloadInfo) + if not setupPayloadInfo[0].passcode: + asserts.assert_true(False, 'passcode must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --passcode ') + + if not setupPayloadInfo[0].filter_value: + asserts.assert_true(False, 'discriminator must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --discriminator ') + self.step(1) + + # 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("3a") + obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) + + self.step("3b") + services = await self.get_txt_record() + if services.txt_record['CM'] != "1": + asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + + self.step("3c") + BI_cluster = Clusters.BasicInformation + nl_attribute = BI_cluster.Attributes.NodeLabel + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + + self.step(4) + # Establishing TH2 + 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) + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) + + self.step(5) + # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th1_fabric_info = await self.get_fabrics(th=self.th1) + + # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) + if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH1 are not the same") + if th1_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") + + # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. + await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(6) + # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th2_fabric_info = await self.get_fabrics(th=self.th2) + + # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) + if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH2 are not the same") + if th2_fabric_info['nodeID'] != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + + await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(7) + # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx + th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] + attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + +if __name__ == "__main__": + default_matter_test_main() From 612c0fb696947a8bcdd6d93983969f538ecce1a4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 16 Oct 2024 17:06:12 +0000 Subject: [PATCH 027/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_4_nofreset.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_4_nofreset.py b/src/python_testing/TC_CADMIN_1_4_nofreset.py index 84d145f5c42d49..9dceeb1713d84f 100644 --- a/src/python_testing/TC_CADMIN_1_4_nofreset.py +++ b/src/python_testing/TC_CADMIN_1_4_nofreset.py @@ -47,6 +47,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_4_nofreset(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -118,10 +119,12 @@ async def test_TC_CADMIN_1_4_noreset(self): setupPayloadInfo = self.get_setup_payload_info() self.print_step("Setup payload info", setupPayloadInfo) if not setupPayloadInfo[0].passcode: - asserts.assert_true(False, 'passcode must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --passcode ') + asserts.assert_true( + False, 'passcode must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --passcode ') if not setupPayloadInfo[0].filter_value: - asserts.assert_true(False, 'discriminator must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --discriminator ') + asserts.assert_true( + False, 'discriminator must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --discriminator ') self.step(1) # Establishing TH1 @@ -195,5 +198,6 @@ async def test_TC_CADMIN_1_4_noreset(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From c48c0cfd5376feba503b7699e461ceb571beddf9 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 10:24:58 -0700 Subject: [PATCH 028/104] Updated TC_CADMIN_1_4_nofreset test module: - Resolved linting errors --- src/python_testing/TC_CADMIN_1_4_nofreset.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_4_nofreset.py b/src/python_testing/TC_CADMIN_1_4_nofreset.py index 9dceeb1713d84f..719411581e4177 100644 --- a/src/python_testing/TC_CADMIN_1_4_nofreset.py +++ b/src/python_testing/TC_CADMIN_1_4_nofreset.py @@ -30,13 +30,10 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === -import asyncio import random -from time import sleep import chip.clusters as Clusters from chip import ChipDeviceCtrl -from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, From 43072632f359e3ec93f20187c95252a2ecc97e9c Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 14:21:57 -0700 Subject: [PATCH 029/104] Updated TC_CADMIN_1_4_nofreset test module and manualTests.json: - Removed TC_CADMIN_1_3 and TC_CADMIN_1_4 from manualTests.json MultipleFabrics section - Updated TC_CADMIN_1_4_nofreset to remove commissioning attempt before start of test. --- src/app/tests/suites/manualTests.json | 2 -- src/python_testing/TC_CADMIN_1_4_nofreset.py | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/app/tests/suites/manualTests.json b/src/app/tests/suites/manualTests.json index 3b0b354840e1c6..ea64cc1acf1e5e 100644 --- a/src/app/tests/suites/manualTests.json +++ b/src/app/tests/suites/manualTests.json @@ -182,8 +182,6 @@ "Test_TC_CADMIN_1_20", "Test_TC_CADMIN_1_21", "Test_TC_CADMIN_1_22", - "Test_TC_CADMIN_1_3", - "Test_TC_CADMIN_1_4", "Test_TC_CADMIN_1_5", "Test_TC_CADMIN_1_6", "Test_TC_CADMIN_1_9", diff --git a/src/python_testing/TC_CADMIN_1_4_nofreset.py b/src/python_testing/TC_CADMIN_1_4_nofreset.py index 719411581e4177..2645d608d2833f 100644 --- a/src/python_testing/TC_CADMIN_1_4_nofreset.py +++ b/src/python_testing/TC_CADMIN_1_4_nofreset.py @@ -89,12 +89,12 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) return current_fabric_index - def pics_TC_CADMIN_1_4_noreset(self) -> list[str]: + def pics_TC_CADMIN_1_4_nofreset(self) -> list[str]: return ["CADMIN.S"] - def steps_TC_CADMIN_1_4_noreset(self) -> list[TestStep]: + def steps_TC_CADMIN_1_4_nofreset(self) -> list[TestStep]: return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=True), + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=False), TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), @@ -112,7 +112,8 @@ def steps_TC_CADMIN_1_4_noreset(self) -> list[TestStep]: ] @async_test_body - async def test_TC_CADMIN_1_4_noreset(self): + async def test_TC_CADMIN_1_4_nofreset(self): + self.step(1) setupPayloadInfo = self.get_setup_payload_info() self.print_step("Setup payload info", setupPayloadInfo) if not setupPayloadInfo[0].passcode: @@ -122,7 +123,6 @@ async def test_TC_CADMIN_1_4_noreset(self): if not setupPayloadInfo[0].filter_value: asserts.assert_true( False, 'discriminator must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --discriminator ') - self.step(1) # Establishing TH1 self.th1 = self.default_controller From 0e3c29e2a9ab3358db02bc673a988e49b2003bdb Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 16:42:14 -0700 Subject: [PATCH 030/104] Moved TC_CADMIN_1_4_nofreset to unit testing framework: - Moved TC_CADMIN_1_4_nofreset to unit testing framework folder and renamed it to test_TC_CADMIN_1_4 --- .../test_TC_CADMIN_1_4.py} | 87 +++++-------------- 1 file changed, 23 insertions(+), 64 deletions(-) rename src/python_testing/{TC_CADMIN_1_4_nofreset.py => test_testing/test_TC_CADMIN_1_4.py} (65%) diff --git a/src/python_testing/TC_CADMIN_1_4_nofreset.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py similarity index 65% rename from src/python_testing/TC_CADMIN_1_4_nofreset.py rename to src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 2645d608d2833f..097d6d764d5354 100644 --- a/src/python_testing/TC_CADMIN_1_4_nofreset.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -1,3 +1,4 @@ +#!/usr/bin/env -S python3 -B # # Copyright (c) 2024 Project CHIP Authors # All rights reserved. @@ -14,21 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# === BEGIN CI TEST ARGUMENTS === -# test-runner-runs: -# run1: -# app: ${ALL_CLUSTERS_APP} -# factory-reset: false -# quiet: false -# 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 -# === END CI TEST ARGUMENTS === + +import asyncio +import os +import sys import random @@ -36,15 +26,20 @@ from chip import ChipDeviceCtrl from chip.interaction_model import Status from chip.tlv import TLVReader -from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, +from chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, default_matter_test_main) +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(parent_dir) from mdns_discovery import mdns_discovery from mobly import asserts +# Reachable attribute is off in the pics file +# MaxPathsPerInvoke is not include in the pics file +# Vendor ID is included on ON in the PICS file + opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - class TC_CADMIN_1_4_nofreset(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -89,66 +84,33 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) return current_fabric_index - def pics_TC_CADMIN_1_4_nofreset(self) -> list[str]: - return ["CADMIN.S"] - - def steps_TC_CADMIN_1_4_nofreset(self) -> list[TestStep]: - return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=False), - TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), - TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", - "DUT_CE opens its Commissioning window to allow a second commissioning."), - TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=1"), - TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", - "Verify DUT_CE responds to both write/read with a success"), - TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", - "Commissioning is successful"), - TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), - TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), - TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", - "TH_CR1 removes TH_CR2 fabric using th2_idx") - ] - @async_test_body async def test_TC_CADMIN_1_4_nofreset(self): - self.step(1) setupPayloadInfo = self.get_setup_payload_info() - self.print_step("Setup payload info", setupPayloadInfo) - if not setupPayloadInfo[0].passcode: + if not setupPayloadInfo: asserts.assert_true( - False, 'passcode must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --passcode ') - - if not setupPayloadInfo[0].filter_value: - asserts.assert_true( - False, 'discriminator must be a provided value in the test in order for this test to work due to using BCM, please rerun test with providing --discriminator ') + False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') # 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("3a") obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) - self.step("3b") - services = await self.get_txt_record() + services = await get_txt_record() if services.txt_record['CM'] != "1": asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") - self.step("3c") BI_cluster = Clusters.BasicInformation nl_attribute = BI_cluster.Attributes.NodeLabel - await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) - await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + await write_nl_attr(th=self.th1, attr_val=nl_attribute) + await read_nl_attr(th=self.th1, attr_val=nl_attribute) - self.step(4) # Establishing TH2 th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) @@ -157,13 +119,12 @@ async def test_TC_CADMIN_1_4_nofreset(self): nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) - self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th1_fabric_info = await self.get_fabrics(th=self.th1) + th1_fabric_info = await get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) + th1_rcac_decoded = await get_rcac_decoded(th=self.th1) if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: @@ -172,13 +133,12 @@ async def test_TC_CADMIN_1_4_nofreset(self): # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_info = await self.get_fabrics(th=self.th2) + th2_fabric_info = await get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) - th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) + th2_rcac_decoded = await get_rcac_decoded(th=self.th2) if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH2 are not the same") if th2_fabric_info['nodeID'] != self.dut_node_id: @@ -186,7 +146,6 @@ async def test_TC_CADMIN_1_4_nofreset(self): await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) outer_key = list(th2_idx.keys())[0] @@ -195,6 +154,6 @@ async def test_TC_CADMIN_1_4_nofreset(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": - default_matter_test_main() + asyncio.run(default_matter_test_main()) + sys.exit(0) From fff8b4a9912bbe793e6a49d1aad209f3ffd6bbe8 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 16:50:18 -0700 Subject: [PATCH 031/104] Updated TC_CADMIN_1_3_4 and unit test test_TC_CADMIN_1_4 - Placed assert for if get_setup_payload_info() at start of test_CADMIN_1_4 test function - updated test_TC_CADMIN_1_4 test function name --- src/python_testing/TC_CADMIN_1_3_4.py | 5 ++++- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 8830a310cda9d4..8c07553a9d8faf 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -284,6 +284,10 @@ def steps_TC_CADMIN_1_4(self) -> list[TestStep]: @async_test_body async def test_TC_CADMIN_1_4(self): self.step(1) + setupPayloadInfo = self.get_setup_payload_info() + if not setupPayloadInfo: + asserts.assert_true( + False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') # Establishing TH1 self.th1 = self.default_controller @@ -314,7 +318,6 @@ async def test_TC_CADMIN_1_4(self): 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) - setupPayloadInfo = self.get_setup_payload_info() await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 097d6d764d5354..4586c9651f255b 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -85,7 +85,7 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: return current_fabric_index @async_test_body - async def test_TC_CADMIN_1_4_nofreset(self): + async def test_TC_CADMIN_1_4(self): setupPayloadInfo = self.get_setup_payload_info() if not setupPayloadInfo: asserts.assert_true( From 69e741ed47cb376746e03a974770a64393d0dac4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 16 Oct 2024 23:53:16 +0000 Subject: [PATCH 032/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 4586c9651f255b..66dbc72a4fa7d5 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,8 @@ # limitations under the License. # +from mobly import asserts +from mdns_discovery import mdns_discovery import asyncio import os import sys @@ -27,11 +29,9 @@ from chip.interaction_model import Status from chip.tlv import TLVReader from chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, - default_matter_test_main) + default_matter_test_main) parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -from mdns_discovery import mdns_discovery -from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file @@ -40,6 +40,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_4_nofreset(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -154,6 +155,7 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": asyncio.run(default_matter_test_main()) sys.exit(0) From b6db17dbf0b9056a2f5a0b6eabed09c25fa60cf1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 16 Oct 2024 23:53:18 +0000 Subject: [PATCH 033/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 66dbc72a4fa7d5..9c0967dbfb3419 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,20 +16,19 @@ # limitations under the License. # -from mobly import asserts -from mdns_discovery import mdns_discovery import asyncio import os -import sys - import random +import sys import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.interaction_model import Status +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, - default_matter_test_main) +from mdns_discovery import mdns_discovery +from mobly import asserts + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) From 5ae1dd98d31cc12ac4bfbff0ebd511bea85be5de Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 16 Oct 2024 22:59:37 -0700 Subject: [PATCH 034/104] Updated test_TC_CADMIN_1_4: - Resolving linting errors --- .../test_testing/test_TC_CADMIN_1_4.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 9c0967dbfb3419..517e3dc5bcf196 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -24,7 +24,7 @@ import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.interaction_model import Status -from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader from mdns_discovery import mdns_discovery from mobly import asserts @@ -102,14 +102,14 @@ async def test_TC_CADMIN_1_4(self): obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) - services = await get_txt_record() + services = await self.get_txt_record() if services.txt_record['CM'] != "1": asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") BI_cluster = Clusters.BasicInformation nl_attribute = BI_cluster.Attributes.NodeLabel - await write_nl_attr(th=self.th1, attr_val=nl_attribute) - await read_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) # Establishing TH2 th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() @@ -120,11 +120,11 @@ async def test_TC_CADMIN_1_4(self): filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th1_fabric_info = await get_fabrics(th=self.th1) + th1_fabric_info = await self.get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await get_rcac_decoded(th=self.th1) + th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: @@ -134,11 +134,11 @@ async def test_TC_CADMIN_1_4(self): await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_info = await get_fabrics(th=self.th2) + th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) - th2_rcac_decoded = await get_rcac_decoded(th=self.th2) + th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: asserts.fail("public keys from fabric and certs for TH2 are not the same") if th2_fabric_info['nodeID'] != self.dut_node_id: @@ -154,7 +154,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": asyncio.run(default_matter_test_main()) sys.exit(0) From 3acc3e50c35a3b965433e7c24ad6b05d3d48fa40 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 06:01:49 +0000 Subject: [PATCH 035/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 517e3dc5bcf196..baaa341a158709 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -154,6 +154,7 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": asyncio.run(default_matter_test_main()) sys.exit(0) From 106a9b105478184144346ba5af97ab53a7886c7d Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 06:09:42 -0700 Subject: [PATCH 036/104] Updated tests.yaml: - Added test_CADMIN_1_4 python unit-test test module to attempt running it in CI --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 63957b64d8f00d..571f72853d9d51 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -531,6 +531,7 @@ jobs: scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestChoiceConformanceSupport.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestMatterTestingSupport.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestSpecParsingSupport.py' + scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_CADMIN_1_4.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_ICDM_2_1.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_IDM_10_4.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_SC_7_1.py' From de0a1706a39ba351171344d31bc93f02edc9f4c9 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 08:11:09 -0700 Subject: [PATCH 037/104] Updated test_TC_CADMIN_1_4 unit-test module: --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index baaa341a158709..33aca58af27065 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -26,12 +26,13 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery -from mobly import asserts parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) +from mdns_discovery import mdns_discovery +from mobly import asserts + # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file # Vendor ID is included on ON in the PICS file From f619eac89c7bb83dff81a1a18960323f532c7e2f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 15:12:33 +0000 Subject: [PATCH 038/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 33aca58af27065..cd7bfaf62db94a 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,8 @@ # limitations under the License. # +from mobly import asserts +from mdns_discovery import mdns_discovery import asyncio import os import random @@ -30,8 +32,6 @@ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -from mdns_discovery import mdns_discovery -from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From ea421d3917f784116663bec65d63c4c20a532ae1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 15:12:36 +0000 Subject: [PATCH 039/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index cd7bfaf62db94a..6ead38ec9892af 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,8 +16,6 @@ # limitations under the License. # -from mobly import asserts -from mdns_discovery import mdns_discovery import asyncio import os import random @@ -28,6 +26,8 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery +from mobly import asserts parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) From 3fdec7488d5996cfa2ea6f91aa4f30ba1fed8582 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 09:50:38 -0700 Subject: [PATCH 040/104] Updated test_TC_CADMIN_1_4 test module --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 6ead38ec9892af..33aca58af27065 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -26,12 +26,12 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery -from mobly import asserts parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) +from mdns_discovery import mdns_discovery +from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From c3ac5d56ac8c8d29cf34cb020c9a3c9d8f5f5905 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 16:52:24 +0000 Subject: [PATCH 041/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 33aca58af27065..cd7bfaf62db94a 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,8 @@ # limitations under the License. # +from mobly import asserts +from mdns_discovery import mdns_discovery import asyncio import os import random @@ -30,8 +32,6 @@ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -from mdns_discovery import mdns_discovery -from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From d3256d8debf58250507e7c8953a9c4ed4250395d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 16:52:27 +0000 Subject: [PATCH 042/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index cd7bfaf62db94a..6ead38ec9892af 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,8 +16,6 @@ # limitations under the License. # -from mobly import asserts -from mdns_discovery import mdns_discovery import asyncio import os import random @@ -28,6 +26,8 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery +from mobly import asserts parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) From 046929cb75615153cfb7fc18f9196a63733997af Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 09:57:29 -0700 Subject: [PATCH 043/104] Updating test_TC_CADMIN_1_4 unit-test module --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 6ead38ec9892af..9c95fa0e11082b 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -21,6 +21,9 @@ import random import sys +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(parent_dir) + import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.interaction_model import Status @@ -29,10 +32,6 @@ from mdns_discovery import mdns_discovery from mobly import asserts -parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.append(parent_dir) - - # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file # Vendor ID is included on ON in the PICS file From dbc548006b3e313df6049b703206d56248f2a0b3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 16:58:53 +0000 Subject: [PATCH 044/104] Restyled by autopep8 --- .../test_testing/test_TC_CADMIN_1_4.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 9c95fa0e11082b..efcbd2f24b0cc2 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,13 @@ # limitations under the License. # +from mobly import asserts +from mdns_discovery import mdns_discovery +from chip.tlv import TLVReader +from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main +from chip.interaction_model import Status +from chip import ChipDeviceCtrl +import chip.clusters as Clusters import asyncio import os import random @@ -24,13 +31,6 @@ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -import chip.clusters as Clusters -from chip import ChipDeviceCtrl -from chip.interaction_model import Status -from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main -from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery -from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From 1d73f52f2389c0093b50ba46bdbe6be895210e0e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 16:58:57 +0000 Subject: [PATCH 045/104] Restyled by isort --- .../test_testing/test_TC_CADMIN_1_4.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index efcbd2f24b0cc2..6ead38ec9892af 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,18 +16,19 @@ # limitations under the License. # -from mobly import asserts -from mdns_discovery import mdns_discovery -from chip.tlv import TLVReader -from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main -from chip.interaction_model import Status -from chip import ChipDeviceCtrl -import chip.clusters as Clusters import asyncio import os import random import sys +import chip.clusters as Clusters +from chip import ChipDeviceCtrl +from chip.interaction_model import Status +from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main +from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery +from mobly import asserts + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) From 8e7170a2f1363ce5758806ba621ad7aed3df60ad Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 10:01:08 -0700 Subject: [PATCH 046/104] Updated test_TC_CADMIN_1_4 unit-test module: - Attempting to get import to be imported so test runs without restyler changing it back --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 6ead38ec9892af..ec98660dad1b4c 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -26,7 +26,6 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery from mobly import asserts parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -87,6 +86,7 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: @async_test_body async def test_TC_CADMIN_1_4(self): + from mdns_discovery import mdns_discovery setupPayloadInfo = self.get_setup_payload_info() if not setupPayloadInfo: asserts.assert_true( From f39a9835acd22cec00a2b896a6c98665d17d0d3a Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 10:17:31 -0700 Subject: [PATCH 047/104] Updating test_TC_CADMIN_1_4 unit-test module: - Resolving lint error --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index ec98660dad1b4c..685c88ab19ea42 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -60,6 +60,7 @@ async def get_rcac_decoded(self, th: str) -> int: return th_rcac_decoded async def get_txt_record(self): + from mdns_discovery import mdns_discovery discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) comm_service = await discovery.get_commissionable_service( discovery_timeout_sec=240, @@ -86,7 +87,6 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: @async_test_body async def test_TC_CADMIN_1_4(self): - from mdns_discovery import mdns_discovery setupPayloadInfo = self.get_setup_payload_info() if not setupPayloadInfo: asserts.assert_true( From 25e9d9912cf0d733f88ee90a54fd2e1a180cd312 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 10:22:00 -0700 Subject: [PATCH 048/104] Updating TC_CADMIN_1_3_4 test module: - Updating CI argument to turn on quiet mode for this test module --- src/python_testing/TC_CADMIN_1_3_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 8c07553a9d8faf..a2e43e3fd631f6 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -19,7 +19,7 @@ # run1: # app: ${ALL_CLUSTERS_APP} # factory-reset: true -# quiet: false +# quiet: true # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > # --storage-path admin_storage.json From 463a3972f48ba661311c18a25427f7555aa02eeb Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 10:58:53 -0700 Subject: [PATCH 049/104] Updated test_TC_CADMIN_1_4: - Updated to using isort off to avoid CI re-sorting the dependencies during this test run --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 685c88ab19ea42..a22bff09510b52 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -28,9 +28,14 @@ from chip.tlv import TLVReader from mobly import asserts +# isort: off + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) +from mdns_discovery import mdns_discovery + +# isort: on # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file @@ -40,7 +45,7 @@ nonce = random.randbytes(32) -class TC_CADMIN_1_4_nofreset(MatterBaseTest): +class TC_CADMIN_1_4_noreset(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials if th == self.th2: @@ -60,7 +65,6 @@ async def get_rcac_decoded(self, th: str) -> int: return th_rcac_decoded async def get_txt_record(self): - from mdns_discovery import mdns_discovery discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) comm_service = await discovery.get_commissionable_service( discovery_timeout_sec=240, From 032914b9eb595648bf9eb0e61c9c40e1262e3d89 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 18:00:29 +0000 Subject: [PATCH 050/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index a22bff09510b52..02cfb1545140eb 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,7 @@ # limitations under the License. # +from mdns_discovery import mdns_discovery import asyncio import os import random @@ -33,7 +34,6 @@ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -from mdns_discovery import mdns_discovery # isort: on From da573e1ffb84c5cc3dfa4dd302093ac3dbfd98ed Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 18:00:31 +0000 Subject: [PATCH 051/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 02cfb1545140eb..618c9721b04623 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,7 +16,6 @@ # limitations under the License. # -from mdns_discovery import mdns_discovery import asyncio import os import random @@ -27,6 +26,7 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery from mobly import asserts # isort: off From 629fbb2577d4ec5ce116d7b214d972d0b0f1224a Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 11:02:37 -0700 Subject: [PATCH 052/104] Updating test_TC_CADMIN_1_4 unit-test module: - Updating to get isort to not sort dependicies for this test --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 618c9721b04623..06798d73757ded 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -26,16 +26,15 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery -from mobly import asserts # isort: off parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) - +from mdns_discovery import mdns_discovery # isort: on +from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From 1d5f2a8b6429ada40fa6b81c29b92e4010a3e18d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 18:04:17 +0000 Subject: [PATCH 053/104] Restyled by autopep8 --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 06798d73757ded..7817bb4cb39ad6 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,6 +16,8 @@ # limitations under the License. # +from mobly import asserts +from mdns_discovery import mdns_discovery import asyncio import os import random @@ -31,10 +33,8 @@ parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(parent_dir) -from mdns_discovery import mdns_discovery # isort: on -from mobly import asserts # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file From e33e86f2faf8853820f6d90427618e58ca537ad0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 18:04:19 +0000 Subject: [PATCH 054/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 7817bb4cb39ad6..04b0d1d69d2f14 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -16,8 +16,6 @@ # limitations under the License. # -from mobly import asserts -from mdns_discovery import mdns_discovery import asyncio import os import random @@ -28,6 +26,8 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery +from mobly import asserts # isort: off From b05ef0e3335ecabaa3e8f3d4eb9386819c94b20b Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 11:06:05 -0700 Subject: [PATCH 055/104] Updating test_TC_CADMIN_1_4 unit-test module: - Reverting back to setting dependency in test function as not able to get isort to not sort it out of position --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 04b0d1d69d2f14..47b7a4e47ba8f3 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -26,15 +26,8 @@ from chip.interaction_model import Status from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery from mobly import asserts -# isort: off - -parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.append(parent_dir) - -# isort: on # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file @@ -64,6 +57,9 @@ async def get_rcac_decoded(self, th: str) -> int: return th_rcac_decoded async def get_txt_record(self): + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + sys.path.append(parent_dir) + from mdns_discovery import mdns_discovery discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) comm_service = await discovery.get_commissionable_service( discovery_timeout_sec=240, From a2f367fe35dc2a92084f712bb88d6c9c796df64f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 18:07:48 +0000 Subject: [PATCH 056/104] Restyled by isort --- src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 47b7a4e47ba8f3..083600da23a9f4 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -28,7 +28,6 @@ from chip.tlv import TLVReader from mobly import asserts - # Reachable attribute is off in the pics file # MaxPathsPerInvoke is not include in the pics file # Vendor ID is included on ON in the PICS file From 9079f771aec9284a4d8d5039867cbae229221a31 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 13:41:32 -0700 Subject: [PATCH 057/104] Added TC_CADMIN_1_4_noreset test module and updated test_TC_CADMIN_1_4: - Added TC_CADMIN_1_4_noreset test module to attempt validation of script with no factory reset between tests - Updated test_TC_CADMIN_1_4 unit-test module to exit if credentials not found. --- src/python_testing/TC_CADMIN_1_4_noreset.py | 201 ++++++++++++++++++ .../test_testing/test_TC_CADMIN_1_4.py | 3 +- 2 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 src/python_testing/TC_CADMIN_1_4_noreset.py diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py new file mode 100644 index 00000000000000..e724f3e8639e97 --- /dev/null +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -0,0 +1,201 @@ +#!/usr/bin/env -S python3 -B +# +# 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: +# app: ${ALL_CLUSTERS_APP} +# factory-reset: false +# quiet: true +# 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 +# === END CI TEST ARGUMENTS === + +import asyncio +import os +import random +import sys + +import chip.clusters as Clusters +from chip import ChipDeviceCtrl +from chip.interaction_model import Status +from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main, TestStep +from chip.tlv import TLVReader +from mdns_discovery import mdns_discovery +from mobly import asserts + +# Reachable attribute is off in the pics file +# MaxPathsPerInvoke is not include in the pics file +# Vendor ID is included on ON in the PICS file + +opcreds = Clusters.OperationalCredentials +nonce = random.randbytes(32) + +class TC_CADMIN_1_4_noreset(MatterBaseTest): + async def get_fabrics(self, th: ChipDeviceCtrl) -> int: + OC_cluster = Clusters.OperationalCredentials + if th == self.th2: + th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) + th2_fabric_data = list(th2_fabric_info.values())[0] + th2_fabric_data = list(th2_fabric_data.values())[0] + fabric_info = vars(list(th2_fabric_data.values())[1][0]) + + else: + fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + return fabric_info + + async def get_rcac_decoded(self, th: str) -> int: + csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) + TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) + th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] + return th_rcac_decoded + + async def get_txt_record(self): + discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) + comm_service = await discovery.get_commissionable_service( + discovery_timeout_sec=240, + log_output=False, + ) + return comm_service + + async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): + result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") + + async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): + try: + await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) + except Exception as e: + asserts.assert_equal(e.err, "Received error message from read attribute attempt") + self.print_step(0, e) + + async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: + cluster = Clusters.OperationalCredentials + attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex + current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) + return current_fabric_index + + @async_test_body + def pics_TC_CADMIN_1_4(self) -> list[str]: + return ["CADMIN.S"] + + def steps_TC_CADMIN_1_4(self) -> list[TestStep]: + return [ + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=False), + TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), + TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", + "DUT_CE opens its Commissioning window to allow a second commissioning."), + TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=1"), + TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", + "Verify DUT_CE responds to both write/read with a success"), + TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", + "Commissioning is successful"), + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), + TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), + TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", + "TH_CR1 removes TH_CR2 fabric using th2_idx") + ] + + @async_test_body + async def test_TC_CADMIN_1_4(self): + self.step(1) + setupPayloadInfo = self.get_setup_payload_info() + if not setupPayloadInfo: + asserts.assert_true( + False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') + + # 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("3a") + obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) + + self.step("3b") + services = await self.get_txt_record() + if services.txt_record['CM'] != "1": + asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + + self.step("3c") + BI_cluster = Clusters.BasicInformation + nl_attribute = BI_cluster.Attributes.NodeLabel + await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) + await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) + + self.step(4) + # Establishing TH2 + 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) + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) + + self.step(5) + # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th1_fabric_info = await self.get_fabrics(th=self.th1) + + # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) + if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH1 are not the same") + if th1_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") + + # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. + await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(6) + # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read + th2_fabric_info = await self.get_fabrics(th=self.th2) + + # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) + if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH2 are not the same") + if th2_fabric_info['nodeID'] != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + + await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + + self.step(7) + # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx + th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) + outer_key = list(th2_idx.keys())[0] + inner_key = list(th2_idx[outer_key].keys())[0] + attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + +if __name__ == "__main__": + default_matter_test_main() diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 083600da23a9f4..7a500635831946 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -89,7 +89,8 @@ async def test_TC_CADMIN_1_4(self): if not setupPayloadInfo: asserts.assert_true( False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') - + sys.exit(0) + # Establishing TH1 self.th1 = self.default_controller From 6dc2606c24eae2be78b68215434d1ba50f3a6a55 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 20:44:06 +0000 Subject: [PATCH 058/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_4_noreset.py | 2 ++ src/python_testing/test_testing/test_TC_CADMIN_1_4.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index e724f3e8639e97..a968cb77d16909 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -51,6 +51,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN_1_4_noreset(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -197,5 +198,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py index 7a500635831946..8e1cc5b0a8fa9e 100644 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py @@ -90,7 +90,7 @@ async def test_TC_CADMIN_1_4(self): asserts.assert_true( False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') sys.exit(0) - + # Establishing TH1 self.th1 = self.default_controller From 82236ad54b8c8fb2ba1442f4ecad8ba2d0ca92e9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 17 Oct 2024 20:44:09 +0000 Subject: [PATCH 059/104] Restyled by isort --- src/python_testing/TC_CADMIN_1_4_noreset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index a968cb77d16909..3d765b9f621265 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -39,7 +39,7 @@ import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.interaction_model import Status -from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main, TestStep +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from chip.tlv import TLVReader from mdns_discovery import mdns_discovery from mobly import asserts From 2a6a8d1908923f26a7af09ab85c1d12df643f851 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 13:55:11 -0700 Subject: [PATCH 060/104] Updated TC_CADMIN_1_4_noreset test module: - Resolving lint issues --- src/python_testing/TC_CADMIN_1_4_noreset.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index 3d765b9f621265..09d6ce5448f1bb 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -31,10 +31,7 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # === END CI TEST ARGUMENTS === -import asyncio -import os import random -import sys import chip.clusters as Clusters from chip import ChipDeviceCtrl From 655e69952680e8076bd31895e2c0822dabbf655f Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 15:52:29 -0700 Subject: [PATCH 061/104] Updated TC_CADMIN_1_4_noreset test module: - reorganizing CI args to attempt testing with factory-reset disabled --- src/python_testing/TC_CADMIN_1_4_noreset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index 09d6ce5448f1bb..1001df080c1cb5 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -19,8 +19,6 @@ # test-runner-runs: # run1: # app: ${ALL_CLUSTERS_APP} -# factory-reset: false -# quiet: true # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > # --storage-path admin_storage.json @@ -29,6 +27,8 @@ # --passcode 20202021 # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# factory-reset: false +# quiet: true # === END CI TEST ARGUMENTS === import random From 2c725ca62c49cb5c17da2423d46f7cd2205dd583 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 17 Oct 2024 23:27:11 -0700 Subject: [PATCH 062/104] Updating TC_CADMIN_1_4_noreset, tests.yaml, and execute_python_test: - Updating to attempt to get TC_CADMIN_1_4_noreset to get it to run in CI --- .github/workflows/tests.yaml | 2 ++ src/python_testing/TC_CADMIN_1_4_noreset.py | 4 ++-- src/python_testing/execute_python_tests.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 571f72853d9d51..57ae6d9f841402 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -522,6 +522,8 @@ jobs: run: | mkdir -p out/trace_data scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/controller/python/test/test_scripts/mobile-device-test.py' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_CADMIN_1_3_4.py' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --no-factory-reset --script src/python_testing/TC_CADMIN_1_4_noreset.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/execute_python_tests.py --env-file /tmp/test_env.yaml --search-directory src/python_testing' scripts/run_in_python_env.sh out/venv './scripts/tests/TestTimeSyncTrustedTimeSourceRunner.py --all-clusters out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test-data-model-check-check-failure-die/chip-all-clusters-app' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestIdChecks.py' diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index 1001df080c1cb5..814535d14e2381 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -28,7 +28,7 @@ # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: false -# quiet: true +# quiet: false # === END CI TEST ARGUMENTS === import random @@ -99,7 +99,7 @@ def pics_TC_CADMIN_1_4(self) -> list[str]: def steps_TC_CADMIN_1_4(self) -> list[TestStep]: return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=False), + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", 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("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), diff --git a/src/python_testing/execute_python_tests.py b/src/python_testing/execute_python_tests.py index 34a391873b3101..ad72d443ee6a1e 100644 --- a/src/python_testing/execute_python_tests.py +++ b/src/python_testing/execute_python_tests.py @@ -64,6 +64,7 @@ def main(search_directory, env_file): "TC_OpstateCommon.py", # Shared code for TC_OPSTATE, not a standalone test "TC_pics_checker.py", # Currently isn't enabled because we don't have any examples with conformant PICS "TC_TMP_2_1.py", # src/python_testing/test_testing/test_TC_TMP_2_1.py is the Unit test of this test + "TC_CADMIN_1_4_noreset.py", # Run only to verify that TC_CADMIN_1_4 works correctly at the end of src/python_testing/TC_CADMIN_1_3_4.py "TC_OCC_3_1.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TC_OCC_3_2.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TestCommissioningTimeSync.py", # Code/Test not being used or not shared code for any other tests From e2dcbed5ee77536b7864709c84ed2a59f9e73577 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 18 Oct 2024 06:29:57 +0000 Subject: [PATCH 063/104] Restyled by autopep8 --- src/python_testing/execute_python_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/execute_python_tests.py b/src/python_testing/execute_python_tests.py index ad72d443ee6a1e..62980d7bf65b3a 100644 --- a/src/python_testing/execute_python_tests.py +++ b/src/python_testing/execute_python_tests.py @@ -64,7 +64,7 @@ def main(search_directory, env_file): "TC_OpstateCommon.py", # Shared code for TC_OPSTATE, not a standalone test "TC_pics_checker.py", # Currently isn't enabled because we don't have any examples with conformant PICS "TC_TMP_2_1.py", # src/python_testing/test_testing/test_TC_TMP_2_1.py is the Unit test of this test - "TC_CADMIN_1_4_noreset.py", # Run only to verify that TC_CADMIN_1_4 works correctly at the end of src/python_testing/TC_CADMIN_1_3_4.py + "TC_CADMIN_1_4_noreset.py", # Run only to verify that TC_CADMIN_1_4 works correctly at the end of src/python_testing/TC_CADMIN_1_3_4.py "TC_OCC_3_1.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TC_OCC_3_2.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TestCommissioningTimeSync.py", # Code/Test not being used or not shared code for any other tests From 1f6cf68509f46df207c3391a74045dde925ea716 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 18 Oct 2024 06:32:43 -0700 Subject: [PATCH 064/104] Updated TC_CADMIN_1_4_noreset test module: - Removed commissioning-method CI argument to not run commissioning before start of this test --- src/python_testing/TC_CADMIN_1_4_noreset.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index 814535d14e2381..5bf47f3a4f87bc 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -22,7 +22,6 @@ # 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 @@ -93,13 +92,12 @@ async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) return current_fabric_index - @async_test_body - def pics_TC_CADMIN_1_4(self) -> list[str]: + def pics_TC_CADMIN_1_4_noreset(self) -> list[str]: return ["CADMIN.S"] - def steps_TC_CADMIN_1_4(self) -> list[TestStep]: + def steps_TC_CADMIN_1_4_noreset(self) -> list[TestStep]: return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE", is_commissioning=True), + TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE"), TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", "DUT_CE opens its Commissioning window to allow a second commissioning."), @@ -117,12 +115,12 @@ def steps_TC_CADMIN_1_4(self) -> list[TestStep]: ] @async_test_body - async def test_TC_CADMIN_1_4(self): + async def test_TC_CADMIN_1_4_noreset(self): self.step(1) setupPayloadInfo = self.get_setup_payload_info() if not setupPayloadInfo: asserts.assert_true( - False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') + False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test providing --passcode and --discriminator ') # Establishing TH1 self.th1 = self.default_controller From 4c4edaa8bab90f13d9a849df7e688e08fc840b0e Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 18 Oct 2024 09:18:54 -0700 Subject: [PATCH 065/104] Delete src/python_testing/test_testing/test_TC_CADMIN_1_4.py Removing unneeded small unit-test due to not needed --- .../test_testing/test_TC_CADMIN_1_4.py | 160 ------------------ 1 file changed, 160 deletions(-) delete mode 100644 src/python_testing/test_testing/test_TC_CADMIN_1_4.py diff --git a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py b/src/python_testing/test_testing/test_TC_CADMIN_1_4.py deleted file mode 100644 index 8e1cc5b0a8fa9e..00000000000000 --- a/src/python_testing/test_testing/test_TC_CADMIN_1_4.py +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env -S python3 -B -# -# 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. -# - -import asyncio -import os -import random -import sys - -import chip.clusters as Clusters -from chip import ChipDeviceCtrl -from chip.interaction_model import Status -from chip.testing.matter_testing import MatterBaseTest, async_test_body, default_matter_test_main -from chip.tlv import TLVReader -from mobly import asserts - -# Reachable attribute is off in the pics file -# MaxPathsPerInvoke is not include in the pics file -# Vendor ID is included on ON in the PICS file - -opcreds = Clusters.OperationalCredentials -nonce = random.randbytes(32) - - -class TC_CADMIN_1_4_noreset(MatterBaseTest): - async def get_fabrics(self, th: ChipDeviceCtrl) -> int: - OC_cluster = Clusters.OperationalCredentials - if th == self.th2: - th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) - th2_fabric_data = list(th2_fabric_info.values())[0] - th2_fabric_data = list(th2_fabric_data.values())[0] - fabric_info = vars(list(th2_fabric_data.values())[1][0]) - - else: - fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) - return fabric_info - - async def get_rcac_decoded(self, th: str) -> int: - csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) - TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) - th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] - return th_rcac_decoded - - async def get_txt_record(self): - parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - sys.path.append(parent_dir) - from mdns_discovery import mdns_discovery - discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) - comm_service = await discovery.get_commissionable_service( - discovery_timeout_sec=240, - log_output=False, - ) - return comm_service - - async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): - result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) - asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") - - async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): - try: - await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) - except Exception as e: - asserts.assert_equal(e.err, "Received error message from read attribute attempt") - self.print_step(0, e) - - async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: - cluster = Clusters.OperationalCredentials - attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex - current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) - return current_fabric_index - - @async_test_body - async def test_TC_CADMIN_1_4(self): - setupPayloadInfo = self.get_setup_payload_info() - if not setupPayloadInfo: - asserts.assert_true( - False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test with providing --passcode and --discriminator ') - sys.exit(0) - - # Establishing TH1 - self.th1 = self.default_controller - - 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 - - obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) - - services = await self.get_txt_record() - if services.txt_record['CM'] != "1": - asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") - - BI_cluster = Clusters.BasicInformation - nl_attribute = BI_cluster.Attributes.NodeLabel - await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) - await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) - - # Establishing TH2 - 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) - await self.th2.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) - - # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th1_fabric_info = await self.get_fabrics(th=self.th1) - - # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) - if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH1 are not the same") - if th1_fabric_info[0].nodeID != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - - # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - - # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_info = await self.get_fabrics(th=self.th2) - - # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) - th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info['nodeID'] != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") - - await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - - # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx - th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) - outer_key = list(th2_idx.keys())[0] - inner_key = list(th2_idx[outer_key].keys())[0] - attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] - removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - - -if __name__ == "__main__": - asyncio.run(default_matter_test_main()) - sys.exit(0) From 68d87ee8ba378de47eee0bf09cbef6dab3e5e0f2 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 18 Oct 2024 09:20:21 -0700 Subject: [PATCH 066/104] Update tests.yaml Removed prior unit-test test_TC_CADMIN_1_4.py as it was deleted --- .github/workflows/tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 57ae6d9f841402..67794557f3c0e5 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -533,7 +533,6 @@ jobs: scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestChoiceConformanceSupport.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestMatterTestingSupport.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestSpecParsingSupport.py' - scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_CADMIN_1_4.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_ICDM_2_1.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_IDM_10_4.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/test_testing/test_TC_SC_7_1.py' From 854da170bf84ed81f5345e63b76fee891f8d4654 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 18 Oct 2024 09:23:10 -0700 Subject: [PATCH 067/104] Removed Test_TC_CADMIN_1_3 and Test_TC_CADMIN_1_4 yaml's: - These 2 yaml scripts are no longer needed as they are being replaced by the python test modules. --- .../certification/Test_TC_CADMIN_1_3.yaml | 549 ------------------ .../certification/Test_TC_CADMIN_1_4.yaml | 369 ------------ 2 files changed, 918 deletions(-) delete mode 100644 src/app/tests/suites/certification/Test_TC_CADMIN_1_3.yaml delete mode 100644 src/app/tests/suites/certification/Test_TC_CADMIN_1_4.yaml diff --git a/src/app/tests/suites/certification/Test_TC_CADMIN_1_3.yaml b/src/app/tests/suites/certification/Test_TC_CADMIN_1_3.yaml deleted file mode 100644 index fbe4e2b7615d36..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_CADMIN_1_3.yaml +++ /dev/null @@ -1,549 +0,0 @@ -# Copyright (c) 2023 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: 24.1.3. [TC-CADMIN-1.3] Node Behavior using ECM [DUT - Commissionee] - -PICS: - - CADMIN.S - -config: - nodeId: 0x12344321 - timeout: 300 - nodeId2: - type: node_id - defaultValue: 0xCAFE - endpoint: 0 - discriminator: - type: int16u - defaultValue: 3840 - payload: - type: char_string - defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically - PakeVerifier: - type: octet_string - defaultValue: "hex:b96170aae803346884724fe9a3b287c30330c2a660375d17bb205a8cf1aecb350457f8ab79ee253ab6a8e46bb09e543ae422736de501e3db37d441fe344920d09548e4c18240630c4ff4913c53513839b7c07fcc0627a1b8573a149fcd1fa466cf" - waitAfterCommissioning: - type: int16u - defaultValue: 5000 - PIXIT.CADMIN.CwDuration: - type: int16u - defaultValue: 180 - -tests: - - label: "Precondition: Reset Devices to factory defaults" - PICS: PICS_SDK_CI_ONLY - cluster: "SystemCommands" - command: "FactoryReset" - - - label: "Precondition: Reset Devices to factory defaults" - verification: | - Reset Devices to factory defaults - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP - arguments: - values: - - name: "message" - value: "Factory Reset the DUT and enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 1a: TH_CR1 starts a commissioning process with DUT_CE" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - name: "payload" - value: payload - - - label: "Step 1b: TH_CR1 commissioned with DUT_CE" - cluster: "DelayCommands" - command: "WaitForCommissionee" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - - label: - "Step 1c: TH1 reads CurrentFabricIndex attribute and save it for - future use." - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "CurrentFabricIndex" - response: - saveAs: TH1FabricIndex - - - label: - "Step 2a: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - - label: "Waiting after opening commissioning window" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 2a: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - - ./chip-tool pairing open-commissioning-window 1 1 PIXIT.CADMIN.CwDuration 2000 3840 - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - [1635864513.699636][3850:3855] CHIP:EM: Sending Standalone Ack for MessageCounter:2599714227 on exchange 60688i - [1635864513.699685][3850:3855] CHIP:IN: Prepared plaintext message 0xffff8a7cd960 to 0x0000000000000000 of type 0x10 - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 2b: DNS-SD records shows DUT_CE advertising.Verify that the - DNS-SD advertisement shows CM=2" - PICS: CADMIN.S.C00.Rsp - cluster: "DiscoveryCommands" - command: "FindCommissionable" - response: - values: - - name: "commissioningMode" - value: 2 - - - label: - "Step 2c: TH_CR1 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "writeAttribute" - PICS: BINFO.S.A0005 - cluster: "Basic Information" - attribute: "NodeLabel" - arguments: - value: "chiptest" - - - label: - "Step 2c: TH_CR1 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "readAttribute" - PICS: BINFO.S.A0005 - cluster: "Basic Information" - attribute: "NodeLabel" - response: - value: "chiptest" - constraints: - type: char_string - maxLength: 32 - - - label: "Step 3a: TH_CR2 starts a commissioning process with DUT_CE" - identity: "beta" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - cluster: "CommissionerCommands" - command: "PairWithCode" - arguments: - values: - - name: "nodeId" - value: nodeId2 - - name: "payload" - value: payload - - - label: "Step 3b: DUT_CE is commissioned by TH_CR2 on Fabric ID2" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - identity: "beta" - cluster: "DelayCommands" - command: "WaitForCommissionee" - arguments: - values: - - name: "nodeId" - value: nodeId2 - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 3: TH_CR2 starts a commissioning process with DUT_CE" - verification: | - On TH_CR2 send the below command - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 --commissioner-name beta - - Verify the below message in the TH_CR2(chip-tool) Log: - - Device commissioning completed with successoning step 'Cleanup' - [1657186359.584743][3509:3514] CHIP:TOO: Device commissioning completed with success - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 3c: TH2 reads CurrentFabricIndex attribute and save it for - future use." - identity: "beta" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "CurrentFabricIndex" - response: - saveAs: TH2FabricIndex - - - label: - "Step 4: Verify DUT_CE is now discoverable over DNS-SD with two SRV - Records" - verification: | - On TH_CR2 send the below command - - Verify if the DUT_CE is broadcasting using - - avahi-browse -rt _matter._tcp - - On TH_CR2(chip-tool) Verify DUT_CE is now discoverable over DNS-SD with two SRV Records - - + eth0 IPv6 9B9C01C971F4119F-0000000000000001 _matter._tcp local - + eth0 IPv6 C8A60CCA27F33379-0000000000000002 _matter._tcp local - = eth0 IPv6 9B9C01C971F4119F-0000000000000001 _matter._tcp local - hostname = [E45F010F27530000.local] - address = [fe80::e65f:1ff:fe0f:2753] - port = [5540] - txt = ["T=1" "SAI=300" "SII=5000"] - = eth0 IPv6 C8A60CCA27F33379-0000000000000002 _matter._tcp local - hostname = [E45F010F27530000.local] - address = [fe80::e65f:1ff:fe0f:2753] - port = [5540] - txt = ["T=1" "SAI=300" "SII=5000"] - ubuntu@ubuntu:~/may16_cntrl/connectedhomeip/examples/chip-tool/out/debug$ - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP - arguments: - values: - - name: "message" - value: "enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 5: TH_CR1 reads the list of Fabrics on DUT_CE" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "Fabrics" - PICS: OPCREDS.S.A0001 - fabricFiltered: false - response: - constraints: - type: list - contains: - [ - { - Label: "", - FabricIndex: TH1FabricIndex, - NodeID: nodeId, - }, - { - Label: "", - FabricIndex: TH2FabricIndex, - NodeID: nodeId2, - }, - ] - - - label: "Step 6: TH_CR2 reads the list of Fabrics on DUT_CE" - identity: "beta" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "Fabrics" - PICS: OPCREDS.S.A0001 - fabricFiltered: false - response: - constraints: - type: list - contains: - [ - { - Label: "", - FabricIndex: TH1FabricIndex, - NodeID: nodeId, - }, - { - Label: "", - FabricIndex: TH2FabricIndex, - NodeID: nodeId2, - }, - ] - - - label: - "Step 7a: TH_CR1 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "writeAttribute" - cluster: "Basic Information" - PICS: BINFO.S.A0005 - attribute: "NodeLabel" - arguments: - value: "chiptest1" - - - label: - "Step 7b: TH_CR1 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "readAttribute" - cluster: "Basic Information" - PICS: BINFO.S.A0005 - attribute: "NodeLabel" - response: - value: "chiptest1" - constraints: - type: char_string - maxLength: 32 - - - label: - "Step 8a: TH_CR2 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - identity: "beta" - command: "writeAttribute" - cluster: "Basic Information" - PICS: BINFO.S.A0005 - attribute: "NodeLabel" - arguments: - value: "chiptest2" - - - label: - "Step 8b: TH_CR2 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - identity: "beta" - command: "readAttribute" - cluster: "Basic Information" - PICS: BINFO.S.A0005 - attribute: "NodeLabel" - response: - value: "chiptest2" - constraints: - type: char_string - maxLength: 32 - - - label: "Step 9: TH_CR2 opens a commissioning window on DUT_CE using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - identity: "beta" - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 9: TH_CR2 opens a commissioning window on DUT_CE using ECM" - verification: | - On TH_CR2 send the below command - - ./chip-tool pairing open-commissioning-window nodeId2 endpoint PIXIT.CADMIN.CwDuration 1000 3840 --commissioner-name beta - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 10: Wait for the commissioning window in step 9 to timeout" - PICS: CADMIN.S.C00.Rsp - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: PIXIT.CADMIN.CwDuration * 1000 - - - label: - "Step 11: TH_CR2 reads the window status to verify the DUT_CE window - is closed" - cluster: "Administrator Commissioning" - PICS: CADMIN.S.A0000 - command: "readAttribute" - attribute: "WindowStatus" - response: - value: 0 - - - label: "Step 12: TH_CR2 opens a commissioning window on DUT_CE using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - identity: "beta" - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - - label: "Waiting after opening commissioning window" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 12: TH_CR2 opens a commissioning window on DUT_CE using ECM" - verification: | - On TH_CR2 send the below command - - ./chip-tool pairing open-commissioning-window 2 1 PIXIT.CADMIN.CwDuration 1000 3840 --commissioner-name beta - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - [1635864513.699636][3850:3855] CHIP:EM: Sending Standalone Ack for MessageCounter:2599714227 on exchange 60688i - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 13: TH_CR1 starts a commissioning process with DUT_CE before the - timeout from step 12" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - arguments: - values: - - name: "nodeId" - value: nodeId - - name: "payload" - value: payload - response: - error: FAILURE - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 13: TH_CR1 starts a commissioning process with DUT_CE before the - timeout from step 12" - verification: | - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 - - Verify the OperationalCert error 9 in DUT_CE(all-clusters-app) Log - - [1660902716.613196][3045:3045] CHIP:DMG: Command handler moving to [AddedComma] - [1660902716.613274][3045:3045] CHIP:ZCL: OpCreds: Failed AddNOC request (err=../../examples/all-clusters-app/linux/third_party/connectedhomeip/src/credentials/FabricTable.cpp:1692: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists) with OperationalCert error 9 - [1660902716.613394][3045:3045] CHIP:DMG: Decreasing reference count for CommandHandler, remaining 0 - [1660902716.613497][3045:3045] CHIP:EM: Piggybacking Ack for MessageCounter:176866087 on exchange: 56605r - - Trying to add a NOC for a fabric that already exists On TH_CR1(chip-tool) Log - - [1651786200275] [36301:315544] CHIP: [DMG] Received Command Response Data, Endpoint=0 Cluster=0x0000_003E Command=0x0000_0008 - [1651786200275] [36301:315544] CHIP: [CTL] Device returned status 9 on receiving the NOC - [1651786200275] [36301:315544] CHIP: [CTL] Add NOC failed with error ../../src/controller/CHIPDeviceController.cpp:1187: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists - [1651786200275] [36301:315544] CHIP: [CTL] Error on commissioning step 'SendNOC': '../../src/controller/CHIPDeviceController.cpp:1187: CHIP Error 0x0000007E: Trying to add a NOC for a fabric that already exists' - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Remove TH2 FabricIndex" - PICS: OPCREDS.S.C0a.Rsp && CADMIN.S - identity: "beta" - cluster: "Operational Credentials" - command: "RemoveFabric" - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "FabricIndex" - value: TH2FabricIndex diff --git a/src/app/tests/suites/certification/Test_TC_CADMIN_1_4.yaml b/src/app/tests/suites/certification/Test_TC_CADMIN_1_4.yaml deleted file mode 100644 index 7c4eb7420173b3..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_CADMIN_1_4.yaml +++ /dev/null @@ -1,369 +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. - -name: 24.1.4. [TC-CADMIN-1.4] Node Behavior using BCM [DUT - Commissionee] - -PICS: - - CADMIN.S - - CADMIN.S.F00 - -config: - nodeId: 0x12344321 - timeout: 300 - nodeId2: - type: node_id - defaultValue: 0xCAFE - endpoint: 0 - payload: - type: char_string - defaultValue: "MT:-24J0AFN00KA0648G00" - waitAfterCommissioning: - type: int16u - defaultValue: 5000 - PIXIT.CADMIN.CwDuration: - type: int16u - defaultValue: 180 - -tests: - - label: "Precondition: Reset Devices to factory defaults" - PICS: PICS_SDK_CI_ONLY - cluster: "SystemCommands" - command: "FactoryReset" - - - label: "Precondition: Reset Devices to factory defaults" - verification: | - Reset Devices to factory defaults - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP - arguments: - values: - - name: "message" - value: "Factory Reset the DUT and enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 1a: TH_CR1 starts a commissioning process with DUT_CE" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - name: "payload" - value: payload - - - label: "Step 1a: TH_CR1 commissioned with DUT_CE" - cluster: "DelayCommands" - command: "WaitForCommissionee" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - - label: - "Step 1b: TH1 reads CurrentFabricIndex attribute and save it for - future use." - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "CurrentFabricIndex" - response: - saveAs: TH1FabricIndex - - - label: "Step 2a: TH_CR1 opens a commissioning window on DUT_CE using BCM" - cluster: "Administrator Commissioning" - command: "OpenBasicCommissioningWindow" - PICS: CADMIN.S.C01.Rsp - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - - label: "Step 2a: Waiting after opening commissioning window" - PICS: CADMIN.S.C01.Rsp - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - - label: "Step 2b: Verify that the DNS-SD advertisement shows CM=1" - PICS: CADMIN.S.C01.Rsp - cluster: "DiscoveryCommands" - command: "FindCommissionable" - response: - values: - - name: "commissioningMode" - value: 1 - - - label: - "Step 2c: TH_CR1 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "writeAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - arguments: - value: "chiptest" - - - label: - "Step 2d: TH_CR1 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "readAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - response: - constraints: - type: char_string - maxLength: 32 - - - label: "Step 3a: TH_CR2 starts a commissioning process with DUT_CE" - identity: "beta" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId2 - - name: "payload" - value: payload - - - label: "Step 3b: DUT_CE is commissioned by TH_CR2 on Fabric ID2 " - identity: "beta" - cluster: "DelayCommands" - command: "WaitForCommissionee" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId2 - - - label: - "Step 3c: TH2 reads CurrentFabricIndex attribute and save it for - future use." - identity: "beta" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "CurrentFabricIndex" - response: - saveAs: TH2FabricIndex - - #Check for DNS-SD advertisement is not possible in YAML - - label: - "Step 4: Verify DUT_CE is now discoverable over DNS-SD with two SRV - Records" - verification: | - On TH_CR2 send the below command - - Verify if the DUT_CE is broadcasting using - - avahi-browse -rt _matter._tcp - + eth0 IPv6 C8A60CCA27F33379-0000000000000002 _matter._tcp local - + eth0 IPv6 3C26C93CF201458F-0000000000000001 _matter._tcp local - = eth0 IPv6 C8A60CCA27F33379-0000000000000002 _matter._tcp local - hostname = [E45F010F27530000.local] - address = [fe80::e65f:1ff:fe0f:2753] - port = [5540] - txt = ["T=1" "SAI=300" "SII=5000"] - = eth0 IPv6 3C26C93CF201458F-0000000000000001 _matter._tcp local - hostname = [E45F010F27530000.local] - address = [fe80::e65f:1ff:fe0f:2753] - port = [5540] - txt = ["T=1" "SAI=300" "SII=5000"] - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP - arguments: - values: - - name: "message" - value: "enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 5: TH_CR1 reads the list of Fabrics on DUT_CE" - command: "readAttribute" - cluster: "Operational Credentials" - PICS: OPCREDS.S.A0001 - attribute: "Fabrics" - fabricFiltered: false - response: - constraints: - type: list - contains: - [ - { - Label: "", - FabricIndex: TH1FabricIndex, - NodeID: nodeId, - }, - { - Label: "", - FabricIndex: TH2FabricIndex, - NodeID: nodeId2, - }, - ] - - - label: "Step 6: TH_CR2 reads the list of Fabrics on DUT_CE" - identity: "beta" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "Fabrics" - PICS: OPCREDS.S.A0001 - fabricFiltered: false - response: - constraints: - type: list - contains: - [ - { - Label: "", - FabricIndex: TH1FabricIndex, - NodeID: nodeId, - }, - { - Label: "", - FabricIndex: TH2FabricIndex, - NodeID: nodeId2, - }, - ] - - - label: - "Step 7a: TH_CR1 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "writeAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - arguments: - value: "chiptest" - - - label: - "Step 7b: TH_CR1 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - command: "readAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - response: - value: "chiptest" - constraints: - type: char_string - maxLength: 32 - - - label: - "Step 8a: TH_CR2 writes the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - identity: "beta" - command: "writeAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - arguments: - value: "chiptest" - - - label: - "Step 8b: TH_CR2 reads the Basic Information Clusters NodeLabel - mandatory attribute of DUT_CE" - identity: "beta" - command: "readAttribute" - cluster: "Basic Information" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - response: - value: "chiptest" - constraints: - type: char_string - maxLength: 32 - - - label: "Step 9: TH_CR2 opens a commissioning window on DUT_CE using BCM" - cluster: "Administrator Commissioning" - command: "OpenBasicCommissioningWindow" - identity: "beta" - PICS: CADMIN.S.C01.Rsp - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - - label: "Step 10: Wait for the commissioning window in step 13 to timeout" - PICS: CADMIN.S.C01.Rsp - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: PIXIT.CADMIN.CwDuration * 1000 - - - label: - "Step 11: TH_CR2 reads the window status to verify the DUT_CE window - is closed" - cluster: "Administrator Commissioning" - PICS: CADMIN.S.A0000 - command: "readAttribute" - attribute: "WindowStatus" - response: - value: 0 - - - label: "Step 12a: TH_CR2 opens a commissioning window on DUT_CE using BCM" - cluster: "Administrator Commissioning" - command: "OpenBasicCommissioningWindow" - identity: "beta" - PICS: CADMIN.S.C01.Rsp - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - - label: "Step 12b: Waiting after opening commissioning window" - PICS: CADMIN.S.C01.Rsp - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - - label: - "Step 13a: TH_CR1 starts a commissioning process with DUT_CE before - the timeout from step 12" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - name: "payload" - value: payload - response: - error: FAILURE - - - label: "Remove TH2 FabricIndex" - PICS: OPCREDS.S.C0a.Rsp && CADMIN.S - identity: "beta" - cluster: "Operational Credentials" - command: "RemoveFabric" - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "FabricIndex" - value: TH2FabricIndex From ab6f90714c013efac19a9a31b4bac14c755fdbf5 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 18 Oct 2024 09:54:25 -0700 Subject: [PATCH 068/104] Updated TC_CADMIN_1_3_4 and TC_CADMIN_1_4_noreset: - Disabled verbose output in CI arguments (quiet mode) --- src/python_testing/TC_CADMIN_1_3_4.py | 4 ++-- src/python_testing/TC_CADMIN_1_4_noreset.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index a2e43e3fd631f6..7462ddc0cd0818 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -18,8 +18,6 @@ # test-runner-runs: # run1: # app: ${ALL_CLUSTERS_APP} -# factory-reset: true -# quiet: true # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > # --storage-path admin_storage.json @@ -28,6 +26,8 @@ # --passcode 20202021 # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# factory-reset: true +# quiet: true # === END CI TEST ARGUMENTS === import asyncio diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py index 5bf47f3a4f87bc..f190a0d4ac2ff5 100644 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ b/src/python_testing/TC_CADMIN_1_4_noreset.py @@ -27,7 +27,7 @@ # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: false -# quiet: false +# quiet: true # === END CI TEST ARGUMENTS === import random From 2e85e98cdffe65c6b85900cb32c5b34e08e9b71c Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 24 Oct 2024 13:30:10 -0700 Subject: [PATCH 069/104] Updating TC_CADMIN_1_3_4 and tests.yaml: - Removed calls in tests.yaml for TC_CADMIN_1_3_4 as not needed individual calls for tests now that we have changed the CI arguments - Removed TC_CADMIN_1_4_noreset standalone test module as we are now using the CI arguments - Removed the line from execute_python_tests test runner module to remove not call for TC_CADMIN_1_4_noreset test module, as no longer needed - Renamed class for tests to TC_CADMIN from TC_CADMIN_1_3_4 to possibly encompaculate all CADMIN tests eventually. - Changed method to get th2_fabric_info to match with the method used to get th1_fabric_info in TC_CADMIN_1_3_4 test module --- .github/workflows/tests.yaml | 2 - src/python_testing/TC_CADMIN_1_3_4.py | 45 ++--- src/python_testing/TC_CADMIN_1_4_noreset.py | 198 -------------------- src/python_testing/execute_python_tests.py | 1 - 4 files changed, 24 insertions(+), 222 deletions(-) delete mode 100644 src/python_testing/TC_CADMIN_1_4_noreset.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 67794557f3c0e5..63957b64d8f00d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -522,8 +522,6 @@ jobs: run: | mkdir -p out/trace_data scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/controller/python/test/test_scripts/mobile-device-test.py' - scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_CADMIN_1_3_4.py' - scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --no-factory-reset --script src/python_testing/TC_CADMIN_1_4_noreset.py' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/execute_python_tests.py --env-file /tmp/test_env.yaml --search-directory src/python_testing' scripts/run_in_python_env.sh out/venv './scripts/tests/TestTimeSyncTrustedTimeSourceRunner.py --all-clusters out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test-data-model-check-check-failure-die/chip-all-clusters-app' scripts/run_in_python_env.sh out/venv 'python3 ./src/python_testing/TestIdChecks.py' diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 7462ddc0cd0818..4a8ee77217ac4f 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -28,6 +28,17 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: true # quiet: true +# run2: +# app: ${ALL_CLUSTERS_APP} +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# script-args: > +# --storage-path admin_storage.json +# --discriminator 1234 +# --passcode 20202021 +# --trace-to json:${TRACE_TEST_JSON}.json +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# factory-reset: false +# quiet: true # === END CI TEST ARGUMENTS === import asyncio @@ -48,17 +59,10 @@ nonce = random.randbytes(32) -class TC_CADMIN_1_3_4(MatterBaseTest): +class TC_CADMIN(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials - if th == self.th2: - th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) - th2_fabric_data = list(th2_fabric_info.values())[0] - th2_fabric_data = list(th2_fabric_data.values())[0] - fabric_info = vars(list(th2_fabric_data.values())[1][0]) - - else: - fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) + fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) return fabric_info async def get_rcac_decoded(self, th: str) -> int: @@ -179,15 +183,15 @@ async def test_TC_CADMIN_1_3(self): self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_data = await self.get_fabrics(th=self.th2) + th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_data["rootPublicKey"] != th2_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_data["nodeID"] != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH1 are not the same") + if th2_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) @@ -342,15 +346,15 @@ async def test_TC_CADMIN_1_4(self): th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) + await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info['nodeID'] != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + asserts.fail("public keys from fabric and certs for TH1 are not the same") + if th2_fabric_info[0].nodeID != self.dut_node_id: + asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - + self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) @@ -360,6 +364,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() diff --git a/src/python_testing/TC_CADMIN_1_4_noreset.py b/src/python_testing/TC_CADMIN_1_4_noreset.py deleted file mode 100644 index f190a0d4ac2ff5..00000000000000 --- a/src/python_testing/TC_CADMIN_1_4_noreset.py +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/bin/env -S python3 -B -# -# 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: -# app: ${ALL_CLUSTERS_APP} -# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json -# script-args: > -# --storage-path admin_storage.json -# --discriminator 1234 -# --passcode 20202021 -# --trace-to json:${TRACE_TEST_JSON}.json -# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto -# factory-reset: false -# quiet: true -# === END CI TEST ARGUMENTS === - -import random - -import chip.clusters as Clusters -from chip import ChipDeviceCtrl -from chip.interaction_model import Status -from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main -from chip.tlv import TLVReader -from mdns_discovery import mdns_discovery -from mobly import asserts - -# Reachable attribute is off in the pics file -# MaxPathsPerInvoke is not include in the pics file -# Vendor ID is included on ON in the PICS file - -opcreds = Clusters.OperationalCredentials -nonce = random.randbytes(32) - - -class TC_CADMIN_1_4_noreset(MatterBaseTest): - async def get_fabrics(self, th: ChipDeviceCtrl) -> int: - OC_cluster = Clusters.OperationalCredentials - if th == self.th2: - th2_fabric_info = await th.ReadAttribute(nodeid=self.dut_node_id, fabricFiltered=True, attributes=[(0, OC_cluster.Attributes.Fabrics)]) - th2_fabric_data = list(th2_fabric_info.values())[0] - th2_fabric_data = list(th2_fabric_data.values())[0] - fabric_info = vars(list(th2_fabric_data.values())[1][0]) - - else: - fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) - return fabric_info - - async def get_rcac_decoded(self, th: str) -> int: - csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) - TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) - th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] - return th_rcac_decoded - - async def get_txt_record(self): - discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) - comm_service = await discovery.get_commissionable_service( - discovery_timeout_sec=240, - log_output=False, - ) - return comm_service - - async def write_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): - result = await th.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) - asserts.assert_equal(result[0].Status, Status.Success, f"{th} node label write failed") - - async def read_nl_attr(self, th: ChipDeviceCtrl, attr_val: object): - try: - await th.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, attr_val)]) - except Exception as e: - asserts.assert_equal(e.err, "Received error message from read attribute attempt") - self.print_step(0, e) - - async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: - cluster = Clusters.OperationalCredentials - attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex - current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) - return current_fabric_index - - def pics_TC_CADMIN_1_4_noreset(self) -> list[str]: - return ["CADMIN.S"] - - def steps_TC_CADMIN_1_4_noreset(self) -> list[TestStep]: - return [ - TestStep(1, "TH_CR1 starts a commissioning process with DUT_CE"), - TestStep(2, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."), - TestStep("3a", "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of max_window_duration using BCM", - "DUT_CE opens its Commissioning window to allow a second commissioning."), - TestStep("3b", "DNS-SD records shows DUT_CE advertising", "Verify that the DNS-SD advertisement shows CM=1"), - TestStep("3c", "TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE", - "Verify DUT_CE responds to both write/read with a success"), - TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", - "Commissioning is successful"), - TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), - TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", - "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), - TestStep(7, "TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx", - "TH_CR1 removes TH_CR2 fabric using th2_idx") - ] - - @async_test_body - async def test_TC_CADMIN_1_4_noreset(self): - self.step(1) - setupPayloadInfo = self.get_setup_payload_info() - if not setupPayloadInfo: - asserts.assert_true( - False, 'passcode and discriminator must be provided values in order for this test to work due to using BCM, please rerun test providing --passcode and --discriminator ') - - # 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("3a") - obcCmd = Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(180) - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=obcCmd, timedRequestTimeoutMs=6000) - - self.step("3b") - services = await self.get_txt_record() - if services.txt_record['CM'] != "1": - asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") - - self.step("3c") - BI_cluster = Clusters.BasicInformation - nl_attribute = BI_cluster.Attributes.NodeLabel - await self.write_nl_attr(th=self.th1, attr_val=nl_attribute) - await self.read_nl_attr(th=self.th1, attr_val=nl_attribute) - - self.step(4) - # Establishing TH2 - 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) - await self.th2.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) - - self.step(5) - # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th1_fabric_info = await self.get_fabrics(th=self.th1) - - # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) - if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH1 are not the same") - if th1_fabric_info[0].nodeID != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - - # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - - self.step(6) - # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read - th2_fabric_info = await self.get_fabrics(th=self.th2) - - # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(self.max_window_duration)) - th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info['rootPublicKey'] != th2_rcac_decoded[9]: - asserts.fail("public keys from fabric and certs for TH2 are not the same") - if th2_fabric_info['nodeID'] != self.dut_node_id: - asserts.fail("DUT node ID from fabric does not match DUT node ID for TH2 during commissioning") - - await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - - self.step(7) - # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx - th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) - outer_key = list(th2_idx.keys())[0] - inner_key = list(th2_idx[outer_key].keys())[0] - attribute_key = list(th2_idx[outer_key][inner_key].keys())[1] - removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - - -if __name__ == "__main__": - default_matter_test_main() diff --git a/src/python_testing/execute_python_tests.py b/src/python_testing/execute_python_tests.py index 62980d7bf65b3a..34a391873b3101 100644 --- a/src/python_testing/execute_python_tests.py +++ b/src/python_testing/execute_python_tests.py @@ -64,7 +64,6 @@ def main(search_directory, env_file): "TC_OpstateCommon.py", # Shared code for TC_OPSTATE, not a standalone test "TC_pics_checker.py", # Currently isn't enabled because we don't have any examples with conformant PICS "TC_TMP_2_1.py", # src/python_testing/test_testing/test_TC_TMP_2_1.py is the Unit test of this test - "TC_CADMIN_1_4_noreset.py", # Run only to verify that TC_CADMIN_1_4 works correctly at the end of src/python_testing/TC_CADMIN_1_3_4.py "TC_OCC_3_1.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TC_OCC_3_2.py", # There are CI issues for the test cases that implements manually controlling sensor device for the occupancy state ON/OFF change "TestCommissioningTimeSync.py", # Code/Test not being used or not shared code for any other tests From 9cbd7192d05736dbd80545a20f28c428e1dfa567 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 24 Oct 2024 20:36:41 +0000 Subject: [PATCH 070/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 4a8ee77217ac4f..029a27af346e23 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -354,7 +354,7 @@ async def test_TC_CADMIN_1_4(self): asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - + self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx th2_idx = await self.th2.ReadAttribute(nodeid=self.dut_node_id, attributes=[(0, Clusters.OperationalCredentials.Attributes.CurrentFabricIndex)]) @@ -364,5 +364,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From 374dc4967e4298734203af0f567d67df732e8d57 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 29 Oct 2024 19:33:17 -0700 Subject: [PATCH 071/104] Updated TC_CADMIN_1_3_4 test module: - Updated method to cross verify root public key, now using self.certificate_authority_manager.activeCaList --- src/python_testing/TC_CADMIN_1_3_4.py | 37 ++++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 029a27af346e23..674e595fef3320 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -27,31 +27,33 @@ # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: true -# quiet: true +# quiet: false # run2: # app: ${ALL_CLUSTERS_APP} # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json # script-args: > +# --tests test_TC_CADMIN_1_4 # --storage-path admin_storage.json # --discriminator 1234 # --passcode 20202021 # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: false -# quiet: true +# quiet: false # === END CI TEST ARGUMENTS === import asyncio import random from time import sleep +import base64 import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, - default_matter_test_main) + default_matter_test_main, MatterStackState) from mdns_discovery import mdns_discovery from mobly import asserts @@ -65,12 +67,6 @@ async def get_fabrics(self, th: ChipDeviceCtrl) -> int: fabric_info = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=True, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics) return fabric_info - async def get_rcac_decoded(self, th: str) -> int: - csrResponse = await self.send_single_cmd(dev_ctrl=th, node_id=self.dut_node_id, cmd=opcreds.Commands.CSRRequest(CSRNonce=nonce, isForUpdateNOC=False)) - TH_certs_real = await th.IssueNOCChain(csrResponse, self.dut_node_id) - th_rcac_decoded = TLVReader(TH_certs_real.rcacBytes).get()["Any"] - return th_rcac_decoded - async def get_txt_record(self): discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) comm_service = await discovery.get_commissionable_service( @@ -172,8 +168,8 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) - if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + th1_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] + if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -187,8 +183,8 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] + if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -332,8 +328,8 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_rcac_decoded = await self.get_rcac_decoded(th=self.th1) - if th1_fabric_info[0].rootPublicKey != th1_rcac_decoded[9]: + th1_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] + if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -347,8 +343,14 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th2_rcac_decoded = await self.get_rcac_decoded(th=self.th2) - if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded[9]: + + # Following try and except needed in order for this test to pass in CI since we are running this test back to back without factory-reset + try: + th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[3]._persistentStorage._jsonData["sdk-config"]["f/4/r"])).get()["Any"][9] + except: + th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[2]._persistentStorage._jsonData["sdk-config"]["f/3/r"])).get()["Any"][9] + + if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -364,6 +366,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() From 24dcc5ced2ccdca36f271ee03885939a96026b04 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 30 Oct 2024 02:35:44 +0000 Subject: [PATCH 072/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 674e595fef3320..f05ddb19394ffd 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -168,7 +168,8 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] + th1_cam_rcac = TLVReader(base64.b64decode( + self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: @@ -183,7 +184,8 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] + th2_cam_rcac = TLVReader(base64.b64decode( + self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: @@ -328,7 +330,8 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th1_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] + th1_cam_rcac = TLVReader(base64.b64decode( + self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: @@ -343,12 +346,14 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - + # Following try and except needed in order for this test to pass in CI since we are running this test back to back without factory-reset try: - th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[3]._persistentStorage._jsonData["sdk-config"]["f/4/r"])).get()["Any"][9] - except: - th2_cam_rcac = TLVReader(base64.b64decode(self.certificate_authority_manager.activeCaList[2]._persistentStorage._jsonData["sdk-config"]["f/3/r"])).get()["Any"][9] + th2_cam_rcac = TLVReader(base64.b64decode( + self.certificate_authority_manager.activeCaList[3]._persistentStorage._jsonData["sdk-config"]["f/4/r"])).get()["Any"][9] + except: + th2_cam_rcac = TLVReader(base64.b64decode( + self.certificate_authority_manager.activeCaList[2]._persistentStorage._jsonData["sdk-config"]["f/3/r"])).get()["Any"][9] if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") @@ -366,5 +371,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From b4ea4688272492f387625554325458ba5804e428 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 30 Oct 2024 02:35:46 +0000 Subject: [PATCH 073/104] Restyled by isort --- src/python_testing/TC_CADMIN_1_3_4.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index f05ddb19394ffd..fc445b71ebe72c 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -43,17 +43,17 @@ # === END CI TEST ARGUMENTS === import asyncio +import base64 import random from time import sleep -import base64 import chip.clusters as Clusters from chip import ChipDeviceCtrl from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader -from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, - default_matter_test_main, MatterStackState) +from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, MatterStackState, TestStep, async_test_body, + default_matter_test_main) from mdns_discovery import mdns_discovery from mobly import asserts From 6176fa0287419d3b73e92354802470d47a774897 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 29 Oct 2024 20:29:36 -0700 Subject: [PATCH 074/104] Updating TC_CADMIN_1_3_4 test module: - Disabling quiet mode in CI arguments --- src/python_testing/TC_CADMIN_1_3_4.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index fc445b71ebe72c..bd6de8be412e61 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -27,7 +27,7 @@ # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: true -# quiet: false +# quiet: true # run2: # app: ${ALL_CLUSTERS_APP} # app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json @@ -39,7 +39,7 @@ # --trace-to json:${TRACE_TEST_JSON}.json # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # factory-reset: false -# quiet: false +# quiet: true # === END CI TEST ARGUMENTS === import asyncio @@ -53,7 +53,7 @@ from chip.interaction_model import Status from chip.tlv import TLVReader from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, MatterStackState, TestStep, async_test_body, - default_matter_test_main) + default_matter_test_main, get_test_info) from mdns_discovery import mdns_discovery from mobly import asserts From 905f21182f2789382c2fff2890229fe60a9e89d9 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 29 Oct 2024 20:46:31 -0700 Subject: [PATCH 075/104] Updating TC_CADMIN_1_3_4 test module: - Resolving linting errors with unused imports --- src/python_testing/TC_CADMIN_1_3_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index bd6de8be412e61..d2566d836ec29c 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -52,8 +52,8 @@ from chip.exceptions import ChipStackError from chip.interaction_model import Status from chip.tlv import TLVReader -from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, MatterStackState, TestStep, async_test_body, - default_matter_test_main, get_test_info) +from matter_testing_infrastructure.chip.testing.matter_testing import (MatterBaseTest, TestStep, async_test_body, + default_matter_test_main) from mdns_discovery import mdns_discovery from mobly import asserts From ab3a31c6e1aa7d31aee4a314dfae9ce8cb68d23d Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 29 Oct 2024 22:39:48 -0700 Subject: [PATCH 076/104] Updating TC_CADMIN_1_3_4 test module: - Updating to resolve linting issue --- src/python_testing/TC_CADMIN_1_3_4.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index d2566d836ec29c..50646e4d760f33 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -351,7 +351,8 @@ async def test_TC_CADMIN_1_4(self): try: th2_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[3]._persistentStorage._jsonData["sdk-config"]["f/4/r"])).get()["Any"][9] - except: + + except IndexError: th2_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[2]._persistentStorage._jsonData["sdk-config"]["f/3/r"])).get()["Any"][9] From 8296533613b796c2e22ab4444be0b8e0ea087d93 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 14 Nov 2024 20:29:16 -0800 Subject: [PATCH 077/104] RCAC data callback implementation during commeissioning: - Updated OpCredsBinding C++ module to include callback functionality to gather RCAC in chip cert format during kGenerateNOCChain commissioning stage - Updated ChipDeviceCtrl python module to include new functions to establish callback during OnNetworkCommissioning and added a new arg "" for this functionality to trigger the callback when wanted to gather rcac data, also passing that data into tests based off new arg value - Updated TC_CADMIN_1_3_4 test module to implement gathering and using the RCAC data to validate the rootpublickey matches during testing. --- src/controller/python/OpCredsBinding.cpp | 104 ++++++++++++++++++- src/controller/python/chip/ChipDeviceCtrl.py | 52 +++++++++- src/python_testing/TC_CADMIN_1_3_4.py | 35 +++---- 3 files changed, 167 insertions(+), 24 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index f5815922cc14eb..cafcba59c1d6f0 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -16,7 +16,7 @@ * 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. - */ +*/ #include @@ -45,6 +45,18 @@ #include #include +//Including AutoCommissioner initialization here for getting RootCert +#include +#include +#include +#include +#include // Added for size_t +#include // Added for std::function +#include +#include +//#include // Include this for std::this_thread +//#include // Include this for std::chrono::milliseconds + using namespace chip; using Py_GenerateNOCChainFunc = void (*)(void * pyContext, const char * csrElements, const char * attestationSignature, @@ -110,8 +122,10 @@ extern chip::app::DefaultICDClientStorage sICDClientStorage; class TestCommissioner : public chip::Controller::AutoCommissioner { public: + using RCACReadyCallback = std::function &)>; TestCommissioner() { Reset(); } ~TestCommissioner() {} + CHIP_ERROR SetCommissioningParameters(const chip::Controller::CommissioningParameters & params) override { mIsWifi = false; @@ -149,6 +163,35 @@ class TestCommissioner : public chip::Controller::AutoCommissioner return CHIP_NO_ERROR; } + if (report.stageCompleted == chip::Controller::CommissioningStage::kGenerateNOCChain) + { + if (report.Is()) + { + auto nocChain = report.Get(); + MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); + + chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); + + // Converting rcac to chip cert format to be decyphered by TLV later in python3 + chip::Platform::ScopedMemoryBuffer chipRcac; + MutableByteSpan chipRcacSpan; + chipRcac.Alloc(Credentials::kMaxCHIPCertLength); + chipRcacSpan = MutableByteSpan(chipRcac.Get(), Credentials::kMaxCHIPCertLength); + chip::Credentials::ConvertX509CertToChipCert(rcacByteSpan, chipRcacSpan); + mCHIPRCACData.assign(chipRcacSpan.data(), chipRcacSpan.data() + chipRcacSpan.size()); + + if (!mCHIPRCACData.empty()) + { + // Notify that mCHIPRCACData data is ready + NotifyRCACDataReady(); + } + else + { + ChipLogError(Controller, "RCAC data is empty. No data to log."); + } + } + } + if (mPrematureCompleteAfter != chip::Controller::CommissioningStage::kError && report.stageCompleted == chip::Controller::CommissioningStage::kSendComplete) { @@ -262,7 +305,9 @@ class TestCommissioner : public chip::Controller::AutoCommissioner mCompletionError = CHIP_NO_ERROR; } bool GetTestCommissionerUsed() { return mTestCommissionerUsed; } + void OnCommissioningSuccess(chip::PeerId peerId) { mReceivedCommissioningSuccess = true; } + void OnCommissioningFailure(chip::PeerId peerId, CHIP_ERROR error, chip::Controller::CommissioningStage stageFailed, chip::Optional additionalErrorInfo) { @@ -291,10 +336,39 @@ class TestCommissioner : public chip::Controller::AutoCommissioner } } } + + CHIP_ERROR GetCommissioningResultError() const + { + return mCommissioningResultError; + } + + void SetOnRCACReadyCallback(RCACReadyCallback callback) + { + std::lock_guard lock(mCallbackMutex); + mOnRCACReadyCallback = callback; + } CHIP_ERROR GetCompletionError() { return mCompletionError; } + // Getter method to access RCAC data + //const std::vector& GetRCACData() const { return mRCACData; } + const std::vector& GetCHIPRCACData() const { return mCHIPRCACData; } + private: + void NotifyRCACDataReady() + { + std::lock_guard lock(mCallbackMutex); + if (mOnRCACReadyCallback && !mCHIPRCACData.empty()) + { + mOnRCACReadyCallback(mCHIPRCACData); + } + } + RCACReadyCallback mOnRCACReadyCallback; + std::mutex mCallbackMutex; // Ensure thread-safe access to callback + + std::vector mCHIPRCACData; + std::vector mRCACData; + CHIP_ERROR mCommissioningResultError; static constexpr uint8_t kNumCommissioningStages = chip::to_underlying(chip::Controller::CommissioningStage::kCleanup) + 1; chip::Controller::CommissioningStage mSimulateFailureOnStage = chip::Controller::CommissioningStage::kError; chip::Controller::CommissioningStage mFailOnReportAfterStage = chip::Controller::CommissioningStage::kError; @@ -391,6 +465,7 @@ void pychip_OnCommissioningSuccess(PeerId peerId) { sTestCommissioner.OnCommissioningSuccess(peerId); } + void pychip_OnCommissioningFailure(chip::PeerId peerId, CHIP_ERROR error, chip::Controller::CommissioningStage stageFailed, chip::Optional additionalErrorInfo) { @@ -549,6 +624,7 @@ PyChipError pychip_OpCreds_AllocateController(OpCredsContext * context, chip::Co { initParams.defaultCommissioner = &sTestCommissioner; pairingDelegate->SetCommissioningSuccessCallback(pychip_OnCommissioningSuccess); + //pairingDelegate->SetCommissioningSuccessCallback([](chip::PeerId peerId) { pychip_OnCommissioningSuccess(peerId, sTestCommissioner.GetRCACData().data(), sTestCommissioner.GetRCACData().size()); }); pairingDelegate->SetCommissioningFailureCallback(pychip_OnCommissioningFailure); pairingDelegate->SetCommissioningStatusUpdateCallback(pychip_OnCommissioningStatusUpdate); } @@ -687,4 +763,30 @@ PyChipError pychip_GetCompletionError() return ToPyChipError(sTestCommissioner.GetCompletionError()); } +extern "C" { + // Define a global callback to set the RCAC data callback + using PythonRCACCallback = void (*)(const uint8_t *, size_t); + static PythonRCACCallback gPythonRCACCallback = nullptr; + + + // Function to set the Python callback + void pychip_SetCommissioningRCACCallback(PythonRCACCallback callback) + { + ChipLogProgress(Controller, "Attempting to set Python RCAC callback in C++"); + gPythonRCACCallback = callback; + + // Set C++ TestCommissioner callback to notify Python when RCAC data is ready + sTestCommissioner.SetOnRCACReadyCallback([](const std::vector & rcacData) { + if (gPythonRCACCallback) + { + ChipLogProgress(Controller, "RCAC callback in C++ set"); + gPythonRCACCallback(rcacData.data(), rcacData.size()); + } + else + { + ChipLogError(Controller, "Python RCAC callback is not set."); + } + }); + } + } } // extern "C" diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 8c751f7f791dd0..9c207950fcef5d 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -61,6 +61,8 @@ # Defined in $CHIP_ROOT/src/lib/core/CHIPError.h CHIP_ERROR_TIMEOUT: int = 50 +_RCACCallbackType = CFUNCTYPE(None, POINTER(c_uint8), c_size_t) + LOGGER = logging.getLogger(__name__) _DevicePairingDelegate_OnPairingCompleteFunct = CFUNCTYPE(None, PyChipError) @@ -266,7 +268,6 @@ async def __aexit__(self, exc_type, exc_value, traceback): self._future = None self._lock.release() - class CommissioningContext(CallbackContext): """A context manager for handling commissioning callbacks that are expected to be called exactly once. @@ -470,6 +471,7 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError): self._dmLib.pychip_DeviceController_SetIcdRegistrationParameters(False, None) if self._dmLib.pychip_TestCommissionerUsed(): + # Prepare pointers to store the results err = self._dmLib.pychip_GetCompletionError() if self._commissioning_context.future is None: @@ -478,6 +480,7 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError): if err.is_success: self._commissioning_context.future.set_result(nodeId) + else: self._commissioning_context.future.set_exception(err.to_exception()) @@ -549,6 +552,7 @@ def HandlePASEEstablishmentComplete(err: PyChipError): self.cbHandleCommissioningCompleteFunct = _DevicePairingDelegate_OnCommissioningCompleteFunct( HandleCommissioningComplete) + self._dmLib.pychip_ScriptDevicePairingDelegate_SetCommissioningCompleteCallback( self.pairingDelegate, self.cbHandleCommissioningCompleteFunct) @@ -1928,6 +1932,11 @@ def _InitLib(self): self._dmLib.pychip_GetCompletionError.argtypes = [] self._dmLib.pychip_GetCompletionError.restype = PyChipError + #self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] + #self._dmLib.pychip_GetCommissioningRCACData.restype = None + self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] + self._dmLib.pychip_SetCommissioningRCACCallback.restype = None + self._dmLib.pychip_DeviceController_IssueNOCChain.argtypes = [ c_void_p, py_object, c_char_p, c_size_t, c_uint64] self._dmLib.pychip_DeviceController_IssueNOCChain.restype = PyChipError @@ -2160,9 +2169,17 @@ def GetFabricCheckResult(self) -> int: ''' Returns the fabric check result if SetCheckMatchingFabric was used.''' return self._fabricCheckNodeId + async def get_commissioning_rcac_data(self): + # Await the future until the RCAC data is available + try: + rcac_data = await asyncio.wait_for(commissioning_future, timeout=60) + return rcac_data + except asyncio.TimeoutError: + raise Exception("Timeout while waiting for RCAC data") + async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, - discoveryTimeoutMsec: int = 30000) -> int: + discoveryTimeoutMsec: int = 30000, get_rcac: bool = False) -> int: ''' Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery. Supported filters are: @@ -2190,6 +2207,12 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, if isinstance(filter, int): filter = str(filter) + if get_rcac: + global commissioning_future + commissioning_future = asyncio.get_event_loop().create_future() + rcac_cb = _RCACCallbackType(self.rcac_callback) + self._dmLib.pychip_SetCommissioningRCACCallback(rcac_cb) + async with self._commissioning_context as ctx: self._enablePairingCompleteCallback(True) await self._ChipStack.CallAsync( @@ -2197,7 +2220,30 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") if filter is not None else None, discoveryTimeoutMsec) ) - return await asyncio.futures.wrap_future(ctx.future) + if get_rcac: + try: + rcac_data, rcac_size = await self.get_commissioning_rcac_data() + rcac_data = bytes(ctypes.cast(rcac_data, ctypes.POINTER(ctypes.c_ubyte * rcac_size)).contents) + + except Exception as e: + LOGGER.exception(f"Error when attempting to get rcac data and size after commissioning: {e}") + return + + if rcac_size > 0: + return (await asyncio.futures.wrap_future(ctx.future), rcac_data) + else: + raise Exception("No RCAC data returned.") + + else: + return await asyncio.futures.wrap_future(ctx.future) + + def rcac_callback(res, rcac_data, rcac_size): + if rcac_size > 0: + # Signal that the rcac data has been received by setting the future result + commissioning_future.set_result((rcac_data, rcac_size)) + else: + LOGGER.exception("RCAC data is empty") + commissioning_future.set_exception(Exception("RCAC data is empty")) async def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: DiscoveryType = DiscoveryType.DISCOVERY_ALL) -> int: ''' Commission with the given nodeid from the setupPayload. diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 50646e4d760f33..f353a7a69ce615 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -157,10 +157,12 @@ async def test_TC_CADMIN_1_3(self): # Establishing TH2 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) - await self.th2.CommissionOnNetwork( + self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) + _, rcac = await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator, get_rcac=True) + + th2_rcac_decoded = TLVReader(rcac).get()["Any"][9] self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read @@ -184,9 +186,10 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - th2_cam_rcac = TLVReader(base64.b64decode( - self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] - if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: + #th2_cam_rcac = TLVReader(base64.b64decode( + # self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] + + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -319,10 +322,12 @@ async def test_TC_CADMIN_1_4(self): # Establishing TH2 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) - await self.th2.CommissionOnNetwork( + self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) + _, rcac = await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value, get_rcac=True) + + th2_rcac_decoded = TLVReader(rcac).get()["Any"][9] self.step(5) # TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read @@ -347,16 +352,7 @@ async def test_TC_CADMIN_1_4(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - # Following try and except needed in order for this test to pass in CI since we are running this test back to back without factory-reset - try: - th2_cam_rcac = TLVReader(base64.b64decode( - self.certificate_authority_manager.activeCaList[3]._persistentStorage._jsonData["sdk-config"]["f/4/r"])).get()["Any"][9] - - except IndexError: - th2_cam_rcac = TLVReader(base64.b64decode( - self.certificate_authority_manager.activeCaList[2]._persistentStorage._jsonData["sdk-config"]["f/3/r"])).get()["Any"][9] - - if th2_fabric_info[0].rootPublicKey != th2_cam_rcac: + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") @@ -372,6 +368,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() From 84e49291fa82e960bbcba04b93e234e24954ce89 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Nov 2024 04:39:08 +0000 Subject: [PATCH 078/104] Restyled by whitespace --- src/controller/python/OpCredsBinding.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index cafcba59c1d6f0..8f2df1736f6019 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -169,7 +169,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner { auto nocChain = report.Get(); MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); - + chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); // Converting rcac to chip cert format to be decyphered by TLV later in python3 @@ -180,7 +180,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner chip::Credentials::ConvertX509CertToChipCert(rcacByteSpan, chipRcacSpan); mCHIPRCACData.assign(chipRcacSpan.data(), chipRcacSpan.data() + chipRcacSpan.size()); - if (!mCHIPRCACData.empty()) + if (!mCHIPRCACData.empty()) { // Notify that mCHIPRCACData data is ready NotifyRCACDataReady(); @@ -336,7 +336,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner } } } - + CHIP_ERROR GetCommissioningResultError() const { return mCommissioningResultError; From 5c94500156f2b428386fe553d77099d2d7202f8d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Nov 2024 04:39:13 +0000 Subject: [PATCH 079/104] Restyled by clang-format --- src/controller/python/OpCredsBinding.cpp | 73 ++++++++++++------------ 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 8f2df1736f6019..667517f23c6753 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -16,7 +16,7 @@ * 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. -*/ + */ #include @@ -45,17 +45,17 @@ #include #include -//Including AutoCommissioner initialization here for getting RootCert +// Including AutoCommissioner initialization here for getting RootCert #include -#include -#include -#include -#include // Added for size_t +#include // Added for size_t #include // Added for std::function #include #include -//#include // Include this for std::this_thread -//#include // Include this for std::chrono::milliseconds +#include +#include +#include +// #include // Include this for std::this_thread +// #include // Include this for std::chrono::milliseconds using namespace chip; @@ -168,7 +168,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner if (report.Is()) { auto nocChain = report.Get(); - MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); + MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); @@ -337,10 +337,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner } } - CHIP_ERROR GetCommissioningResultError() const - { - return mCommissioningResultError; - } + CHIP_ERROR GetCommissioningResultError() const { return mCommissioningResultError; } void SetOnRCACReadyCallback(RCACReadyCallback callback) { @@ -351,8 +348,8 @@ class TestCommissioner : public chip::Controller::AutoCommissioner CHIP_ERROR GetCompletionError() { return mCompletionError; } // Getter method to access RCAC data - //const std::vector& GetRCACData() const { return mRCACData; } - const std::vector& GetCHIPRCACData() const { return mCHIPRCACData; } + // const std::vector& GetRCACData() const { return mRCACData; } + const std::vector & GetCHIPRCACData() const { return mCHIPRCACData; } private: void NotifyRCACDataReady() @@ -624,7 +621,8 @@ PyChipError pychip_OpCreds_AllocateController(OpCredsContext * context, chip::Co { initParams.defaultCommissioner = &sTestCommissioner; pairingDelegate->SetCommissioningSuccessCallback(pychip_OnCommissioningSuccess); - //pairingDelegate->SetCommissioningSuccessCallback([](chip::PeerId peerId) { pychip_OnCommissioningSuccess(peerId, sTestCommissioner.GetRCACData().data(), sTestCommissioner.GetRCACData().size()); }); + // pairingDelegate->SetCommissioningSuccessCallback([](chip::PeerId peerId) { pychip_OnCommissioningSuccess(peerId, + // sTestCommissioner.GetRCACData().data(), sTestCommissioner.GetRCACData().size()); }); pairingDelegate->SetCommissioningFailureCallback(pychip_OnCommissioningFailure); pairingDelegate->SetCommissioningStatusUpdateCallback(pychip_OnCommissioningStatusUpdate); } @@ -764,29 +762,28 @@ PyChipError pychip_GetCompletionError() } extern "C" { - // Define a global callback to set the RCAC data callback - using PythonRCACCallback = void (*)(const uint8_t *, size_t); - static PythonRCACCallback gPythonRCACCallback = nullptr; +// Define a global callback to set the RCAC data callback +using PythonRCACCallback = void (*)(const uint8_t *, size_t); +static PythonRCACCallback gPythonRCACCallback = nullptr; +// Function to set the Python callback +void pychip_SetCommissioningRCACCallback(PythonRCACCallback callback) +{ + ChipLogProgress(Controller, "Attempting to set Python RCAC callback in C++"); + gPythonRCACCallback = callback; - // Function to set the Python callback - void pychip_SetCommissioningRCACCallback(PythonRCACCallback callback) - { - ChipLogProgress(Controller, "Attempting to set Python RCAC callback in C++"); - gPythonRCACCallback = callback; - - // Set C++ TestCommissioner callback to notify Python when RCAC data is ready - sTestCommissioner.SetOnRCACReadyCallback([](const std::vector & rcacData) { - if (gPythonRCACCallback) - { - ChipLogProgress(Controller, "RCAC callback in C++ set"); - gPythonRCACCallback(rcacData.data(), rcacData.size()); - } - else - { - ChipLogError(Controller, "Python RCAC callback is not set."); - } - }); + // Set C++ TestCommissioner callback to notify Python when RCAC data is ready + sTestCommissioner.SetOnRCACReadyCallback([](const std::vector & rcacData) { + if (gPythonRCACCallback) + { + ChipLogProgress(Controller, "RCAC callback in C++ set"); + gPythonRCACCallback(rcacData.data(), rcacData.size()); } - } + else + { + ChipLogError(Controller, "Python RCAC callback is not set."); + } + }); +} +} } // extern "C" From bd8c021bd933087337ccaf26b57e7bc2e99bf66e Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Nov 2024 04:39:22 +0000 Subject: [PATCH 080/104] Restyled by autopep8 --- src/controller/python/chip/ChipDeviceCtrl.py | 7 ++++--- src/python_testing/TC_CADMIN_1_3_4.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 9c207950fcef5d..cf74a5034570af 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -268,6 +268,7 @@ async def __aexit__(self, exc_type, exc_value, traceback): self._future = None self._lock.release() + class CommissioningContext(CallbackContext): """A context manager for handling commissioning callbacks that are expected to be called exactly once. @@ -1936,7 +1937,7 @@ def _InitLib(self): #self._dmLib.pychip_GetCommissioningRCACData.restype = None self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] self._dmLib.pychip_SetCommissioningRCACCallback.restype = None - + self._dmLib.pychip_DeviceController_IssueNOCChain.argtypes = [ c_void_p, py_object, c_char_p, c_size_t, c_uint64] self._dmLib.pychip_DeviceController_IssueNOCChain.restype = PyChipError @@ -2226,8 +2227,8 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, rcac_data = bytes(ctypes.cast(rcac_data, ctypes.POINTER(ctypes.c_ubyte * rcac_size)).contents) except Exception as e: - LOGGER.exception(f"Error when attempting to get rcac data and size after commissioning: {e}") - return + LOGGER.exception(f"Error when attempting to get rcac data and size after commissioning: {e}") + return if rcac_size > 0: return (await asyncio.futures.wrap_future(ctx.future), rcac_data) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index f353a7a69ce615..e61422769002b9 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -186,9 +186,9 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - #th2_cam_rcac = TLVReader(base64.b64decode( + # th2_cam_rcac = TLVReader(base64.b64decode( # self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] - + if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: @@ -368,5 +368,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From c952ec8b67f6064fb700a8059bacba255b3e21de Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 15 Nov 2024 09:56:07 -0800 Subject: [PATCH 081/104] Updated OpCredsBinding C++ module: - Removed some unneccessary dependencies that had been used during debugging --- src/controller/python/OpCredsBinding.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 667517f23c6753..eb596ff1ce7848 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -44,18 +44,7 @@ #include #include #include - -// Including AutoCommissioner initialization here for getting RootCert -#include #include // Added for size_t -#include // Added for std::function -#include -#include -#include -#include -#include -// #include // Include this for std::this_thread -// #include // Include this for std::chrono::milliseconds using namespace chip; From d2f32f8f110612561e3cd355b5c0e20637fdac04 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 15 Nov 2024 10:10:19 -0800 Subject: [PATCH 082/104] Updating OpsCredsBinding.cpp and ChipDeviceCtrl.py: - Some further cleanup performed. --- src/controller/python/OpCredsBinding.cpp | 2 -- src/controller/python/chip/ChipDeviceCtrl.py | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index eb596ff1ce7848..0be168fc700d50 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -610,8 +610,6 @@ PyChipError pychip_OpCreds_AllocateController(OpCredsContext * context, chip::Co { initParams.defaultCommissioner = &sTestCommissioner; pairingDelegate->SetCommissioningSuccessCallback(pychip_OnCommissioningSuccess); - // pairingDelegate->SetCommissioningSuccessCallback([](chip::PeerId peerId) { pychip_OnCommissioningSuccess(peerId, - // sTestCommissioner.GetRCACData().data(), sTestCommissioner.GetRCACData().size()); }); pairingDelegate->SetCommissioningFailureCallback(pychip_OnCommissioningFailure); pairingDelegate->SetCommissioningStatusUpdateCallback(pychip_OnCommissioningStatusUpdate); } diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index cf74a5034570af..249016f68042a6 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -472,7 +472,6 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError): self._dmLib.pychip_DeviceController_SetIcdRegistrationParameters(False, None) if self._dmLib.pychip_TestCommissionerUsed(): - # Prepare pointers to store the results err = self._dmLib.pychip_GetCompletionError() if self._commissioning_context.future is None: @@ -1933,8 +1932,6 @@ def _InitLib(self): self._dmLib.pychip_GetCompletionError.argtypes = [] self._dmLib.pychip_GetCompletionError.restype = PyChipError - #self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] - #self._dmLib.pychip_GetCommissioningRCACData.restype = None self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] self._dmLib.pychip_SetCommissioningRCACCallback.restype = None From 6ff757fafbbb2ed76318a42afbbbe367859b790c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 15 Nov 2024 18:13:29 +0000 Subject: [PATCH 083/104] Restyled by clang-format --- src/controller/python/OpCredsBinding.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 0be168fc700d50..598f5c727f5e9a 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -44,7 +44,7 @@ #include #include #include -#include // Added for size_t +#include // Added for size_t using namespace chip; From 6b5109fc3a7e20ce4421107e623d5d6470efcdfe Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 20 Nov 2024 17:26:10 -0800 Subject: [PATCH 084/104] Updated OpCredsBinding C++ module: - Removed some unneccessary code for cleanup of debugging session - Removed else statement from pychip_SetCommissioningRCACCallback void function --- src/controller/python/OpCredsBinding.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 598f5c727f5e9a..7f98191f13c4d9 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -326,8 +326,6 @@ class TestCommissioner : public chip::Controller::AutoCommissioner } } - CHIP_ERROR GetCommissioningResultError() const { return mCommissioningResultError; } - void SetOnRCACReadyCallback(RCACReadyCallback callback) { std::lock_guard lock(mCallbackMutex); @@ -336,8 +334,6 @@ class TestCommissioner : public chip::Controller::AutoCommissioner CHIP_ERROR GetCompletionError() { return mCompletionError; } - // Getter method to access RCAC data - // const std::vector& GetRCACData() const { return mRCACData; } const std::vector & GetCHIPRCACData() const { return mCHIPRCACData; } private: @@ -353,8 +349,6 @@ class TestCommissioner : public chip::Controller::AutoCommissioner std::mutex mCallbackMutex; // Ensure thread-safe access to callback std::vector mCHIPRCACData; - std::vector mRCACData; - CHIP_ERROR mCommissioningResultError; static constexpr uint8_t kNumCommissioningStages = chip::to_underlying(chip::Controller::CommissioningStage::kCleanup) + 1; chip::Controller::CommissioningStage mSimulateFailureOnStage = chip::Controller::CommissioningStage::kError; chip::Controller::CommissioningStage mFailOnReportAfterStage = chip::Controller::CommissioningStage::kError; @@ -766,10 +760,6 @@ void pychip_SetCommissioningRCACCallback(PythonRCACCallback callback) ChipLogProgress(Controller, "RCAC callback in C++ set"); gPythonRCACCallback(rcacData.data(), rcacData.size()); } - else - { - ChipLogError(Controller, "Python RCAC callback is not set."); - } }); } } From 5cde629466480fa1c56fff7c58b115368f4d9de3 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 21 Nov 2024 13:59:31 -0800 Subject: [PATCH 085/104] Updated OpCredsBinding C++ module: - Changed from using ScopedMemoryBuffer to establishing pointer in vector to avoid leaks --- src/controller/python/OpCredsBinding.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 7f98191f13c4d9..10d36fa87d5188 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -158,14 +158,11 @@ class TestCommissioner : public chip::Controller::AutoCommissioner { auto nocChain = report.Get(); MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); - chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); // Converting rcac to chip cert format to be decyphered by TLV later in python3 - chip::Platform::ScopedMemoryBuffer chipRcac; - MutableByteSpan chipRcacSpan; - chipRcac.Alloc(Credentials::kMaxCHIPCertLength); - chipRcacSpan = MutableByteSpan(chipRcac.Get(), Credentials::kMaxCHIPCertLength); + std::vector chipRcac(Credentials::kMaxCHIPCertLength); + MutableByteSpan chipRcacSpan(chipRcac.data(), chipRcac.size()); chip::Credentials::ConvertX509CertToChipCert(rcacByteSpan, chipRcacSpan); mCHIPRCACData.assign(chipRcacSpan.data(), chipRcacSpan.data() + chipRcacSpan.size()); From 08995e7a21f37ffdbe0481786a487840569b21f2 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Mon, 25 Nov 2024 22:04:43 -0800 Subject: [PATCH 086/104] Updating OpCredsBinding C++ module and ChipDeviceCtrl python module: - Removed prior callbacks and replaced with function to remove additional complexity that could cause issues, making it simple --- src/controller/python/OpCredsBinding.cpp | 62 +++++++------------- src/controller/python/chip/ChipDeviceCtrl.py | 61 +++++++++++-------- src/python_testing/TC_CADMIN_1_3_4.py | 5 +- 3 files changed, 61 insertions(+), 67 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 10d36fa87d5188..6ff81a46b481d1 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -111,7 +111,6 @@ extern chip::app::DefaultICDClientStorage sICDClientStorage; class TestCommissioner : public chip::Controller::AutoCommissioner { public: - using RCACReadyCallback = std::function &)>; TestCommissioner() { Reset(); } ~TestCommissioner() {} @@ -156,20 +155,21 @@ class TestCommissioner : public chip::Controller::AutoCommissioner { if (report.Is()) { - auto nocChain = report.Get(); - MutableByteSpan rcacSpan(const_cast(nocChain.rcac.data()), nocChain.rcac.size()); + + auto nocChain = report.Get().rcac; + MutableByteSpan rcacSpan(const_cast(nocChain.data()), nocChain.size()); chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); - // Converting rcac to chip cert format to be decyphered by TLV later in python3 + // Convert RCAC to CHIP cert format to be deciphered by TLV later in python3 std::vector chipRcac(Credentials::kMaxCHIPCertLength); MutableByteSpan chipRcacSpan(chipRcac.data(), chipRcac.size()); chip::Credentials::ConvertX509CertToChipCert(rcacByteSpan, chipRcacSpan); + mCHIPRCACData.assign(chipRcacSpan.data(), chipRcacSpan.data() + chipRcacSpan.size()); if (!mCHIPRCACData.empty()) { - // Notify that mCHIPRCACData data is ready - NotifyRCACDataReady(); + ChipLogProgress(Controller, "RCAC data converted and stored."); } else { @@ -323,28 +323,11 @@ class TestCommissioner : public chip::Controller::AutoCommissioner } } - void SetOnRCACReadyCallback(RCACReadyCallback callback) - { - std::lock_guard lock(mCallbackMutex); - mOnRCACReadyCallback = callback; - } - CHIP_ERROR GetCompletionError() { return mCompletionError; } const std::vector & GetCHIPRCACData() const { return mCHIPRCACData; } private: - void NotifyRCACDataReady() - { - std::lock_guard lock(mCallbackMutex); - if (mOnRCACReadyCallback && !mCHIPRCACData.empty()) - { - mOnRCACReadyCallback(mCHIPRCACData); - } - } - RCACReadyCallback mOnRCACReadyCallback; - std::mutex mCallbackMutex; // Ensure thread-safe access to callback - std::vector mCHIPRCACData; static constexpr uint8_t kNumCommissioningStages = chip::to_underlying(chip::Controller::CommissioningStage::kCleanup) + 1; chip::Controller::CommissioningStage mSimulateFailureOnStage = chip::Controller::CommissioningStage::kError; @@ -740,24 +723,23 @@ PyChipError pychip_GetCompletionError() } extern "C" { -// Define a global callback to set the RCAC data callback -using PythonRCACCallback = void (*)(const uint8_t *, size_t); -static PythonRCACCallback gPythonRCACCallback = nullptr; - -// Function to set the Python callback -void pychip_SetCommissioningRCACCallback(PythonRCACCallback callback) +// Function to get the RCAC data from the sTestCommissioner +void pychip_GetCommissioningRCACData(uint8_t ** rcacDataPtr, size_t * rcacSize) { - ChipLogProgress(Controller, "Attempting to set Python RCAC callback in C++"); - gPythonRCACCallback = callback; + ChipLogProgress(Controller, "Attempting to get Python RCAC data in C++"); + const auto & rcacData = sTestCommissioner.GetCHIPRCACData(); - // Set C++ TestCommissioner callback to notify Python when RCAC data is ready - sTestCommissioner.SetOnRCACReadyCallback([](const std::vector & rcacData) { - if (gPythonRCACCallback) - { - ChipLogProgress(Controller, "RCAC callback in C++ set"); - gPythonRCACCallback(rcacData.data(), rcacData.size()); - } - }); + if (rcacData.empty()) + { + ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); + *rcacDataPtr = nullptr; + *rcacSize = 0; + } + else + { + *rcacSize = rcacData.size(); + *rcacDataPtr = const_cast(rcacData.data()); + } } } -} // extern "C" +} // extern "C" \ No newline at end of file diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 249016f68042a6..94e07a24aa35ee 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -37,6 +37,7 @@ import json import logging import secrets +from time import sleep import threading import typing from ctypes import (CDLL, CFUNCTYPE, POINTER, Structure, byref, c_bool, c_char, c_char_p, c_int, c_int32, c_size_t, c_uint8, @@ -1932,8 +1933,11 @@ def _InitLib(self): self._dmLib.pychip_GetCompletionError.argtypes = [] self._dmLib.pychip_GetCompletionError.restype = PyChipError - self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] - self._dmLib.pychip_SetCommissioningRCACCallback.restype = None + #self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] + #self._dmLib.pychip_SetCommissioningRCACCallback.restype = None + + self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] + self._dmLib.pychip_GetCommissioningRCACData.restype = None self._dmLib.pychip_DeviceController_IssueNOCChain.argtypes = [ c_void_p, py_object, c_char_p, c_size_t, c_uint64] @@ -2167,6 +2171,7 @@ def GetFabricCheckResult(self) -> int: ''' Returns the fabric check result if SetCheckMatchingFabric was used.''' return self._fabricCheckNodeId + ''' async def get_commissioning_rcac_data(self): # Await the future until the RCAC data is available try: @@ -2174,6 +2179,18 @@ async def get_commissioning_rcac_data(self): return rcac_data except asyncio.TimeoutError: raise Exception("Timeout while waiting for RCAC data") + ''' + + # Function to await the RCAC data + async def get_commissioning_rcac_data_async(self): + try: + # Directly call the non-async function to get the data + rcac_data = self.get_commissioning_rcac_data() + LOGGER.info(f"RCAC data from get_commissioning_rcac_data was {rcac_data}") + return rcac_data + except Exception as e: + LOGGER.error(f"Error while getting RCAC data: {e}") + raise async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, @@ -2205,12 +2222,6 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, if isinstance(filter, int): filter = str(filter) - if get_rcac: - global commissioning_future - commissioning_future = asyncio.get_event_loop().create_future() - rcac_cb = _RCACCallbackType(self.rcac_callback) - self._dmLib.pychip_SetCommissioningRCACCallback(rcac_cb) - async with self._commissioning_context as ctx: self._enablePairingCompleteCallback(True) await self._ChipStack.CallAsync( @@ -2218,31 +2229,33 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") if filter is not None else None, discoveryTimeoutMsec) ) + # If RCAC data is needed, await the result if get_rcac: try: - rcac_data, rcac_size = await self.get_commissioning_rcac_data() - rcac_data = bytes(ctypes.cast(rcac_data, ctypes.POINTER(ctypes.c_ubyte * rcac_size)).contents) + sleep(60) + rcac_data_ptr = POINTER(c_uint8)() + rcac_size = c_size_t() + + # Call the C++ function to get the RCAC data + self._dmLib.pychip_GetCommissioningRCACData(byref(rcac_data_ptr), byref(rcac_size)) + + # Check if data is available + if rcac_size.value > 0: + # Convert the data to a Python bytes object + rcac_data = cast(rcac_data_ptr, POINTER(c_uint8 * rcac_size.value)).contents + rcac_bytes = bytes(rcac_data) + else: + raise Exception("RCAC data is empty") except Exception as e: - LOGGER.exception(f"Error when attempting to get rcac data and size after commissioning: {e}") - return + LOGGER.error(f"Error during RCAC data fetching: {e}") - if rcac_size > 0: - return (await asyncio.futures.wrap_future(ctx.future), rcac_data) - else: - raise Exception("No RCAC data returned.") + LOGGER.info(f"Commissioning RCAC Data: {rcac_bytes}") + return (await asyncio.futures.wrap_future(ctx.future), rcac_bytes) else: return await asyncio.futures.wrap_future(ctx.future) - def rcac_callback(res, rcac_data, rcac_size): - if rcac_size > 0: - # Signal that the rcac data has been received by setting the future result - commissioning_future.set_result((rcac_data, rcac_size)) - else: - LOGGER.exception("RCAC data is empty") - commissioning_future.set_exception(Exception("RCAC data is empty")) - async def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: DiscoveryType = DiscoveryType.DISCOVERY_ALL) -> int: ''' Commission with the given nodeid from the setupPayload. setupPayload may be a QR or manual code. diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index e61422769002b9..c8821c729944ab 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -60,7 +60,6 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) - class TC_CADMIN(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -106,7 +105,7 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: "Verify DUT_CE responds to both write/read with a success"), TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", "Commissioning is successful"), - TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), @@ -186,7 +185,7 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - # th2_cam_rcac = TLVReader(base64.b64decode( + #th2_cam_rcac = TLVReader(base64.b64decode( # self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: From fb4bf96c20a48290edbc4211702df0d49f38e61c Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Tue, 26 Nov 2024 00:06:28 -0800 Subject: [PATCH 087/104] Update manualTests.json Removing files TC_CADMIN_1_21 and TC_CADMIN_1_22 as latest merge from TC_CADMIN_1_22 and TC_CADMIN_1_24 should have removed those files from this file. --- src/app/tests/suites/manualTests.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/app/tests/suites/manualTests.json b/src/app/tests/suites/manualTests.json index fcb15dc81a5923..c7b3ca869c84c7 100644 --- a/src/app/tests/suites/manualTests.json +++ b/src/app/tests/suites/manualTests.json @@ -174,10 +174,6 @@ "Test_TC_CADMIN_1_16", "Test_TC_CADMIN_1_17", "Test_TC_CADMIN_1_18", - "Test_TC_CADMIN_1_19", - "Test_TC_CADMIN_1_20", - "Test_TC_CADMIN_1_21", - "Test_TC_CADMIN_1_22", "Test_TC_CADMIN_1_5", "Test_TC_CADMIN_1_6", "Test_TC_CADMIN_1_10", From b65ccbbad348fdfd6999db9e549914d2383ee663 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 26 Nov 2024 08:07:04 +0000 Subject: [PATCH 088/104] Restyled by whitespace --- src/controller/python/OpCredsBinding.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index d34b4d93827c33..2cb16b4fbf9fe2 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -155,7 +155,7 @@ class TestCommissioner : public chip::Controller::AutoCommissioner { if (report.Is()) { - + auto nocChain = report.Get().rcac; MutableByteSpan rcacSpan(const_cast(nocChain.data()), nocChain.size()); chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); @@ -742,4 +742,4 @@ void pychip_GetCommissioningRCACData(uint8_t ** rcacDataPtr, size_t * rcacSize) } } } -} // extern "C" \ No newline at end of file +} // extern "C" From c7008a971a7ee393912e4b0220acf5925c63935d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 26 Nov 2024 08:07:08 +0000 Subject: [PATCH 089/104] Restyled by clang-format --- src/controller/python/OpCredsBinding.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 2cb16b4fbf9fe2..6f9fc42b5825c1 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -733,11 +733,11 @@ void pychip_GetCommissioningRCACData(uint8_t ** rcacDataPtr, size_t * rcacSize) { ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); *rcacDataPtr = nullptr; - *rcacSize = 0; + *rcacSize = 0; } else { - *rcacSize = rcacData.size(); + *rcacSize = rcacData.size(); *rcacDataPtr = const_cast(rcacData.data()); } } From 11a790f06d4620b171ebbd189f5afedc5dd16403 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 26 Nov 2024 08:07:15 +0000 Subject: [PATCH 090/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index c8821c729944ab..e61422769002b9 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -60,6 +60,7 @@ opcreds = Clusters.OperationalCredentials nonce = random.randbytes(32) + class TC_CADMIN(MatterBaseTest): async def get_fabrics(self, th: ChipDeviceCtrl) -> int: OC_cluster = Clusters.OperationalCredentials @@ -105,7 +106,7 @@ def steps_TC_CADMIN_1_3(self) -> list[TestStep]: "Verify DUT_CE responds to both write/read with a success"), TestStep(4, "TH creates a controller (TH_CR2) on a new fabric and commissions DUT_CE using that controller. TH_CR2 should commission the device using a different NodeID than TH_CR1.", "Commissioning is successful"), - TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", + TestStep(5, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", "Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device."), TestStep(6, "TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read", "Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device."), @@ -185,7 +186,7 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - #th2_cam_rcac = TLVReader(base64.b64decode( + # th2_cam_rcac = TLVReader(base64.b64decode( # self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: From a19739f99f23c7a4e574812ec06e80efc95b5861 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 26 Nov 2024 08:07:17 +0000 Subject: [PATCH 091/104] Restyled by isort --- src/controller/python/chip/ChipDeviceCtrl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 25d8831845e180..5125e66e6d6b7f 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -37,12 +37,12 @@ import json import logging import secrets -from time import sleep import threading import typing from ctypes import (CDLL, CFUNCTYPE, POINTER, Structure, byref, c_bool, c_char, c_char_p, c_int, c_int32, c_size_t, c_uint8, c_uint16, c_uint32, c_uint64, c_void_p, cast, create_string_buffer, pointer, py_object, resize, string_at) from dataclasses import dataclass +from time import sleep import dacite # type: ignore From e3bf1bae857b4b14b12d108bea99798e42c0cca0 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 5 Dec 2024 16:27:06 -0800 Subject: [PATCH 092/104] Updating ChipDeviceCtrl and TC_CADMIN_1_3_4 modules: - Removed additional commented out line of code in TC_CADMIN_1_3_4 test module. - Updated ChipDeviceCtrl module to move rcac_bytes var setting to a new function, removed additional print line. - Updated ChipDeviceCtrl module to await before setting the rcac_bytes var. --- src/controller/python/chip/ChipDeviceCtrl.py | 44 +++++++++++--------- src/python_testing/TC_CADMIN_1_3_4.py | 3 -- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 5125e66e6d6b7f..56c6af852add57 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -2260,32 +2260,36 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") if filter is not None else None, discoveryTimeoutMsec) ) - # If RCAC data is needed, await the result - if get_rcac: - try: - sleep(60) - rcac_data_ptr = POINTER(c_uint8)() - rcac_size = c_size_t() + res = await asyncio.futures.wrap_future(ctx.future) - # Call the C++ function to get the RCAC data - self._dmLib.pychip_GetCommissioningRCACData(byref(rcac_data_ptr), byref(rcac_size)) + # If RCAC data is wanted, attempt to pull the result + if get_rcac: + rcac_bytes = self.get_rcac() + return (res, rcac_bytes) - # Check if data is available - if rcac_size.value > 0: - # Convert the data to a Python bytes object - rcac_data = cast(rcac_data_ptr, POINTER(c_uint8 * rcac_size.value)).contents - rcac_bytes = bytes(rcac_data) - else: - raise Exception("RCAC data is empty") + else: + return res - except Exception as e: - LOGGER.error(f"Error during RCAC data fetching: {e}") + def get_rcac(self): + try: + rcac_data_ptr = POINTER(c_uint8)() + rcac_size = c_size_t() - LOGGER.info(f"Commissioning RCAC Data: {rcac_bytes}") - return (await asyncio.futures.wrap_future(ctx.future), rcac_bytes) + # Call the C++ function to get the RCAC data + self._dmLib.pychip_GetCommissioningRCACData(byref(rcac_data_ptr), byref(rcac_size)) + # Check if data is available + if rcac_size.value > 0: + # Convert the data to a Python bytes object + rcac_data = cast(rcac_data_ptr, POINTER(c_uint8 * rcac_size.value)).contents + rcac_bytes = bytes(rcac_data) else: - return await asyncio.futures.wrap_future(ctx.future) + raise Exception("RCAC data is empty") + + except Exception as e: + LOGGER.error(f"Error during RCAC data fetching: {e}") + + return rcac_bytes async def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: DiscoveryType = DiscoveryType.DISCOVERY_ALL) -> int: ''' Commission with the given nodeid from the setupPayload. diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index e61422769002b9..12946291a5fca1 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -186,8 +186,6 @@ async def test_TC_CADMIN_1_3(self): # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) - # th2_cam_rcac = TLVReader(base64.b64decode( - # self.certificate_authority_manager.activeCaList[1]._persistentStorage._jsonData["sdk-config"]["f/2/r"])).get()["Any"][9] if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") @@ -368,6 +366,5 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) - if __name__ == "__main__": default_matter_test_main() From 9556f5e7f1307f8fe89d30119d39904322da61c9 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 5 Dec 2024 17:07:46 -0800 Subject: [PATCH 093/104] Updating OpCredsBinding C++ module: - Removed rcacByteSpan var as not needed in order to convert data before passing data to python3 --- src/controller/python/OpCredsBinding.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 6f9fc42b5825c1..337f409f65ebbf 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -157,13 +157,11 @@ class TestCommissioner : public chip::Controller::AutoCommissioner { auto nocChain = report.Get().rcac; - MutableByteSpan rcacSpan(const_cast(nocChain.data()), nocChain.size()); - chip::ByteSpan rcacByteSpan(rcacSpan.data(), rcacSpan.size()); // Convert RCAC to CHIP cert format to be deciphered by TLV later in python3 std::vector chipRcac(Credentials::kMaxCHIPCertLength); MutableByteSpan chipRcacSpan(chipRcac.data(), chipRcac.size()); - chip::Credentials::ConvertX509CertToChipCert(rcacByteSpan, chipRcacSpan); + chip::Credentials::ConvertX509CertToChipCert(nocChain, chipRcacSpan); mCHIPRCACData.assign(chipRcacSpan.data(), chipRcacSpan.data() + chipRcacSpan.size()); From 252d9e431bd7b0220e62698fa38eaf8be3abc524 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 6 Dec 2024 01:09:52 +0000 Subject: [PATCH 094/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 12946291a5fca1..55e52b18404190 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -366,5 +366,6 @@ async def test_TC_CADMIN_1_4(self): removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2_idx[outer_key][inner_key][attribute_key]) await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From a471608dcf0139c9c12fc281fc021cef17e6fc56 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 5 Dec 2024 17:27:10 -0800 Subject: [PATCH 095/104] Updating ChipDeviceCtrl module: - Resolving linting error --- src/controller/python/chip/ChipDeviceCtrl.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 56c6af852add57..7aee0710f9b070 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -42,7 +42,6 @@ from ctypes import (CDLL, CFUNCTYPE, POINTER, Structure, byref, c_bool, c_char, c_char_p, c_int, c_int32, c_size_t, c_uint8, c_uint16, c_uint32, c_uint64, c_void_p, cast, create_string_buffer, pointer, py_object, resize, string_at) from dataclasses import dataclass -from time import sleep import dacite # type: ignore From df6ca974dcb50bf01d6d9579e18affd13f7efda1 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 6 Dec 2024 01:59:45 -0800 Subject: [PATCH 096/104] Updating TC_CADMIN_1_3_4 test module: - Changing to using self.th1.OpenCommissioningWindow() in place of self.openCommissioningWindow() to resolve issue noticed in CI. --- src/python_testing/TC_CADMIN_1_3_4.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 55e52b18404190..ed842cf219deef 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -140,7 +140,9 @@ async def test_TC_CADMIN_1_3(self): self.max_window_duration = duration.maxCumulativeFailsafeSeconds self.step("3a") - params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) + #params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) + params = await self.th1.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=1000, discriminator=1234, option=1) + self.print_step("TH1 params", params) self.step("3b") services = await self.get_txt_record() @@ -159,8 +161,8 @@ async def test_TC_CADMIN_1_3(self): th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) _, rcac = await self.th2.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator, get_rcac=True) + nodeId=self.dut_node_id, setupPinCode=params.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=1234, get_rcac=True) th2_rcac_decoded = TLVReader(rcac).get()["Any"][9] @@ -231,14 +233,15 @@ async def test_TC_CADMIN_1_3(self): self.step(12) # TH_CR2 opens a commissioning window on DUT_CE using ECM self.discriminator = random.randint(0, 4095) - params2 = await self.openCommissioningWindow(dev_ctrl=self.th2, node_id=self.dut_node_id) + #params2 = await self.openCommissioningWindow(dev_ctrl=self.th2, node_id=self.dut_node_id) + params2 = await self.th2.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=1000, discriminator=1234, option=1) self.step(13) # TH_CR1 starts a commissioning process with DUT_CE before the timeout from step 12 try: await self.th1.CommissionOnNetwork( - nodeId=self.dut_node_id, setupPinCode=params2.commissioningParameters.setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params2.randomDiscriminator) + nodeId=self.dut_node_id, setupPinCode=params2.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=1234) except ChipStackError as e: asserts.assert_equal(e.err, 0x0000007E, "Expected to return Trying to add NOC for fabric that already exists") From b217ca3f88ae2736e0d6e6fdcd3247c7ef75dd4d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 6 Dec 2024 10:03:00 +0000 Subject: [PATCH 097/104] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_3_4.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index ed842cf219deef..10a12897ab89a6 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -140,7 +140,7 @@ async def test_TC_CADMIN_1_3(self): self.max_window_duration = duration.maxCumulativeFailsafeSeconds self.step("3a") - #params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) + # params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id) params = await self.th1.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=1000, discriminator=1234, option=1) self.print_step("TH1 params", params) @@ -233,7 +233,7 @@ async def test_TC_CADMIN_1_3(self): self.step(12) # TH_CR2 opens a commissioning window on DUT_CE using ECM self.discriminator = random.randint(0, 4095) - #params2 = await self.openCommissioningWindow(dev_ctrl=self.th2, node_id=self.dut_node_id) + # params2 = await self.openCommissioningWindow(dev_ctrl=self.th2, node_id=self.dut_node_id) params2 = await self.th2.OpenCommissioningWindow(nodeid=self.dut_node_id, timeout=self.max_window_duration, iteration=1000, discriminator=1234, option=1) self.step(13) From be49186bdb19411f969cf8cd14f09ea7e765c34d Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 6 Dec 2024 17:37:22 -0800 Subject: [PATCH 098/104] Updating ChipDeviceCtrl and TC_CADMIN_1_3_4 modules: - Moved get_rcac() to a standalone function that can be called after commissioning is completed in ChipDeviceCtrl module - Updated TC_CADMIN_1_3_4 test module to using the new standalone function self.th.get_rcac() --- src/controller/python/chip/ChipDeviceCtrl.py | 12 ++---------- src/python_testing/TC_CADMIN_1_3_4.py | 10 ++++++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 7aee0710f9b070..92842c50361655 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -2224,7 +2224,7 @@ async def get_commissioning_rcac_data_async(self): async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, - discoveryTimeoutMsec: int = 30000, get_rcac: bool = False) -> int: + discoveryTimeoutMsec: int = 30000) -> int: ''' Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery. Supported filters are: @@ -2259,15 +2259,7 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") if filter is not None else None, discoveryTimeoutMsec) ) - res = await asyncio.futures.wrap_future(ctx.future) - - # If RCAC data is wanted, attempt to pull the result - if get_rcac: - rcac_bytes = self.get_rcac() - return (res, rcac_bytes) - - else: - return res + return await asyncio.futures.wrap_future(ctx.future) def get_rcac(self): try: diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 10a12897ab89a6..9748c42b22cf8c 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -160,9 +160,10 @@ async def test_TC_CADMIN_1_3(self): 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) - _, rcac = await self.th2.CommissionOnNetwork( + await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params.setupPinCode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=1234, get_rcac=True) + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=1234) + rcac = self.th2.get_rcac() th2_rcac_decoded = TLVReader(rcac).get()["Any"][9] @@ -324,9 +325,10 @@ async def test_TC_CADMIN_1_4(self): 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) - _, rcac = await self.th2.CommissionOnNetwork( + await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setupPayloadInfo[0].passcode, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value, get_rcac=True) + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=setupPayloadInfo[0].filter_value) + rcac = self.th2.get_rcac() th2_rcac_decoded = TLVReader(rcac).get()["Any"][9] From d0f1908ae8102f40f96e3176ea378dafd4f2a8a2 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Sat, 7 Dec 2024 22:48:33 -0800 Subject: [PATCH 099/104] Updating OpCredsBinding C++ and ChipDeviceCtrl python modules: - Changing to allocating memory from python to store RCAC data captured from C++ module --- src/controller/python/OpCredsBinding.cpp | 34 +++++++++++--------- src/controller/python/chip/ChipDeviceCtrl.py | 19 +++++++---- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index 337f409f65ebbf..f5f46e87c1c27b 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -720,24 +720,26 @@ PyChipError pychip_GetCompletionError() return ToPyChipError(sTestCommissioner.GetCompletionError()); } -extern "C" { -// Function to get the RCAC data from the sTestCommissioner -void pychip_GetCommissioningRCACData(uint8_t ** rcacDataPtr, size_t * rcacSize) -{ - ChipLogProgress(Controller, "Attempting to get Python RCAC data in C++"); - const auto & rcacData = sTestCommissioner.GetCHIPRCACData(); - if (rcacData.empty()) - { - ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); - *rcacDataPtr = nullptr; - *rcacSize = 0; - } - else +extern "C" { + // Function to get the RCAC data from the sTestCommissioner + void pychip_GetCommissioningRCACData(uint8_t * rcacDataPtr, size_t * rcacSize) { - *rcacSize = rcacData.size(); - *rcacDataPtr = const_cast(rcacData.data()); + // Attempting to get Python RCAC data in C++ + const auto & rcacData = sTestCommissioner.GetCHIPRCACData(); + + if (rcacData.empty()) + { + ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); + *rcacSize = 0; + return; + } + + // Ensure the size is passed back to Python + *rcacSize = rcacData.size(); + + // Copy the data from C++ to Python's allocated memory + std::memcpy(rcacDataPtr, rcacData.data(), *rcacSize); } } -} } // extern "C" diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 92842c50361655..2510c7ae67c309 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -1966,7 +1966,8 @@ def _InitLib(self): #self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] #self._dmLib.pychip_SetCommissioningRCACCallback.restype = None - self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] + #self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] + self._dmLib.pychip_GetCommissioningRCACData.argtypes = [ctypes.POINTER(ctypes.c_uint8), ctypes.POINTER(ctypes.c_size_t)] self._dmLib.pychip_GetCommissioningRCACData.restype = None self._dmLib.pychip_DeviceController_IssueNOCChain.argtypes = [ @@ -2261,18 +2262,22 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, return await asyncio.futures.wrap_future(ctx.future) + def get_rcac(self): try: - rcac_data_ptr = POINTER(c_uint8)() - rcac_size = c_size_t() + # Assume rcac_size is the size you want to allocate + rcac_size = 1024 # Allocate sufficient memory based on expected size + rcac_buffer = (ctypes.c_uint8 * rcac_size)() # Allocate a ctypes buffer - # Call the C++ function to get the RCAC data - self._dmLib.pychip_GetCommissioningRCACData(byref(rcac_data_ptr), byref(rcac_size)) + actual_rcac_size = ctypes.c_size_t() + # Call the C++ function to get the RCAC data + self._dmLib.pychip_GetCommissioningRCACData(ctypes.cast(rcac_buffer, ctypes.POINTER(ctypes.c_uint8)), ctypes.byref(actual_rcac_size)) + # Check if data is available - if rcac_size.value > 0: + if actual_rcac_size.value > 0: # Convert the data to a Python bytes object - rcac_data = cast(rcac_data_ptr, POINTER(c_uint8 * rcac_size.value)).contents + rcac_data = bytearray(rcac_buffer[:actual_rcac_size.value]) rcac_bytes = bytes(rcac_data) else: raise Exception("RCAC data is empty") From 427834d6979ee8aaee2d0c4bb82fc64347fdad32 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Sat, 7 Dec 2024 22:56:41 -0800 Subject: [PATCH 100/104] Updated ChipDeviceCtrl python module: - Changed buffer size for storing RCAC to 650 from 1024 --- src/controller/python/chip/ChipDeviceCtrl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 2510c7ae67c309..23d346d4f2c98f 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -2264,9 +2264,10 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, def get_rcac(self): + # Passes captured RCAC data back to python test modules to be used for validation try: # Assume rcac_size is the size you want to allocate - rcac_size = 1024 # Allocate sufficient memory based on expected size + rcac_size = 650 # Allocate sufficient memory based on expected size rcac_buffer = (ctypes.c_uint8 * rcac_size)() # Allocate a ctypes buffer actual_rcac_size = ctypes.c_size_t() From 0ca175b6a137202030b33b582b21fec903f22acd Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 8 Dec 2024 06:58:46 +0000 Subject: [PATCH 101/104] Restyled by clang-format --- src/controller/python/OpCredsBinding.cpp | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/controller/python/OpCredsBinding.cpp b/src/controller/python/OpCredsBinding.cpp index f5f46e87c1c27b..697edd34d98227 100644 --- a/src/controller/python/OpCredsBinding.cpp +++ b/src/controller/python/OpCredsBinding.cpp @@ -720,26 +720,25 @@ PyChipError pychip_GetCompletionError() return ToPyChipError(sTestCommissioner.GetCompletionError()); } - extern "C" { - // Function to get the RCAC data from the sTestCommissioner - void pychip_GetCommissioningRCACData(uint8_t * rcacDataPtr, size_t * rcacSize) - { - // Attempting to get Python RCAC data in C++ - const auto & rcacData = sTestCommissioner.GetCHIPRCACData(); +// Function to get the RCAC data from the sTestCommissioner +void pychip_GetCommissioningRCACData(uint8_t * rcacDataPtr, size_t * rcacSize) +{ + // Attempting to get Python RCAC data in C++ + const auto & rcacData = sTestCommissioner.GetCHIPRCACData(); - if (rcacData.empty()) - { - ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); - *rcacSize = 0; - return; - } + if (rcacData.empty()) + { + ChipLogError(Controller, "RCAC data is empty in C++. Nothing to return."); + *rcacSize = 0; + return; + } - // Ensure the size is passed back to Python - *rcacSize = rcacData.size(); + // Ensure the size is passed back to Python + *rcacSize = rcacData.size(); - // Copy the data from C++ to Python's allocated memory - std::memcpy(rcacDataPtr, rcacData.data(), *rcacSize); - } + // Copy the data from C++ to Python's allocated memory + std::memcpy(rcacDataPtr, rcacData.data(), *rcacSize); +} } } // extern "C" From b9c2f98087ad381e3f75b8e4396ec8efdbfcaeef Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 8 Dec 2024 06:58:53 +0000 Subject: [PATCH 102/104] Restyled by autopep8 --- src/controller/python/chip/ChipDeviceCtrl.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 23d346d4f2c98f..435c2d5c957937 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -2262,19 +2262,19 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, return await asyncio.futures.wrap_future(ctx.future) - def get_rcac(self): # Passes captured RCAC data back to python test modules to be used for validation try: # Assume rcac_size is the size you want to allocate - rcac_size = 650 # Allocate sufficient memory based on expected size + rcac_size = 650 # Allocate sufficient memory based on expected size rcac_buffer = (ctypes.c_uint8 * rcac_size)() # Allocate a ctypes buffer actual_rcac_size = ctypes.c_size_t() # Call the C++ function to get the RCAC data - self._dmLib.pychip_GetCommissioningRCACData(ctypes.cast(rcac_buffer, ctypes.POINTER(ctypes.c_uint8)), ctypes.byref(actual_rcac_size)) - + self._dmLib.pychip_GetCommissioningRCACData(ctypes.cast( + rcac_buffer, ctypes.POINTER(ctypes.c_uint8)), ctypes.byref(actual_rcac_size)) + # Check if data is available if actual_rcac_size.value > 0: # Convert the data to a Python bytes object From 9ed0164686690aad5ab5e832e6f94b815cf3b2bb Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 11 Dec 2024 17:26:54 -0800 Subject: [PATCH 103/104] Updated ChipDeviceCtrl and TC_CADMIN_1_3_4 python modules: - Removed unneeded get_commissioning_rcac_data_async() - Removed commented out python bindings - Removed fail safes as no longer needed with new method of gathering RCAC in place --- src/controller/python/chip/ChipDeviceCtrl.py | 31 ++------------------ src/python_testing/TC_CADMIN_1_3_4.py | 19 ++++++------ 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 435c2d5c957937..f833ba28f2265c 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -1963,10 +1963,6 @@ def _InitLib(self): self._dmLib.pychip_GetCompletionError.argtypes = [] self._dmLib.pychip_GetCompletionError.restype = PyChipError - #self._dmLib.pychip_SetCommissioningRCACCallback.argtypes = [_RCACCallbackType] - #self._dmLib.pychip_SetCommissioningRCACCallback.restype = None - - #self._dmLib.pychip_GetCommissioningRCACData.argtypes = [POINTER(POINTER(c_uint8)), POINTER(c_size_t)] self._dmLib.pychip_GetCommissioningRCACData.argtypes = [ctypes.POINTER(ctypes.c_uint8), ctypes.POINTER(ctypes.c_size_t)] self._dmLib.pychip_GetCommissioningRCACData.restype = None @@ -2202,27 +2198,6 @@ def GetFabricCheckResult(self) -> int: ''' Returns the fabric check result if SetCheckMatchingFabric was used.''' return self._fabricCheckNodeId - ''' - async def get_commissioning_rcac_data(self): - # Await the future until the RCAC data is available - try: - rcac_data = await asyncio.wait_for(commissioning_future, timeout=60) - return rcac_data - except asyncio.TimeoutError: - raise Exception("Timeout while waiting for RCAC data") - ''' - - # Function to await the RCAC data - async def get_commissioning_rcac_data_async(self): - try: - # Directly call the non-async function to get the data - rcac_data = self.get_commissioning_rcac_data() - LOGGER.info(f"RCAC data from get_commissioning_rcac_data was {rcac_data}") - return rcac_data - except Exception as e: - LOGGER.error(f"Error while getting RCAC data: {e}") - raise - async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, discoveryTimeoutMsec: int = 30000) -> int: @@ -2265,13 +2240,11 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, def get_rcac(self): # Passes captured RCAC data back to python test modules to be used for validation try: - # Assume rcac_size is the size you want to allocate - rcac_size = 650 # Allocate sufficient memory based on expected size - rcac_buffer = (ctypes.c_uint8 * rcac_size)() # Allocate a ctypes buffer + rcac_size = 650 + rcac_buffer = (ctypes.c_uint8 * rcac_size)() actual_rcac_size = ctypes.c_size_t() - # Call the C++ function to get the RCAC data self._dmLib.pychip_GetCommissioningRCACData(ctypes.cast( rcac_buffer, ctypes.POINTER(ctypes.c_uint8)), ctypes.byref(actual_rcac_size)) diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index 9748c42b22cf8c..f35ee28529826f 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -172,31 +172,32 @@ async def test_TC_CADMIN_1_3(self): th1_fabric_info = await self.get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + #await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] + if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th1_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + #await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + #await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE @@ -337,7 +338,7 @@ async def test_TC_CADMIN_1_4(self): th1_fabric_info = await self.get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + #await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: @@ -346,21 +347,21 @@ async def test_TC_CADMIN_1_4(self): asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + #await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + #await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx From 24ee444259dd8b33bf0b29d0ba9c54bfb8d0063b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 12 Dec 2024 01:30:12 +0000 Subject: [PATCH 104/104] Restyled by autopep8 --- src/controller/python/chip/ChipDeviceCtrl.py | 2 +- src/python_testing/TC_CADMIN_1_3_4.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index f833ba28f2265c..83986bba9dd26d 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -2241,7 +2241,7 @@ def get_rcac(self): # Passes captured RCAC data back to python test modules to be used for validation try: rcac_size = 650 - rcac_buffer = (ctypes.c_uint8 * rcac_size)() + rcac_buffer = (ctypes.c_uint8 * rcac_size)() actual_rcac_size = ctypes.c_size_t() diff --git a/src/python_testing/TC_CADMIN_1_3_4.py b/src/python_testing/TC_CADMIN_1_3_4.py index f35ee28529826f..594de789c0964b 100644 --- a/src/python_testing/TC_CADMIN_1_3_4.py +++ b/src/python_testing/TC_CADMIN_1_3_4.py @@ -172,7 +172,7 @@ async def test_TC_CADMIN_1_3(self): th1_fabric_info = await self.get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - #await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + # await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] @@ -182,22 +182,22 @@ async def test_TC_CADMIN_1_3(self): asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + # await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - #await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + # await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - #await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) - #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + # await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + # await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR1 writes and reads the Basic Information Cluster’s NodeLabel mandatory attribute of DUT_CE @@ -338,7 +338,7 @@ async def test_TC_CADMIN_1_4(self): th1_fabric_info = await self.get_fabrics(th=self.th1) # Verify that the RootPublicKey matches the root public key for TH_CR1 and the NodeID matches the node ID used when TH_CR1 commissioned the device. - #await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + # await self.send_single_cmd(dev_ctrl=self.th1, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) th1_cam_rcac = TLVReader(base64.b64decode( self.certificate_authority_manager.activeCaList[0]._persistentStorage._jsonData["sdk-config"]["f/1/r"])).get()["Any"][9] if th1_fabric_info[0].rootPublicKey != th1_cam_rcac: @@ -347,21 +347,21 @@ async def test_TC_CADMIN_1_4(self): asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") # Expiring the failsafe timer in an attempt to clean up before TH2 attempt. - #await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + # await self.th1.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(6) # TH_CR2 reads the Fabrics attribute from the Node Operational Credentials cluster using a fabric-filtered read th2_fabric_info = await self.get_fabrics(th=self.th2) # Verify that the RootPublicKey matches the root public key for TH_CR2 and the NodeID matches the node ID used when TH_CR2 commissioned the device. - #await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) + # await self.send_single_cmd(dev_ctrl=self.th2, node_id=self.dut_node_id, cmd=Clusters.GeneralCommissioning.Commands.ArmFailSafe(10)) if th2_fabric_info[0].rootPublicKey != th2_rcac_decoded: asserts.fail("public keys from fabric and certs for TH1 are not the same") if th2_fabric_info[0].nodeID != self.dut_node_id: asserts.fail("DUT node ID from fabric does not equal DUT node ID for TH1 during commissioning") - #await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) + # await self.th2.SendCommand(self.dut_node_id, 0, Clusters.GeneralCommissioning.Commands.ArmFailSafe(0)) self.step(7) # TH_CR2 reads the CurrentFabricIndex attribute from the Operational Credentials cluster and saves as th2_idx, TH_CR1 sends the RemoveFabric command to the DUT with the FabricIndex set to th2_idx