blob: a1ace3e287b7326d0e13497194eed45b49084302 [file] [log] [blame]
Etan Cohen872a6be2017-05-16 08:08:15 -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 string
Etan Cohenfb7f3b12017-05-19 06:54:03 -070018import time
Etan Cohen872a6be2017-05-16 08:08:15 -070019
20from acts import asserts
21from acts.test_utils.wifi.aware import aware_const as aconsts
22from acts.test_utils.wifi.aware import aware_test_utils as autils
23from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
24
25
26class DiscoveryTest(AwareBaseTest):
27 """Set of tests for Wi-Fi Aware discovery."""
28
29 # configuration parameters used by tests
30 PAYLOAD_SIZE_MIN = 0
31 PAYLOAD_SIZE_TYPICAL = 1
32 PAYLOAD_SIZE_MAX = 2
33
34 # message strings
35 query_msg = "How are you doing? 你好嗎?"
36 response_msg = "Doing ok - thanks! 做的不錯 - 謝謝!"
37
38 # message re-transmit counter (increases reliability in open-environment)
39 # Note: reliability of message transmission is tested elsewhere
40 msg_retx_count = 5 # hard-coded max value, internal API
41
42 def __init__(self, controllers):
43 AwareBaseTest.__init__(self, controllers)
44
Etan Cohenfb7f3b12017-05-19 06:54:03 -070045 def create_base_config(self, caps, is_publish, ptype, stype, payload_size,
46 ttl, term_ind_on, null_match):
Etan Cohen872a6be2017-05-16 08:08:15 -070047 """Create a base configuration based on input parameters.
48
49 Args:
Etan Cohenfb7f3b12017-05-19 06:54:03 -070050 caps: device capability dictionary
Etan Cohen872a6be2017-05-16 08:08:15 -070051 is_publish: True if a publish config, else False
52 ptype: unsolicited or solicited (used if is_publish is True)
53 stype: passive or active (used if is_publish is False)
54 payload_size: min, typical, max (PAYLOAD_SIZE_xx)
55 ttl: time-to-live configuration (0 - forever)
56 term_ind_on: is termination indication enabled
57 null_match: null-out the middle match filter
58 Returns:
59 publish discovery configuration object.
60 """
61 config = {}
62 if is_publish:
63 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = ptype
64 else:
65 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = stype
66 config[aconsts.DISCOVERY_KEY_TTL] = ttl
67 config[aconsts.DISCOVERY_KEY_TERM_CB_ENABLED] = term_ind_on
68 if payload_size == self.PAYLOAD_SIZE_MIN:
69 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "a"
70 config[aconsts.DISCOVERY_KEY_SSI] = None
Etan Cohen0bc1cab2017-05-18 15:30:41 -070071 config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = []
Etan Cohen872a6be2017-05-16 08:08:15 -070072 elif payload_size == self.PAYLOAD_SIZE_TYPICAL:
73 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "GoogleTestServiceX"
74 if is_publish:
75 config[aconsts.DISCOVERY_KEY_SSI] = string.ascii_letters
76 else:
77 config[aconsts.DISCOVERY_KEY_SSI] = string.ascii_letters[::
78 -1] # reverse
79 config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(
80 [(10).to_bytes(1, byteorder="big"), "hello there string"
81 if not null_match else None,
82 bytes(range(40))])
Etan Cohen5a629a62017-05-19 15:11:18 -070083 else: # PAYLOAD_SIZE_MAX
84 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "VeryLong" + "X" * (
85 caps[aconsts.CAP_MAX_SERVICE_NAME_LEN] - 8)
86 config[aconsts.DISCOVERY_KEY_SSI] = ("P" if is_publish else "S") * caps[
87 aconsts.CAP_MAX_SERVICE_SPECIFIC_INFO_LEN]
88 mf = autils.construct_max_match_filter(
89 caps[aconsts.CAP_MAX_MATCH_FILTER_LEN])
90 if null_match:
91 mf[2] = None
92 config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(mf)
93
Etan Cohen872a6be2017-05-16 08:08:15 -070094 return config
95
Etan Cohenfb7f3b12017-05-19 06:54:03 -070096 def create_publish_config(self, caps, ptype, payload_size, ttl, term_ind_on,
Etan Cohen872a6be2017-05-16 08:08:15 -070097 null_match):
98 """Create a publish configuration based on input parameters.
99
100 Args:
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700101 caps: device capability dictionary
Etan Cohen872a6be2017-05-16 08:08:15 -0700102 ptype: unsolicited or solicited
103 payload_size: min, typical, max (PAYLOAD_SIZE_xx)
104 ttl: time-to-live configuration (0 - forever)
105 term_ind_on: is termination indication enabled
106 null_match: null-out the middle match filter
107 Returns:
108 publish discovery configuration object.
109 """
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700110 return self.create_base_config(caps, True, ptype, None, payload_size, ttl,
Etan Cohen872a6be2017-05-16 08:08:15 -0700111 term_ind_on, null_match)
112
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700113 def create_subscribe_config(self, caps, stype, payload_size, ttl, term_ind_on,
Etan Cohen872a6be2017-05-16 08:08:15 -0700114 null_match):
115 """Create a subscribe configuration based on input parameters.
116
117 Args:
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700118 caps: device capability dictionary
Etan Cohen872a6be2017-05-16 08:08:15 -0700119 stype: passive or active
120 payload_size: min, typical, max (PAYLOAD_SIZE_xx)
121 ttl: time-to-live configuration (0 - forever)
122 term_ind_on: is termination indication enabled
123 null_match: null-out the middle match filter
124 Returns:
125 subscribe discovery configuration object.
126 """
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700127 return self.create_base_config(caps, False, None, stype, payload_size, ttl,
Etan Cohen872a6be2017-05-16 08:08:15 -0700128 term_ind_on, null_match)
129
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700130 def positive_discovery_test_utility(self, ptype, stype, payload_size):
Etan Cohen872a6be2017-05-16 08:08:15 -0700131 """Utility which runs a positive discovery test:
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700132 - Discovery (publish/subscribe) with TTL=0 (non-self-terminating)
Etan Cohen872a6be2017-05-16 08:08:15 -0700133 - Exchange messages
134 - Update publish/subscribe
135 - Terminate
136
137 Args:
138 ptype: Publish discovery type
139 stype: Subscribe discovery type
140 payload_size: One of PAYLOAD_SIZE_* constants - MIN, TYPICAL, MAX
Etan Cohen872a6be2017-05-16 08:08:15 -0700141 """
142 p_dut = self.android_devices[0]
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700143 p_dut.pretty_name = "Publisher"
Etan Cohen872a6be2017-05-16 08:08:15 -0700144 s_dut = self.android_devices[1]
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700145 s_dut.pretty_name = "Subscriber"
Etan Cohen872a6be2017-05-16 08:08:15 -0700146
147 # Publisher+Subscriber: attach and wait for confirmation
148 p_id = p_dut.droid.wifiAwareAttach(False)
149 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
Etan Cohen76ff8012017-06-16 13:13:44 -0700150 time.sleep(self.device_startup_offset)
Etan Cohen872a6be2017-05-16 08:08:15 -0700151 s_id = s_dut.droid.wifiAwareAttach(False)
152 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
153
154 # Publisher: start publish and wait for confirmation
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700155 p_config = self.create_publish_config(
156 p_dut.aware_capabilities,
157 ptype,
158 payload_size,
159 ttl=0,
160 term_ind_on=False,
161 null_match=False)
Etan Cohen872a6be2017-05-16 08:08:15 -0700162 p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config)
163 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
164
165 # Subscriber: start subscribe and wait for confirmation
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700166 s_config = self.create_subscribe_config(
167 s_dut.aware_capabilities,
168 stype,
169 payload_size,
170 ttl=0,
171 term_ind_on=False,
172 null_match=True)
Etan Cohen872a6be2017-05-16 08:08:15 -0700173 s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config)
174 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
175
176 # Subscriber: wait for service discovery
177 discovery_event = autils.wait_for_event(
178 s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
179 peer_id_on_sub = discovery_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
180
Etan Cohen1ac02c82017-05-24 07:28:26 -0700181 # Subscriber: validate contents of discovery:
182 # - SSI: publisher's
183 # - Match filter: UNSOLICITED - publisher, SOLICITED - subscriber
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700184 autils.assert_equal_strings(
Etan Cohen872a6be2017-05-16 08:08:15 -0700185 bytes(discovery_event["data"][
186 aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"),
187 p_config[aconsts.DISCOVERY_KEY_SSI],
188 "Discovery mismatch: service specific info (SSI)")
189 asserts.assert_equal(
190 autils.decode_list(
191 discovery_event["data"][aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]),
Etan Cohen1ac02c82017-05-24 07:28:26 -0700192 autils.decode_list(p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]
193 if ptype == aconsts.PUBLISH_TYPE_UNSOLICITED else
194 s_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]),
Etan Cohen872a6be2017-05-16 08:08:15 -0700195 "Discovery mismatch: match filter")
196
197 # Subscriber: send message to peer (Publisher)
198 s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
199 self.get_next_msg_id(), self.query_msg,
200 self.msg_retx_count)
201 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
202
203 # Publisher: wait for received message
204 pub_rx_msg_event = autils.wait_for_event(
205 p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
206 peer_id_on_pub = pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
207
208 # Publisher: validate contents of message
209 asserts.assert_equal(
210 pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
211 self.query_msg, "Subscriber -> Publisher message corrupted")
212
213 # Publisher: send message to peer (Subscriber)
214 p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub,
215 self.get_next_msg_id(), self.response_msg,
216 self.msg_retx_count)
217 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
218
219 # Subscriber: wait for received message
220 sub_rx_msg_event = autils.wait_for_event(
221 s_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
222
223 # Subscriber: validate contents of message
224 asserts.assert_equal(
225 sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID],
226 peer_id_on_sub,
227 "Subscriber received message from different peer ID then discovery!?")
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700228 autils.assert_equal_strings(
Etan Cohen872a6be2017-05-16 08:08:15 -0700229 sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING],
230 self.response_msg, "Publisher -> Subscriber message corrupted")
231
232 # Subscriber: validate that we're not getting another Service Discovery
233 autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
234
235 # Publisher: update publish and wait for confirmation
236 p_config[aconsts.DISCOVERY_KEY_SSI] = "something else"
237 p_dut.droid.wifiAwareUpdatePublish(p_disc_id, p_config)
238 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED)
239
240 # Subscriber: expect a new service discovery
241 discovery_event = autils.wait_for_event(
242 s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
243
244 # Subscriber: validate contents of discovery
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700245 autils.assert_equal_strings(
Etan Cohen872a6be2017-05-16 08:08:15 -0700246 bytes(discovery_event["data"][
247 aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"),
248 p_config[aconsts.DISCOVERY_KEY_SSI],
249 "Discovery mismatch (after pub update): service specific info (SSI)")
250 asserts.assert_equal(
251 autils.decode_list(
252 discovery_event["data"][aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]),
Etan Cohen1ac02c82017-05-24 07:28:26 -0700253 autils.decode_list(p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]
254 if ptype == aconsts.PUBLISH_TYPE_UNSOLICITED else
255 s_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]),
Etan Cohen872a6be2017-05-16 08:08:15 -0700256 "Discovery mismatch: match filter")
257
258 # Subscribe: update subscribe and wait for confirmation
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700259 s_config = self.create_subscribe_config(
260 s_dut.aware_capabilities,
261 stype,
262 payload_size,
263 ttl=0,
264 term_ind_on=False,
265 null_match=False)
Etan Cohen872a6be2017-05-16 08:08:15 -0700266 s_dut.droid.wifiAwareUpdateSubscribe(s_disc_id, s_config)
267 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED)
268
Etan Cohen872a6be2017-05-16 08:08:15 -0700269 # Publisher+Subscriber: Terminate sessions
270 p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
271 s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)
272
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700273 # sleep for timeout period and then verify all 'fail_on_event' together
274 time.sleep(autils.EVENT_TIMEOUT)
275
Etan Cohen2c8db552017-05-22 11:00:03 -0700276 # verify that there were no other events
Etan Cohen60a9b522017-05-22 14:10:01 -0700277 autils.verify_no_more_events(p_dut, timeout=0)
278 autils.verify_no_more_events(s_dut, timeout=0)
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700279
Etan Cohene0cff1c2017-06-22 15:23:26 -0700280 # verify that forbidden callbacks aren't called
281 autils.validate_forbidden_callbacks(p_dut, {aconsts.CB_EV_MATCH: 0})
282
Etan Cohen2c8db552017-05-22 11:00:03 -0700283 def verify_discovery_session_term(self, dut, disc_id, config, is_publish,
284 term_ind_on):
285 """Utility to verify that the specified discovery session has terminated (by
286 waiting for the TTL and then attempting to reconfigure).
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700287
Etan Cohen2c8db552017-05-22 11:00:03 -0700288 Args:
289 dut: device under test
290 disc_id: discovery id for the existing session
291 config: configuration of the existing session
292 is_publish: True if the configuration was publish, False if subscribe
293 term_ind_on: True if a termination indication is expected, False otherwise
294 """
295 # Wait for session termination
296 if term_ind_on:
297 autils.wait_for_event(
298 dut,
299 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
300 disc_id))
301 else:
302 # can't defer wait to end since in any case have to wait for session to
303 # expire
304 autils.fail_on_event(
305 dut,
306 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
307 disc_id))
308
309 # Validate that session expired by trying to configure it (expect failure)
310 config[aconsts.DISCOVERY_KEY_SSI] = "something else"
311 if is_publish:
312 dut.droid.wifiAwareUpdatePublish(disc_id, config)
313 else:
314 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
Etan Coheneb809a52017-05-24 10:30:30 -0700315
316 # The response to update discovery session is:
317 # term_ind_on=True: session was cleaned-up so won't get an explicit failure, but won't get a
318 # success either. Can check for no SESSION_CB_ON_SESSION_CONFIG_UPDATED but
319 # will defer to the end of the test (no events on queue).
320 # term_ind_on=False: session was not cleaned-up (yet). So expect
321 # SESSION_CB_ON_SESSION_CONFIG_FAILED.
322 if not term_ind_on:
323 autils.wait_for_event(
324 dut,
325 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_FAILED,
326 disc_id))
Etan Cohen2c8db552017-05-22 11:00:03 -0700327
328 def positive_ttl_test_utility(self, is_publish, ptype, stype, term_ind_on):
329 """Utility which runs a positive discovery session TTL configuration test
330
331 Iteration 1: Verify session started with TTL
332 Iteration 2: Verify session started without TTL and reconfigured with TTL
333 Iteration 3: Verify session started with (long) TTL and reconfigured with
334 (short) TTL
335
336 Args:
337 is_publish: True if testing publish, False if testing subscribe
338 ptype: Publish discovery type (used if is_publish is True)
339 stype: Subscribe discovery type (used if is_publish is False)
340 term_ind_on: Configuration of termination indication
341 """
342 SHORT_TTL = 5 # 5 seconds
343 LONG_TTL = 100 # 100 seconds
344 dut = self.android_devices[0]
345
346 # Attach and wait for confirmation
347 id = dut.droid.wifiAwareAttach(False)
348 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
349
350 # Iteration 1: Start discovery session with TTL
351 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
352 stype, self.PAYLOAD_SIZE_TYPICAL,
353 SHORT_TTL, term_ind_on, False)
354 if is_publish:
355 disc_id = dut.droid.wifiAwarePublish(id, config, True)
356 autils.wait_for_event(dut,
357 autils.decorate_event(
358 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
359 else:
360 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
361 autils.wait_for_event(
362 dut,
363 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
364 disc_id))
365
366 # Wait for session termination & verify
367 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
368 term_ind_on)
369
370 # Iteration 2: Start a discovery session without TTL
371 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
372 stype, self.PAYLOAD_SIZE_TYPICAL, 0,
373 term_ind_on, False)
374 if is_publish:
375 disc_id = dut.droid.wifiAwarePublish(id, config, True)
376 autils.wait_for_event(dut,
377 autils.decorate_event(
378 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
379 else:
380 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
381 autils.wait_for_event(
382 dut,
383 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
384 disc_id))
385
386 # Update with a TTL
387 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
388 stype, self.PAYLOAD_SIZE_TYPICAL,
389 SHORT_TTL, term_ind_on, False)
390 if is_publish:
391 dut.droid.wifiAwareUpdatePublish(disc_id, config)
392 else:
393 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
394 autils.wait_for_event(
395 dut,
396 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
397 disc_id))
398
399 # Wait for session termination & verify
400 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
401 term_ind_on)
402
403 # Iteration 3: Start a discovery session with (long) TTL
404 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
405 stype, self.PAYLOAD_SIZE_TYPICAL, LONG_TTL,
406 term_ind_on, False)
407 if is_publish:
408 disc_id = dut.droid.wifiAwarePublish(id, config, True)
409 autils.wait_for_event(dut,
410 autils.decorate_event(
411 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
412 else:
413 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
414 autils.wait_for_event(
415 dut,
416 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
417 disc_id))
418
419 # Update with a TTL
420 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
421 stype, self.PAYLOAD_SIZE_TYPICAL,
422 SHORT_TTL, term_ind_on, False)
423 if is_publish:
424 dut.droid.wifiAwareUpdatePublish(disc_id, config)
425 else:
426 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
427 autils.wait_for_event(
428 dut,
429 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
430 disc_id))
431
432 # Wait for session termination & verify
433 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
434 term_ind_on)
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700435
436 # verify that there were no other events
Etan Cohen2c8db552017-05-22 11:00:03 -0700437 autils.verify_no_more_events(dut)
Etan Cohen872a6be2017-05-16 08:08:15 -0700438
Etan Cohene0cff1c2017-06-22 15:23:26 -0700439 # verify that forbidden callbacks aren't called
440 if not term_ind_on:
441 autils.validate_forbidden_callbacks(dut, {
442 aconsts.CB_EV_PUBLISH_TERMINATED: 0,
443 aconsts.CB_EV_SUBSCRIBE_TERMINATED: 0
444 })
445
Etan Cohenc1b65f12017-05-24 08:10:42 -0700446 def discovery_mismatch_test_utility(self,
447 is_expected_to_pass,
448 p_type,
449 s_type,
450 p_service_name=None,
451 s_service_name=None,
452 p_mf_1=None,
453 s_mf_1=None):
Etan Cohen60a9b522017-05-22 14:10:01 -0700454 """Utility which runs the negative discovery test for mismatched service
Etan Cohend8d58082017-05-22 15:03:17 -0700455 configs.
Etan Cohen60a9b522017-05-22 14:10:01 -0700456
457 Args:
Etan Cohenc1b65f12017-05-24 08:10:42 -0700458 is_expected_to_pass: True if positive test, False if negative
Etan Cohen60a9b522017-05-22 14:10:01 -0700459 p_type: Publish discovery type
460 s_type: Subscribe discovery type
Etan Cohen6677a2a2017-05-22 14:38:04 -0700461 p_service_name: Publish service name (or None to leave unchanged)
462 s_service_name: Subscribe service name (or None to leave unchanged)
Etan Cohend8d58082017-05-22 15:03:17 -0700463 p_mf_1: Publish match filter element [1] (or None to leave unchanged)
464 s_mf_1: Subscribe match filter element [1] (or None to leave unchanged)
Etan Cohen60a9b522017-05-22 14:10:01 -0700465 """
466 p_dut = self.android_devices[0]
467 p_dut.pretty_name = "Publisher"
468 s_dut = self.android_devices[1]
469 s_dut.pretty_name = "Subscriber"
470
471 # create configurations
472 p_config = self.create_publish_config(
473 p_dut.aware_capabilities,
474 p_type,
475 self.PAYLOAD_SIZE_TYPICAL,
476 ttl=0,
477 term_ind_on=False,
478 null_match=False)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700479 if p_service_name is not None:
480 p_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = p_service_name
Etan Cohend8d58082017-05-22 15:03:17 -0700481 if p_mf_1 is not None:
482 p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(
483 [(10).to_bytes(1, byteorder="big"),
484 p_mf_1,
485 bytes(range(40))])
Etan Cohen60a9b522017-05-22 14:10:01 -0700486 s_config = self.create_publish_config(
487 s_dut.aware_capabilities,
488 s_type,
489 self.PAYLOAD_SIZE_TYPICAL,
490 ttl=0,
491 term_ind_on=False,
492 null_match=False)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700493 if s_service_name is not None:
494 s_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = s_service_name
Etan Cohend8d58082017-05-22 15:03:17 -0700495 if s_mf_1 is not None:
496 s_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(
497 [(10).to_bytes(1, byteorder="big"),
498 s_mf_1,
499 bytes(range(40))])
Etan Cohen60a9b522017-05-22 14:10:01 -0700500
Etan Cohenc1b65f12017-05-24 08:10:42 -0700501 p_id = p_dut.droid.wifiAwareAttach(False)
502 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
Etan Cohen76ff8012017-06-16 13:13:44 -0700503 time.sleep(self.device_startup_offset)
Etan Cohenc1b65f12017-05-24 08:10:42 -0700504 s_id = s_dut.droid.wifiAwareAttach(False)
505 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
506
507 # Publisher: start publish and wait for confirmation
508 p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config)
509 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
510
511 # Subscriber: start subscribe and wait for confirmation
512 s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config)
513 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
514
515 # Subscriber: fail on service discovery
516 if is_expected_to_pass:
517 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
518 else:
519 autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
520
521 # Publisher+Subscriber: Terminate sessions
522 p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
523 s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)
524
525 # verify that there were no other events (including terminations)
526 time.sleep(autils.EVENT_TIMEOUT)
527 autils.verify_no_more_events(p_dut, timeout=0)
528 autils.verify_no_more_events(s_dut, timeout=0)
Etan Cohen60a9b522017-05-22 14:10:01 -0700529
530
Etan Cohen872a6be2017-05-16 08:08:15 -0700531 #######################################
532 # Positive tests key:
533 #
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700534 # names is: test_<pub_type>_<sub_type>_<size>
Etan Cohen872a6be2017-05-16 08:08:15 -0700535 # where:
536 #
537 # pub_type: Type of publish discovery session: unsolicited or solicited.
538 # sub_type: Type of subscribe discovery session: passive or active.
539 # size: Size of payload fields (service name, service specific info, and match
540 # filter: typical, max, or min.
Etan Cohen872a6be2017-05-16 08:08:15 -0700541 #######################################
542
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700543 def test_positive_unsolicited_passive_typical(self):
Etan Cohen872a6be2017-05-16 08:08:15 -0700544 """Functional test case / Discovery test cases / positive test case:
545 - Solicited publish + passive subscribe
546 - Typical payload fields size
Etan Cohen872a6be2017-05-16 08:08:15 -0700547
548 Verifies that discovery and message exchange succeeds.
549 """
550 self.positive_discovery_test_utility(
551 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
552 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700553 payload_size=self.PAYLOAD_SIZE_TYPICAL)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700554
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700555 def test_positive_unsolicited_passive_min(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700556 """Functional test case / Discovery test cases / positive test case:
557 - Solicited publish + passive subscribe
558 - Minimal payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700559
560 Verifies that discovery and message exchange succeeds.
561 """
562 self.positive_discovery_test_utility(
563 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
564 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700565 payload_size=self.PAYLOAD_SIZE_MIN)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700566
Etan Cohen5a629a62017-05-19 15:11:18 -0700567 def test_positive_unsolicited_passive_max(self):
568 """Functional test case / Discovery test cases / positive test case:
569 - Solicited publish + passive subscribe
570 - Maximal payload fields size
571
572 Verifies that discovery and message exchange succeeds.
573 """
574 self.positive_discovery_test_utility(
575 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
576 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
577 payload_size=self.PAYLOAD_SIZE_MAX)
578
579
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700580 def test_positive_solicited_active_typical(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700581 """Functional test case / Discovery test cases / positive test case:
582 - Unsolicited publish + active subscribe
583 - Typical payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700584
585 Verifies that discovery and message exchange succeeds.
586 """
587 self.positive_discovery_test_utility(
588 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
589 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700590 payload_size=self.PAYLOAD_SIZE_TYPICAL)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700591
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700592 def test_positive_solicited_active_min(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700593 """Functional test case / Discovery test cases / positive test case:
594 - Unsolicited publish + active subscribe
595 - Minimal payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700596
597 Verifies that discovery and message exchange succeeds.
598 """
599 self.positive_discovery_test_utility(
600 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
601 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700602 payload_size=self.PAYLOAD_SIZE_MIN)
Etan Cohen5a629a62017-05-19 15:11:18 -0700603
604 def test_positive_solicited_active_max(self):
605 """Functional test case / Discovery test cases / positive test case:
606 - Unsolicited publish + active subscribe
607 - Maximal payload fields size
608
609 Verifies that discovery and message exchange succeeds.
610 """
611 self.positive_discovery_test_utility(
612 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
613 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
614 payload_size=self.PAYLOAD_SIZE_MAX)
Etan Cohen2c8db552017-05-22 11:00:03 -0700615
616 #######################################
617 # TTL tests key:
618 #
619 # names is: test_ttl_<pub_type|sub_type>_<term_ind>
620 # where:
621 #
622 # pub_type: Type of publish discovery session: unsolicited or solicited.
623 # sub_type: Type of subscribe discovery session: passive or active.
624 # term_ind: ind_on or ind_off
625 #######################################
626
627 def test_ttl_unsolicited_ind_on(self):
628 """Functional test case / Discovery test cases / TTL test case:
629 - Unsolicited publish
630 - Termination indication enabled
631 """
632 self.positive_ttl_test_utility(
633 is_publish=True,
634 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
635 stype=None,
636 term_ind_on=True)
Etan Cohen3010bc22017-05-22 12:47:17 -0700637
638 def test_ttl_unsolicited_ind_off(self):
639 """Functional test case / Discovery test cases / TTL test case:
640 - Unsolicited publish
641 - Termination indication disabled
642 """
643 self.positive_ttl_test_utility(
644 is_publish=True,
645 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
646 stype=None,
647 term_ind_on=False)
648
649 def test_ttl_solicited_ind_on(self):
650 """Functional test case / Discovery test cases / TTL test case:
651 - Solicited publish
652 - Termination indication enabled
653 """
654 self.positive_ttl_test_utility(
655 is_publish=True,
656 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
657 stype=None,
658 term_ind_on=True)
659
660 def test_ttl_solicited_ind_off(self):
661 """Functional test case / Discovery test cases / TTL test case:
662 - Solicited publish
663 - Termination indication disabled
664 """
665 self.positive_ttl_test_utility(
666 is_publish=True,
667 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
668 stype=None,
669 term_ind_on=False)
670
671 def test_ttl_passive_ind_on(self):
672 """Functional test case / Discovery test cases / TTL test case:
673 - Passive subscribe
674 - Termination indication enabled
675 """
676 self.positive_ttl_test_utility(
677 is_publish=False,
678 ptype=None,
679 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
680 term_ind_on=True)
681
682 def test_ttl_passive_ind_off(self):
683 """Functional test case / Discovery test cases / TTL test case:
684 - Passive subscribe
685 - Termination indication disabled
686 """
687 self.positive_ttl_test_utility(
688 is_publish=False,
689 ptype=None,
690 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
691 term_ind_on=False)
692
693 def test_ttl_active_ind_on(self):
694 """Functional test case / Discovery test cases / TTL test case:
695 - Active subscribe
696 - Termination indication enabled
697 """
698 self.positive_ttl_test_utility(
699 is_publish=False,
700 ptype=None,
701 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
702 term_ind_on=True)
703
704 def test_ttl_active_ind_off(self):
705 """Functional test case / Discovery test cases / TTL test case:
706 - Active subscribe
707 - Termination indication disabled
708 """
709 self.positive_ttl_test_utility(
710 is_publish=False,
711 ptype=None,
712 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
713 term_ind_on=False)
Etan Cohen60a9b522017-05-22 14:10:01 -0700714
715 #######################################
716 # Mismatched service name tests key:
717 #
718 # names is: test_mismatch_service_name_<pub_type>_<sub_type>
719 # where:
720 #
721 # pub_type: Type of publish discovery session: unsolicited or solicited.
722 # sub_type: Type of subscribe discovery session: passive or active.
723 #######################################
724
725 def test_mismatch_service_name_unsolicited_passive(self):
726 """Functional test case / Discovery test cases / Mismatch service name
727 - Unsolicited publish
728 - Passive subscribe
729 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700730 self.discovery_mismatch_test_utility(
731 is_expected_to_pass=False,
Etan Cohen60a9b522017-05-22 14:10:01 -0700732 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
733 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE,
734 p_service_name="GoogleTestServiceXXX",
735 s_service_name="GoogleTestServiceYYY")
736
737 def test_mismatch_service_name_solicited_active(self):
738 """Functional test case / Discovery test cases / Mismatch service name
739 - Solicited publish
740 - Active subscribe
741 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700742 self.discovery_mismatch_test_utility(
743 is_expected_to_pass=False,
Etan Cohen60a9b522017-05-22 14:10:01 -0700744 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
745 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE,
746 p_service_name="GoogleTestServiceXXX",
Etan Cohen6677a2a2017-05-22 14:38:04 -0700747 s_service_name="GoogleTestServiceYYY")
748
749 #######################################
750 # Mismatched discovery session type tests key:
751 #
752 # names is: test_mismatch_service_type_<pub_type>_<sub_type>
753 # where:
754 #
755 # pub_type: Type of publish discovery session: unsolicited or solicited.
756 # sub_type: Type of subscribe discovery session: passive or active.
757 #######################################
758
759 def test_mismatch_service_type_unsolicited_active(self):
760 """Functional test case / Discovery test cases / Mismatch service name
761 - Unsolicited publish
762 - Active subscribe
763 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700764 self.discovery_mismatch_test_utility(
765 is_expected_to_pass=True,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700766 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
Etan Cohend8d58082017-05-22 15:03:17 -0700767 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700768
769 def test_mismatch_service_type_solicited_passive(self):
770 """Functional test case / Discovery test cases / Mismatch service name
771 - Unsolicited publish
772 - Active subscribe
773 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700774 self.discovery_mismatch_test_utility(
775 is_expected_to_pass=False,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700776 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
Etan Cohend8d58082017-05-22 15:03:17 -0700777 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE)
778
779 #######################################
780 # Mismatched discovery match filter tests key:
781 #
782 # names is: test_mismatch_match_filter_<pub_type>_<sub_type>
783 # where:
784 #
785 # pub_type: Type of publish discovery session: unsolicited or solicited.
786 # sub_type: Type of subscribe discovery session: passive or active.
787 #######################################
788
789 def test_mismatch_match_filter_unsolicited_passive(self):
790 """Functional test case / Discovery test cases / Mismatch match filter
791 - Unsolicited publish
792 - Passive subscribe
793 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700794 self.discovery_mismatch_test_utility(
795 is_expected_to_pass=False,
Etan Cohend8d58082017-05-22 15:03:17 -0700796 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700797 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohend8d58082017-05-22 15:03:17 -0700798 p_mf_1="hello there string",
799 s_mf_1="goodbye there string")
800
801 def test_mismatch_match_filter_solicited_active(self):
802 """Functional test case / Discovery test cases / Mismatch match filter
803 - Solicited publish
804 - Active subscribe
805 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700806 self.discovery_mismatch_test_utility(
807 is_expected_to_pass=False,
Etan Cohend8d58082017-05-22 15:03:17 -0700808 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
809 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE,
810 p_mf_1="hello there string",
811 s_mf_1="goodbye there string")