Skip to content

Commit e45b3c9

Browse files
committed
Implement test steps 5-9
1 parent ba9faf2 commit e45b3c9

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

src/python_testing/TC_WHM_2_1.py

+72-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# === END CI TEST ARGUMENTS ===
2929

3030
import logging
31+
from enum import Enum
3132

3233
import chip.clusters as Clusters
3334
from chip.interaction_model import Status
@@ -76,18 +77,37 @@ def pics_TC_WHM_2_1(self) -> list[str]:
7677
@async_test_body
7778
async def test_TC_WHM_2_1(self):
7879

80+
asserts.assert_true('PIXIT.WHM.MODE_CHANGE_OK' in self.matter_test_config.global_test_params,
81+
"PIXIT.WHM.MODE_CHANGE_OK must be included on the command line in "
82+
"the --int-arg flag as PIXIT.WHM.MODE_CHANGE_OK:<mode id>")
83+
asserts.assert_true('PIXIT.WHM.MODE_CHANGE_FAIL' in self.matter_test_config.global_test_params,
84+
"PIXIT.WHM.MODE_CHANGE_FAIL must be included on the command line in "
85+
"the --int-arg flag as PIXIT.WHM.MODE_CHANGE_FAIL:<mode id>")
86+
87+
self.endpoint = self.matter_test_config.endpoint
88+
self.mode_ok = self.matter_test_config.global_test_params['PIXIT.WHM.MODE_CHANGE_OK']
89+
self.mode_fail = self.matter_test_config.global_test_params['PIXIT.WHM.MODE_CHANGE_FAIL']
90+
self.is_ci = self.check_pics("PICS_SDK_CI_ONLY")
91+
if self.is_ci:
92+
app_pid = self.matter_test_config.app_pid
93+
if app_pid == 0:
94+
asserts.fail("The --app-pid flag must be set when PICS_SDK_CI_ONLY is set.c")
95+
self.app_pipe = self.app_pipe + str(app_pid)
96+
7997
# Valid modes. Only ModeManual referred to in this test
8098
# ModeOff = 0
8199
ModeManual = 1
82100
# ModeTimed = 2
83101

84-
self.endpoint = self.matter_test_config.endpoint
85-
86102
attributes = Clusters.WaterHeaterMode.Attributes
87103

88104
self.step(1)
89105
# Commission DUT - already done
90106

107+
# Ensure that the device is in the correct state
108+
if self.is_ci:
109+
self.write_to_app_pipe({"Name": "Reset"})
110+
91111
self.step(2)
92112

93113
supported_modes = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.SupportedModes)
@@ -107,20 +127,64 @@ async def test_TC_WHM_2_1(self):
107127
modes = [m.mode for m in supported_modes]
108128
invalid_mode = max(modes) + 1
109129

130+
class CommonCodes(Enum):
131+
SUCCESS = 0x00
132+
UNSUPPORTED_MODE = 0x01
133+
GENERIC_FAILURE = 0x02
134+
INVALID_IN_MODE = 0x03
135+
110136
self.step(4)
111137

112138
ret = await self.send_change_to_mode_cmd(newMode=old_current_mode)
113139
logging.info(f"ret.status {ret.status}")
114140
asserts.assert_equal(ret.status, Status.Success,
115141
"Changing the mode to the current mode should be a no-op")
116142

117-
# Steps 5-9 are not performed as WHM.S.M.CAN_TEST_MODE_FAILURE is false
118-
# TODO - see issue 34565
119-
self.step(5)
120-
self.step(6)
121-
self.step(7)
122-
self.step(8)
143+
if 1 or self.check_pics("WHM.S.M.CAN_TEST_MODE_FAILURE"):
144+
asserts.assert_true(self.mode_fail in modes,
145+
"The MODE_CHANGE_FAIL PIXIT value (%d) is not a supported mode" % (self.mode_fail))
146+
self.step(5)
147+
if self.is_ci:
148+
print("Change to WHM mode ManualMode")
149+
await self.send_change_to_mode_cmd(newMode=1)
150+
else:
151+
self.wait_for_user_input(
152+
prompt_msg="Manually put the device in a state from which it will FAIL to transition to mode %d, and press Enter when ready." % (self.mode_fail))
153+
154+
self.step(6)
155+
old_current_mode = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)
156+
157+
logging.info("CurrentMode: %s" % (old_current_mode))
158+
159+
self.step(7)
160+
161+
ret = await self.send_change_to_mode_cmd(newMode=self.mode_fail)
162+
st = ret.status
163+
is_mfg_code = st in range(0x80, 0xC0)
164+
is_err_code = (st == CommonCodes.GENERIC_FAILURE.value) or (st == CommonCodes.INVALID_IN_MODE.value) or is_mfg_code
165+
asserts.assert_true(is_err_code, "Changing to mode %d must fail due to the current state of the device" % (self.mode_fail))
166+
st_text_len = len(ret.statusText)
167+
asserts.assert_true(st_text_len in range(1, 65), "StatusText length (%d) must be between 1 and 64" % (st_text_len))
168+
169+
self.step(8)
170+
current_mode = await self.read_mode_attribute_expect_success(endpoint=self.endpoint, attribute=attributes.CurrentMode)
171+
172+
logging.info("CurrentMode: %s" % (current_mode))
173+
174+
asserts.assert_true(current_mode == old_current_mode, "CurrentMode changed after failed ChangeToMode command!")
175+
176+
else:
177+
self.step(5)
178+
self.step(6)
179+
self.step(7)
180+
self.step(8)
181+
123182
self.step(9)
183+
if self.is_ci:
184+
print("Continuing...")
185+
else:
186+
self.wait_for_user_input(
187+
prompt_msg="Manually put the device in a state from which it will SUCCESSFULLY transition to mode %d, and press Enter when ready." % (self.mode_ok))
124188

125189
self.step(10)
126190

0 commit comments

Comments
 (0)