blob: 76af4a226cc362feb44e634169109a3de48dd12d [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 Cohen2c8db552017-05-22 11:00:03 -0700280 def verify_discovery_session_term(self, dut, disc_id, config, is_publish,
281 term_ind_on):
282 """Utility to verify that the specified discovery session has terminated (by
283 waiting for the TTL and then attempting to reconfigure).
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700284
Etan Cohen2c8db552017-05-22 11:00:03 -0700285 Args:
286 dut: device under test
287 disc_id: discovery id for the existing session
288 config: configuration of the existing session
289 is_publish: True if the configuration was publish, False if subscribe
290 term_ind_on: True if a termination indication is expected, False otherwise
291 """
292 # Wait for session termination
293 if term_ind_on:
294 autils.wait_for_event(
295 dut,
296 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
297 disc_id))
298 else:
299 # can't defer wait to end since in any case have to wait for session to
300 # expire
301 autils.fail_on_event(
302 dut,
303 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED,
304 disc_id))
305
306 # Validate that session expired by trying to configure it (expect failure)
307 config[aconsts.DISCOVERY_KEY_SSI] = "something else"
308 if is_publish:
309 dut.droid.wifiAwareUpdatePublish(disc_id, config)
310 else:
311 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
Etan Coheneb809a52017-05-24 10:30:30 -0700312
313 # The response to update discovery session is:
314 # term_ind_on=True: session was cleaned-up so won't get an explicit failure, but won't get a
315 # success either. Can check for no SESSION_CB_ON_SESSION_CONFIG_UPDATED but
316 # will defer to the end of the test (no events on queue).
317 # term_ind_on=False: session was not cleaned-up (yet). So expect
318 # SESSION_CB_ON_SESSION_CONFIG_FAILED.
319 if not term_ind_on:
320 autils.wait_for_event(
321 dut,
322 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_FAILED,
323 disc_id))
Etan Cohen2c8db552017-05-22 11:00:03 -0700324
325 def positive_ttl_test_utility(self, is_publish, ptype, stype, term_ind_on):
326 """Utility which runs a positive discovery session TTL configuration test
327
328 Iteration 1: Verify session started with TTL
329 Iteration 2: Verify session started without TTL and reconfigured with TTL
330 Iteration 3: Verify session started with (long) TTL and reconfigured with
331 (short) TTL
332
333 Args:
334 is_publish: True if testing publish, False if testing subscribe
335 ptype: Publish discovery type (used if is_publish is True)
336 stype: Subscribe discovery type (used if is_publish is False)
337 term_ind_on: Configuration of termination indication
338 """
339 SHORT_TTL = 5 # 5 seconds
340 LONG_TTL = 100 # 100 seconds
341 dut = self.android_devices[0]
342
343 # Attach and wait for confirmation
344 id = dut.droid.wifiAwareAttach(False)
345 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
346
347 # Iteration 1: Start discovery session with TTL
348 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
349 stype, self.PAYLOAD_SIZE_TYPICAL,
350 SHORT_TTL, term_ind_on, False)
351 if is_publish:
352 disc_id = dut.droid.wifiAwarePublish(id, config, True)
353 autils.wait_for_event(dut,
354 autils.decorate_event(
355 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
356 else:
357 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
358 autils.wait_for_event(
359 dut,
360 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
361 disc_id))
362
363 # Wait for session termination & verify
364 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
365 term_ind_on)
366
367 # Iteration 2: Start a discovery session without TTL
368 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
369 stype, self.PAYLOAD_SIZE_TYPICAL, 0,
370 term_ind_on, False)
371 if is_publish:
372 disc_id = dut.droid.wifiAwarePublish(id, config, True)
373 autils.wait_for_event(dut,
374 autils.decorate_event(
375 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
376 else:
377 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
378 autils.wait_for_event(
379 dut,
380 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
381 disc_id))
382
383 # Update with a TTL
384 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
385 stype, self.PAYLOAD_SIZE_TYPICAL,
386 SHORT_TTL, term_ind_on, False)
387 if is_publish:
388 dut.droid.wifiAwareUpdatePublish(disc_id, config)
389 else:
390 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
391 autils.wait_for_event(
392 dut,
393 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
394 disc_id))
395
396 # Wait for session termination & verify
397 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
398 term_ind_on)
399
400 # Iteration 3: Start a discovery session with (long) TTL
401 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
402 stype, self.PAYLOAD_SIZE_TYPICAL, LONG_TTL,
403 term_ind_on, False)
404 if is_publish:
405 disc_id = dut.droid.wifiAwarePublish(id, config, True)
406 autils.wait_for_event(dut,
407 autils.decorate_event(
408 aconsts.SESSION_CB_ON_PUBLISH_STARTED, disc_id))
409 else:
410 disc_id = dut.droid.wifiAwareSubscribe(id, config, True)
411 autils.wait_for_event(
412 dut,
413 autils.decorate_event(aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED,
414 disc_id))
415
416 # Update with a TTL
417 config = self.create_base_config(dut.aware_capabilities, is_publish, ptype,
418 stype, self.PAYLOAD_SIZE_TYPICAL,
419 SHORT_TTL, term_ind_on, False)
420 if is_publish:
421 dut.droid.wifiAwareUpdatePublish(disc_id, config)
422 else:
423 dut.droid.wifiAwareUpdateSubscribe(disc_id, config)
424 autils.wait_for_event(
425 dut,
426 autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED,
427 disc_id))
428
429 # Wait for session termination & verify
430 self.verify_discovery_session_term(dut, disc_id, config, is_publish,
431 term_ind_on)
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700432
433 # verify that there were no other events
Etan Cohen2c8db552017-05-22 11:00:03 -0700434 autils.verify_no_more_events(dut)
Etan Cohen872a6be2017-05-16 08:08:15 -0700435
Etan Cohenc1b65f12017-05-24 08:10:42 -0700436 def discovery_mismatch_test_utility(self,
437 is_expected_to_pass,
438 p_type,
439 s_type,
440 p_service_name=None,
441 s_service_name=None,
442 p_mf_1=None,
443 s_mf_1=None):
Etan Cohen60a9b522017-05-22 14:10:01 -0700444 """Utility which runs the negative discovery test for mismatched service
Etan Cohend8d58082017-05-22 15:03:17 -0700445 configs.
Etan Cohen60a9b522017-05-22 14:10:01 -0700446
447 Args:
Etan Cohenc1b65f12017-05-24 08:10:42 -0700448 is_expected_to_pass: True if positive test, False if negative
Etan Cohen60a9b522017-05-22 14:10:01 -0700449 p_type: Publish discovery type
450 s_type: Subscribe discovery type
Etan Cohen6677a2a2017-05-22 14:38:04 -0700451 p_service_name: Publish service name (or None to leave unchanged)
452 s_service_name: Subscribe service name (or None to leave unchanged)
Etan Cohend8d58082017-05-22 15:03:17 -0700453 p_mf_1: Publish match filter element [1] (or None to leave unchanged)
454 s_mf_1: Subscribe match filter element [1] (or None to leave unchanged)
Etan Cohen60a9b522017-05-22 14:10:01 -0700455 """
456 p_dut = self.android_devices[0]
457 p_dut.pretty_name = "Publisher"
458 s_dut = self.android_devices[1]
459 s_dut.pretty_name = "Subscriber"
460
461 # create configurations
462 p_config = self.create_publish_config(
463 p_dut.aware_capabilities,
464 p_type,
465 self.PAYLOAD_SIZE_TYPICAL,
466 ttl=0,
467 term_ind_on=False,
468 null_match=False)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700469 if p_service_name is not None:
470 p_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = p_service_name
Etan Cohend8d58082017-05-22 15:03:17 -0700471 if p_mf_1 is not None:
472 p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(
473 [(10).to_bytes(1, byteorder="big"),
474 p_mf_1,
475 bytes(range(40))])
Etan Cohen60a9b522017-05-22 14:10:01 -0700476 s_config = self.create_publish_config(
477 s_dut.aware_capabilities,
478 s_type,
479 self.PAYLOAD_SIZE_TYPICAL,
480 ttl=0,
481 term_ind_on=False,
482 null_match=False)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700483 if s_service_name is not None:
484 s_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = s_service_name
Etan Cohend8d58082017-05-22 15:03:17 -0700485 if s_mf_1 is not None:
486 s_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list(
487 [(10).to_bytes(1, byteorder="big"),
488 s_mf_1,
489 bytes(range(40))])
Etan Cohen60a9b522017-05-22 14:10:01 -0700490
Etan Cohenc1b65f12017-05-24 08:10:42 -0700491 p_id = p_dut.droid.wifiAwareAttach(False)
492 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
Etan Cohen76ff8012017-06-16 13:13:44 -0700493 time.sleep(self.device_startup_offset)
Etan Cohenc1b65f12017-05-24 08:10:42 -0700494 s_id = s_dut.droid.wifiAwareAttach(False)
495 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
496
497 # Publisher: start publish and wait for confirmation
498 p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config)
499 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
500
501 # Subscriber: start subscribe and wait for confirmation
502 s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config)
503 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
504
505 # Subscriber: fail on service discovery
506 if is_expected_to_pass:
507 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
508 else:
509 autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
510
511 # Publisher+Subscriber: Terminate sessions
512 p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
513 s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)
514
515 # verify that there were no other events (including terminations)
516 time.sleep(autils.EVENT_TIMEOUT)
517 autils.verify_no_more_events(p_dut, timeout=0)
518 autils.verify_no_more_events(s_dut, timeout=0)
Etan Cohen60a9b522017-05-22 14:10:01 -0700519
520
Etan Cohen872a6be2017-05-16 08:08:15 -0700521 #######################################
522 # Positive tests key:
523 #
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700524 # names is: test_<pub_type>_<sub_type>_<size>
Etan Cohen872a6be2017-05-16 08:08:15 -0700525 # where:
526 #
527 # pub_type: Type of publish discovery session: unsolicited or solicited.
528 # sub_type: Type of subscribe discovery session: passive or active.
529 # size: Size of payload fields (service name, service specific info, and match
530 # filter: typical, max, or min.
Etan Cohen872a6be2017-05-16 08:08:15 -0700531 #######################################
532
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700533 def test_positive_unsolicited_passive_typical(self):
Etan Cohen872a6be2017-05-16 08:08:15 -0700534 """Functional test case / Discovery test cases / positive test case:
535 - Solicited publish + passive subscribe
536 - Typical payload fields size
Etan Cohen872a6be2017-05-16 08:08:15 -0700537
538 Verifies that discovery and message exchange succeeds.
539 """
540 self.positive_discovery_test_utility(
541 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
542 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700543 payload_size=self.PAYLOAD_SIZE_TYPICAL)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700544
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700545 def test_positive_unsolicited_passive_min(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700546 """Functional test case / Discovery test cases / positive test case:
547 - Solicited publish + passive subscribe
548 - Minimal payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700549
550 Verifies that discovery and message exchange succeeds.
551 """
552 self.positive_discovery_test_utility(
553 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
554 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700555 payload_size=self.PAYLOAD_SIZE_MIN)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700556
Etan Cohen5a629a62017-05-19 15:11:18 -0700557 def test_positive_unsolicited_passive_max(self):
558 """Functional test case / Discovery test cases / positive test case:
559 - Solicited publish + passive subscribe
560 - Maximal payload fields size
561
562 Verifies that discovery and message exchange succeeds.
563 """
564 self.positive_discovery_test_utility(
565 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
566 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
567 payload_size=self.PAYLOAD_SIZE_MAX)
568
569
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700570 def test_positive_solicited_active_typical(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700571 """Functional test case / Discovery test cases / positive test case:
572 - Unsolicited publish + active subscribe
573 - Typical payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700574
575 Verifies that discovery and message exchange succeeds.
576 """
577 self.positive_discovery_test_utility(
578 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
579 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700580 payload_size=self.PAYLOAD_SIZE_TYPICAL)
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700581
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700582 def test_positive_solicited_active_min(self):
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700583 """Functional test case / Discovery test cases / positive test case:
584 - Unsolicited publish + active subscribe
585 - Minimal payload fields size
Etan Cohen0bc1cab2017-05-18 15:30:41 -0700586
587 Verifies that discovery and message exchange succeeds.
588 """
589 self.positive_discovery_test_utility(
590 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
591 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
Etan Cohenfb7f3b12017-05-19 06:54:03 -0700592 payload_size=self.PAYLOAD_SIZE_MIN)
Etan Cohen5a629a62017-05-19 15:11:18 -0700593
594 def test_positive_solicited_active_max(self):
595 """Functional test case / Discovery test cases / positive test case:
596 - Unsolicited publish + active subscribe
597 - Maximal payload fields size
598
599 Verifies that discovery and message exchange succeeds.
600 """
601 self.positive_discovery_test_utility(
602 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
603 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
604 payload_size=self.PAYLOAD_SIZE_MAX)
Etan Cohen2c8db552017-05-22 11:00:03 -0700605
606 #######################################
607 # TTL tests key:
608 #
609 # names is: test_ttl_<pub_type|sub_type>_<term_ind>
610 # where:
611 #
612 # pub_type: Type of publish discovery session: unsolicited or solicited.
613 # sub_type: Type of subscribe discovery session: passive or active.
614 # term_ind: ind_on or ind_off
615 #######################################
616
617 def test_ttl_unsolicited_ind_on(self):
618 """Functional test case / Discovery test cases / TTL test case:
619 - Unsolicited publish
620 - Termination indication enabled
621 """
622 self.positive_ttl_test_utility(
623 is_publish=True,
624 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
625 stype=None,
626 term_ind_on=True)
Etan Cohen3010bc22017-05-22 12:47:17 -0700627
628 def test_ttl_unsolicited_ind_off(self):
629 """Functional test case / Discovery test cases / TTL test case:
630 - Unsolicited publish
631 - Termination indication disabled
632 """
633 self.positive_ttl_test_utility(
634 is_publish=True,
635 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
636 stype=None,
637 term_ind_on=False)
638
639 def test_ttl_solicited_ind_on(self):
640 """Functional test case / Discovery test cases / TTL test case:
641 - Solicited publish
642 - Termination indication enabled
643 """
644 self.positive_ttl_test_utility(
645 is_publish=True,
646 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
647 stype=None,
648 term_ind_on=True)
649
650 def test_ttl_solicited_ind_off(self):
651 """Functional test case / Discovery test cases / TTL test case:
652 - Solicited publish
653 - Termination indication disabled
654 """
655 self.positive_ttl_test_utility(
656 is_publish=True,
657 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
658 stype=None,
659 term_ind_on=False)
660
661 def test_ttl_passive_ind_on(self):
662 """Functional test case / Discovery test cases / TTL test case:
663 - Passive subscribe
664 - Termination indication enabled
665 """
666 self.positive_ttl_test_utility(
667 is_publish=False,
668 ptype=None,
669 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
670 term_ind_on=True)
671
672 def test_ttl_passive_ind_off(self):
673 """Functional test case / Discovery test cases / TTL test case:
674 - Passive subscribe
675 - Termination indication disabled
676 """
677 self.positive_ttl_test_utility(
678 is_publish=False,
679 ptype=None,
680 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
681 term_ind_on=False)
682
683 def test_ttl_active_ind_on(self):
684 """Functional test case / Discovery test cases / TTL test case:
685 - Active subscribe
686 - Termination indication enabled
687 """
688 self.positive_ttl_test_utility(
689 is_publish=False,
690 ptype=None,
691 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
692 term_ind_on=True)
693
694 def test_ttl_active_ind_off(self):
695 """Functional test case / Discovery test cases / TTL test case:
696 - Active subscribe
697 - Termination indication disabled
698 """
699 self.positive_ttl_test_utility(
700 is_publish=False,
701 ptype=None,
702 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
703 term_ind_on=False)
Etan Cohen60a9b522017-05-22 14:10:01 -0700704
705 #######################################
706 # Mismatched service name tests key:
707 #
708 # names is: test_mismatch_service_name_<pub_type>_<sub_type>
709 # where:
710 #
711 # pub_type: Type of publish discovery session: unsolicited or solicited.
712 # sub_type: Type of subscribe discovery session: passive or active.
713 #######################################
714
715 def test_mismatch_service_name_unsolicited_passive(self):
716 """Functional test case / Discovery test cases / Mismatch service name
717 - Unsolicited publish
718 - Passive subscribe
719 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700720 self.discovery_mismatch_test_utility(
721 is_expected_to_pass=False,
Etan Cohen60a9b522017-05-22 14:10:01 -0700722 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
723 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE,
724 p_service_name="GoogleTestServiceXXX",
725 s_service_name="GoogleTestServiceYYY")
726
727 def test_mismatch_service_name_solicited_active(self):
728 """Functional test case / Discovery test cases / Mismatch service name
729 - Solicited publish
730 - Active subscribe
731 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700732 self.discovery_mismatch_test_utility(
733 is_expected_to_pass=False,
Etan Cohen60a9b522017-05-22 14:10:01 -0700734 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
735 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE,
736 p_service_name="GoogleTestServiceXXX",
Etan Cohen6677a2a2017-05-22 14:38:04 -0700737 s_service_name="GoogleTestServiceYYY")
738
739 #######################################
740 # Mismatched discovery session type tests key:
741 #
742 # names is: test_mismatch_service_type_<pub_type>_<sub_type>
743 # where:
744 #
745 # pub_type: Type of publish discovery session: unsolicited or solicited.
746 # sub_type: Type of subscribe discovery session: passive or active.
747 #######################################
748
749 def test_mismatch_service_type_unsolicited_active(self):
750 """Functional test case / Discovery test cases / Mismatch service name
751 - Unsolicited publish
752 - Active subscribe
753 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700754 self.discovery_mismatch_test_utility(
755 is_expected_to_pass=True,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700756 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
Etan Cohend8d58082017-05-22 15:03:17 -0700757 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE)
Etan Cohen6677a2a2017-05-22 14:38:04 -0700758
759 def test_mismatch_service_type_solicited_passive(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=False,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700766 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
Etan Cohend8d58082017-05-22 15:03:17 -0700767 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE)
768
769 #######################################
770 # Mismatched discovery match filter tests key:
771 #
772 # names is: test_mismatch_match_filter_<pub_type>_<sub_type>
773 # where:
774 #
775 # pub_type: Type of publish discovery session: unsolicited or solicited.
776 # sub_type: Type of subscribe discovery session: passive or active.
777 #######################################
778
779 def test_mismatch_match_filter_unsolicited_passive(self):
780 """Functional test case / Discovery test cases / Mismatch match filter
781 - Unsolicited publish
782 - Passive subscribe
783 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700784 self.discovery_mismatch_test_utility(
785 is_expected_to_pass=False,
Etan Cohend8d58082017-05-22 15:03:17 -0700786 p_type=aconsts.PUBLISH_TYPE_UNSOLICITED,
Etan Cohen6677a2a2017-05-22 14:38:04 -0700787 s_type=aconsts.SUBSCRIBE_TYPE_PASSIVE,
Etan Cohend8d58082017-05-22 15:03:17 -0700788 p_mf_1="hello there string",
789 s_mf_1="goodbye there string")
790
791 def test_mismatch_match_filter_solicited_active(self):
792 """Functional test case / Discovery test cases / Mismatch match filter
793 - Solicited publish
794 - Active subscribe
795 """
Etan Cohenc1b65f12017-05-24 08:10:42 -0700796 self.discovery_mismatch_test_utility(
797 is_expected_to_pass=False,
Etan Cohend8d58082017-05-22 15:03:17 -0700798 p_type=aconsts.PUBLISH_TYPE_SOLICITED,
799 s_type=aconsts.SUBSCRIBE_TYPE_ACTIVE,
800 p_mf_1="hello there string",
801 s_mf_1="goodbye there string")