1 #!/usr/bin/env python3.4 2 # 3 # Copyright 2017 - 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 17 import logging 18 import os 19 import time 20 from acts import base_test 21 from acts.controllers.ap_lib import hostapd_constants as hc 22 from acts.test_decorators import test_tracker_info 23 from acts.test_utils.wifi import wifi_test_utils as wutils 24 from acts.test_utils.wifi import wifi_power_test_utils as wputils 25 26 27 class PowerdtimTest(base_test.BaseTestClass): 28 def __init__(self, controllers): 29 30 base_test.BaseTestClass.__init__(self, controllers) 31 self.tests = ('test_2g_screenoff_dtimx1', 'test_2g_screenoff_dtimx2', 32 'test_2g_screenoff_dtimx4', 'test_2g_screenoff_dtimx9', 33 'test_2g_screenon_dtimx1', 'test_2g_screenon_dtimx4', 34 'test_5g_screenoff_dtimx1', 'test_5g_screenoff_dtimx2', 35 'test_5g_screenoff_dtimx4', 'test_5g_screenoff_dtimx9', 36 'test_5g_screenon_dtimx1', 'test_5g_screenon_dtimx4') 37 38 def setup_class(self): 39 40 self.log = logging.getLogger() 41 self.dut = self.android_devices[0] 42 self.access_point = self.access_points[0] 43 req_params = ['main_network', 'aux_network', 'dtimtest_params'] 44 self.unpack_userparams(req_params) 45 self.unpack_testparams(self.dtimtest_params) 46 self.mon_data_path = os.path.join(self.log_path, 'Monsoon') 47 self.mon = self.monsoons[0] 48 self.mon.set_max_current(8.0) 49 self.mon.set_voltage(4.2) 50 self.mon.attach_device(self.dut) 51 self.mon_info = wputils.create_monsoon_info(self) 52 self.num_atten = self.attenuators[0].instrument.num_atten 53 54 def teardown_class(self): 55 56 self.mon.usb('on') 57 58 def unpack_testparams(self, bulk_params): 59 """Unpack all the test specific parameters. 60 61 Args: 62 bulk_params: dict with all test specific params in the config file 63 """ 64 for key in bulk_params.keys(): 65 setattr(self, key, bulk_params[key]) 66 67 def dtim_test_func(self, dtim, screen_status, network, dtim_max=6): 68 """A reusable function for DTIM test. 69 Covering different DTIM value, with screen ON or OFF and 2g/5g network 70 71 Args: 72 dtim: the value for DTIM set on the phone 73 screen_status: screen on or off 74 network: a dict of information for the network to connect 75 """ 76 # Initialize the dut to rock-bottom state 77 wputils.change_dtim( 78 self.dut, gEnableModulatedDTIM=dtim, gMaxLIModulatedDTIM=dtim_max) 79 self.dut.log.info('DTIM value of the phone is now {}'.format(dtim)) 80 wputils.dut_rockbottom(self.dut) 81 wutils.wifi_toggle_state(self.dut, True) 82 [ 83 self.attenuators[i].set_atten(self.atten_level['zero_atten'][i]) 84 for i in range(self.num_atten) 85 ] 86 self.log.info('Set attenuation level to connect the main AP') 87 wputils.ap_setup(self.access_point, network) 88 wutils.wifi_connect(self.dut, network) 89 if screen_status == 'OFF': 90 self.dut.droid.goToSleepNow() 91 self.dut.log.info('Screen is OFF') 92 time.sleep(5) 93 # Collect power data and plot 94 file_path, avg_current = wputils.monsoon_data_collect_save( 95 self.dut, self.mon_info, self.current_test_name, self.bug_report) 96 wputils.monsoon_data_plot(self.mon_info, file_path) 97 # Close AP controller 98 self.access_point.close() 99 # Pass and fail check 100 wputils.pass_fail_check(self, avg_current) 101 102 # Test cases 103 @test_tracker_info(uuid='2a70a78b-93a8-46a6-a829-e1624b8239d2') 104 def test_2g_screenoff_dtimx1(self): 105 network = self.main_network[hc.BAND_2G] 106 self.dtim_test_func(1, 'OFF', network) 107 108 @test_tracker_info(uuid='b6c4114d-984a-4269-9e77-2bec0e4b6e6f') 109 def test_2g_screenoff_dtimx2(self): 110 network = self.main_network[hc.BAND_2G] 111 self.dtim_test_func(2, 'OFF', network) 112 113 @test_tracker_info(uuid='2ae5bc29-3d5f-4fbb-9ff6-f5bd499a9d6e') 114 def test_2g_screenoff_dtimx4(self): 115 network = self.main_network[hc.BAND_2G] 116 self.dtim_test_func(4, 'OFF', network) 117 118 @test_tracker_info(uuid='b37fa75f-6166-4247-b15c-adcda8c7038e') 119 def test_2g_screenoff_dtimx9(self): 120 network = self.main_network[hc.BAND_2G] 121 self.dtim_test_func(9, 'OFF', network, dtim_max=10) 122 123 @test_tracker_info(uuid='384d3b0f-4335-4b00-8363-308ec27a150c') 124 def test_2g_screenon_dtimx1(self): 125 """With screen on, modulated dtim isn't wokring, always DTIMx1. 126 So not running through all DTIM cases 127 128 """ 129 network = self.main_network[hc.BAND_2G] 130 self.dtim_test_func(1, 'ON', network) 131 132 @test_tracker_info(uuid='79d0f065-2c46-4400-b02c-5ad60e79afea') 133 def test_2g_screenon_dtimx4(self): 134 """Run only extra DTIMx4 for screen on to compare with DTIMx1. 135 They should be the same if everything is correct. 136 137 """ 138 network = self.main_network[hc.BAND_2G] 139 self.dtim_test_func(4, 'ON', network) 140 141 @test_tracker_info(uuid='5e2f73cb-7e4e-4a25-8fd5-c85adfdf466e') 142 def test_5g_screenoff_dtimx1(self): 143 network = self.main_network[hc.BAND_5G] 144 self.dtim_test_func(1, 'OFF', network) 145 146 @test_tracker_info(uuid='017f57c3-e133-461d-80be-d025d1491d8a') 147 def test_5g_screenoff_dtimx2(self): 148 network = self.main_network[hc.BAND_5G] 149 self.dtim_test_func(2, 'OFF', network) 150 151 @test_tracker_info(uuid='b84a1cb3-9573-4bfd-9875-0f33cb171cc5') 152 def test_5g_screenoff_dtimx4(self): 153 network = self.main_network[hc.BAND_5G] 154 self.dtim_test_func(4, 'OFF', network) 155 156 @test_tracker_info(uuid='75644df4-2cc8-4bbd-8985-0656a4f9d056') 157 def test_5g_screenoff_dtimx9(self): 158 network = self.main_network[hc.BAND_5G] 159 self.dtim_test_func(9, 'OFF', network, dtim_max=10) 160 161 @test_tracker_info(uuid='327af44d-d9e7-49e0-9bda-accad6241dc7') 162 def test_5g_screenon_dtimx1(self): 163 """With screen on, modulated dtim isn't wokring, always DTIMx1. 164 So not running through all DTIM cases 165 166 """ 167 network = self.main_network[hc.BAND_5G] 168 self.dtim_test_func(1, 'ON', network) 169 170 @test_tracker_info(uuid='8b32585f-2517-426b-a2c9-8087093cf991') 171 def test_5g_screenon_dtimx4(self): 172 """Run only extra DTIMx4 for screen on to compare with DTIMx1. 173 They should be the same if everything is correct. 174 175 """ 176 network = self.main_network[hc.BAND_5G] 177 self.dtim_test_func(4, 'ON', network) 178