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.test_utils.power import PowerWiFiBaseTest as PWBT 23from acts.test_utils.wifi import wifi_constants as wc 24from acts.test_utils.wifi import wifi_test_utils as wutils 25from acts.test_utils.wifi import wifi_power_test_utils as wputils 26 27PHONE_BATTERY_VOLTAGE = 4.2 28 29class PowerWiFiroamingTest(PWBT.PowerWiFiBaseTest): 30 def teardown_test(self): 31 # Delete the brconfigs attributes as this is duplicated with one of the 32 # ap's bridge interface config 33 delattr(self, 'brconfigs') 34 super().teardown_test() 35 36 # Test cases 37 @test_tracker_info(uuid='392622d3-0c5c-4767-afa2-abfb2058b0b8') 38 def test_screenoff_roaming(self): 39 """Test roaming power consumption with screen off. 40 Change the attenuation level to trigger roaming between two APs 41 42 """ 43 # Setup both APs 44 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 45 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 46 self.log.info('Set attenuation to connect device to the aux AP') 47 self.set_attenuation(self.atten_level[wc.AP_AUX]) 48 self.brconfigs_aux = self.setup_ap_connection( 49 network_aux, ap=self.access_point_aux) 50 self.log.info('Set attenuation to connect device to the main AP') 51 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 52 self.brconfigs_main = self.setup_ap_connection( 53 network_main, ap=self.access_point_main) 54 self.dut.droid.goToSleepNow() 55 time.sleep(5) 56 # Set attenuator to trigger roaming 57 self.dut.log.info('Trigger roaming now') 58 self.set_attenuation(self.atten_level[self.current_test_name]) 59 self.measure_power_and_validate() 60 61 @test_tracker_info(uuid='a0459b7c-74ce-4adb-8e55-c5365bc625eb') 62 def test_screenoff_toggle_between_AP(self): 63 64 # Set attenuator to connect phone to both networks 65 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 66 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 67 # Connect to both APs 68 network_main = self.main_network[hc.BAND_2G] 69 network_aux = self.aux_network[hc.BAND_2G] 70 self.log.info('Set attenuation to connect device to the main AP') 71 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 72 self.brconfigs_main = self.setup_ap_connection( 73 network_main, ap=self.access_point_main) 74 self.log.info('Set attenuation to connect device to the aux AP') 75 self.set_attenuation(self.atten_level[wc.AP_AUX]) 76 self.brconfigs_aux = self.setup_ap_connection( 77 network_aux, ap=self.access_point_aux) 78 self.mon_info.duration = self.toggle_interval 79 self.dut.droid.goToSleepNow() 80 time.sleep(5) 81 # Toggle between two networks 82 begin_time = utils.get_current_epoch_time() 83 for i in range(self.toggle_times): 84 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 85 self.dut.droid.wifiConnect(network_main) 86 file_path, avg_current = self.monsoon_data_collect_save() 87 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 88 self.dut.droid.wifiConnect(network_aux) 89 file_path, avg_current = self.monsoon_data_collect_save() 90 [plot, dt] = wputils.monsoon_data_plot(self.mon_info, file_path) 91 self.test_result = dt.source.data['y0'][0] 92 self.power_consumption = self.test_result * PHONE_BATTERY_VOLTAGE 93 # Take Bugreport 94 if self.bug_report: 95 self.dut.take_bug_report(self.test_name, begin_time) 96 # Path fail check 97 self.pass_fail_check() 98 99 @test_tracker_info(uuid='e5ff95c0-b17e-425c-a903-821ba555a9b9') 100 def test_screenon_toggle_between_AP(self): 101 102 # Set attenuator to connect phone to both networks 103 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 104 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 105 # Connect to both APs 106 network_main = self.main_network[hc.BAND_2G] 107 network_aux = self.aux_network[hc.BAND_2G] 108 self.log.info('Set attenuation to connect device to the main AP') 109 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 110 self.brconfigs_main = self.setup_ap_connection( 111 network_main, ap=self.access_point_main) 112 self.log.info('Set attenuation to connect device to the aux AP') 113 self.set_attenuation(self.atten_level[wc.AP_AUX]) 114 self.brconfigs_aux = self.setup_ap_connection( 115 network_aux, ap=self.access_point_aux) 116 self.mon_info.duration = self.toggle_interval 117 time.sleep(5) 118 # Toggle between two networks 119 begin_time = utils.get_current_epoch_time() 120 for i in range(self.toggle_times): 121 self.dut.log.info('Connecting to %s' % network_main[wc.SSID]) 122 self.dut.droid.wifiConnect(network_main) 123 file_path, avg_current = self.monsoon_data_collect_save() 124 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) 125 self.dut.droid.wifiConnect(network_aux) 126 file_path, avg_current = self.monsoon_data_collect_save() 127 [plot, dt] = wputils.monsoon_data_plot(self.mon_info, file_path) 128 self.test_result = dt.source.data['y0'][0] 129 self.power_consumption = self.test_result * PHONE_BATTERY_VOLTAGE 130 # Take Bugreport 131 if self.bug_report: 132 self.dut.take_bug_report(self.test_name, begin_time) 133 # Path fail check 134 self.pass_fail_check() 135 136 @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4') 137 def test_screenoff_wifi_wedge(self): 138 139 # Set attenuator to connect phone to both networks 140 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] 141 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] 142 # Connect to both APs 143 network_main = self.main_network[hc.BAND_2G] 144 network_aux = self.aux_network[hc.BAND_2G] 145 self.log.info('Set attenuation to connect device to the main AP') 146 self.set_attenuation(self.atten_level[wc.AP_MAIN]) 147 self.brconfigs_main = self.setup_ap_connection( 148 network_main, ap=self.access_point_main) 149 self.log.info('Set attenuation to connect device to the aux AP') 150 self.set_attenuation(self.atten_level[wc.AP_AUX]) 151 self.brconfigs_aux = self.setup_ap_connection( 152 network_aux, ap=self.access_point_aux) 153 self.log.info('Forget network {}'.format(network_aux[wc.SSID])) 154 wutils.wifi_forget_network(self.dut, network_aux[wc.SSID]) 155 self.log.info('Set attenuation to trigger wedge condition') 156 self.set_attenuation(self.atten_level[self.current_test_name]) 157 self.dut.droid.goToSleepNow() 158 self.measure_power_and_validate() 159