Skip to content

Commit c4a5a95

Browse files
Updates to BRBINFO_4_1 after issues discovered during TE2 (project-chip#35040)
* Updates to BRBINFO_4_1 after issues discovered during TE2 * Update test step 3 text * Restyled by autopep8 --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b7b6738 commit c4a5a95

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

src/python_testing/TC_BRBINFO_4_1.py

+57-39
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# limitations under the License.
1616
#
1717

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
2020
# 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
2222

2323
import logging
2424
import os
@@ -62,7 +62,8 @@ def steps_TC_BRBINFO_4_1(self) -> list[TestStep]:
6262
TestStep("1a", "TH reads from the ICD the A_IDLE_MODE_DURATION, A_ACTIVE_MODE_DURATION, and ACTIVE_MODE_THRESHOLD attributes"),
6363
TestStep("1b", "Simple KeepActive command w/ subscription. ActiveChanged event received by TH contains PromisedActiveDuration"),
6464
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"),
6667
]
6768
return steps
6869

@@ -110,9 +111,10 @@ async def setup_class(self):
110111

111112
super().setup_class()
112113
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)
114116
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>')
116118

117119
self.kvs = f'kvs_{str(uuid.uuid4())}'
118120
self.port = 5543
@@ -129,6 +131,7 @@ async def setup_class(self):
129131
logging.info("Commissioning of ICD to fabric one (TH)")
130132
self.icd_nodeid = 1111
131133

134+
self.default_controller.EnableICDRegistration(self.default_controller.GenerateICDRegistrationParameters())
132135
await self.default_controller.CommissionOnNetwork(nodeId=self.icd_nodeid, setupPinCode=passcode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator)
133136

134137
logging.info("Commissioning of ICD to fabric two (DUT)")
@@ -138,9 +141,10 @@ async def setup_class(self):
138141
params.commissioningParameters.setupManualCode, params.commissioningParameters.setupQRCode)
139142

140143
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
142145
# and there is nothing to remove
143146
if self.app_process is not None:
147+
self.resume_th_icd_server(check_state=False)
144148
logging.warning("Stopping app with SIGTERM")
145149
self.app_process.send_signal(signal.SIGTERM.value)
146150
self.app_process.wait()
@@ -150,6 +154,24 @@ def teardown_class(self):
150154

151155
super().teardown_class()
152156

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+
153175
#
154176
# BRBINFO 4.1 Test Body
155177
#
@@ -232,58 +254,54 @@ async def test_TC_BRBINFO_4_1(self):
232254

233255
self.step("2")
234256

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)
248259
# 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})")
250262
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})")
253264
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})")
256266
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)
258268

259269
logging.info("Waiting for ActiveChanged from DUT...")
260270
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")
263272

264273
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")
265278

279+
logging.info("TH waiting for checkin from TH_ICD...")
280+
await self.default_controller.WaitForActive(self.icd_nodeid, stayActiveDurationMs=10000)
266281
stay_active_duration_ms = 10000
267282
logging.info(f"Sending KeepActiveCommand({stay_active_duration_ms})")
268283
await self._send_keep_active_command(stay_active_duration_ms, dynamic_endpoint_id)
269284

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, "")
272293

273294
if not self.is_ci:
274295
logging.info("Waiting for 60 minutes")
275-
self._timeout
276296
time.sleep(60*60)
277297

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)
280299

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")
287305

288306

289307
if __name__ == "__main__":

0 commit comments

Comments
 (0)