1#!/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 18 19from acts import asserts 20from acts.test_decorators import test_tracker_info 21from acts_contrib.test_utils.wifi.aware import aware_const as aconsts 22from acts_contrib.test_utils.wifi.aware import aware_test_utils as autils 23from acts_contrib.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest 24 25 26class DiscoveryStressTest(AwareBaseTest): 27 """Stress tests for Discovery sessions""" 28 29 # Number of iterations on create/destroy Attach sessions. 30 ATTACH_ITERATIONS = 2 31 32 # Number of iterations on create/destroy Discovery sessions 33 DISCOVERY_ITERATIONS = 40 34 35 #################################################################### 36 37 @test_tracker_info(uuid="783791e5-7726-44e0-ac5b-98c1dbf493cb") 38 def test_discovery_stress(self): 39 """Create and destroy a random array of discovery sessions, up to the 40 limit of capabilities.""" 41 dut = self.android_devices[0] 42 43 discovery_setup_success = 0 44 discovery_setup_fail = 0 45 46 for attach_iter in range(self.ATTACH_ITERATIONS): 47 # attach 48 session_id = dut.droid.wifiAwareAttach(True) 49 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) 50 51 p_discovery_ids = [] 52 s_discovery_ids = [] 53 for discovery_iter in range(self.DISCOVERY_ITERATIONS): 54 service_name = 'GoogleTestService-%d-%d' % (attach_iter, 55 discovery_iter) 56 57 p_config = None 58 s_config = None 59 60 if discovery_iter % 4 == 0: # publish/unsolicited 61 p_config = autils.create_discovery_config( 62 service_name, aconsts.PUBLISH_TYPE_UNSOLICITED) 63 elif discovery_iter % 4 == 1: # publish/solicited 64 p_config = autils.create_discovery_config( 65 service_name, aconsts.PUBLISH_TYPE_SOLICITED) 66 elif discovery_iter % 4 == 2: # subscribe/passive 67 s_config = autils.create_discovery_config( 68 service_name, aconsts.SUBSCRIBE_TYPE_PASSIVE) 69 elif discovery_iter % 4 == 3: # subscribe/active 70 s_config = autils.create_discovery_config( 71 service_name, aconsts.SUBSCRIBE_TYPE_ACTIVE) 72 73 if p_config is not None: 74 if len(p_discovery_ids) == dut.aware_capabilities[ 75 aconsts.CAP_MAX_PUBLISHES]: 76 dut.droid.wifiAwareDestroyDiscoverySession( 77 p_discovery_ids.pop( 78 dut.aware_capabilities[aconsts. 79 CAP_MAX_PUBLISHES] // 80 2)) 81 disc_id = dut.droid.wifiAwarePublish(session_id, p_config) 82 event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED 83 p_discovery_ids.append(disc_id) 84 else: 85 if len(s_discovery_ids) == dut.aware_capabilities[ 86 aconsts.CAP_MAX_SUBSCRIBES]: 87 dut.droid.wifiAwareDestroyDiscoverySession( 88 s_discovery_ids.pop( 89 dut.aware_capabilities[aconsts. 90 CAP_MAX_SUBSCRIBES] // 91 2)) 92 disc_id = dut.droid.wifiAwareSubscribe( 93 session_id, s_config) 94 event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED 95 s_discovery_ids.append(disc_id) 96 97 try: 98 dut.ed.pop_event(event_name, autils.EVENT_TIMEOUT) 99 discovery_setup_success = discovery_setup_success + 1 100 except queue.Empty: 101 discovery_setup_fail = discovery_setup_fail + 1 102 103 dut.droid.wifiAwareDestroy(session_id) 104 105 results = {} 106 results['discovery_setup_success'] = discovery_setup_success 107 results['discovery_setup_fail'] = discovery_setup_fail 108 asserts.assert_equal( 109 discovery_setup_fail, 110 0, 111 'Discovery setup failures', 112 extras=results) 113 asserts.explicit_pass('test_discovery_stress done', extras=results) 114