Skip to content

Commit d6a1870

Browse files
j-ororkerestyled-commitscecille
authored
[Test] Creating CADMIN 1.19 python3 test module (project-chip#35611)
* [Test] Creating CADMIN 1.19 test module: - Test module created following steps in PR: CHIP-Specifications/chip-test-plans#4669 * Restyled by autopep8 * Update TC_CADMIN_1_19 test module: - Resolving linting issues * Removing yaml test module for TC_CADMIN_1_19: - Removed yaml test as we have created python test module in its place * Update TC_CADMIN_1_19.py - Removed debugging print statements as no longer needed in test code * Update src/python_testing/TC_CADMIN_1_19.py Co-authored-by: C Freeman <cecille@google.com> * Update src/python_testing/TC_CADMIN_1_19.py Co-authored-by: C Freeman <cecille@google.com> * Updating TC_CADMIN_1_19 and matter_testing scripts: - Updated CI Arguments - Updated dependency location for matter_testing_support - Removed local OpenCommissioningWindow function, updated to using MatterBaseTest version - Removed local CommissioningAttempt function, moved to using function call directly in test - Removed initialization of TH2 controller as not needed - Removed additional dictionary names and delimited it down to just using numbers instead. - Updated matter_testing support script to include setting timeout value dynamically in openCommissioningWindow function * Restyled by autopep8 * Update TC_CADMIN_1_19.py Resolving Linting errors * Update TC_CADMIN_1_19.py - Moved location of print_step to top of for range for creating virtual fragments - Removed unnecessary print_step for catching error * Updated TC_CADMIN_1_19 test module: - Created new variable for current_fabric + 1 - Replaced if statements with asserts.assert_equal() - Changed start of range from 1 to 0 - Changed test steps to match test plan better, removed test step 1 * Restyled by autopep8 * Updated TC_CADMIN_1_19 test module: - Added new criteria to test step 3 where max_fabrics is checked to make sure it is greater than initial_fabrics count * Updated TC_CADMIN_1_19 test module: - Removed print statement from debugging session * Restyled by autopep8 --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: C Freeman <cecille@google.com>
1 parent 563ac33 commit d6a1870

File tree

3 files changed

+174
-129
lines changed

3 files changed

+174
-129
lines changed

src/app/tests/suites/certification/Test_TC_CADMIN_1_19.yaml

-127
This file was deleted.

src/python_testing/TC_CADMIN_1_19.py

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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+
# === BEGIN CI TEST ARGUMENTS ===
18+
# test-runner-runs:
19+
# run1:
20+
# app: ${ALL_CLUSTERS_APP}
21+
# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
22+
# script-args: >
23+
# --storage-path admin_storage.json
24+
# --commissioning-method on-network
25+
# --discriminator 1234
26+
# --passcode 20202021
27+
# --trace-to json:${TRACE_TEST_JSON}.json
28+
# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
29+
# --PICS src/app/tests/suites/certification/ci-pics-values
30+
# factory-reset: true
31+
# quiet: true
32+
# === END CI TEST ARGUMENTS ===
33+
34+
import random
35+
36+
import chip.clusters as Clusters
37+
from chip import ChipDeviceCtrl
38+
from chip.exceptions import ChipStackError
39+
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
40+
from mobly import asserts
41+
42+
43+
class TC_CADMIN_1_19(MatterBaseTest):
44+
def generate_unique_random_value(self, value):
45+
while True:
46+
random_value = random.randint(10000000, 99999999)
47+
asserts.assert_equal(random_value, value)
48+
return random_value
49+
50+
async def get_fabrics(self, th: ChipDeviceCtrl) -> int:
51+
OC_cluster = Clusters.OperationalCredentials
52+
fabrics = await self.read_single_attribute_check_success(dev_ctrl=th, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.Fabrics)
53+
return fabrics
54+
55+
def steps_TC_CADMIN_1_19(self) -> list[TestStep]:
56+
return [
57+
TestStep(
58+
1, "TH_CR1 reads the BasicCommissioningInfo attribute from the General Commissioning cluster and saves the MaxCumulativeFailsafeSeconds field as max_window_duration."),
59+
TestStep(2, "TH_CR1 reads the Fabrics attribute from the Node Operational Credentials cluster using a non-fabric-filtered read. Save the number of fabrics in the list as initial_number_of_fabrics"),
60+
TestStep(3, "TH_CR1 reads the SupportedFabrics attribute from the Node Operational Credentials cluster. Save max_fabrics",
61+
"Verify that max_fabrics is larger than initial_number_of_fabrics. If not, instruct the tester to remove one non-test-harness fabric and re-start the test."),
62+
TestStep(4, "Repeat the following steps (5a and 5b) max_fabrics - initial_number_of_fabrics times"),
63+
TestStep(
64+
"4a", "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"),
65+
TestStep("4b", "TH creates a controller on a new fabric and commissions DUT_CE using that controller",
66+
"Commissioning is successful"),
67+
TestStep(5, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.",
68+
"Verify this is equal to max_fabrics"),
69+
TestStep(
70+
6, "TH_CR1 send an OpenCommissioningWindow command to DUT_CE using a commissioning timeout of max_window_duration", "{resDutSuccess}"),
71+
TestStep(7, "TH creates a controller on a new fabric and commissions DUT_CE using that controller",
72+
"Verify DUT_CE responds with NOCResponse with a StatusCode field value of TableFull(5)"),
73+
TestStep(8, "Repeat the following steps (9a and 9b) for each controller (TH_CRn) created by this test"),
74+
TestStep("8a", "The controller reads the CurrentFabricIndex from the Node Operational Credentials cluster. Save as fabric_index."),
75+
TestStep("8b", "TH_CR1 sends the RemoveFabric command to DUT_CE", "{resDutSuccess}"),
76+
TestStep(9, "TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.",
77+
"Verify this is equal to initial_number_of_fabrics."),
78+
]
79+
80+
def pics_TC_CADMIN_1_19(self) -> list[str]:
81+
return ["CADMIN.S"]
82+
83+
@async_test_body
84+
async def test_TC_CADMIN_1_19(self):
85+
self.step(1)
86+
# Establishing TH1
87+
self.th1 = self.default_controller
88+
89+
GC_cluster = Clusters.GeneralCommissioning
90+
attribute = GC_cluster.Attributes.BasicCommissioningInfo
91+
duration = await self.read_single_attribute_check_success(endpoint=0, cluster=GC_cluster, attribute=attribute)
92+
self.max_window_duration = duration.maxCumulativeFailsafeSeconds
93+
94+
self.step(2)
95+
fabrics = await self.get_fabrics(th=self.th1)
96+
initial_number_of_fabrics = len(fabrics)
97+
98+
self.step(3)
99+
OC_cluster = Clusters.OperationalCredentials
100+
max_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics)
101+
asserts.assert_greater(max_fabrics, initial_number_of_fabrics,
102+
"max fabrics must be greater than initial fabrics, please remove one non-test-harness fabric and try test again")
103+
104+
self.step(4)
105+
fids_ca_dir = {}
106+
fids_fa_dir = {}
107+
fids = {}
108+
for fid in range(0, max_fabrics - initial_number_of_fabrics):
109+
self.print_step("commissioning iteration", fid + 1)
110+
# Make sure that current test step is 5, resets here after each loop
111+
self.current_step_index = 4
112+
113+
self.step("4a")
114+
params = await self.openCommissioningWindow(dev_ctrl=self.th1, timeout=self.max_window_duration, node_id=self.dut_node_id)
115+
116+
self.step("4b")
117+
fids_ca_dir[fid] = self.certificate_authority_manager.NewCertificateAuthority()
118+
fids_fa_dir[fid] = fids_ca_dir[fid].NewFabricAdmin(vendorId=0xFFF1, fabricId=fid + 1)
119+
fids[fid] = fids_fa_dir[fid].NewController(nodeId=fid + 1)
120+
121+
await fids[fid].CommissionOnNetwork(
122+
nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode,
123+
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)
124+
125+
self.step(5)
126+
# TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster
127+
current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.SupportedFabrics)
128+
asserts.assert_equal(current_fabrics, max_fabrics, "Expected number of fabrics not correct")
129+
130+
self.step(6)
131+
params = await self.openCommissioningWindow(dev_ctrl=self.th1, node_id=self.dut_node_id)
132+
133+
self.step(7)
134+
# TH creates a controller on a new fabric and attempts to commission DUT_CE using that controller
135+
next_fabric = current_fabrics + 1
136+
fids_ca_dir[next_fabric] = self.certificate_authority_manager.NewCertificateAuthority()
137+
fids_fa_dir[next_fabric] = fids_ca_dir[current_fabrics +
138+
1].NewFabricAdmin(vendorId=0xFFF1, fabricId=next_fabric)
139+
try:
140+
fids[next_fabric] = fids_fa_dir[next_fabric].NewController(nodeId=next_fabric)
141+
await fids[next_fabric].CommissionOnNetwork(
142+
nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode,
143+
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator)
144+
145+
except ChipStackError as e:
146+
# When attempting to create a new controller we are expected to get the following response:
147+
# src/credentials/FabricTable.cpp:833: CHIP Error 0x0000000B: No memory
148+
# Since the FabricTable is full and unable to create any new fabrics
149+
self.print_step("Max number of fabrics", "reached")
150+
asserts.assert_equal(e.err, 0x0000000B,
151+
"Expected to return table is full since max number of fabrics has been created already")
152+
153+
self.step(8)
154+
for thc in fids.keys():
155+
# Make sure that current test step is 11 (9 + 2 since 5a and 5b test steps included in count), resets here after each loop
156+
self.current_step_index = 10
157+
158+
self.step("8a")
159+
fabric_index = await self.read_single_attribute_check_success(dev_ctrl=fids[thc], endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CurrentFabricIndex)
160+
161+
self.step("8b")
162+
removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(fabric_index)
163+
await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd)
164+
165+
self.step(9)
166+
# TH reads the CommissionedFabrics attributes from the Node Operational Credentials cluster.
167+
current_fabrics = await self.read_single_attribute_check_success(dev_ctrl=self.th1, fabric_filtered=False, endpoint=0, cluster=OC_cluster, attribute=OC_cluster.Attributes.CommissionedFabrics)
168+
asserts.assert_equal(current_fabrics, initial_number_of_fabrics, "Expected number of fabrics not correct")
169+
170+
171+
if __name__ == "__main__":
172+
default_matter_test_main()

src/python_testing/matter_testing_infrastructure/chip/testing/matter_testing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1141,10 +1141,10 @@ def check_pics(self, pics_key: str) -> bool:
11411141
def is_pics_sdk_ci_only(self) -> bool:
11421142
return self.check_pics('PICS_SDK_CI_ONLY')
11431143

1144-
async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int) -> CustomCommissioningParameters:
1144+
async def openCommissioningWindow(self, dev_ctrl: ChipDeviceCtrl, node_id: int, timeout: int = 900) -> CustomCommissioningParameters:
11451145
rnd_discriminator = random.randint(0, 4095)
11461146
try:
1147-
commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=900, iteration=1000,
1147+
commissioning_params = await dev_ctrl.OpenCommissioningWindow(nodeid=node_id, timeout=timeout, iteration=1000,
11481148
discriminator=rnd_discriminator, option=1)
11491149
params = CustomCommissioningParameters(commissioning_params, rnd_discriminator)
11501150
return params

0 commit comments

Comments
 (0)