1 #!/usr/bin/env 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 17 import logging 18 import os 19 import time 20 from acts import base_test 21 from acts.controllers.ap_lib import hostapd_constants as hc 22 from acts.test_decorators import test_tracker_info 23 from acts.test_utils.wifi import wifi_constants as wc 24 from acts.test_utils.wifi import wifi_test_utils as wutils 25 from acts.test_utils.wifi import wifi_power_test_utils as wputils 26 27 28 class PowerroamingTest(base_test.BaseTestClass): 29 def __init__(self, controllers): 30 31 base_test.BaseTestClass.__init__(self, controllers) 32 self.tests = ('test_screenoff_roaming', 'test_screenoff_fastroaming', 33 'test_screenon_toggle_between_AP', 34 'test_screenoff_toggle_between_AP', 35 'test_screenoff_wifi_wedge') 36 37 def setup_class(self): 38 39 self.log = logging.getLogger() 40 self.dut = self.android_devices[0] 41 self.access_point_main = self.access_points[0] 42 self.access_point_aux = self.access_points[1] 43 req_params = ('main_network', 'aux_network', 'roamingtest_params') 44 self.unpack_userparams(req_params) 45 self.unpack_testparams(self.roamingtest_params) 46 self.mon_data_path = os.path.join(self.log_path, 'Monsoon') 47 self.mon = self.monsoons[0] 48 self.mon.set_max_current(8.0) 49 self.mon.set_voltage(4.2) 50 self.mon_duration_all = self.mon_duration 51 self.mon.attach_device(self.dut) 52 self.mon_info = wputils.create_monsoon_info(self) 53 self.num_atten = self.attenuators[0].instrument.num_atten 54 55 def teardown_class(self): 56 57 self.mon.usb('on') 58 59 def unpack_testparams(self, bulk_params): 60 """Unpack all the test specific parameters. 61 62 Args: 63 bulk_params: dict with all test specific params in the config file 64 """ 65 for key in bulk_params.keys(): 66 setattr(self, key, bulk_params[key]) 67 68 def ap_close_all(self): 69 """Close all the AP controller objects in roaming tests. 70 71 """ 72 for ap in self.access_points: 73 ap.close() 74 75 # Test cases 76 @test_tracker_info(uuid='392622d3-0c5c-4767-afa2-abfb2058b0b8') 77 def test_screenoff_roaming(self): 78 """Test roaming power consumption with screen off. 79 Change the attenuation level to trigger roaming between two APs 80 81 """ 82 # Setup both APs 83 network_main = self.main_network[hc.BAND_2G] 84 wputils.ap_setup(self.access_point_main, network_main) 85 network_aux = self.aux_network[hc.BAND_2G] 86 wputils.ap_setup(self.access_point_aux, network_aux) 87 # Initialize the dut to rock-bottom state 88 wputils.dut_rockbottom(self.dut) 89 wutils.wifi_toggle_state(self.dut, True) 90 # Set attenuator and add two networks to the phone 91 self.log.info('Set attenuation to connect device to both APs') 92 [ 93 self.attenuators[i].set_atten(self.atten_level['zero_atten'][i]) 94 for i in range(self.num_atten) 95 ] 96 wutils.wifi_connect(self.dut, network_aux) 97 time.sleep(5) 98 wutils.wifi_connect(self.dut, network_main) 99 self.dut.droid.goToSleepNow() 100 time.sleep(5) 101 # Set attenuator to trigger roaming 102 self.dut.log.info('Trigger roaming now') 103 [ 104 self.attenuators[i].set_atten( 105 self.atten_level[self.current_test_name][i]) 106 for i in range(self.num_atten) 107 ] 108 file_path, avg_current = wputils.monsoon_data_collect_save( 109 self.dut, self.mon_info, self.current_test_name, self.bug_report) 110 wputils.monsoon_data_plot(self.mon_info, file_path) 111 # Close AP controller 112 self.ap_close_all() 113 # Path fail check 114 wputils.pass_fail_check(self, avg_current) 115 116 @test_tracker_info(uuid='2fec5208-043a-410a-8fd2-6784d70a3587') 117 def test_screenoff_fastroaming(self): 118 119 # Initialize the dut to rock-bottom state 120 wputils.dut_rockbottom(self.dut) 121 wutils.wifi_toggle_state(self.dut, True) 122 # Setup the aux AP 123 network_main = self.main_network[hc.BAND_2G] 124 network_aux = self.aux_network[hc.BAND_2G] 125 # Set the same SSID for the AUX AP for fastroaming purpose 126 network_aux[wc.SSID] = network_main[wc.SSID] 127 wputils.ap_setup(self.access_point_aux, network_aux) 128 # Set attenuator and add two networks to the phone 129 self.log.info('Set attenuation to connect device to the aux AP') 130 [ 131 self.attenuators[i].set_atten(self.atten_level[wc.AP_MAIN][i]) 132 for i in range(self.num_atten) 133 ] 134 wutils.wifi_connect(self.dut, network_aux) 135 time.sleep(5) 136 # Setup the main AP 137 wputils.ap_setup(self.access_point_main, network_main) 138 # Set attenuator to connect the phone to main AP 139 self.log.info('Set attenuation to connect device to the main AP') 140 [ 141 self.attenuators[i].set_atten(self.atten_level[wc.AP_MAIN][i]) 142 for i in range(self.num_atten) 143 ] 144 wutils.wifi_connect(self.dut, network_main) 145 time.sleep(5) 146 self.dut.droid.goToSleepNow() 147 # Trigger fastroaming 148 self.dut.log.info('Trigger fastroaming now') 149 [ 150 self.attenuators[i].set_atten(self.atten_level[wc.AP_MAIN][i]) 151 for i in range(self.num_atten) 152 ] 153 file_path, avg_current = wputils.monsoon_data_collect_save( 154 self.dut, self.mon_info, self.current_test_name, self.bug_report) 155 wputils.monsoon_data_plot(self.mon_info, file_path) 156 # Close AP controller 157 self.ap_close_all() 158 # Path fail check 159 wputils.pass_fail_check(self, avg_current) 160 161 @test_tracker_info(uuid='a0459b7c-74ce-4adb-8e55-c5365bc625eb') 162 def test_screenoff_toggle_between_AP(self): 163 164 # Setup both APs 165 network_main = self.main_network[hc.BAND_2G] 166 wputils.ap_setup(self.access_point_main, network_main) 167 network_aux = self.aux_network[hc.BAND_2G] 168 wputils.ap_setup(self.access_point_aux, network_aux) 169 # Initialize the dut to rock-bottom state 170 wputils.dut_rockbottom(self.dut) 171 wutils.wifi_toggle_state(self.dut, True) 172 self.mon_info['duration'] = self.toggle_interval 173 self.dut.droid.goToSleepNow() 174 time.sleep(5) 175 self.log.info('Set attenuation to connect device to both APs') 176 [ 177 self.attenuators[i].set_atten( 178 self.atten_level[self.current_test_name][i]) 179 for i in range(self.num_atten) 180 ] 181 # Toggle between two networks 182 for i in range(self.toggle_times): 183 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 184 self.dut.droid.wifiConnect(network_main) 185 file_path, avg_current = wputils.monsoon_data_collect_save( 186 self.dut, self.mon_info, self.current_test_name, 0) 187 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 188 self.dut.droid.wifiConnect(network_aux) 189 file_path, avg_current = wputils.monsoon_data_collect_save( 190 self.dut, self.mon_info, self.current_test_name, 0) 191 wputils.monsoon_data_plot(self.mon_info, file_path) 192 # Close AP controller 193 self.ap_close_all() 194 # Path fail check 195 wputils.pass_fail_check(self, avg_current) 196 197 @test_tracker_info(uuid='e5ff95c0-b17e-425c-a903-821ba555a9b9') 198 def test_screenon_toggle_between_AP(self): 199 200 # Setup both APs 201 network_main = self.main_network[hc.BAND_5G] 202 wputils.ap_setup(self.access_point_main, network_main) 203 network_aux = self.aux_network[hc.BAND_5G] 204 wputils.ap_setup(self.access_point_aux, network_aux) 205 # Initialize the dut to rock-bottom state 206 wputils.dut_rockbottom(self.dut) 207 wutils.wifi_toggle_state(self.dut, True) 208 self.mon_info['duration'] = self.toggle_interval 209 self.log.info('Set attenuation to connect device to both APs') 210 [ 211 self.attenuators[i].set_atten( 212 self.atten_level[self.current_test_name][i]) 213 for i in range(self.num_atten) 214 ] 215 # Toggle between two networks 216 for i in range(self.toggle_times): 217 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 218 self.dut.droid.wifiConnect(network_main) 219 file_path, avg_current = wputils.monsoon_data_collect_save( 220 self.dut, self.mon_info, self.current_test_name, 0) 221 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 222 self.dut.droid.wifiConnect(network_aux) 223 file_path, avg_current = wputils.monsoon_data_collect_save( 224 self.dut, self.mon_info, self.current_test_name, 0) 225 wputils.monsoon_data_plot(self.mon_info, file_path) 226 # Close AP controller 227 self.ap_close_all() 228 # Path fail check 229 wputils.pass_fail_check(self, avg_current) 230 231 @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4') 232 def test_screenoff_wifi_wedge(self): 233 234 # Setup both APs 235 network_main = self.main_network[hc.BAND_2G] 236 wputils.ap_setup(self.access_point_main, network_main) 237 network_aux = self.aux_network[hc.BAND_2G] 238 wputils.ap_setup(self.access_point_aux, network_aux) 239 # Initialize the dut to rock-bottom state 240 wputils.dut_rockbottom(self.dut) 241 wutils.wifi_toggle_state(self.dut, True) 242 # Set attenuator to connect phone to both networks 243 self.log.info('Set attenuation to connect device to both APs') 244 [ 245 self.attenuators[i].set_atten(self.atten_level['zero_atten'][i]) 246 for i in range(self.num_atten) 247 ] 248 wutils.wifi_connect(self.dut, network_main) 249 wutils.wifi_connect(self.dut, network_aux) 250 self.log.info('Forget network {}'.format(network_aux[wc.SSID])) 251 wutils.wifi_forget_network(self.dut, network_aux[wc.SSID]) 252 self.log.info('Set attenuation to trigger wedge condition') 253 [ 254 self.attenuators[i].set_atten( 255 self.atten_level[self.current_test_name][i]) 256 for i in range(self.num_atten) 257 ] 258 self.dut.droid.goToSleepNow() 259 file_path, avg_current = wputils.monsoon_data_collect_save( 260 self.dut, self.mon_info, self.current_test_name, self.bug_report) 261 wputils.monsoon_data_plot(self.mon_info, file_path) 262 # Close AP controller 263 self.ap_close_all() 264 # Path fail check 265 wputils.pass_fail_check(self, avg_current) 266