Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 | |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 17 | import copy |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 18 | import time |
| 19 | from acts import utils |
| 20 | from acts.controllers.ap_lib import hostapd_constants as hc |
| 21 | from acts.test_decorators import test_tracker_info |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 22 | from acts_contrib.test_utils.power import PowerWiFiBaseTest as PWBT |
| 23 | from acts_contrib.test_utils.wifi import wifi_constants as wc |
| 24 | from acts_contrib.test_utils.wifi import wifi_test_utils as wutils |
| 25 | from acts_contrib.test_utils.power import plot_utils |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 26 | |
Qi Jiang | fcfc224 | 2018-11-13 16:32:23 -0800 | [diff] [blame] | 27 | PHONE_BATTERY_VOLTAGE = 4.2 |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 28 | |
Mark De Ruyter | 85fb538 | 2019-08-19 20:15:41 -0700 | [diff] [blame] | 29 | |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 30 | class PowerWiFiroamingTest(PWBT.PowerWiFiBaseTest): |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 31 | def setup_class(self): |
| 32 | super().setup_class() |
| 33 | self.unpack_userparams(toggle_interval=20, toggle_times=10) |
| 34 | |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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() |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 | """ |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 48 | # Setup both APs |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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]) |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 53 | self.brconfigs_aux = self.setup_ap_connection(network_aux, |
| 54 | ap=self.access_point_aux) |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 | |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 70 | network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] |
| 71 | network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 72 | # Connect to both APs |
| 73 | network_main = self.main_network[hc.BAND_2G] |
| 74 | network_aux = self.aux_network[hc.BAND_2G] |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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]) |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 81 | self.brconfigs_aux = self.setup_ap_connection(network_aux, |
| 82 | ap=self.access_point_aux) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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() |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 88 | results = [] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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) |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 92 | results.append(self.power_monitor_data_collect_save()) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 93 | self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) |
| 94 | self.dut.droid.wifiConnect(network_aux) |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 95 | results.append(self.power_monitor_data_collect_save()) |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 96 | |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 97 | # Join all results in a single list |
| 98 | joint_result = [] |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 99 | for result in results: |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 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) |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 109 | |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 110 | self.power_result.metric_value = [ |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 111 | sum([sample[1] for sample in result]) / len(result) |
| 112 | for result in results |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 113 | ] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 114 | # Take Bugreport |
| 115 | if self.bug_report: |
| 116 | self.dut.take_bug_report(self.test_name, begin_time) |
| 117 | # Path fail check |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 118 | self.pass_fail_check(average_current) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 124 | network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] |
| 125 | network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 126 | # Connect to both APs |
| 127 | network_main = self.main_network[hc.BAND_2G] |
| 128 | network_aux = self.aux_network[hc.BAND_2G] |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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]) |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 135 | self.brconfigs_aux = self.setup_ap_connection(network_aux, |
| 136 | ap=self.access_point_aux) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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() |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 141 | results = [] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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) |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 145 | results.append(self.power_monitor_data_collect_save()) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 146 | self.dut.log.info('Connecting to %s' % network_aux[wc.SSID]) |
| 147 | self.dut.droid.wifiConnect(network_aux) |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 148 | results.append(self.power_monitor_data_collect_save()) |
| 149 | # Join all results in a single list |
| 150 | joint_result = [] |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 151 | for result in results: |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 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) |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 161 | |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 162 | self.power_result.metric_value = [ |
Ignacio Guarna | 8b7054f | 2020-09-16 22:55:40 -0300 | [diff] [blame] | 163 | sum([sample[1] for sample in result]) / len(result) |
| 164 | for result in results |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 165 | ] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 166 | # Take Bugreport |
| 167 | if self.bug_report: |
| 168 | self.dut.take_bug_report(self.test_name, begin_time) |
| 169 | # Path fail check |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 170 | self.pass_fail_check(average_current) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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 |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 176 | network_main = copy.deepcopy(self.main_network)[hc.BAND_2G] |
| 177 | network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G] |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 178 | # Connect to both APs |
| 179 | network_main = self.main_network[hc.BAND_2G] |
| 180 | network_aux = self.aux_network[hc.BAND_2G] |
Qi Jiang | ddd0114 | 2018-10-18 22:51:42 -0700 | [diff] [blame] | 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]) |
Qi | d705359 | 2019-11-19 14:56:26 -0800 | [diff] [blame] | 187 | self.brconfigs_aux = self.setup_ap_connection(network_aux, |
| 188 | ap=self.access_point_aux) |
Qi Jiang | 2a128de | 2018-04-27 23:00:12 -0700 | [diff] [blame] | 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() |