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_contrib.test_utils.wifi.wifi_test_utils as wutils 23 24from acts import asserts 25from acts.test_decorators import test_tracker_info 26from acts_contrib.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 super().setup_test() 71 self.dut.droid.wakeLockAcquireBright() 72 self.dut.droid.wakeUpNow() 73 74 def teardown_test(self): 75 super().teardown_test() 76 self.dut.droid.wakeLockRelease() 77 self.dut.droid.goToSleepNow() 78 wutils.reset_wifi(self.dut) 79 80 def teardown_class(self): 81 if "iperf_server_address" in self.user_params: 82 self.iperf_server.stop() 83 84 """Helper Functions""" 85 86 def connect_to_wifi_network(self, network): 87 """Connection logic for open and psk wifi networks. 88 89 Args: 90 params: Dictionary with network info. 91 """ 92 SSID = network[WifiEnums.SSID_KEY] 93 self.dut.ed.clear_all_events() 94 wutils.start_wifi_connection_scan(self.dut) 95 scan_results = self.dut.droid.wifiGetScanResults() 96 wutils.assert_network_in_list({WifiEnums.SSID_KEY: SSID}, scan_results) 97 wutils.wifi_connect(self.dut, network, num_of_tries=3) 98 99 def run_iperf_client(self, network): 100 """Run iperf traffic after connection. 101 102 Args: 103 params: Dictionary with network info. 104 """ 105 if "iperf_server_address" in self.user_params: 106 wait_time = 5 107 SSID = network[WifiEnums.SSID_KEY] 108 self.log.info("Starting iperf traffic through {}".format(SSID)) 109 time.sleep(wait_time) 110 port_arg = "-p {}".format(self.iperf_server.port) 111 success, data = self.dut.run_iperf_client(self.iperf_server_address, 112 port_arg) 113 self.log.debug(pprint.pformat(data)) 114 asserts.assert_true(success, "Error occurred in iPerf traffic.") 115 116 def connect_to_wifi_network_and_run_iperf(self, network): 117 """Connection logic for open and psk wifi networks. 118 119 Logic steps are 120 1. Connect to the network. 121 2. Run iperf traffic. 122 123 Args: 124 params: A dictionary with network info. 125 """ 126 self.connect_to_wifi_network(network) 127 self.run_iperf_client(network) 128 129 """Tests""" 130 131 @test_tracker_info(uuid="0e4ad6ed-595c-4629-a4c9-c6be9c3c58e0") 132 def test_iot_connection_to_ASUS_RT_AC68U_2G(self): 133 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 134 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 135 136 @test_tracker_info(uuid="a76d8acc-808e-4a5d-a52b-5ba07d07b810") 137 def test_iot_connection_to_ASUS_RT_AC68U_5G(self): 138 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 139 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 140 141 @test_tracker_info(uuid="659a3e5e-07eb-4905-9cda-92e959c7b674") 142 def test_iot_connection_to_D_Link_DIR_868L_2G(self): 143 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 144 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 145 146 @test_tracker_info(uuid="6bcfd736-30fc-48a8-b4fb-723d1d113f3c") 147 def test_iot_connection_to_D_Link_DIR_868L_5G(self): 148 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 149 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 150 151 @test_tracker_info(uuid="c9da945a-2c4a-44e1-881d-adf307b39b21") 152 def test_iot_connection_to_TP_LINK_WR940N_2G(self): 153 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 154 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 155 156 @test_tracker_info(uuid="db0d224d-df81-401f-bf35-08ad02e41a71") 157 def test_iot_connection_to_ASUS_RT_N66U_2G(self): 158 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 159 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 160 161 @test_tracker_info(uuid="845ff1d6-618d-40f3-81c3-6ed3a0751fde") 162 def test_iot_connection_to_ASUS_RT_N66U_5G(self): 163 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 164 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 165 166 @test_tracker_info(uuid="6908039b-ccc9-4777-a0f1-3494ce642014") 167 def test_iot_connection_to_ASUS_RT_AC54U_2G(self): 168 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 169 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 170 171 @test_tracker_info(uuid="2647c15f-2aad-47d7-8dee-b2ee1ac4cef6") 172 def test_iot_connection_to_ASUS_RT_AC54U_5G(self): 173 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 174 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 175 176 @test_tracker_info(uuid="99678f66-ddf1-454d-87e4-e55177ec380d") 177 def test_iot_connection_to_ASUS_RT_N56U_2G(self): 178 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 179 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 180 181 @test_tracker_info(uuid="4dd75e81-9a8e-44fd-9449-09f5ab8a63c3") 182 def test_iot_connection_to_ASUS_RT_N56U_5G(self): 183 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 184 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 185 186 @test_tracker_info(uuid="315397ce-50d5-4abf-a11c-1abcaef832d3") 187 def test_iot_connection_to_BELKIN_F9K1002v1_2G(self): 188 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 189 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 190 191 @test_tracker_info(uuid="05ba464a-b1ef-4ac1-a32f-c919ec4aa1dd") 192 def test_iot_connection_to_CISCO_E1200_2G(self): 193 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 194 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 195 196 @test_tracker_info(uuid="04912868-4a47-40ce-877e-4e4c89849557") 197 def test_iot_connection_to_TP_LINK_C2_2G(self): 198 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 199 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 200 201 @test_tracker_info(uuid="53517a21-3802-4185-b8bb-6eaace063a42") 202 def test_iot_connection_to_TP_LINK_C2_5G(self): 203 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 204 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 205 206 @test_tracker_info(uuid="71c08c1c-415d-4da4-a151-feef43fb6ad8") 207 def test_iot_connection_to_ASUS_RT_AC66U_2G(self): 208 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 209 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 210 211 @test_tracker_info(uuid="2322c155-07d1-47c9-bd21-2e358e3df6ee") 212 def test_iot_connection_to_ASUS_RT_AC66U_5G(self): 213 ssid_key = self.current_test_name.replace(self.iot_test_prefix, "") 214 self.connect_to_wifi_network_and_run_iperf(self.ssid_map[ssid_key]) 215