1#!/usr/bin/env python3.4 2# 3# Copyright 2018 - 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 copy 18import time 19from acts import utils 20from acts.controllers.ap_lib import hostapd_constants as hc 21from acts.test_decorators import test_tracker_info 22from acts_contrib.test_utils.power import PowerWiFiBaseTest as PWBT 23from acts_contrib.test_utils.wifi import wifi_constants as wc 24from acts_contrib.test_utils.wifi import wifi_test_utils as wutils 25from acts_contrib.test_utils.power import plot_utils 26 27PHONE_BATTERY_VOLTAGE = 4.2 28 29 30class PowerWiFiroamingTest(PWBT.PowerWiFiBaseTest): 31 def setup_class(self): 32 super().setup_class() 33 self.unpack_userparams(toggle_interval=20, toggle_times=10) 34 35 def teardown_test(self): 36 # Delete the brconfigs attributes as this is duplicated with one of the 37 # ap's bridge interface config 38 delattr(self, 'brconfigs') 39 super().teardown_test() 40 41 # Test cases 42 @test_tracker_info(uuid='392622d3-0c5c-4767-afa2-abfb2058b0b8') 43 def test_screenoff_roaming(self): 44 """Test roaming power consumption with screen off. 45 Change the attenuation level to trigger roaming between two APs 46 47 """ 48 # Setup both APs 49 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 50 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 51 self.log.info('Set attenuation to connect device to the aux AP') 52 self.set_attenuation(self.atten_level[wc.AP_AUX]) 53 self.brconfigs_aux = self.setup_ap_connection(network_aux, 54 ap=self.access_point_aux) 55 self.log.info('Set attenuation to connect device to the main AP') 56 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 57 self.brconfigs_main = self.setup_ap_connection( 58 network_main, ap=self.access_point_main) 59 self.dut.droid.goToSleepNow() 60 time.sleep(5) 61 # Set attenuator to trigger roaming 62 self.dut.log.info('Trigger roaming now') 63 self.set_attenuation(self.atten_level[self.current_test_name]) 64 self.measure_power_and_validate() 65 66 @test_tracker_info(uuid='a0459b7c-74ce-4adb-8e55-c5365bc625eb') 67 def test_screenoff_toggle_between_AP(self): 68 69 # Set attenuator to connect phone to both networks 70 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 71 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 72 # Connect to both APs 73 network_main = self.main_network[hc.BAND_2G] 74 network_aux = self.aux_network[hc.BAND_2G] 75 self.log.info('Set attenuation to connect device to the main AP') 76 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 77 self.brconfigs_main = self.setup_ap_connection( 78 network_main, ap=self.access_point_main) 79 self.log.info('Set attenuation to connect device to the aux AP') 80 self.set_attenuation(self.atten_level[wc.AP_AUX]) 81 self.brconfigs_aux = self.setup_ap_connection(network_aux, 82 ap=self.access_point_aux) 83 self.mon_info.duration = self.toggle_interval 84 self.dut.droid.goToSleepNow() 85 time.sleep(5) 86 # Toggle between two networks 87 begin_time = utils.get_current_epoch_time() 88 results = [] 89 for i in range(self.toggle_times): 90 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 91 self.dut.droid.wifiConnect(network_main) 92 results.append(self.power_monitor_data_collect_save()) 93 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 94 self.dut.droid.wifiConnect(network_aux) 95 results.append(self.power_monitor_data_collect_save()) 96 97 # Join all results in a single list 98 joint_result = [] 99 for result in results: 100 joint_result.extend(result) 101 102 plot_title = '{}_{}_{}'.format(self.test_name, self.dut.model, 103 self.dut.build_info['build_id']) 104 plot_utils.current_waveform_plot(joint_result, self.mon_voltage, 105 self.mon_info.data_path, plot_title) 106 107 average_current = sum([sample[1] * 1000 108 for sample in joint_result]) / len(joint_result) 109 110 self.power_result.metric_value = [ 111 sum([sample[1] for sample in result]) / len(result) 112 for result in results 113 ] 114 # Take Bugreport 115 if self.bug_report: 116 self.dut.take_bug_report(self.test_name, begin_time) 117 # Path fail check 118 self.pass_fail_check(average_current) 119 120 @test_tracker_info(uuid='e5ff95c0-b17e-425c-a903-821ba555a9b9') 121 def test_screenon_toggle_between_AP(self): 122 123 # Set attenuator to connect phone to both networks 124 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 125 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 126 # Connect to both APs 127 network_main = self.main_network[hc.BAND_2G] 128 network_aux = self.aux_network[hc.BAND_2G] 129 self.log.info('Set attenuation to connect device to the main AP') 130 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 131 self.brconfigs_main = self.setup_ap_connection( 132 network_main, ap=self.access_point_main) 133 self.log.info('Set attenuation to connect device to the aux AP') 134 self.set_attenuation(self.atten_level[wc.AP_AUX]) 135 self.brconfigs_aux = self.setup_ap_connection(network_aux, 136 ap=self.access_point_aux) 137 self.mon_info.duration = self.toggle_interval 138 time.sleep(5) 139 # Toggle between two networks 140 begin_time = utils.get_current_epoch_time() 141 results = [] 142 for i in range(self.toggle_times): 143 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 144 self.dut.droid.wifiConnect(network_main) 145 results.append(self.power_monitor_data_collect_save()) 146 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 147 self.dut.droid.wifiConnect(network_aux) 148 results.append(self.power_monitor_data_collect_save()) 149 # Join all results in a single list 150 joint_result = [] 151 for result in results: 152 joint_result.extend(result) 153 154 plot_title = '{}_{}_{}'.format(self.test_name, self.dut.model, 155 self.dut.build_info['build_id']) 156 plot_utils.current_waveform_plot(joint_result, self.mon_voltage, 157 self.mon_info.data_path, plot_title) 158 159 average_current = sum([sample[1] * 1000 160 for sample in joint_result]) / len(joint_result) 161 162 self.power_result.metric_value = [ 163 sum([sample[1] for sample in result]) / len(result) 164 for result in results 165 ] 166 # Take Bugreport 167 if self.bug_report: 168 self.dut.take_bug_report(self.test_name, begin_time) 169 # Path fail check 170 self.pass_fail_check(average_current) 171 172 @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4') 173 def test_screenoff_wifi_wedge(self): 174 175 # Set attenuator to connect phone to both networks 176 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 177 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 178 # Connect to both APs 179 network_main = self.main_network[hc.BAND_2G] 180 network_aux = self.aux_network[hc.BAND_2G] 181 self.log.info('Set attenuation to connect device to the main AP') 182 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 183 self.brconfigs_main = self.setup_ap_connection( 184 network_main, ap=self.access_point_main) 185 self.log.info('Set attenuation to connect device to the aux AP') 186 self.set_attenuation(self.atten_level[wc.AP_AUX]) 187 self.brconfigs_aux = self.setup_ap_connection(network_aux, 188 ap=self.access_point_aux) 189 self.log.info('Forget network {}'.format(network_aux[wc.SSID])) 190 wutils.wifi_forget_network(self.dut, network_aux[wc.SSID]) 191 self.log.info('Set attenuation to trigger wedge condition') 192 self.set_attenuation(self.atten_level[self.current_test_name]) 193 self.dut.droid.goToSleepNow() 194 self.measure_power_and_validate() 195