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