Skip to content

Commit

Permalink
Added python testing for secondary network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DejinChen committed Jul 8, 2024
1 parent 6e31453 commit 8846edd
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/python_testing/TC_CNET_1_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# 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 logging
import string
from typing import Optional

import chip.clusters as Clusters
from chip.clusters.Types import NullValue
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main, type_matches
from mobly import asserts


class TC_CNET_1_4(MatterBaseTest):
def steps_TC_CNET_1_4(self):
return [TestStep(1, 'TH reads from the DUT the Network Commissioning Cluster FeatureMap with wildcard endpoint. If fewer than two endpoints have Network Commissioning Cluster, skip the remaining steps in this test case'),
TestStep(2, 'TH reads from the DUT the General Commissioning Cluster SupportsConcurrentConnection attribute and checks that it is true'),
TestStep(3, 'TH reads from the DUT the Descriptor Cluster DeviceTypeList attribute and check that the device type of the endpoint with Network Commissioning Cluster is Root Node or Secondary Network Interface.')]

def def_TC_CNET_1_4(self):
return '[TC-CNET-1.4] Verification for Secondary Network Interface [DUT-Server]'

def pics_TC_CNET_1_4(self):
return ['CNET.S']

@async_test_body
async def test_TC_CNET_1_4(self):
cnet = Clusters.NetworkCommissioning
afeam = cnet.Attributes.FeatureMap

self.step(1)
# Read FeatureMap attribute with wildcard endpoint
feature_map_results = await self.default_controller.ReadAttribute(self.dut_node_id, [(afeam)], fabricFiltered=True)

if len(feature_map_results) <= 1:
logging.info('Fewer than two endpoints have Network Commissioning Cluster, skipping remaining steps')
self.skip_all_remaining_steps(2)
return

endpoints = []
for endpoint, data in feature_map_results.items():
endpoints.append(endpoint)
logging.info(f"Network Commissioning Cluster on endpoints: {endpoints}")

self.step(2)
cgen = Clusters.GeneralCommissioning
ascc = cgen.Attributes.SupportsConcurrentConnection
concurrent_connection = await self.read_single_attribute_check_success(cluster=cgen, attribute=ascc)
asserts.assert_true(concurrent_connection, "The device does not support concurrent connection commissioning")

self.step(3)
cdesc = Clusters.Descriptor
adevt = cdesc.Attributes.DeviceTypeList

for endpoint in endpoints:
device_type_list = await self.read_single_attribute_check_success(cluster=Clusters.Descriptor, attribute=adevt, endpoint=endpoint)
required_device_types = {17, 25} # Root Node device id: 0x11, Secondary Network Interface device id: 0x19
found_device_types = {device.deviceType for device in device_type_list}
asserts.assert_true(required_device_types.intersection(found_device_types),
"Network Commissioning Cluster is not on Root Node or Secondary Network Interface")

if __name__ == "__main__":
default_matter_test_main()

0 comments on commit 8846edd

Please sign in to comment.