Skip to content

Commit 6180583

Browse files
DejinChenrestyled-commitsReneJosefsen
authored
Added python testing for secondary network interface (project-chip#34307)
* Added python testing for secondary network interface * Restyled by autopep8 * Restyled by isort * Modified test steps * Use NumNetworkCommissioning in test * Fix CI error. * Update src/python_testing/TC_CNET_1_4.py Co-authored-by: René Josefsen <69624991+ReneJosefsen@users.noreply.github.com> * Update src/python_testing/TC_CNET_1_4.py Co-authored-by: René Josefsen <69624991+ReneJosefsen@users.noreply.github.com> * check response instead of reading on endpoint 0 * modified step description * Modified step description. * Update steps. * Update steps. --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: René Josefsen <69624991+ReneJosefsen@users.noreply.github.com>
1 parent 7d26280 commit 6180583

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ jobs:
503503
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_ACE_1_5.py'
504504
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'
505505
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'
506+
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'
506507
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'
507508
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_5.py'
508509
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_7.py'

src/python_testing/TC_CNET_1_4.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments
19+
# for details about the block below.
20+
#
21+
# === BEGIN CI TEST ARGUMENTS ===
22+
# test-runner-runs: run1
23+
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
24+
# test-runner-run/run1/factoryreset: True
25+
# test-runner-run/run1/quiet: True
26+
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
27+
# test-runner-run/run1/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:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
28+
# === END CI TEST ARGUMENTS ===
29+
30+
import logging
31+
32+
import chip.clusters as Clusters
33+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
34+
from mobly import asserts
35+
36+
kRootEndpointId = 0
37+
kSecondaryNetworkInterfaceDeviceTypeId = 0x0019
38+
39+
40+
class TC_CNET_1_4(MatterBaseTest):
41+
def steps_TC_CNET_1_4(self):
42+
return [TestStep(1, "TH is commissioned", is_commissioning=True),
43+
TestStep(2, 'TH performs a wildcard read of the FeatureMap attribute on Network Commissioning clusters across all endpoints, and saves the response as `NetworkCommissioningResponse`'),
44+
TestStep(3, 'If `NetworkCommissioningResponse` does not contain any entries for Network Commissioning cluster, skip remaining steps and end test case'),
45+
TestStep(4, 'If `NetworkCommissioningResponse` contains only a single entry for Network Commissioning cluster on Endpoint 0, skip remaining steps and end test case. Verify `NetworkCommissioningResponse` contains an entry for Network Commissioning cluster on Endpoint 0'),
46+
TestStep(5, 'TH reads from the DUT the Descriptor Cluster DeviceTypeList attribute on each endpoint from the `NetworkCommissioningResponse` (except for Endpoint 0), verify that the Secondary Network Interface device type id (0x0019) is listed in the DeviceTypeList'),
47+
TestStep(6, 'TH reads from the DUT the General Commissioning Cluster SupportsConcurrentConnection attribute, verify that it is true')]
48+
49+
def def_TC_CNET_1_4(self):
50+
return '[TC-CNET-1.4] Verification for Secondary Network Interface [DUT-Server]'
51+
52+
def pics_TC_CNET_1_4(self):
53+
return ['CNET.S']
54+
55+
# Override default timeout.
56+
@property
57+
def default_timeout(self) -> int:
58+
return 200
59+
60+
@async_test_body
61+
async def test_TC_CNET_1_4(self):
62+
# Commissioning is already done
63+
self.step(1)
64+
65+
self.step(2)
66+
# Read FeatureMap attribute with wildcard endpoint
67+
NetworkCommissioningResponse = await self.default_controller.ReadAttribute(self.dut_node_id, [(Clusters.NetworkCommissioning.Attributes.FeatureMap)], fabricFiltered=True)
68+
69+
self.step(3)
70+
NumNetworkCommissioning = len(NetworkCommissioningResponse)
71+
if NumNetworkCommissioning == 0:
72+
logging.info('No endpoint has Network Commissioning Cluster, skipping remaining steps')
73+
self.skip_all_remaining_steps(4)
74+
return
75+
76+
self.step(4)
77+
endpoints = []
78+
for endpoint, _ in NetworkCommissioningResponse.items():
79+
endpoints.append(endpoint)
80+
if kRootEndpointId not in endpoints:
81+
asserts.assert_true(False, "There is no Network Commissioning Cluster on endpoint 0")
82+
83+
if NumNetworkCommissioning == 1:
84+
logging.info('Only endpoint 0 has Network Commissioning Cluster, skipping remaining steps')
85+
self.skip_all_remaining_steps(5)
86+
return
87+
88+
self.step(5)
89+
for endpoint in endpoints:
90+
if endpoint == kRootEndpointId:
91+
continue
92+
device_type_list = await self.read_single_attribute_check_success(cluster=Clusters.Descriptor,
93+
attribute=Clusters.Descriptor.Attributes.DeviceTypeList, endpoint=endpoint)
94+
required_device_types = {kSecondaryNetworkInterfaceDeviceTypeId}
95+
found_device_types = {device.deviceType for device in device_type_list}
96+
asserts.assert_true(required_device_types.intersection(found_device_types),
97+
"Network Commissioning Cluster is not on Root Node or Secondary Network Interface")
98+
99+
self.step(6)
100+
concurrent_connection = await self.read_single_attribute_check_success(cluster=Clusters.GeneralCommissioning,
101+
attribute=Clusters.GeneralCommissioning.Attributes.SupportsConcurrentConnection)
102+
asserts.assert_true(concurrent_connection, "The device does not support concurrent connection commissioning")
103+
104+
105+
if __name__ == "__main__":
106+
default_matter_test_main()

0 commit comments

Comments
 (0)