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 17import itertools 18import pprint 19import time 20 21import acts.signals 22import acts.test_utils.wifi.wifi_test_utils as wutils 23 24from acts import asserts 25from acts.test_decorators import test_tracker_info 26from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 27 28WifiEnums = wutils.WifiEnums 29 30 31class WifiIOTtpeTest(WifiBaseTest): 32 """ Tests for wifi IOT 33 34 Test Bed Requirement: 35 * One Android device 36 * Wi-Fi IOT networks visible to the device 37 """ 38 39 def setup_class(self): 40 super().setup_class() 41 42 self.dut = self.android_devices[0] 43 wutils.wifi_test_device_init(self.dut) 44 45 req_params = [ "iot_networks", ] 46 opt_params = [ "open_network", "iperf_server_address" ] 47 self.unpack_userparams(req_param_names=req_params, 48 opt_param_names=opt_params) 49 50 asserts.assert_true( 51 len(self.iot_networks) > 0, 52 "Need at least one iot network with psk.") 53 54 if getattr(self, 'open_network', False): 55 self.iot_networks.append(self.open_network) 56 57 wutils.wifi_toggle_state(self.dut, True) 58 if "iperf_server_address" in self.user_params: 59 self.iperf_server = self.iperf_servers[0] 60 self.iperf_server.start() 61 62 # create hashmap for testcase name and SSIDs 63 self.iot_test_prefix = "test_iot_connection_to_" 64 self.ssid_map = {} 65 for network in self.iot_networks: 66 SSID = network['SSID'].replace('-','_') 67 self.ssid_map[SSID] = network 68 69 def setup_test(self): 70 self.dut.droid.wakeLockAcquireBright() 71 self.dut.droid.wakeUpNow() 72 73 def teardown_test(self): 74 self.dut.droid.wakeLockRelease() 75 self.dut.droid.goToSleepNow() 76 wutils.reset_wifi(self.dut) 77 78 def teardown_class(self): 79 if "iperf_server_address" in self.user_params: 80 self.iperf_server.stop() 81 82 def on_fail(self, test_name, begin_time): 83 self.dut.take_bug_report(test_name, begin_time) 84 self.dut.cat_adb_log(test_name, begin_time) 85 86 """Helper Functions""" 87 88 def connect_to_wifi_network(self, network): 89 """Connection logic for open and psk wifi networks. 90 91 Args: 92 params: Dictionary with network info. 93 """ 94 SSID = network[WifiEnums.SSID_KEY] 95 self.dut.ed.clear_all_events() 96 wutils.start_wifi_connection_scan(self.dut) 97 scan_results = self.dut.droid.wifiGetScanResults() 98 wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results) 99 wutils.wifi_connect(self.dut, network, num_of_tries=3) 100 101 def run_iperf_client(self, network): 102 """Run iperf traffic after connection. 103 104 Args: 105 params: Dictionary with network info. 106 """ 107 if "iperf_server_address" in self.user_params: 108 wait_time = 5 109 SSID = network[WifiEnums.SSID_KEY] 110 self.log.info("Starting iperf traffic through {}".format(SSID)) 111 time.sleep(wait_time) 112 port_arg = "-p {}".format(self.iperf_server.port) 113 success, data = self.dut.run_iperf_client(self.iperf_server_address, 114 port_arg) 115 self.log.debug(pprint.pformat(data)) 116 asserts.assert_true(success, "Error occurred in iPerf traffic.") 117 118 def connect_to_wifi_network_and_run_iperf(self, network): 119 """Connection logic for open and psk wifi networks. 120 121 Logic steps are 122 1. Connect to the network. 123 2. Run iperf traffic. 124 125 Args: 126 params: A dictionary with network info. 127 """ 128 self.connect_to_wifi_network(network) 129 self.run_iperf_client(network) 130 131 """Tests""" 132 133 @test_tracker_info(uuid="0e4ad6ed-595c-4629-a4c9-c6be9c3c58e0") 134 def test_iot_connection_to_ASUS_RT_AC68U_2G(self): 135 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 136 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 137 138 @test_tracker_info(uuid="a76d8acc-808e-4a5d-a52b-5ba07d07b810") 139 def test_iot_connection_to_ASUS_RT_AC68U_5G(self): 140 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 141 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 142 143 @test_tracker_info(uuid="659a3e5e-07eb-4905-9cda-92e959c7b674") 144 def test_iot_connection_to_D_Link_DIR_868L_2G(self): 145 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 146 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 147 148 @test_tracker_info(uuid="6bcfd736-30fc-48a8-b4fb-723d1d113f3c") 149 def test_iot_connection_to_D_Link_DIR_868L_5G(self): 150 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 151 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 152 153 @test_tracker_info(uuid="c9da945a-2c4a-44e1-881d-adf307b39b21") 154 def test_iot_connection_to_TP_LINK_WR940N_2G(self): 155 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 156 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 157 158 @test_tracker_info(uuid="db0d224d-df81-401f-bf35-08ad02e41a71") 159 def test_iot_connection_to_ASUS_RT_N66U_2G(self): 160 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 161 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 162 163 @test_tracker_info(uuid="845ff1d6-618d-40f3-81c3-6ed3a0751fde") 164 def test_iot_connection_to_ASUS_RT_N66U_5G(self): 165 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 166 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 167 168 @test_tracker_info(uuid="6908039b-ccc9-4777-a0f1-3494ce642014") 169 def test_iot_connection_to_ASUS_RT_AC54U_2G(self): 170 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 171 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 172 173 @test_tracker_info(uuid="2647c15f-2aad-47d7-8dee-b2ee1ac4cef6") 174 def test_iot_connection_to_ASUS_RT_AC54U_5G(self): 175 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 176 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 177 178 @test_tracker_info(uuid="99678f66-ddf1-454d-87e4-e55177ec380d") 179 def test_iot_connection_to_ASUS_RT_N56U_2G(self): 180 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 181 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 182 183 @test_tracker_info(uuid="4dd75e81-9a8e-44fd-9449-09f5ab8a63c3") 184 def test_iot_connection_to_ASUS_RT_N56U_5G(self): 185 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 186 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 187 188 @test_tracker_info(uuid="315397ce-50d5-4abf-a11c-1abcaef832d3") 189 def test_iot_connection_to_BELKIN_F9K1002v1_2G(self): 190 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 191 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 192 193 @test_tracker_info(uuid="05ba464a-b1ef-4ac1-a32f-c919ec4aa1dd") 194 def test_iot_connection_to_CISCO_E1200_2G(self): 195 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 196 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 197 198 @test_tracker_info(uuid="04912868-4a47-40ce-877e-4e4c89849557") 199 def test_iot_connection_to_TP_LINK_C2_2G(self): 200 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 201 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 202 203 @test_tracker_info(uuid="53517a21-3802-4185-b8bb-6eaace063a42") 204 def test_iot_connection_to_TP_LINK_C2_5G(self): 205 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 206 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 207 208 @test_tracker_info(uuid="71c08c1c-415d-4da4-a151-feef43fb6ad8") 209 def test_iot_connection_to_ASUS_RT_AC66U_2G(self): 210 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 211 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 212 213 @test_tracker_info(uuid="2322c155-07d1-47c9-bd21-2e358e3df6ee") 214 def test_iot_connection_to_ASUS_RT_AC66U_5G(self): 215 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 216 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 217