blob: b3c7c2c440f5d7367aa9a0aab2155942ecad2a05 [file] [log] [blame]
Etan Cohen2b1b03b2017-06-08 11:27:50 -07001#!/usr/bin/python3.4
2#
3# Copyright 2017 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import queue
18import time
19
20from acts import asserts
Etan Cohen8e9104f2017-06-13 08:33:52 -070021from acts.test_utils.net import connectivity_const as cconsts
Etan Cohen2b1b03b2017-06-08 11:27:50 -070022from acts.test_utils.wifi.aware import aware_const as aconsts
23from acts.test_utils.wifi.aware import aware_test_utils as autils
24from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
25
26
27class LatencyTest(AwareBaseTest):
28 """Set of tests for Wi-Fi Aware to measure latency of Aware operations."""
Etan Cohen7185c482017-06-12 14:30:59 -070029 SERVICE_NAME = "GoogleTestServiceXY"
Etan Cohen2b1b03b2017-06-08 11:27:50 -070030
Etan Cohen2b1b03b2017-06-08 11:27:50 -070031 # number of second to 'reasonably' wait to make sure that devices synchronize
32 # with each other - useful for OOB test cases, where the OOB discovery would
33 # take some time
34 WAIT_FOR_CLUSTER = 5
35
36 def __init__(self, controllers):
37 AwareBaseTest.__init__(self, controllers)
38
39 def start_discovery_session(self, dut, session_id, is_publish, dtype):
40 """Start a discovery session
41
42 Args:
43 dut: Device under test
44 session_id: ID of the Aware session in which to start discovery
45 is_publish: True for a publish session, False for subscribe session
46 dtype: Type of the discovery session
47
48 Returns:
49 Discovery session started event.
50 """
51 config = {}
52 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype
53 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "GoogleTestServiceXY"
54
55 if is_publish:
56 disc_id = dut.droid.wifiAwarePublish(session_id, config)
57 event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED
58 else:
59 disc_id = dut.droid.wifiAwareSubscribe(session_id, config)
60 event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED
61
62 event = autils.wait_for_event(dut, event_name)
63 return disc_id, event
64
65 def run_discovery_latency(self, results, do_unsolicited_passive, dw_24ghz,
Etan Cohen9b11b182017-06-12 09:51:12 -070066 dw_5ghz, num_iterations):
Etan Cohen2b1b03b2017-06-08 11:27:50 -070067 """Run the service discovery latency test with the specified DW intervals.
68
69 Args:
70 results: Result array to be populated - will add results (not erase it)
71 do_unsolicited_passive: True for unsolicited/passive, False for
72 solicited/active.
73 dw_24ghz: DW interval in the 2.4GHz band.
74 dw_5ghz: DW interval in the 5GHz band.
75 """
76 key = "%s_dw24_%d_dw5_%d" % (
77 "unsolicited_passive"
78 if do_unsolicited_passive else "solicited_active", dw_24ghz, dw_5ghz)
79 results[key] = {}
Etan Cohen9b11b182017-06-12 09:51:12 -070080 results[key]["num_iterations"] = num_iterations
Etan Cohen2b1b03b2017-06-08 11:27:50 -070081
82 p_dut = self.android_devices[0]
83 p_dut.pretty_name = "Publisher"
84 s_dut = self.android_devices[1]
85 s_dut.pretty_name = "Subscriber"
86
Etan Cohen9b11b182017-06-12 09:51:12 -070087 # override the default DW configuration
88 autils.configure_dw(p_dut, is_default=True, is_24_band=True, value=dw_24ghz)
89 autils.configure_dw(
90 p_dut, is_default=False, is_24_band=True, value=dw_24ghz)
91 autils.configure_dw(p_dut, is_default=True, is_24_band=False, value=dw_5ghz)
92 autils.configure_dw(
93 p_dut, is_default=False, is_24_band=False, value=dw_5ghz)
94 autils.configure_dw(s_dut, is_default=True, is_24_band=True, value=dw_24ghz)
95 autils.configure_dw(
96 s_dut, is_default=False, is_24_band=True, value=dw_24ghz)
97 autils.configure_dw(s_dut, is_default=True, is_24_band=False, value=dw_5ghz)
98 autils.configure_dw(
99 s_dut, is_default=False, is_24_band=False, value=dw_5ghz)
100
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700101 # Publisher+Subscriber: attach and wait for confirmation
102 p_id = p_dut.droid.wifiAwareAttach(False)
103 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
104 s_id = s_dut.droid.wifiAwareAttach(False)
105 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
106
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700107 # start publish
108 p_disc_event = self.start_discovery_session(
109 p_dut, p_id, True, aconsts.PUBLISH_TYPE_UNSOLICITED
110 if do_unsolicited_passive else aconsts.PUBLISH_TYPE_SOLICITED)
111
112 # wait for for devices to synchronize with each other - used so that first
113 # discovery isn't biased by synchronization.
114 time.sleep(self.WAIT_FOR_CLUSTER)
115
116 # loop, perform discovery, and collect latency information
117 latencies = []
118 failed_discoveries = 0
Etan Cohen9b11b182017-06-12 09:51:12 -0700119 for i in range(num_iterations):
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700120 # start subscribe
121 s_disc_id, s_session_event = self.start_discovery_session(
122 s_dut, s_id, False, aconsts.SUBSCRIBE_TYPE_PASSIVE
123 if do_unsolicited_passive else aconsts.SUBSCRIBE_TYPE_ACTIVE)
124
125 # wait for discovery (allow for failures here since running lots of
126 # samples and would like to get the partial data even in the presence of
127 # errors)
128 try:
129 discovery_event = s_dut.ed.pop_event(
130 aconsts.SESSION_CB_ON_SERVICE_DISCOVERED, autils.EVENT_TIMEOUT)
131 except queue.Empty:
132 s_dut.log.info("[Subscriber] Timed out while waiting for "
133 "SESSION_CB_ON_SERVICE_DISCOVERED")
134 failed_discoveries = failed_discoveries + 1
135 continue
136 finally:
137 # destroy subscribe
138 s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)
139
140 # collect latency information
141 latencies.append(
142 discovery_event["data"][aconsts.SESSION_CB_KEY_TIMESTAMP_MS] -
143 s_session_event["data"][aconsts.SESSION_CB_KEY_TIMESTAMP_MS])
144 self.log.info("Latency #%d = %d" % (i, latencies[-1]))
145
146 autils.extract_stats(
147 s_dut,
148 data=latencies,
149 results=results[key],
150 key_prefix="",
151 log_prefix="Subscribe Session Discovery (%s, dw24=%d, dw5=%d)" %
152 ("Unsolicited/Passive"
153 if do_unsolicited_passive else "Solicited/Active", dw_24ghz, dw_5ghz))
154 results[key]["num_failed_discovery"] = failed_discoveries
155
Etan Cohen9b11b182017-06-12 09:51:12 -0700156 # clean up
157 p_dut.droid.wifiAwareDestroyAll()
158 s_dut.droid.wifiAwareDestroyAll()
159
Etan Cohen7185c482017-06-12 14:30:59 -0700160 def run_message_latency(self, results, dw_24ghz, dw_5ghz, num_iterations):
161 """Run the message tx latency test with the specified DW intervals.
162
163 Args:
164 results: Result array to be populated - will add results (not erase it)
165 dw_24ghz: DW interval in the 2.4GHz band.
166 dw_5ghz: DW interval in the 5GHz band.
167 """
168 key = "dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
169 results[key] = {}
170 results[key]["num_iterations"] = num_iterations
171
172 p_dut = self.android_devices[0]
173 s_dut = self.android_devices[1]
174
175 # override the default DW configuration
176 autils.configure_dw(p_dut, is_default=True, is_24_band=True, value=dw_24ghz)
177 autils.configure_dw(
178 p_dut, is_default=False, is_24_band=True, value=dw_24ghz)
179 autils.configure_dw(p_dut, is_default=True, is_24_band=False, value=dw_5ghz)
180 autils.configure_dw(
181 p_dut, is_default=False, is_24_band=False, value=dw_5ghz)
182 autils.configure_dw(s_dut, is_default=True, is_24_band=True, value=dw_24ghz)
183 autils.configure_dw(
184 s_dut, is_default=False, is_24_band=True, value=dw_24ghz)
185 autils.configure_dw(s_dut, is_default=True, is_24_band=False, value=dw_5ghz)
186 autils.configure_dw(
187 s_dut, is_default=False, is_24_band=False, value=dw_5ghz)
188
189 # Start up a discovery session
190 (p_id, s_id, p_disc_id, s_disc_id,
191 peer_id_on_sub) = autils.create_discovery_pair(
192 p_dut,
193 s_dut,
194 p_config=autils.create_discovery_config(
195 self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED),
196 s_config=autils.create_discovery_config(
197 self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE))
198
199 latencies = []
200 failed_tx = 0
201 messages_rx = 0
202 missing_rx = 0
203 corrupted_rx = 0
204 for i in range(num_iterations):
205 # send message
206 msg_s2p = "Message Subscriber -> Publisher #%d" % i
207 next_msg_id = self.get_next_msg_id()
208 s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub, next_msg_id,
209 msg_s2p, 0)
210
211 # wait for Tx confirmation
212 try:
213 sub_tx_msg_event = s_dut.ed.pop_event(
214 aconsts.SESSION_CB_ON_MESSAGE_SENT, 2 * autils.EVENT_TIMEOUT)
215 latencies.append(
216 sub_tx_msg_event["data"][aconsts.SESSION_CB_KEY_LATENCY_MS])
217 except queue.Empty:
218 s_dut.log.info("[Subscriber] Timed out while waiting for "
219 "SESSION_CB_ON_MESSAGE_SENT")
220 failed_tx = failed_tx + 1
221 continue
222
223 # wait for Rx confirmation (and validate contents)
224 try:
225 pub_rx_msg_event = p_dut.ed.pop_event(
226 aconsts.SESSION_CB_ON_MESSAGE_RECEIVED, 2 * autils.EVENT_TIMEOUT)
227 messages_rx = messages_rx + 1
228 if (pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING]
229 != msg_s2p):
230 corrupted_rx = corrupted_rx + 1
231 except queue.Empty:
232 s_dut.log.info("[Publisher] Timed out while waiting for "
233 "SESSION_CB_ON_MESSAGE_RECEIVED")
234 missing_rx = missing_rx + 1
235 continue
236
237 autils.extract_stats(
238 s_dut,
239 data=latencies,
240 results=results[key],
241 key_prefix="",
242 log_prefix="Subscribe Session Discovery (dw24=%d, dw5=%d)" %
243 (dw_24ghz, dw_5ghz))
244 results[key]["failed_tx"] = failed_tx
245 results[key]["messages_rx"] = messages_rx
246 results[key]["missing_rx"] = missing_rx
247 results[key]["corrupted_rx"] = corrupted_rx
248
249 # clean up
250 p_dut.droid.wifiAwareDestroyAll()
251 s_dut.droid.wifiAwareDestroyAll()
252
Etan Cohen8e9104f2017-06-13 08:33:52 -0700253 def run_ndp_oob_latency(self, results, dw_24ghz, dw_5ghz, num_iterations):
254 """Runs the NDP setup with OOB (out-of-band) discovery latency test.
255
256 Args:
257 results: Result array to be populated - will add results (not erase it)
258 dw_24ghz: DW interval in the 2.4GHz band.
259 dw_5ghz: DW interval in the 5GHz band.
260 """
261 key_avail = "on_avail_dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
262 key_link_props = "link_props_dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
263 results[key_avail] = {}
264 results[key_link_props] = {}
265 results[key_avail]["num_iterations"] = num_iterations
266
267 init_dut = self.android_devices[0]
268 init_dut.pretty_name = 'Initiator'
269 resp_dut = self.android_devices[1]
270 resp_dut.pretty_name = 'Responder'
271
272 # override the default DW configuration
273 autils.configure_dw(
274 init_dut, is_default=True, is_24_band=True, value=dw_24ghz)
275 autils.configure_dw(
276 init_dut, is_default=False, is_24_band=True, value=dw_24ghz)
277 autils.configure_dw(
278 init_dut, is_default=True, is_24_band=False, value=dw_5ghz)
279 autils.configure_dw(
280 init_dut, is_default=False, is_24_band=False, value=dw_5ghz)
281 autils.configure_dw(
282 resp_dut, is_default=True, is_24_band=True, value=dw_24ghz)
283 autils.configure_dw(
284 resp_dut, is_default=False, is_24_band=True, value=dw_24ghz)
285 autils.configure_dw(
286 resp_dut, is_default=True, is_24_band=False, value=dw_5ghz)
287 autils.configure_dw(
288 resp_dut, is_default=False, is_24_band=False, value=dw_5ghz)
289
290 # Initiator+Responder: attach and wait for confirmation & identity
291 init_id = init_dut.droid.wifiAwareAttach(True)
292 autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
293 init_ident_event = autils.wait_for_event(init_dut,
294 aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
295 init_mac = init_ident_event['data']['mac']
296 resp_id = resp_dut.droid.wifiAwareAttach(True)
297 autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
298 resp_ident_event = autils.wait_for_event(resp_dut,
299 aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
300 resp_mac = resp_ident_event['data']['mac']
301
302 # wait for for devices to synchronize with each other - there are no other
303 # mechanisms to make sure this happens for OOB discovery (except retrying
304 # to execute the data-path request)
305 time.sleep(autils.WAIT_FOR_CLUSTER)
306
307 on_available_latencies = []
308 link_props_latencies = []
309 ndp_setup_failures = 0
310 for i in range(num_iterations):
311 # Responder: request network
312 resp_req_key = autils.request_network(
313 resp_dut,
314 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
315 resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, None))
316
317 # Initiator: request network
318 init_req_key = autils.request_network(
319 init_dut,
320 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
321 init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, None))
322
323 # Initiator & Responder: wait for network formation
324 got_on_available = False
325 got_on_link_props = False
326 while not got_on_available or not got_on_link_props:
327 try:
328 nc_event = init_dut.ed.pop_event(cconsts.EVENT_NETWORK_CALLBACK,
329 autils.EVENT_TIMEOUT)
330 if nc_event["data"][
331 cconsts.NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
332 got_on_available = True
333 on_available_latencies.append(
334 nc_event["data"][cconsts.NETWORK_CB_KEY_CURRENT_TS] -
335 nc_event["data"][cconsts.NETWORK_CB_KEY_CREATE_TS])
336 elif (nc_event["data"][cconsts.NETWORK_CB_KEY_EVENT] ==
337 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
338 got_on_link_props = True
339 link_props_latencies.append(
340 nc_event["data"][cconsts.NETWORK_CB_KEY_CURRENT_TS] -
341 nc_event["data"][cconsts.NETWORK_CB_KEY_CREATE_TS])
342 except queue.Empty:
343 ndp_setup_failures = ndp_setup_failures + 1
344 init_dut.log.info("[Initiator] Timed out while waiting for "
345 "EVENT_NETWORK_CALLBACK")
346 break
347
348 if not got_on_available or not got_on_link_props:
349 continue
350
351 # clean-up
352 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
353 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
354
355 autils.extract_stats(
356 init_dut,
357 data=on_available_latencies,
358 results=results[key_avail],
359 key_prefix="",
360 log_prefix="NDP setup OnAvailable(dw24=%d, dw5=%d)" % (dw_24ghz,
361 dw_5ghz))
362 autils.extract_stats(
363 init_dut,
364 data=link_props_latencies,
365 results=results[key_link_props],
366 key_prefix="",
367 log_prefix="NDP setup OnLinkProperties (dw24=%d, dw5=%d)" % (dw_24ghz,
368 dw_5ghz))
369 results[key_avail]["ndp_setup_failures"] = ndp_setup_failures
370
Etan Cohen7185c482017-06-12 14:30:59 -0700371
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700372 ########################################################################
373
374 def test_discovery_latency_default_dws(self):
375 """Measure the service discovery latency with the default DW configuration.
376 """
377 results = {}
378 self.run_discovery_latency(
Etan Cohen9b11b182017-06-12 09:51:12 -0700379 results=results, do_unsolicited_passive=True, dw_24ghz=1, dw_5ghz=1,
380 num_iterations=100)
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700381 asserts.explicit_pass(
382 "test_discovery_latency_default_parameters finished", extras=results)
383
384 def test_discovery_latency_non_interactive_dws(self):
385 """Measure the service discovery latency with the DW configuration for non
386 -interactive mode (lower power)."""
387 results = {}
388 self.run_discovery_latency(
Etan Cohen9b11b182017-06-12 09:51:12 -0700389 results=results, do_unsolicited_passive=True, dw_24ghz=4, dw_5ghz=0,
390 num_iterations=100)
Etan Cohen2b1b03b2017-06-08 11:27:50 -0700391 asserts.explicit_pass(
392 "test_discovery_latency_non_interactive_dws finished", extras=results)
Etan Cohen9b11b182017-06-12 09:51:12 -0700393
394 def test_discovery_latency_all_dws(self):
395 """Measure the service discovery latency with all DW combinations (low
396 iteration count)"""
397 results = {}
398 for dw24 in range(1, 6): # permitted values: 1-5
399 for dw5 in range(0, 6): # permitted values: 0, 1-5
400 self.run_discovery_latency(
401 results=results,
402 do_unsolicited_passive=True,
403 dw_24ghz=dw24,
404 dw_5ghz=dw5,
405 num_iterations=10)
406 asserts.explicit_pass(
407 "test_discovery_latency_all_dws finished", extras=results)
Etan Cohen7185c482017-06-12 14:30:59 -0700408
409 def test_message_latency_default_dws(self):
410 """Measure the send message latency with the default DW configuration. Test
411 performed on non-queued message transmission - i.e. waiting for confirmation
412 of reception (ACK) before sending the next message."""
413 results = {}
414 self.run_message_latency(
415 results=results, dw_24ghz=1, dw_5ghz=1, num_iterations=100)
416 asserts.explicit_pass(
417 "test_message_latency_default_dws finished", extras=results)
418
419 def test_message_latency_non_interactive_dws(self):
420 """Measure the send message latency with the DW configuration for
421 non-interactive mode. Test performed on non-queued message transmission -
422 i.e. waiting for confirmation of reception (ACK) before sending the next
423 message."""
424 results = {}
425 self.run_message_latency(
426 results=results, dw_24ghz=4, dw_5ghz=0, num_iterations=100)
427 asserts.explicit_pass(
428 "test_message_latency_non_interactive_dws finished", extras=results)
Etan Cohen8e9104f2017-06-13 08:33:52 -0700429
430 def test_oob_ndp_setup_latency_default_dws(self):
431 """Measure the NDP setup latency with the default DW configuration. The
432 NDP is setup with OOB (out-of-band) configuration."""
433 results = {}
434 self.run_ndp_oob_latency(
435 results=results, dw_24ghz=1, dw_5ghz=1, num_iterations=10)
436 asserts.explicit_pass(
437 "test_ndp_setup_latency_default_dws finished", extras=results)
438
439 def test_oob_ndp_setup_latency_non_interactive_dws(self):
440 """Measure the NDP setup latency with the DW configuration for
441 non-interactive mode. The NDP is setup with OOB (out-of-band)
442 configuration"""
443 results = {}
444 self.run_ndp_oob_latency(
445 results=results, dw_24ghz=4, dw_5ghz=0, num_iterations=10)
446 asserts.explicit_pass(
447 "test_ndp_setup_latency_non_interactive_dws finished", extras=results)