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 bridge_interface as bi 22 from acts.controllers.ap_lib import hostapd_constants as hc 23 from acts.test_decorators import test_tracker_info 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 from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 27 import acts.controllers.iperf_server as ipf 28 29 30 class PowertrafficTest(base_test.BaseTestClass): 31 def __init__(self, controllers): 32 33 WifiBaseTest.__init__(self, controllers) 34 self.tests = ('test_screenoff_iperf_2g_highrssi', 35 'test_screenoff_iperf_2g_mediumrssi', 36 'test_screenoff_iperf_2g_lowrssi', 37 'test_screenoff_iperf_5g_highrssi', 38 'test_screenoff_iperf_5g_mediumrssi', 39 'test_screenoff_iperf_5g_lowrssi') 40 41 def setup_class(self): 42 43 self.log = logging.getLogger() 44 self.dut = self.android_devices[0] 45 req_params = ['main_network', 'traffictest_params'] 46 self.unpack_userparams(req_params) 47 self.unpack_testparams(self.traffictest_params) 48 self.num_atten = self.attenuators[0].instrument.num_atten 49 self.mon_data_path = os.path.join(self.log_path, 'Monsoon') 50 self.mon_duration = self.iperf_duration - 10 51 self.mon = self.monsoons[0] 52 self.mon.set_max_current(8.0) 53 self.mon.set_voltage(4.2) 54 self.mon.attach_device(self.dut) 55 self.mon_info = wputils.create_monsoon_info(self) 56 self.iperf_server = self.iperf_servers[0] 57 self.access_point = self.access_points[0] 58 self.pkt_sender = self.packet_senders[0] 59 60 def teardown_test(self): 61 self.iperf_server.stop() 62 self.access_point.close() 63 64 def unpack_testparams(self, bulk_params): 65 """Unpack all the test specific parameters. 66 67 Args: 68 bulk_params: dict with all test specific params in the config file 69 """ 70 for key in bulk_params.keys(): 71 setattr(self, key, bulk_params[key]) 72 73 def iperf_power_test_func(self, screen_status, band): 74 """Test function for iperf power measurement at different RSSI level. 75 76 Args: 77 screen_status: screen ON or OFF 78 band: desired band for AP to operate on 79 """ 80 wputils.dut_rockbottom(self.dut) 81 wutils.wifi_toggle_state(self.dut, True) 82 83 # Set up the AP 84 network = self.main_network[band] 85 channel = network['channel'] 86 configs = self.access_point.generate_bridge_configs(channel) 87 brconfigs = bi.BridgeInterfaceConfigs(configs[0], configs[1], 88 configs[2]) 89 self.access_point.bridge.startup(brconfigs) 90 wputils.ap_setup(self.access_point, network) 91 92 # Wait for DHCP on the ethernet port and get IP as Iperf server address 93 # Time out in 60 seconds if not getting DHCP address 94 iface_eth = self.pkt_sender.interface 95 self.iperf_server_address = wputils.wait_for_dhcp(iface_eth) 96 97 # Set attenuator to desired level 98 self.log.info('Set attenuation to desired RSSI level') 99 for i in range(self.num_atten): 100 attenuation = self.atten_level[self.current_test_name][i] 101 self.attenuators[i].set_atten(attenuation) 102 103 # Connect the phone to the AP 104 wutils.wifi_connect(self.dut, network) 105 time.sleep(5) 106 if screen_status == 'OFF': 107 self.dut.droid.goToSleepNow() 108 RSSI = wputils.get_wifi_rssi(self.dut) 109 110 # Run IPERF session 111 iperf_args = '-i 1 -t %d > /dev/null' % self.iperf_duration 112 self.iperf_server.start() 113 wputils.run_iperf_client_nonblocking( 114 self.dut, self.iperf_server_address, iperf_args) 115 116 # Collect power data and plot 117 file_path, avg_current = wputils.monsoon_data_collect_save( 118 self.dut, self.mon_info, self.current_test_name, self.bug_report) 119 iperf_result = ipf.IPerfResult(self.iperf_server.log_files[-1]) 120 121 # Monsoon Power data plot with IPerf throughput information 122 tag = '_RSSI_{0:d}dBm_Throughput_{1:.2f}Mbps'.format( 123 RSSI, (iperf_result.avg_receive_rate * 8)) 124 wputils.monsoon_data_plot(self.mon_info, file_path, tag) 125 126 # Bring down bridge interface 127 self.access_point.bridge.teardown(brconfigs) 128 129 # Bring down the AP object 130 self.access_point.close() 131 132 # Pass and fail check 133 wputils.pass_fail_check(self, avg_current) 134 135 # Test cases 136 @test_tracker_info(uuid='43d9b146-3547-4a27-9d79-c9341c32ccda') 137 def test_screenoff_iperf_2g_highrssi(self): 138 139 self.iperf_power_test_func('OFF', hc.BAND_2G) 140 141 @test_tracker_info(uuid='f00a868b-c8b1-4b36-8136-b39b5c2396a7') 142 def test_screenoff_iperf_2g_mediumrssi(self): 143 144 self.iperf_power_test_func('OFF', hc.BAND_2G) 145 146 @test_tracker_info(uuid='cd0c37ac-23fe-4dd1-9130-ccb2dfa71020') 147 def test_screenoff_iperf_2g_lowrssi(self): 148 149 self.iperf_power_test_func('OFF', hc.BAND_2G) 150 151 @test_tracker_info(uuid='f9173d39-b46d-4d80-a5a5-7966f5eed9de') 152 def test_screenoff_iperf_5g_highrssi(self): 153 154 self.iperf_power_test_func('OFF', hc.BAND_5G) 155 156 @test_tracker_info(uuid='cf77e1dc-30bc-4df9-88be-408f1fddc24f') 157 def test_screenoff_iperf_5g_mediumrssi(self): 158 159 self.iperf_power_test_func('OFF', hc.BAND_5G) 160 161 @test_tracker_info(uuid='48f91745-22dc-47c9-ace6-c2719df651d6') 162 def test_screenoff_iperf_5g_lowrssi(self): 163 164 self.iperf_power_test_func('OFF', hc.BAND_5G) 165