Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cdf03e2

Browse files
committedJul 28, 2024·
Add TC_ECOINFO_2_1.py test implementation
1 parent 55786a0 commit cdf03e2

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed
 

‎src/python_testing/TC_ECOINFO_2_1.py

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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.clusters.Types import NullValue
22+
from chip.interaction_model import Status
23+
from chip.tlv import uint
24+
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, type_matches
25+
from mobly import asserts
26+
27+
28+
class TC_ECOINFO_2_1(MatterBaseTest):
29+
30+
def steps_TC_ECOINFO_2_1(self) -> list[TestStep]:
31+
steps = [TestStep(1, "Identify endpoints with Ecosystem Information Cluster", is_commissioning=True),
32+
TestStep(2, "Reading RemovedOn Attribute"),
33+
TestStep(3, "Reading DeviceDirectory Attribute"),
34+
TestStep(4, "Reading LocationDirectory Attribute"),
35+
TestStep(5, "Try Writing to RemovedOn Attribute"),
36+
TestStep(6, "Try Writing to DeviceDirectory Attribute"),
37+
TestStep(7, "Try Writing to LocationDirectory Attribute"),
38+
TestStep(8, "Repeating steps 2 to 7 for each endpoint identified in step 1")]
39+
return steps
40+
41+
@async_test_body
42+
async def test_TC_IDM_1_4(self):
43+
dev_ctrl = self.default_controller
44+
dut_node_id = self.dut_node_id
45+
46+
self.print_step(0, "Commissioning, already done")
47+
48+
first_cluster_validation = True
49+
self.step(1)
50+
endpoint_wild_card_read = await dev_ctrl.ReadAttribute(dut_node_id, [(Clusters.EcosystemInformation.Attributes.ClusterRevision)])
51+
list_of_endpoints = list(endpoint_wild_card_read.keys())
52+
53+
for cluster_endpoint in list_of_endpoints:
54+
if first_cluster_validation:
55+
self.step(2)
56+
removed_on = await self.read_single_attribute(
57+
dev_ctrl,
58+
dut_node_id,
59+
endpoint=cluster_endpoint,
60+
attribute=Clusters.EcosystemInformation.Attributes.RemovedOn)
61+
62+
removed_on_is_null = removed_on is NullValue
63+
if not removed_on_is_null:
64+
asserts.assert_true(type_matches(removed_on, uint))
65+
asserts.assert_greater(removed_on, 0, "RemovedOn must be greater than 0", "RemovedOn should be a uint")
66+
67+
if first_cluster_validation:
68+
self.step(3)
69+
device_directory = await self.read_single_attribute(
70+
dev_ctrl,
71+
dut_node_id,
72+
endpoint=cluster_endpoint,
73+
attribute=Clusters.EcosystemInformation.Attributes.DeviceDirectory,
74+
fabricFiltered=False)
75+
76+
num_of_devices = len(device_directory)
77+
if removed_on_is_null:
78+
asserts.assert_less_equal(num_of_devices, 256, "Too many device entries")
79+
for device in device_directory:
80+
# TODO do fabric index check first
81+
if device.deviceName is not None:
82+
asserts.assert_true(type_matches(device.deviceName, str), "DeviceName should be a string")
83+
asserts.assert_less_equal(len(device.deviceName), 64, "DeviceName should be <= 64")
84+
asserts.assert_true(type_matches(device.deviceNameLastEdit, uint), "DeviceNameLastEdit should be a uint")
85+
asserts.assert_greater(device.deviceNameLastEdit, 0, "DeviceNameLastEdit must be greater than 0")
86+
else:
87+
asserts.assert_true(device.deviceNameLastEdit is None, "DeviceNameLastEdit should not be provided when there is no DeviceName")
88+
89+
asserts.assert_true(type_matches(device.bridgedEndpoint, uint), "BridgedEndpoint should be a uint")
90+
asserts.assert_greater_equal(device.bridgedEndpoint, 0, "BridgedEndpoint >= 0")
91+
asserts.assert_less_equal(device.bridgedEndpoint, 0xffff_ffff, "BridgedEndpoint less than or equal to Invalid Endpoint value")
92+
93+
asserts.assert_true(type_matches(device.originalEndpoint, uint), "OriginalEndpoint should be a uint")
94+
asserts.assert_greater_equal(device.originalEndpoint, 0, "OriginalEndpoint >= 0")
95+
asserts.assert_less(device.originalEndpoint, 0xffff_ffff, "OriginalEndpoint less than or equal to Invalid Endpoint value")
96+
97+
asserts.assert_true(type_matches(device.deviceTypes, list), "DeviceTypes should be a list")
98+
asserts.assert_greater_equal(len(device.deviceTypes), 1, "DeviceTypes list must contains at least one entry")
99+
for device_type in device.deviceTypes:
100+
asserts.assert_true(type_matches(device_type.deviceType, uint), "DeviceType should be a uint")
101+
# TODO what other validation can we do here to device_type.deviceType
102+
asserts.assert_true(type_matches(device_type.revision, uint), "device type's revision should be a uint")
103+
asserts.assert_greater_equal(device_type.revision, 1, "device type's revision must >= 1")
104+
105+
asserts.assert_true(type_matches(device.uniqueLocationIDs, list), "UniqueLocationIds should be a list")
106+
num_of_unique_location_ids = len(device.uniqueLocationIDs)
107+
asserts.assert_less_equal(num_of_unique_location_ids, 64, "UniqueLocationIds list should be <= 64")
108+
for location_id in device.uniqueLocationIDs:
109+
asserts.assert_true(type_matches(location_id, str), "UniqueLocationId should be a string")
110+
location_id_string_length = len(location_id)
111+
asserts.assert_greater_equal(location_id_string_length, 1, "UniqueLocationId must contain at least one character")
112+
asserts.assert_less_equal(location_id_string_length, 64, "UniqueLocationId should be <= 64")
113+
114+
asserts.assert_true(type_matches(device.uniqueLocationIDsLastEdit, uint), "UniqueLocationIdsLastEdit should be a uint")
115+
if num_of_unique_location_ids:
116+
asserts.assert_greater(device.uniqueLocationIDsLastEdit, 0, "UniqueLocationIdsLastEdit must be non-zero")
117+
else:
118+
# TODO double check this is actually a true thing to be asserting.
119+
asserts.assert_equal(device.uniqueLocationIDsLastEdit, 0, "UniqueLocationIdsLastEdit must be 0 if there are no UniqueLocationIds")
120+
else:
121+
asserts.assert_equal(num_of_devices, 0, "Device was removed, there should be no devices in DeviceDirectory")
122+
123+
if first_cluster_validation:
124+
self.step(4)
125+
location_directory = await self.read_single_attribute(
126+
dev_ctrl,
127+
dut_node_id,
128+
endpoint=cluster_endpoint,
129+
attribute=Clusters.EcosystemInformation.Attributes.LocationDirectory,
130+
fabricFiltered=False)
131+
132+
num_of_locations = len(location_directory)
133+
if removed_on_is_null:
134+
asserts.assert_less_equal(num_of_locations, 64, "Too many location entries")
135+
for location in location_directory:
136+
asserts.assert_true(type_matches(location.uniqueLocationID, str), "UniqueLocationId should be a string")
137+
location_id_string_length = len(location.uniqueLocationID)
138+
asserts.assert_greater_equal(location_id_string_length, 1, "UniqueLocationId must contain at least one character")
139+
asserts.assert_less_equal(location_id_string_length, 64, "UniqueLocationId should be <= 64")
140+
141+
asserts.assert_true(type_matches(location.locationDescriptor.locationName, str), "LocationName should be a string")
142+
asserts.assert_less_equal(len(location.locationDescriptor.locationName), 64, "LocationName should be <= 64")
143+
144+
if location.locationDescriptor.floorNumber is not NullValue:
145+
asserts.assert_true(type_matches(location.locationDescriptor.floorNumber, int), "FloorNumber should be an int")
146+
# TODO check in range of int16.
147+
148+
if location.locationDescriptor.areaType is not NullValue:
149+
# TODO check areaType is valid.
150+
pass
151+
152+
asserts.assert_true(type_matches(location.locationDescriptorLastEdit, uint), "UniqueLocationIdsLastEdit should be a uint")
153+
asserts.assert_greater(location.locationDescriptorLastEdit, 0, "LocationDescriptorLastEdit must be non-zero")
154+
155+
156+
else:
157+
asserts.assert_equal(num_of_locations, 0, "Device was removed, there should be no location in LocationDirectory")
158+
159+
if first_cluster_validation:
160+
self.step(5)
161+
result = await dev_ctrl.WriteAttribute(dut_node_id, [(cluster_endpoint, Clusters.EcosystemInformation.Attributes.RemovedOn(2))])
162+
asserts.assert_equal(len(result), 1, "Expecting only one result from trying to write to RemovedOn Attribute")
163+
asserts.assert_equal(result[0].Status, Status.UnsupportedWrite, "Expecting Status of UnsupportedWrite")
164+
165+
if first_cluster_validation:
166+
self.step(6)
167+
result = await dev_ctrl.WriteAttribute(dut_node_id, [(cluster_endpoint, Clusters.EcosystemInformation.Attributes.DeviceDirectory([]))])
168+
asserts.assert_equal(len(result), 1, "Expecting only one result from trying to write to DeviceDirectory Attribute")
169+
asserts.assert_equal(result[0].Status, Status.UnsupportedWrite, "Expecting Status of UnsupportedWrite")
170+
171+
if first_cluster_validation:
172+
self.step(7)
173+
result = await dev_ctrl.WriteAttribute(dut_node_id, [(cluster_endpoint, Clusters.EcosystemInformation.Attributes.DeviceDirectory([]))])
174+
asserts.assert_equal(len(result), 1, "Expecting only one result from trying to write to LocationDirectory Attribute")
175+
asserts.assert_equal(result[0].Status, Status.UnsupportedWrite, "Expecting Status of UnsupportedWrite")
176+
177+
if first_cluster_validation:
178+
self.step(8)
179+
180+
first_cluster_validation = False

0 commit comments

Comments
 (0)
Please sign in to comment.