blob: b3665840a2725529f472593ec37e0116cc1cd347 [file] [log] [blame]
Qi Jiang2a128de2018-04-27 23:00:12 -07001#!/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
Qi Jiangddd01142018-10-18 22:51:42 -070017import copy
Qi Jiang2a128de2018-04-27 23:00:12 -070018import time
19from acts import utils
20from acts.controllers.ap_lib import hostapd_constants as hc
21from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000022from 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
Qi Jiang2a128de2018-04-27 23:00:12 -070026
Qi Jiangfcfc2242018-11-13 16:32:23 -080027PHONE_BATTERY_VOLTAGE = 4.2
Qi Jiang2a128de2018-04-27 23:00:12 -070028
Mark De Ruyter85fb5382019-08-19 20:15:41 -070029
Qi Jiang2a128de2018-04-27 23:00:12 -070030class PowerWiFiroamingTest(PWBT.PowerWiFiBaseTest):
Qid7053592019-11-19 14:56:26 -080031 def setup_class(self):
32 super().setup_class()
33 self.unpack_userparams(toggle_interval=20, toggle_times=10)
34
Qi Jiangddd01142018-10-18 22:51:42 -070035 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()
Qi Jiang2a128de2018-04-27 23:00:12 -070040
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 """
Qi Jiang2a128de2018-04-27 23:00:12 -070048 # Setup both APs
Qi Jiangddd01142018-10-18 22:51:42 -070049 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])
Qid7053592019-11-19 14:56:26 -080053 self.brconfigs_aux = self.setup_ap_connection(network_aux,
54 ap=self.access_point_aux)
Qi Jiangddd01142018-10-18 22:51:42 -070055 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)
Qi Jiang2a128de2018-04-27 23:00:12 -070059 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
Qi Jiang2a128de2018-04-27 23:00:12 -070066 @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
Qi Jiangddd01142018-10-18 22:51:42 -070070 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
71 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -070072 # Connect to both APs
73 network_main = self.main_network[hc.BAND_2G]
74 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -070075 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])
Qid7053592019-11-19 14:56:26 -080081 self.brconfigs_aux = self.setup_ap_connection(network_aux,
82 ap=self.access_point_aux)
Qi Jiang2a128de2018-04-27 23:00:12 -070083 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()
Mark De Ruytere54396c2019-08-20 12:54:37 -070088 results = []
Qi Jiang2a128de2018-04-27 23:00:12 -070089 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)
Ignacio Guarna8b7054f2020-09-16 22:55:40 -030092 results.append(self.power_monitor_data_collect_save())
Qi Jiang2a128de2018-04-27 23:00:12 -070093 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID])
94 self.dut.droid.wifiConnect(network_aux)
Ignacio Guarna8b7054f2020-09-16 22:55:40 -030095 results.append(self.power_monitor_data_collect_save())
Mark De Ruytere54396c2019-08-20 12:54:37 -070096
Ignacio Guarna8b7054f2020-09-16 22:55:40 -030097 # Join all results in a single list
98 joint_result = []
Mark De Ruytere54396c2019-08-20 12:54:37 -070099 for result in results:
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300100 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)
Mark De Ruytere54396c2019-08-20 12:54:37 -0700109
Qid7053592019-11-19 14:56:26 -0800110 self.power_result.metric_value = [
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300111 sum([sample[1] for sample in result]) / len(result)
112 for result in results
Qid7053592019-11-19 14:56:26 -0800113 ]
Qi Jiang2a128de2018-04-27 23:00:12 -0700114 # Take Bugreport
115 if self.bug_report:
116 self.dut.take_bug_report(self.test_name, begin_time)
117 # Path fail check
Mark De Ruytere54396c2019-08-20 12:54:37 -0700118 self.pass_fail_check(average_current)
Qi Jiang2a128de2018-04-27 23:00:12 -0700119
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
Qi Jiangddd01142018-10-18 22:51:42 -0700124 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
125 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -0700126 # Connect to both APs
127 network_main = self.main_network[hc.BAND_2G]
128 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -0700129 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])
Qid7053592019-11-19 14:56:26 -0800135 self.brconfigs_aux = self.setup_ap_connection(network_aux,
136 ap=self.access_point_aux)
Qi Jiang2a128de2018-04-27 23:00:12 -0700137 self.mon_info.duration = self.toggle_interval
138 time.sleep(5)
139 # Toggle between two networks
140 begin_time = utils.get_current_epoch_time()
Mark De Ruytere54396c2019-08-20 12:54:37 -0700141 results = []
Qi Jiang2a128de2018-04-27 23:00:12 -0700142 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)
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300145 results.append(self.power_monitor_data_collect_save())
Qi Jiang2a128de2018-04-27 23:00:12 -0700146 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID])
147 self.dut.droid.wifiConnect(network_aux)
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300148 results.append(self.power_monitor_data_collect_save())
149 # Join all results in a single list
150 joint_result = []
Mark De Ruytere54396c2019-08-20 12:54:37 -0700151 for result in results:
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300152 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)
Mark De Ruytere54396c2019-08-20 12:54:37 -0700161
Qid7053592019-11-19 14:56:26 -0800162 self.power_result.metric_value = [
Ignacio Guarna8b7054f2020-09-16 22:55:40 -0300163 sum([sample[1] for sample in result]) / len(result)
164 for result in results
Qid7053592019-11-19 14:56:26 -0800165 ]
Qi Jiang2a128de2018-04-27 23:00:12 -0700166 # Take Bugreport
167 if self.bug_report:
168 self.dut.take_bug_report(self.test_name, begin_time)
169 # Path fail check
Mark De Ruytere54396c2019-08-20 12:54:37 -0700170 self.pass_fail_check(average_current)
Qi Jiang2a128de2018-04-27 23:00:12 -0700171
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
Qi Jiangddd01142018-10-18 22:51:42 -0700176 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
177 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -0700178 # Connect to both APs
179 network_main = self.main_network[hc.BAND_2G]
180 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -0700181 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])
Qid7053592019-11-19 14:56:26 -0800187 self.brconfigs_aux = self.setup_ap_connection(network_aux,
188 ap=self.access_point_aux)
Qi Jiang2a128de2018-04-27 23:00:12 -0700189 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()