Skip to content

Commit 75fcadb

Browse files
j-ororkerestyled-commitscecille
authored
Created automated test TC_ADMIN_1_9: (#34342)
* Created automated test TC_ADMIN_1_9: - Follows test steps in test plan PR #CHIP-Specifications/chip-test-plans#4267: -- TH1 able to open commissioning window on DUT -- TH2 Fails to connect to endpoint for 20 iterations with correct payload but incorrect passcode -- TH2 Fails to connect to endpoint due to commissioning window being closed after the 20th failed attempt -- TH1 able to open commissioning window on the endpoint again -- TH1 able to revoke commissioning window on the endpoint * Restyled by autopep8 * Updated TC_CADMIN_1_9 test: - Replaced method to get incorrect pincode with using correct pincode in test step 4. * Update src/python_testing/TC_CADMIN_1_9.py Changing test async function to correct name, thank you Cecille! Co-authored-by: C Freeman <cecille@google.com> * Update src/python_testing/TC_CADMIN_1_9.py Co-authored-by: C Freeman <cecille@google.com> * Update src/python_testing/TC_CADMIN_1_9.py Co-authored-by: C Freeman <cecille@google.com> * Updated tests.yaml and TC_CADMIN_1_9.py: - Added test module TC_CADMIN_1_9 into tests.yaml script - Created new steps method to contain test steps, then call those in variables in main test code area. - Inserted comment for why sleep time duration is needed between test steps 3 and 4, moved sleep time duration into main test code area - Added setting variable for duration of commissioning window using maxCumulativeFailsafeSeconds * Restyled by autopep8 * Updated TC_CADMIN_1_9 test module: - added CI argument blocks to attempt to get test to run in CI * Updated TC_CADMIN_1_9: - Changed method for setting setupPinCode as in CI/CD pipeline it was failing previously. * Restyled by autopep8 * Updated TC_CADMIN_1_9: - Changed factory reset to false to attempt running in CI/CD pipeline * Updated TC_CADMIN_1_9: - Changed factory reset back to true as commissioning failed in CI/CD pipeline without it being set to true * Updated TC_CADMIN_1_9: - Removed PICS call in CI/CD as not needed - Turned off quiet mode when running test in CI/CD pipeline to help flush out current issue * Updated TC_CADMIN_1_9: - Added back removing PICS from script args for running CI/CD pipeline to see if this gets pipeline working again. * Updated TC_CADMIN_1_9: - Added an additional await to see if we can get test to pass in CI/CD pipeline * Updated TC_CADMIN_1_9: - Changed method in which CommissionOnNetwork was being established, needed to run through asserts module. - Added await async method for opening commissioning window. * Updated TC_CADMIN_1_9: - Turned quiet mode back on for CI/CD pipeline for this test as test is now passing. --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: C Freeman <cecille@google.com>
1 parent 65c388a commit 75fcadb

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ jobs:
511511
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_AccessChecker.py'
512512
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_CC_2_2.py'
513513
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_CC_10_1.py'
514+
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_9.py'
514515
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_CGEN_2_4.py'
515516
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_CNET_1_4.py'
516517
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_DA_1_2.py'

src/python_testing/TC_CADMIN_1_9.py

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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: run1
19+
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
20+
# test-runner-run/run1/factoryreset: True
21+
# test-runner-run/run1/quiet: True
22+
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
23+
# 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
24+
# === END CI TEST ARGUMENTS ===
25+
26+
import logging
27+
import random
28+
from time import sleep
29+
30+
import chip.clusters as Clusters
31+
from chip import ChipDeviceCtrl
32+
from chip.ChipDeviceCtrl import CommissioningParameters
33+
from chip.exceptions import ChipStackError
34+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
35+
from mobly import asserts
36+
37+
38+
class TC_CADMIN_1_9(MatterBaseTest):
39+
async def OpenCommissioningWindow(self) -> CommissioningParameters:
40+
try:
41+
cluster = Clusters.GeneralCommissioning
42+
attribute = cluster.Attributes.BasicCommissioningInfo
43+
duration = await self.read_single_attribute_check_success(endpoint=0, cluster=cluster, attribute=attribute)
44+
params = await self.th1.OpenCommissioningWindow(
45+
nodeid=self.dut_node_id, timeout=duration.maxCumulativeFailsafeSeconds, iteration=10000, discriminator=self.discriminator, option=1)
46+
return params
47+
48+
except Exception as e:
49+
logging.exception('Error running OpenCommissioningWindow %s', e)
50+
asserts.assert_true(False, 'Failed to open commissioning window')
51+
52+
def steps_TC_CADMIN_1_9(self) -> list[TestStep]:
53+
return [
54+
TestStep(1, "Commissioning, already done", is_commissioning=True),
55+
TestStep(
56+
2, "TH1 opens commissioning window on DUT with duration set to value for maxCumulativeFailsafeSeconds"),
57+
TestStep(3, "TH2 attempts to connect 20 times to endpoint with incorrect passcode"),
58+
TestStep(4, "TH2 attempts to connect to endpoint with correct passcode"),
59+
TestStep(5, "TH1 opening Commissioning Window one more time to validate ability to do so"),
60+
TestStep(6, "TH1 revoking Commissioning Window"),
61+
]
62+
63+
def generate_unique_random_value(self, value):
64+
while True:
65+
random_value = random.randint(10000000, 99999999)
66+
if random_value != value:
67+
return random_value
68+
69+
async def CommissionOnNetwork(
70+
self, setup_code: int
71+
):
72+
ctx = asserts.assert_raises(ChipStackError)
73+
with ctx:
74+
await self.th2.CommissionOnNetwork(
75+
nodeId=self.dut_node_id, setupPinCode=setup_code,
76+
filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator)
77+
errcode = ctx.exception.chip_error
78+
return errcode
79+
80+
async def CommissionAttempt(
81+
self, setupPinCode: int, expectedErrCode: int):
82+
83+
if expectedErrCode == 3:
84+
for cycle in range(20):
85+
logging.info("-----------------Current Iteration {}-------------------------".format(cycle+1))
86+
setup_code = self.generate_unique_random_value(setupPinCode)
87+
errcode = await self.CommissionOnNetwork(setup_code)
88+
logging.info('Commissioning complete done. Successful? {}, errorcode = {}, cycle={}'.format(
89+
errcode.is_success, errcode, (cycle+1)))
90+
asserts.assert_false(errcode.is_success, 'Commissioning complete did not error as expected')
91+
asserts.assert_true(errcode.sdk_code == expectedErrCode,
92+
'Unexpected error code returned from CommissioningComplete')
93+
94+
elif expectedErrCode == 50:
95+
logging.info("-----------------Attempting connection expecting timeout-------------------------")
96+
errcode = await self.CommissionOnNetwork(setupPinCode)
97+
logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format(errcode.is_success, errcode))
98+
asserts.assert_false(errcode.is_success, 'Commissioning complete did not error as expected')
99+
asserts.assert_true(errcode.sdk_code == expectedErrCode, 'Unexpected error code returned from CommissioningComplete')
100+
101+
def pics_TC_CADMIN_1_9(self) -> list[str]:
102+
return ["CADMIN.S"]
103+
104+
@async_test_body
105+
async def test_TC_CADMIN_1_9(self):
106+
self.step(1)
107+
108+
# Establishing TH1 and TH2
109+
self.th1 = self.default_controller
110+
self.discriminator = random.randint(0, 4095)
111+
th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority()
112+
th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1)
113+
self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True)
114+
115+
self.step(2)
116+
params = await self.OpenCommissioningWindow()
117+
setupPinCode = params.setupPinCode
118+
119+
self.step(3)
120+
await self.CommissionAttempt(setupPinCode, expectedErrCode=0x03)
121+
# TODO: Found if we don't add sleep time after test completes that we get unexpected error code and response after the 21st iteration.
122+
# Link to Bug Filed: https://github.com/project-chip/connectedhomeip/issues/34383
123+
sleep(1)
124+
125+
self.step(4)
126+
await self.CommissionAttempt(setupPinCode, expectedErrCode=0x32)
127+
128+
self.step(5)
129+
params = await self.OpenCommissioningWindow()
130+
131+
self.step(6)
132+
revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning()
133+
await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000)
134+
# The failsafe cleanup is scheduled after the command completes, so give it a bit of time to do that
135+
sleep(1)
136+
137+
138+
if __name__ == "__main__":
139+
default_matter_test_main()

0 commit comments

Comments
 (0)