Skip to content

Commit 0ff709f

Browse files
authored
TC-ACE_1.5: Add (#30972)
* chore(python_testing): steps 1 and 2 * chore(python_testing): opencommissionwindow, oncommission methods, read currentfabric and steps 3, 4 * chore(python_testing): create ACL structures for th1 and th2. Working on steps (7,8,9,10) * chore(python_testing): change read_descriptor and read_basic for unsupported and expect success all steps added * chore(TC_ACE_1_5): complete all test steps ready to executed * chore(TC_ACE-1.5): fix errors using flake8 Python linter * chore(TC_ACE-1.5): fix errors using flake8 python linter * chore(TC_ACE-1.5): fix error using Restyled path * chore(base): Add openCommissioningWindow to matter base test * chore(TC_ACE-1.5): fix error using wrong node to openComissioningWindow method * chore(base): return a tuple of params onCommissioningWindow Added new random discriminator is store on a dictionary. When is calling onCommissioningWindow method is return as a tuple (CommissioningParameters, random_discriminator) * chore(TC_ACE-1.5): use InteractionModelError instead Exception to handle error onCommissioningWindow * chore(ci): add new test case TC_ACE-1.5 * chore(TC_ACE-1.5): modify openCommissioningWindow and type annotations * chore(TC_ACE-1.5): implement all suggestions by PR
1 parent 6aefe30 commit 0ff709f

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ jobs:
463463
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ACE_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
464464
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ACE_1_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --int-arg PIXIT.ACE.APPENDPOINT:1 PIXIT.ACE.APPDEVTYPEID:0x0100 --string-arg PIXIT.ACE.APPCLUSTER:OnOff PIXIT.ACE.APPATTRIBUTE:OnOff --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
465465
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ACE_1_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
466+
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ACE_1_5.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
466467
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_CGEN_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
467468
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DA_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'
468469
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TestGroupTableReports.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"'

src/python_testing/TC_ACE_1_5.py

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#
2+
# Copyright (c) 2024 Project CHIP Authors
3+
# All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
import logging
19+
20+
import chip.clusters as Clusters
21+
from chip import ChipDeviceCtrl
22+
from chip.interaction_model import Status
23+
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
24+
from mobly import asserts
25+
26+
27+
class TC_ACE_1_5(MatterBaseTest):
28+
29+
async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int:
30+
cluster = Clusters.Objects.OperationalCredentials
31+
attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex
32+
current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute)
33+
return current_fabric_index
34+
35+
async def write_acl(self, acl: Clusters.AccessControl, th: ChipDeviceCtrl):
36+
result = await th.WriteAttribute(self.dut_node_id, [(0, Clusters.AccessControl.Attributes.Acl(acl))])
37+
asserts.assert_equal(result[0].Status, Status.Success, "ACL write failed")
38+
39+
@async_test_body
40+
async def test_TC_ACE_1_5(self):
41+
self.print_step(1, "Comissioning, already done")
42+
self.th1 = self.default_controller
43+
44+
# TODO: move into base class and adjust tests (#31521)
45+
new_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority()
46+
new_fabric_admin = new_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.matter_test_config.fabric_id + 1)
47+
48+
TH1_nodeid = self.matter_test_config.controller_node_id
49+
TH2_nodeid = self.matter_test_config.controller_node_id + 2
50+
51+
self.th2 = new_fabric_admin.NewController(nodeId=TH2_nodeid,
52+
paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path))
53+
54+
params = self.openCommissioningWindow(self.th1, self.dut_node_id)
55+
self.print_step(2, "TH1 opens the commissioning window on the DUT")
56+
57+
errcode = self.th2.CommissionOnNetwork(
58+
nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode,
59+
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)
60+
logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format(errcode.is_success, errcode))
61+
self.print_step(3, "TH2 commissions DUT using admin node ID N2")
62+
63+
self.print_step(4, "TH2 reads its fabric index from the Operational Credentials cluster CurrentFabricIndex attribute")
64+
th2FabricIndex = await self.read_currentfabricindex(self.th2)
65+
66+
self.print_step(
67+
5, "TH1 writes DUT Endpoint 0 ACL cluster ACL attribute, value is list of ACLEntryStruct containing 2 elements")
68+
admin_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct(
69+
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister,
70+
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
71+
subjects=[TH1_nodeid],
72+
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.AccessControl.id)])
73+
descriptor_view = Clusters.AccessControl.Structs.AccessControlEntryStruct(
74+
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView,
75+
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
76+
subjects=[],
77+
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.Descriptor.id)])
78+
acl = [admin_acl, descriptor_view]
79+
await self.write_acl(acl, self.th1)
80+
81+
self.print_step(
82+
6, "TH2 writes DUT Endpoint 0 ACL cluster ACL attribute, value is list of ACLEntryStruct containing 2 elements")
83+
admin_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct(
84+
fabricIndex=th2FabricIndex,
85+
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister,
86+
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
87+
subjects=[TH2_nodeid],
88+
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.AccessControl.id)])
89+
descriptor_view = Clusters.AccessControl.Structs.AccessControlEntryStruct(
90+
fabricIndex=th2FabricIndex,
91+
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView,
92+
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
93+
subjects=[],
94+
targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.BasicInformation.id)])
95+
acl = [admin_acl, descriptor_view]
96+
await self.write_acl(acl, self.th2)
97+
98+
self.print_step(7, "TH1 reads DUT Endpoint 0 Descriptor cluster DeviceTypeList attribute")
99+
await self.read_single_attribute_check_success(
100+
dev_ctrl=self.th1, endpoint=0,
101+
cluster=Clusters.Objects.Descriptor,
102+
attribute=Clusters.Descriptor.Attributes.DeviceTypeList)
103+
104+
self.print_step(8, "TH1 reads DUT Endpoint 0 Basic Information cluster VendorID attribute")
105+
await self.read_single_attribute_expect_error(
106+
dev_ctrl=self.th1, endpoint=0,
107+
cluster=Clusters.Objects.BasicInformation,
108+
attribute=Clusters.BasicInformation.Attributes.VendorID,
109+
error=Status.UnsupportedAccess)
110+
111+
self.print_step(9, "TH2 reads DUT Endpoint 0 Descriptor cluster DeviceTypeList attribute")
112+
await self.read_single_attribute_expect_error(
113+
dev_ctrl=self.th2, endpoint=0,
114+
cluster=Clusters.Objects.Descriptor,
115+
attribute=Clusters.Descriptor.Attributes.DeviceTypeList,
116+
error=Status.UnsupportedAccess)
117+
118+
self.print_step(10, "TH2 reads DUT Endpoint 0 Basic Information cluster VendorID attribute")
119+
await self.read_single_attribute_check_success(
120+
dev_ctrl=self.th2, endpoint=0,
121+
cluster=Clusters.Objects.BasicInformation,
122+
attribute=Clusters.BasicInformation.Attributes.VendorID)
123+
124+
self.print_step(11, "TH1 resets the ACLs to default value by writing DUT EP0")
125+
full_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct(
126+
privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister,
127+
authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase,
128+
subjects=[TH1_nodeid],
129+
targets=[])
130+
131+
acl = [full_acl]
132+
await self.write_acl(acl, self.th1)
133+
134+
self.print_step(
135+
12, "TH1 removes the TH2 fabric by sending the RemoveFabric command to the DUT with the FabricIndex set to th2FabricIndex")
136+
removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2FabricIndex)
137+
await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd)
138+
139+
140+
if __name__ == "__main__":
141+
default_matter_test_main()

src/python_testing/matter_testing_support.py

+19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os
2525
import pathlib
2626
import queue
27+
import random
2728
import re
2829
import sys
2930
import typing
@@ -42,6 +43,7 @@
4243
from chip import ChipDeviceCtrl # Needed before chip.FabricAdmin
4344
import chip.FabricAdmin # Needed before chip.CertificateAuthority
4445
import chip.CertificateAuthority
46+
from chip.ChipDeviceCtrl import CommissioningParameters
4547

4648
# isort: on
4749
import chip.clusters as Clusters
@@ -379,6 +381,12 @@ def cluster_id_str(id):
379381
return 'HERE IS THE PROBLEM'
380382

381383

384+
@dataclass
385+
class CustomCommissioningParameters:
386+
commissioningParameters: CommissioningParameters
387+
randomDiscriminator: int
388+
389+
382390
@dataclass
383391
class AttributePathLocation:
384392
endpoint_id: int
@@ -728,6 +736,17 @@ def check_pics(self, pics_key: str) -> bool:
728736
pics_key = pics_key.strip()
729737
return pics_key in picsd and picsd[pics_key]
730738

739+
def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int) -> CustomCommissioningParameters:
740+
rnd_discriminator = random.randint(0, 4095)
741+
try:
742+
commissioning_params = dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=900, iteration=1000,
743+
discriminator=rnd_discriminator, option=1)
744+
params = CustomCommissioningParameters(commissioning_params, rnd_discriminator)
745+
return params
746+
747+
except InteractionModelError as e:
748+
asserts.fail(e.status, 'Failed to open commissioning window')
749+
731750
async def read_single_attribute(
732751
self, dev_ctrl: ChipDeviceCtrl, node_id: int, endpoint: int, attribute: object, fabricFiltered: bool = True) -> object:
733752
result = await dev_ctrl.ReadAttribute(node_id, [(endpoint, attribute)], fabricFiltered=fabricFiltered)

0 commit comments

Comments
 (0)