Skip to content

Commit 5baa83a

Browse files
Updates test steps, refactors dut reads that only need to be read once
1 parent 6ce438e commit 5baa83a

File tree

1 file changed

+61
-56
lines changed

1 file changed

+61
-56
lines changed

src/python_testing/TC_FAN_3_1.py

+61-56
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,26 @@ class OrderEnum(Enum):
6060
class TC_FAN_3_1(MatterBaseTest):
6161
def steps_TC_FAN_3_1(self):
6262
return [TestStep(1, "[FC] Commissioning already done.", is_commissioning=True),
63-
TestStep(2, "[FC] TH checks the DUT for the presence of the SpeedSetting feature.",
64-
"Save the result for future use."),
65-
TestStep(3, "[FC] TH subscribes to the DUT's FanControl cluster.", "Enables the TH to receive attribute updates."),
66-
TestStep(4, "[FC] TH configures the testing setup for the following scenario: Updating the PercentSetting attribute in ascending order and monitoring the FanMode (and SpeedSetting, if supported) attributes.",
63+
TestStep(2, "[FC] TH reads the FanModeSequence attribute to retreive the available fan modes.",
64+
"Save the result for future reference."),
65+
TestStep(3, "[FC] TH reads the FeatureMap attribute from the DUT.",
66+
"Check for the existence of the SpeedSetting feature. If the SpeedSetting feature is supported, read the SpeedMax attribute and save the result for future reference."),
67+
TestStep(4, "[FC] TH subscribes to the DUT's FanControl cluster.", "Enables the TH to receive attribute updates."),
68+
TestStep(5, "[FC] TH configures the testing setup for the following scenario: Updating the PercentSetting attribute in ascending order and monitoring the FanMode (and SpeedSetting, if supported) attributes.",
6769
"Initialize attribute values: - FanMode: 0 (Off). - PercentSetting: 0. - SpeedSetting (if supported): 0. Read the attribute values back and verify that they match the written values."),
68-
TestStep(5, "[FC] TH updates the value of the PercentSetting attribute of the DUT iteratively, in ascending order (from 1 to 100). For each iteration, the TH reads the value of the FanMode attribute (and SpeedSetting, if supported) from the DUT.",
70+
TestStep(6, "[FC] TH updates the value of the PercentSetting attribute of the DUT iteratively, in ascending order (from 1 to 100). For each iteration, the TH reads the value of the FanMode attribute (and SpeedSetting, if supported) from the DUT.",
6971
"For each update, the DUT shall return either a SUCCESS or an INVALID_IN_STATE status code. Verify the following for the FanMode attribute value (and SpeedSetting, if supported): - For iterations where the DUT returns a SUCCESS status code after the PercentSetting attribute value update, and a change in the attribute value is detected, verify that the current value is greater than the previous one. - For iterations where the DUT returns an INVALID_IN_STATE status code after the PercentSetting attribute value update, which means that no update operation occurred, verify that the current value is the same as the previous one."),
70-
TestStep(6, "[FC] TH configures the testing setup for the following scenario: Updating the PercentSetting attribute in descending order and monitoring the FanMode (and SpeedSetting, if supported) attributes.",
72+
TestStep(7, "[FC] TH configures the testing setup for the following scenario: Updating the PercentSetting attribute in descending order and monitoring the FanMode (and SpeedSetting, if supported) attributes.",
7173
"Initialize attribute values: - FanMode: 3 (High). - PercentSetting: 100. - SpeedSetting (if supported): SpeedMax attribute value. Read the attribute values back and verify that they match the written values."),
72-
TestStep(7, "[FC] TH updates the value of the PercentSetting attribute of the DUT iteratively, in descending order (from 99 to 0). For each iteration, the TH reads the value of the FanMode attribute (and SpeedSetting, if supported) from the DUT.",
74+
TestStep(8, "[FC] TH updates the value of the PercentSetting attribute of the DUT iteratively, in descending order (from 99 to 0). For each iteration, the TH reads the value of the FanMode attribute (and SpeedSetting, if supported) from the DUT.",
7375
"For each update, the DUT shall return either a SUCCESS or an INVALID_IN_STATE status code. Verify the following for the FanMode attribute value (and SpeedSetting, if supported): - For iterations where the DUT returns a SUCCESS status code after the PercentSetting attribute value update, and a change in the attribute value is detected, verify that the current value is less than the previous one. - For iterations where the DUT returns an INVALID_IN_STATE status code after the PercentSetting attribute value update, which means that no update operation occurred, verify that the current value is the same as the previous one."),
74-
TestStep(8, "[FC] TH configures the testing setup for the following scenario: Updating the FanMode attribute in ascending order and monitoring the PercentSetting (and SpeedSetting, if supported) attributes.",
76+
TestStep(9, "[FC] TH updates the DUT's FanMode attribute value iteratively, in accordance with the available fan modes provided by the FanModeSequence attribute, in ascending order from the fan mode subsequent to 0 (Off) to 3 (High). For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
7577
"Initialize attribute values: - FanMode: 0 (Off). - PercentSetting: 0. - SpeedSetting (if supported): 0. Read the attribute values back and verify that they match the written values."),
76-
TestStep(9, "[FC] TH updates the value of the FanMode attribute of the DUT iteratively, in ascending order (from 0 (Off) to 3 (High)). For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
78+
TestStep(10, "[FC] TH updates the value of the FanMode attribute of the DUT iteratively, in ascending order (from 0 (Off) to 3 (High)). For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
7779
"For each update, the DUT shall return either a SUCCESS or an INVALID_IN_STATE status code. Verify the following for the PercentSetting attribute value (and SpeedSetting, if supported): - For iterations where the DUT returns a SUCCESS status code after the FanMode attribute value update, and a change in the attribute value is detected, verify that the current value is greater than the previous one. - For iterations where the DUT returns an INVALID_IN_STATE status code after the FanMode attribute value update, which means that no update operation occurred, verify that the current value is the same as the previous one."),
78-
TestStep(10, "[FC] TH configures the testing setup for the following scenario: Updating the FanMode attribute in descending order and monitoring the PercentSetting (and SpeedSetting, if supported) attributes.",
80+
TestStep(11, "[FC] TH updates the DUT's FanMode attribute value iteratively, in accordance with the available fan modes provided by the FanModeSequence attribute, in descending order from the fan mode prior to 3 (High) to 0 (Off). For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
7981
"Initialize attribute values: - FanMode: 3 (High). - PercentSetting: 100. - SpeedSetting (if supported): SpeedMax attribute value. Read the attribute values back and verify that they match the written values."),
80-
TestStep(11, "[FC] TH updates the value of the FanMode attribute of the DUT iteratively, in descending order (from 3 (High) to 0 (Off)) For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
82+
TestStep(12, "[FC] TH updates the value of the FanMode attribute of the DUT iteratively, in descending order (from 3 (High) to 0 (Off)) For each iteration, the TH reads the value of the PercentSetting attribute (and SpeedSetting, if supported) from the DUT.",
8183
"For each update, the DUT shall return either a SUCCESS or an INVALID_IN_STATE status code. Verify the following for the PercentSetting attribute value (and SpeedSetting, if supported): - For iterations where the DUT returns a SUCCESS status code after the FanMode attribute value update, and a change in the attribute value is detected, verify that the current value is less than the previous one. - For iterations where the DUT returns an INVALID_IN_STATE status code after the FanMode attribute value update, which means that no update operation occurred, verify that the current value is the same as the previous one."),
8284
]
8385

@@ -162,7 +164,7 @@ async def get_fan_modes(self, endpoint, exclude_auto: bool = False) -> list[int]
162164

163165
return fan_modes
164166

165-
async def get_initialization_parametes(self, endpoint, attr_to_update, order):
167+
async def get_initialization_parametes(self, attr_to_update, order):
166168
cluster = Clusters.FanControl
167169
fan_mode_attr = cluster.Attributes.FanMode
168170
percent_setting_attr = cluster.Attributes.PercentSetting
@@ -180,14 +182,13 @@ async def get_initialization_parametes(self, endpoint, attr_to_update, order):
180182
value_init_update = 0 if order == OrderEnum.Ascending else percent_setting_max_value
181183
elif attr_to_update == fan_mode_attr:
182184
attr_to_verify = percent_setting_attr
183-
fan_modes = await self.get_fan_modes(endpoint, exclude_auto=True)
184-
iteration_range = range(1, len(fan_modes)) if order == OrderEnum.Ascending else range(len(fan_modes) - 2, -1, -1)
185+
iteration_range = range(1, len(self.fan_modes)) if order == OrderEnum.Ascending else range(len(self.fan_modes) - 2, -1, -1)
185186
value_init_verify = 0 if order == OrderEnum.Ascending else percent_setting_max_value
186187
value_init_update = fan_mode_off if order == OrderEnum.Ascending else fan_mode_high
187188

188189
return attr_to_verify, value_init_verify, value_init_update, iteration_range
189190

190-
def verify_attribute_progression(self, attr_to_verify, value_current, value_previous, order) -> None:
191+
def verify_attribute_change(self, attr_to_verify, value_current, value_previous, order) -> None:
191192
if order == OrderEnum.Ascending:
192193
# Verify that the current attribute value is greater than the previous attribute value
193194
asserts.assert_greater(value_current, value_previous,
@@ -220,7 +221,7 @@ async def log_scenario(self, endpoint, attr_to_update, attr_to_verify, speed_set
220221
logging.info(
221222
f"[FC] Initialization values: FanMode({fan_mode_log}:{fan_mode_log.name}) PercentSetting({percent_setting_log}){sub_text}")
222223

223-
async def verify_fan_control_attribute_values(self, endpoint, attr_to_update, order) -> None:
224+
async def verify_fan_control_attribute_progression(self, endpoint, attr_to_update, order) -> None:
224225
# Setup
225226
cluster = Clusters.FanControl
226227
speed_setting_attr = cluster.Attributes.SpeedSetting
@@ -237,9 +238,7 @@ async def verify_fan_control_attribute_values(self, endpoint, attr_to_update, or
237238

238239
# Get initialization parameters
239240
attr_to_verify, value_init_verify, value_init_update, iteration_range = \
240-
await self.get_initialization_parametes(
241-
endpoint, attr_to_update, order
242-
)
241+
await self.get_initialization_parametes(attr_to_update, order)
243242

244243
# Initializatization of the attribute to update (Write and read back verification)
245244
await self.write_and_verify_attribute(endpoint, attr_to_update, value_init_update)
@@ -249,8 +248,7 @@ async def verify_fan_control_attribute_values(self, endpoint, attr_to_update, or
249248

250249
# Initializatization of the SpeedSetting attribute, if supported (Write and read back verification)
251250
if self.supports_speed:
252-
speed_max = await self.read_setting(endpoint, speed_max_attr)
253-
speed_setting_init = 0 if order == OrderEnum.Ascending else speed_max
251+
speed_setting_init = 0 if order == OrderEnum.Ascending else self.speed_max
254252
speed_setting_read = await self.write_and_verify_attribute(endpoint, speed_setting_attr, speed_setting_init)
255253

256254
# *** NEXT STEP ***
@@ -277,18 +275,18 @@ async def verify_fan_control_attribute_values(self, endpoint, attr_to_update, or
277275
# Verify that the current attribute value is greater than the previous
278276
# one if order was set to Ascending, or less if order was set to Descending
279277
if write_status == Status.Success:
280-
# Get current attribute value and verify progression
278+
# Get current attribute value and verify correct increment/decrement
281279
queue = self.attribute_subscription.attribute_queue.queue
282280
attr_value_current = await self.get_attribute_value_from_queue(queue, attr_to_verify, timeout_sec)
283281
if attr_value_current is not None:
284-
self.verify_attribute_progression(attr_to_verify, attr_value_current, attr_value_previous, order)
282+
self.verify_attribute_change(attr_to_verify, attr_value_current, attr_value_previous, order)
285283
attr_value_previous = attr_value_current
286284

287-
# Get current SpeedSetting attribute value and verify progression (if supported)
285+
# Get current SpeedSetting attribute value and verify correct increment/decrement (if supported)
288286
if self.supports_speed:
289287
speed_setting_current = await self.get_attribute_value_from_queue(queue, speed_setting_attr, timeout_sec)
290288
if speed_setting_current is not None:
291-
self.verify_attribute_progression(speed_setting_attr, speed_setting_current, speed_setting_previous, order)
289+
self.verify_attribute_change(speed_setting_attr, speed_setting_current, speed_setting_previous, order)
292290
speed_setting_previous = speed_setting_current
293291

294292
# If the write status is INVALID_IN_STATE, it means no write operation occurred
@@ -311,49 +309,56 @@ def pics_TC_FAN_3_1(self) -> list[str]:
311309
@async_test_body
312310
async def test_TC_FAN_3_1(self):
313311
# Setup
314-
endpoint = self.get_endpoint(default=1)
312+
ep = self.get_endpoint(default=1)
315313
cluster = Clusters.FanControl
316314
attributes = cluster.Attributes
317-
315+
318316
# *** STEP 1 ***
319317
# Commissioning already done
320318
self.step(1)
321319

322320
# *** STEP 2 ***
323-
# TH checks for the existence of the SpeedSetting feature
321+
# TH reads the FanModeSequence attribute to retreive the available fan modes
324322
self.step(2)
325-
feature_map = await self.read_setting(endpoint, attributes.FeatureMap)
326-
self.supports_speed = bool(feature_map & cluster.Bitmaps.Feature.kMultiSpeed)
323+
self.fan_modes = await self.get_fan_modes(ep, exclude_auto=True)
327324

328325
# *** STEP 3 ***
329-
# TH subscribes to the DUT's FanControl cluster
326+
# TH reads the FeatureMap attribute to check for support of the SpeedSetting feature
330327
self.step(3)
328+
feature_map = await self.read_setting(ep, attributes.FeatureMap)
329+
self.supports_speed = bool(feature_map & cluster.Bitmaps.Feature.kMultiSpeed)
330+
if self.supports_speed:
331+
self.speed_max = await self.read_setting(ep, attributes.SpeedMax)
332+
333+
# *** STEP 4 ***
334+
# TH subscribes to the DUT's FanControl cluster
335+
self.step(4)
331336
self.attribute_subscription = ClusterAttributeChangeAccumulator(cluster)
332-
await self.attribute_subscription.start(self.default_controller, self.dut_node_id, endpoint)
333-
334-
# TH writes to the DUT the PercentSetting attribute iteratively within
335-
# a range of 1 to 100 one at a time in ascending order
336-
# Verifies that FanMode and SpeedSetting values (if supported) are being
337-
# updated accordingly (current values greater than previous values)
338-
await self.verify_fan_control_attribute_values(endpoint, attributes.PercentSetting, OrderEnum.Ascending)
339-
340-
# TH writes to the DUT the PercentSetting attribute iteratively within
341-
# a range of 99 to 0 one at a time in descending order
342-
# Verifies that FanMode and SpeedSetting values (if supported) are being
343-
# updated accordingly (current values less than previous values)
344-
await self.verify_fan_control_attribute_values(endpoint, attributes.PercentSetting, OrderEnum.Descending)
345-
346-
# TH writes to the DUT the FanMode attribute iteratively within a range of
347-
# 0 (Off) to the number of available fan modes one at a time in ascending order
348-
# Verifies that PercentSetting and SpeedSetting values (if supported) are being
349-
# updated accordingly (current values greater than previous values)
350-
await self.verify_fan_control_attribute_values(endpoint, attributes.FanMode, OrderEnum.Ascending)
351-
352-
# TH writes to the DUT the FanMode attribute iteratively within a range of
353-
# the number of available fan modes one at a time in descending order
354-
# Verifies that PercentSetting and SpeedSetting values (if supported) are being
355-
# updated accordingly (current values less than previous values)
356-
await self.verify_fan_control_attribute_values(endpoint, attributes.FanMode, OrderEnum.Descending)
337+
await self.attribute_subscription.start(self.default_controller, self.dut_node_id, ep)
338+
339+
# TH updates the DUT's PercentSetting attribute value iteratively, in ascending order (from 1 to 100)
340+
# and monitors the FanMode (and SpeedSetting, if supported) attribute value's correct progression
341+
# (current value greater than previous value)
342+
await self.verify_fan_control_attribute_progression(ep, attributes.PercentSetting, OrderEnum.Ascending)
343+
344+
# TH updates the DUT's PercentSetting attribute value iteratively, in descending order (from 99 to 0)
345+
# and monitors the FanMode (and SpeedSetting, if supported) attribute value's correct progression
346+
# (current value less than previous value)
347+
await self.verify_fan_control_attribute_progression(ep, attributes.PercentSetting, OrderEnum.Descending)
348+
349+
# TH updates the DUT's FanMode attribute value iteratively, in accordance with the
350+
# available fan modes provided by the FanModeSequence attribute, in ascending order
351+
# from the fan mode subsequent to 0 (Off) to 3 (High) and monitors the PercentSetting
352+
# (and SpeedSetting, if supported) attribute value's correct progression
353+
# (current value greater than previous value)
354+
await self.verify_fan_control_attribute_progression(ep, attributes.FanMode, OrderEnum.Ascending)
355+
356+
# TH updates the DUT's FanMode attribute value iteratively, in accordance with the
357+
# available fan modes provided by the FanModeSequence attribute, in descending order
358+
# from the fan mode prior to 3 (High) to 0 (Off) and monitors the PercentSetting
359+
# (and SpeedSetting, if supported) attribute value's correct progression
360+
# (current value less than previous value)
361+
await self.verify_fan_control_attribute_progression(ep, attributes.FanMode, OrderEnum.Descending)
357362

358363

359364
if __name__ == "__main__":

0 commit comments

Comments
 (0)