15
15
# limitations under the License.
16
16
#
17
17
18
- # This test requires a TH_SERVER application. Please specify with --string-arg th_server_app_path :<path_to_app>
19
- # TH_SERVER must support following arguments: --secured-device-port --discriminator --passcode --KVS
18
+ # This test requires a TH_ICD_SERVER application. Please specify with --string-arg th_icd_server_app_path :<path_to_app>
19
+ # TH_ICD_SERVER must support following arguments: --secured-device-port --discriminator --passcode --KVS
20
20
# E.g: python3 src/python_testing/TC_BRBINFO_4_1.py --commissioning-method on-network --qr-code MT:-24J042C00KA0648G00 \
21
- # --string-arg th_server_app_path :out/linux-x64-lit-icd/lit-icd-app
21
+ # --string-arg th_icd_server_app_path :out/linux-x64-lit-icd/lit-icd-app
22
22
23
23
import logging
24
24
import os
@@ -62,7 +62,8 @@ def steps_TC_BRBINFO_4_1(self) -> list[TestStep]:
62
62
TestStep ("1a" , "TH reads from the ICD the A_IDLE_MODE_DURATION, A_ACTIVE_MODE_DURATION, and ACTIVE_MODE_THRESHOLD attributes" ),
63
63
TestStep ("1b" , "Simple KeepActive command w/ subscription. ActiveChanged event received by TH contains PromisedActiveDuration" ),
64
64
TestStep ("2" , "Sends 3x KeepActive commands w/ subscription. ActiveChanged event received ONCE and contains PromisedActiveDuration" ),
65
- TestStep ("3" , "KeepActive not returned after 60 minutes of offline ICD" ),
65
+ TestStep ("3" , "TH waits for check-in from TH_ICD to confirm no additional ActiveChanged events are recieved" ),
66
+ TestStep ("4" , "KeepActive not returned after 60 minutes of offline ICD" ),
66
67
]
67
68
return steps
68
69
@@ -110,9 +111,10 @@ async def setup_class(self):
110
111
111
112
super ().setup_class ()
112
113
self .app_process = None
113
- app = self .user_params .get ("th_server_app_path" , None )
114
+ self .app_process_paused = False
115
+ app = self .user_params .get ("th_icd_server_app_path" , None )
114
116
if not app :
115
- asserts .fail ('This test requires a TH_SERVER app. Specify app path with --string-arg th_server_app_path :<path_to_app>' )
117
+ asserts .fail ('This test requires a TH_ICD_SERVER app. Specify app path with --string-arg th_icd_server_app_path :<path_to_app>' )
116
118
117
119
self .kvs = f'kvs_{ str (uuid .uuid4 ())} '
118
120
self .port = 5543
@@ -129,6 +131,7 @@ async def setup_class(self):
129
131
logging .info ("Commissioning of ICD to fabric one (TH)" )
130
132
self .icd_nodeid = 1111
131
133
134
+ self .default_controller .EnableICDRegistration (self .default_controller .GenerateICDRegistrationParameters ())
132
135
await self .default_controller .CommissionOnNetwork (nodeId = self .icd_nodeid , setupPinCode = passcode , filterType = ChipDeviceCtrl .DiscoveryFilterType .LONG_DISCRIMINATOR , filter = discriminator )
133
136
134
137
logging .info ("Commissioning of ICD to fabric two (DUT)" )
@@ -138,9 +141,10 @@ async def setup_class(self):
138
141
params .commissioningParameters .setupManualCode , params .commissioningParameters .setupQRCode )
139
142
140
143
def teardown_class (self ):
141
- # In case the th_server_app_path does not exist, then we failed the test
144
+ # In case the th_icd_server_app_path does not exist, then we failed the test
142
145
# and there is nothing to remove
143
146
if self .app_process is not None :
147
+ self .resume_th_icd_server (check_state = False )
144
148
logging .warning ("Stopping app with SIGTERM" )
145
149
self .app_process .send_signal (signal .SIGTERM .value )
146
150
self .app_process .wait ()
@@ -150,6 +154,24 @@ def teardown_class(self):
150
154
151
155
super ().teardown_class ()
152
156
157
+ def pause_th_icd_server (self , check_state ):
158
+ if check_state :
159
+ asserts .assert_false (self .app_process_paused , "ICD TH Server unexpectedly is already paused" )
160
+ if self .app_process_paused :
161
+ return
162
+ # stops (halts) the ICD server process by sending a SIGTOP signal
163
+ self .app_process .send_signal (signal .SIGSTOP .value )
164
+ self .app_process_paused = True
165
+
166
+ def resume_th_icd_server (self , check_state ):
167
+ if check_state :
168
+ asserts .assert_true (self .app_process_paused , "ICD TH Server unexpectedly is already running" )
169
+ if not self .app_process_paused :
170
+ return
171
+ # resumes (continues) the ICD server process by sending a SIGCONT signal
172
+ self .app_process .send_signal (signal .SIGCONT .value )
173
+ self .app_process_paused = False
174
+
153
175
#
154
176
# BRBINFO 4.1 Test Body
155
177
#
@@ -232,58 +254,54 @@ async def test_TC_BRBINFO_4_1(self):
232
254
233
255
self .step ("2" )
234
256
235
- stay_active_duration_ms = 1500
236
- logging .info (f"Sending KeepActiveCommand({ stay_active_duration_ms } ms)" )
237
- await self ._send_keep_active_command (stay_active_duration_ms , dynamic_endpoint_id )
238
-
239
- logging .info ("Waiting for ActiveChanged from DUT..." )
240
- timeout_s = idle_mode_duration_s + max (active_mode_duration_ms , stay_active_duration_ms )/ 1000
241
- promised_active_duration_ms = await self ._wait_for_active_changed_event (timeout_s )
242
-
243
- # wait for active time duration
244
- sleep_time_s = max (stay_active_duration_ms , promised_active_duration_ms )/ 1000
245
- time .sleep (sleep_time_s )
246
- # ICD now should be in idle mode
247
-
257
+ # Prevent icd app from sending any check-in messages.
258
+ self .pause_th_icd_server (check_state = True )
248
259
# sends 3x keep active commands
249
- logging .info (f"Step3 Sending first KeepActiveCommand({ stay_active_duration_ms } )" )
260
+ stay_active_duration_ms = 2000
261
+ logging .info (f"Sending first KeepActiveCommand({ stay_active_duration_ms } )" )
250
262
await self ._send_keep_active_command (stay_active_duration_ms , dynamic_endpoint_id )
251
- time .sleep (0.1 )
252
- logging .info (f"Step3 Sending second KeepActiveCommand({ stay_active_duration_ms } )" )
263
+ logging .info (f"Sending second KeepActiveCommand({ stay_active_duration_ms } )" )
253
264
await self ._send_keep_active_command (stay_active_duration_ms , dynamic_endpoint_id )
254
- time .sleep (0.1 )
255
- logging .info (f"Step3 Sending third KeepActiveCommand({ stay_active_duration_ms } )" )
265
+ logging .info (f"Sending third KeepActiveCommand({ stay_active_duration_ms } )" )
256
266
await self ._send_keep_active_command (stay_active_duration_ms , dynamic_endpoint_id )
257
- time . sleep ( 0.1 )
267
+ self . resume_th_icd_server ( check_state = True )
258
268
259
269
logging .info ("Waiting for ActiveChanged from DUT..." )
260
270
promised_active_duration_ms = await self ._wait_for_active_changed_event ((idle_mode_duration_s + max (active_mode_duration_ms , stay_active_duration_ms ))/ 1000 )
261
-
262
- asserts .assert_equal (self .q .qSize (), 0 , "More than one event received from DUT" )
271
+ asserts .assert_equal (self .q .qsize (), 0 , "More than one event received from DUT" )
263
272
264
273
self .step ("3" )
274
+ await self .default_controller .WaitForActive (self .icd_nodeid , stayActiveDurationMs = 5000 )
275
+ asserts .assert_equal (self .q .qsize (), 0 , "More than one event received from DUT" )
276
+
277
+ self .step ("4" )
265
278
279
+ logging .info ("TH waiting for checkin from TH_ICD..." )
280
+ await self .default_controller .WaitForActive (self .icd_nodeid , stayActiveDurationMs = 10000 )
266
281
stay_active_duration_ms = 10000
267
282
logging .info (f"Sending KeepActiveCommand({ stay_active_duration_ms } )" )
268
283
await self ._send_keep_active_command (stay_active_duration_ms , dynamic_endpoint_id )
269
284
270
- # stops (halts) the ICD server process by sending a SIGTOP signal
271
- self .app_process .send_signal (signal .SIGSTOP .value )
285
+ self .pause_th_icd_server (check_state = True )
286
+ # If we are seeing assertion below fail test assumption is likely incorrect.
287
+ # Test assumes after TH waits for check-in from TH_ICD it has enough time to
288
+ # call the KeepActive command and pause the app to prevent it from checking in
289
+ # after DUT recieved the KeepActive command. Should this assumption be incorrect
290
+ # we could look into using existing ICDTestEventTriggerEvent, or adding test
291
+ # event trigger that will help suppress check-ins from the TH_ICD_SERVER.
292
+ asserts .assert_equal (self .q .qsize (), 0 , "" )
272
293
273
294
if not self .is_ci :
274
295
logging .info ("Waiting for 60 minutes" )
275
- self ._timeout
276
296
time .sleep (60 * 60 )
277
297
278
- # resumes (continues) the ICD server process by sending a SIGCONT signal
279
- self .app_process .send_signal (signal .SIGCONT .value )
298
+ self .resume_th_icd_server (check_state = True )
280
299
281
- # wait for active changed event, expect no event will be sent
282
- event_timeout = (idle_mode_duration_s + max (active_mode_duration_ms , stay_active_duration_ms ))/ 1000
283
- try :
284
- promised_active_duration_ms = self .q .get (block = True , timeout = event_timeout )
285
- finally :
286
- asserts .assert_true (queue .Empty (), "ActiveChanged event received when not expected" )
300
+ logging .info ("TH waiting for first checkin from TH_ICD..." )
301
+ await self .default_controller .WaitForActive (self .icd_nodeid , stayActiveDurationMs = 10000 )
302
+ logging .info ("TH waiting for second checkin from TH_ICD..." )
303
+ await self .default_controller .WaitForActive (self .icd_nodeid , stayActiveDurationMs = 10000 )
304
+ asserts .assert_equal (self .q .qsize (), 0 , "More than one event received from DUT" )
287
305
288
306
289
307
if __name__ == "__main__" :
0 commit comments