28
28
# === END CI TEST ARGUMENTS ===
29
29
30
30
import logging
31
+ from enum import Enum
31
32
32
33
import chip .clusters as Clusters
33
34
from chip .interaction_model import Status
@@ -76,18 +77,37 @@ def pics_TC_WHM_2_1(self) -> list[str]:
76
77
@async_test_body
77
78
async def test_TC_WHM_2_1 (self ):
78
79
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
+
79
97
# Valid modes. Only ModeManual referred to in this test
80
98
# ModeOff = 0
81
99
ModeManual = 1
82
100
# ModeTimed = 2
83
101
84
- self .endpoint = self .matter_test_config .endpoint
85
-
86
102
attributes = Clusters .WaterHeaterMode .Attributes
87
103
88
104
self .step (1 )
89
105
# Commission DUT - already done
90
106
107
+ # Ensure that the device is in the correct state
108
+ if self .is_ci :
109
+ self .write_to_app_pipe ({"Name" : "Reset" })
110
+
91
111
self .step (2 )
92
112
93
113
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):
107
127
modes = [m .mode for m in supported_modes ]
108
128
invalid_mode = max (modes ) + 1
109
129
130
+ class CommonCodes (Enum ):
131
+ SUCCESS = 0x00
132
+ UNSUPPORTED_MODE = 0x01
133
+ GENERIC_FAILURE = 0x02
134
+ INVALID_IN_MODE = 0x03
135
+
110
136
self .step (4 )
111
137
112
138
ret = await self .send_change_to_mode_cmd (newMode = old_current_mode )
113
139
logging .info (f"ret.status { ret .status } " )
114
140
asserts .assert_equal (ret .status , Status .Success ,
115
141
"Changing the mode to the current mode should be a no-op" )
116
142
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
+
123
182
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 ))
124
188
125
189
self .step (10 )
126
190
0 commit comments