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 17import WifiRvrTest 18from acts import base_test 19from acts.test_decorators import test_tracker_info 20from acts.test_utils.wifi import wifi_test_utils as wutils 21 22 23class WifiSoftApRvrTest(WifiRvrTest.WifiRvrTest): 24 def __init__(self, controllers): 25 base_test.BaseTestClass.__init__(self, controllers) 26 self.tests = ("test_rvr_TCP_DL_2GHz", "test_rvr_TCP_UL_2GHz", 27 "test_rvr_TCP_DL_5GHz", "test_rvr_TCP_UL_5GHz") 28 29 def get_sap_connection_info(self): 30 info = {} 31 info["client_ip_address"] = self.android_devices[ 32 1].droid.connectivityGetIPv4Addresses('wlan0')[0] 33 info["ap_ip_address"] = self.android_devices[ 34 0].droid.connectivityGetIPv4Addresses('wlan0')[0] 35 info["frequency"] = self.client_dut.adb.shell( 36 "wpa_cli status | grep freq").split("=")[1] 37 info["channel"] = wutils.WifiEnums.freq_to_channel[int( 38 info["frequency"])] 39 return info 40 41 def sap_rvr_test_func(self): 42 """Main function to test Soft AP RvR. 43 44 The function sets up the phones in the correct soft ap and client mode 45 configuration and calls run_rvr to sweep attenuation and measure 46 throughput 47 48 Args: 49 channel: Specifies AP's channel 50 mode: Specifies AP's bandwidth/mode (11g, VHT20, VHT40, VHT80) 51 Returns: 52 rvr_result: dict containing rvr_results and meta data 53 """ 54 #Initialize RvR test parameters 55 num_atten_steps = int((self.test_params["rvr_atten_stop"] - 56 self.test_params["rvr_atten_start"]) / 57 self.test_params["rvr_atten_step"]) 58 self.rvr_atten_range = [ 59 self.test_params["rvr_atten_start"] + 60 x * self.test_params["rvr_atten_step"] 61 for x in range(0, num_atten_steps) 62 ] 63 rvr_result = {} 64 # Reset WiFi on all devices 65 for dev in self.android_devices: 66 wutils.reset_wifi(dev) 67 dev.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) 68 # Setup Soft AP 69 sap_config = wutils.create_softap_config() 70 wutils.start_wifi_tethering( 71 self.android_devices[0], sap_config[wutils.WifiEnums.SSID_KEY], 72 sap_config[wutils.WifiEnums.PWD_KEY], self.sap_band_enum) 73 self.main_network = { 74 "SSID": sap_config[wutils.WifiEnums.SSID_KEY], 75 "password": sap_config[wutils.WifiEnums.PWD_KEY] 76 } 77 # Set attenuator to 0 dB 78 [self.attenuators[i].set_atten(0) for i in range(self.num_atten)] 79 # Connect DUT to Network 80 wutils.wifi_connect( 81 self.android_devices[1], 82 self.main_network, 83 num_of_tries=5, 84 assert_on_fail=False) 85 connection_info = self.get_sap_connection_info() 86 self.test_params["iperf_server_address"] = connection_info[ 87 "ap_ip_address"] 88 # Run RvR and log result 89 rvr_result["test_name"] = self.current_test_name 90 rvr_result["attenuation"] = list(self.rvr_atten_range) 91 rvr_result["fixed_attenuation"] = self.test_params[ 92 "fixed_attenuation"][str(connection_info["channel"])] 93 rvr_result["throughput_receive"] = self.rvr_test() 94 self.testclass_results.append(rvr_result) 95 wutils.stop_wifi_tethering(self.android_devices[0]) 96 return rvr_result 97 98 def _test_rvr(self): 99 """ Function that gets called for each test case 100 101 The function gets called in each rvr test case. The function customizes 102 the rvr test based on the test name of the test that called it 103 """ 104 test_params = self.current_test_name.split("_") 105 self.sap_band = test_params[4] 106 if self.sap_band == "2GHz": 107 self.sap_band_enum = wutils.WifiEnums.WIFI_CONFIG_APBAND_2G 108 else: 109 self.sap_band_enum = wutils.WifiEnums.WIFI_CONFIG_APBAND_5G 110 self.iperf_args = '-i 1 -t {} -J '.format( 111 self.test_params["iperf_duration"]) 112 if test_params[2] == "UDP": 113 self.iperf_args = self.iperf_args + "-u -b {}".format( 114 self.test_params["UDP_rates"]["VHT80"]) 115 if test_params[3] == "DL": 116 self.iperf_args = self.iperf_args + ' -R' 117 self.use_client_output = True 118 else: 119 self.use_client_output = False 120 rvr_result = self.sap_rvr_test_func() 121 self.post_process_results(rvr_result) 122 self.pass_fail_check(rvr_result) 123 124 #Test cases 125 @test_tracker_info(uuid='7910112e-49fd-4e49-bc5c-f84da0cbb9f6') 126 def test_rvr_TCP_DL_2GHz(self): 127 self._test_rvr() 128 129 @test_tracker_info(uuid='b3c00814-6fdf-496b-b345-6a719bef657e') 130 def test_rvr_TCP_UL_2GHz(self): 131 self._test_rvr() 132 133 @test_tracker_info(uuid='a2f727b5-68ba-46e5-a7fe-f86c0a082fc9') 134 def test_rvr_TCP_DL_5GHz(self): 135 self._test_rvr() 136 137 @test_tracker_info(uuid='0cca9352-3f06-4bba-be17-8897a1b42a0f') 138 def test_rvr_TCP_UL_5GHz(self): 139 self._test_rvr() 140