blob: 98409895f4026de5451bd08a53bed8e7e992d40b [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
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
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):
Qi Jiangddd01142018-10-18 22:51:42 -070031 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 Jiang2a128de2018-04-27 23:00:12 -070036
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 Jiang2a128de2018-04-27 23:00:12 -070044 # Setup both APs
Qi Jiangddd01142018-10-18 22:51:42 -070045 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 Jiang2a128de2018-04-27 23:00:12 -070055 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 Jiang2a128de2018-04-27 23:00:12 -070062 @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 Jiangddd01142018-10-18 22:51:42 -070066 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
67 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -070068 # Connect to both APs
69 network_main = self.main_network[hc.BAND_2G]
70 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -070071 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 Jiang2a128de2018-04-27 23:00:12 -070079 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 Jiangddd01142018-10-18 22:51:42 -070087 file_path, avg_current = self.monsoon_data_collect_save()
Qi Jiang2a128de2018-04-27 23:00:12 -070088 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID])
89 self.dut.droid.wifiConnect(network_aux)
Qi Jiangddd01142018-10-18 22:51:42 -070090 file_path, avg_current = self.monsoon_data_collect_save()
Qi Jiang2a128de2018-04-27 23:00:12 -070091 [plot, dt] = wputils.monsoon_data_plot(self.mon_info, file_path)
Qi Jiangddd01142018-10-18 22:51:42 -070092 self.test_result = dt.source.data['y0'][0]
Mark De Ruyter85fb5382019-08-19 20:15:41 -070093 self.power_result.metric_value = (
94 self.test_result * PHONE_BATTERY_VOLTAGE)
Qi Jiang2a128de2018-04-27 23:00:12 -070095 # Take Bugreport
96 if self.bug_report:
97 self.dut.take_bug_report(self.test_name, begin_time)
98 # Path fail check
Qi Jiangddd01142018-10-18 22:51:42 -070099 self.pass_fail_check()
Qi Jiang2a128de2018-04-27 23:00:12 -0700100
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 Jiangddd01142018-10-18 22:51:42 -0700105 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
106 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -0700107 # Connect to both APs
108 network_main = self.main_network[hc.BAND_2G]
109 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -0700110 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 Jiang2a128de2018-04-27 23:00:12 -0700118 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 Jiangddd01142018-10-18 22:51:42 -0700125 file_path, avg_current = self.monsoon_data_collect_save()
Qi Jiang2a128de2018-04-27 23:00:12 -0700126 self.dut.log.info('Connecting to %s' % network_aux[wc.SSID])
127 self.dut.droid.wifiConnect(network_aux)
Qi Jiangddd01142018-10-18 22:51:42 -0700128 file_path, avg_current = self.monsoon_data_collect_save()
Qi Jiang2a128de2018-04-27 23:00:12 -0700129 [plot, dt] = wputils.monsoon_data_plot(self.mon_info, file_path)
Qi Jiangddd01142018-10-18 22:51:42 -0700130 self.test_result = dt.source.data['y0'][0]
Mark De Ruyter85fb5382019-08-19 20:15:41 -0700131 self.power_result.metric_value = (
132 self.test_result * PHONE_BATTERY_VOLTAGE)
Qi Jiang2a128de2018-04-27 23:00:12 -0700133 # Take Bugreport
134 if self.bug_report:
135 self.dut.take_bug_report(self.test_name, begin_time)
136 # Path fail check
Qi Jiangddd01142018-10-18 22:51:42 -0700137 self.pass_fail_check()
Qi Jiang2a128de2018-04-27 23:00:12 -0700138
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 Jiangddd01142018-10-18 22:51:42 -0700143 network_main = copy.deepcopy(self.main_network)[hc.BAND_2G]
144 network_aux = copy.deepcopy(self.aux_network)[hc.BAND_2G]
Qi Jiang2a128de2018-04-27 23:00:12 -0700145 # Connect to both APs
146 network_main = self.main_network[hc.BAND_2G]
147 network_aux = self.aux_network[hc.BAND_2G]
Qi Jiangddd01142018-10-18 22:51:42 -0700148 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 Jiang2a128de2018-04-27 23:00:12 -0700156 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()