Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 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 | |
| 17 | import itertools |
| 18 | import pprint |
| 19 | import queue |
| 20 | import time |
| 21 | |
| 22 | import acts.base_test |
| 23 | import acts.signals |
| 24 | import acts.test_utils.wifi.wifi_test_utils as wutils |
| 25 | import acts.utils |
| 26 | |
| 27 | from acts import asserts |
| 28 | from acts.test_decorators import test_tracker_info |
| 29 | from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest |
| 30 | |
| 31 | |
| 32 | class WifiHiddenSSIDTest(WifiBaseTest): |
| 33 | """Tests for APIs in Android's WifiManager class. |
| 34 | |
| 35 | Test Bed Requirement: |
| 36 | * One Android device |
| 37 | * Several Wi-Fi networks visible to the device, including an open Wi-Fi |
| 38 | network. |
| 39 | """ |
| 40 | |
| 41 | def __init__(self, controllers): |
| 42 | WifiBaseTest.__init__(self, controllers) |
| 43 | |
| 44 | def setup_class(self): |
| 45 | self.dut = self.android_devices[0] |
| 46 | wutils.wifi_test_device_init(self.dut) |
| 47 | req_params = [] |
| 48 | opt_param = [ |
| 49 | "open_network", "reference_networks"] |
| 50 | self.unpack_userparams( |
| 51 | req_param_names=req_params, opt_param_names=opt_param) |
| 52 | |
| 53 | if "AccessPoint" in self.user_params: |
| 54 | self.legacy_configure_ap_and_start(hidden=True) |
| 55 | |
| 56 | asserts.assert_true( |
| 57 | len(self.reference_networks) > 0, |
| 58 | "Need at least one reference network with psk.") |
| 59 | self.open_hidden_2g = self.open_network[0]["2g"] |
| 60 | self.open_hidden_5g = self.open_network[0]["5g"] |
| 61 | self.wpa_hidden_2g = self.reference_networks[0]["2g"] |
| 62 | self.wpa_hidden_5g = self.reference_networks[0]["5g"] |
| 63 | |
| 64 | def setup_test(self): |
| 65 | self.dut.droid.wakeLockAcquireBright() |
| 66 | self.dut.droid.wakeUpNow() |
| 67 | |
| 68 | def teardown_test(self): |
| 69 | self.dut.droid.wakeLockRelease() |
| 70 | self.dut.droid.goToSleepNow() |
| 71 | |
| 72 | def on_fail(self, test_name, begin_time): |
| 73 | self.dut.take_bug_report(test_name, begin_time) |
| 74 | self.dut.cat_adb_log(test_name, begin_time) |
| 75 | |
| 76 | def teardown_class(self): |
| 77 | wutils.reset_wifi(self.dut) |
| 78 | if "AccessPoint" in self.user_params: |
| 79 | del self.user_params["reference_networks"] |
| 80 | del self.user_params["open_network"] |
| 81 | |
| 82 | """Helper Functions""" |
| 83 | |
| 84 | def check_hiddenSSID_in_scan(self, ap_ssid, max_tries=2): |
| 85 | """Check if the ap started by wifi tethering is seen in scan results. |
| 86 | |
| 87 | Args: |
| 88 | ap_ssid: SSID of the ap we are looking for. |
| 89 | max_tries: Number of scans to try. |
| 90 | Returns: |
| 91 | True: if ap_ssid is found in scan results. |
| 92 | False: if ap_ssid is not found in scan results. |
| 93 | """ |
| 94 | for num_tries in range(max_tries): |
| 95 | wutils.start_wifi_connection_scan(self.dut) |
| 96 | scan_results = self.dut.droid.wifiGetScanResults() |
| 97 | match_results = wutils.match_networks( |
| 98 | {wutils.WifiEnums.SSID_KEY: ap_ssid}, scan_results) |
| 99 | if len(match_results) > 0: |
| 100 | return True |
| 101 | return False |
| 102 | |
| 103 | def add_hiddenSSID_and_connect(self, hidden_network): |
| 104 | """Add the hidden network and connect to it. |
| 105 | |
| 106 | Args: |
| 107 | hidden_network: The hidden network config to connect to. |
| 108 | |
| 109 | """ |
Hsiu-Chang Chen | ce489dd | 2019-06-12 15:37:19 +0800 | [diff] [blame^] | 110 | wutils.connect_to_wifi_network(self.dut, hidden_network, hidden=True) |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 111 | if not wutils.validate_connection(self.dut): |
| 112 | raise signals.TestFailure("Fail to connect to internet on %s" % |
| 113 | hidden_network) |
| 114 | |
| 115 | """Tests""" |
| 116 | |
| 117 | @test_tracker_info(uuid="d0871f98-6049-4937-a288-ec4a2746c771") |
| 118 | def test_connect_to_wpa_hidden_2g(self): |
| 119 | """Connect to a WPA, 2G network. |
| 120 | |
| 121 | Steps: |
| 122 | 1. Add a WPA, 2G hidden network. |
| 123 | 2. Ensure the network is visible in scan. |
| 124 | 3. Connect and run ping. |
| 125 | |
| 126 | """ |
| 127 | self.add_hiddenSSID_and_connect(self.wpa_hidden_2g) |
| 128 | |
| 129 | @test_tracker_info(uuid="c558b31a-549a-4012-9052-275623992187") |
| 130 | def test_connect_to_wpa_hidden_5g(self): |
| 131 | """Connect to a WPA, 5G hidden network. |
| 132 | |
| 133 | Steps: |
| 134 | 1. Add a WPA, 5G hidden network. |
| 135 | 2. Ensure the network is visible in scan. |
| 136 | 3. Connect and run ping. |
| 137 | |
| 138 | """ |
| 139 | self.add_hiddenSSID_and_connect(self.wpa_hidden_5g) |
| 140 | |
| 141 | @test_tracker_info(uuid="cdfce76f-6374-439d-aa1d-e920508269d2") |
| 142 | def test_connect_to_open_hidden_2g(self): |
| 143 | """Connect to a Open, 2G hidden network. |
| 144 | |
| 145 | Steps: |
| 146 | 1. Add a Open, 2G hidden network. |
| 147 | 2. Ensure the network is visible in scan. |
| 148 | 3. Connect and run ping. |
| 149 | |
| 150 | """ |
| 151 | self.add_hiddenSSID_and_connect(self.open_hidden_2g) |
| 152 | |
| 153 | @test_tracker_info(uuid="29ccbae4-4382-4df8-8fc5-00e3104230d0") |
| 154 | def test_connect_to_open_hidden_5g(self): |
| 155 | """Connect to a Open, 5G hidden network. |
| 156 | |
| 157 | Steps: |
| 158 | 1. Add a Open, 5G hidden network. |
| 159 | 2. Ensure the network is visible in scan. |
| 160 | 3. Connect and run ping. |
| 161 | |
| 162 | """ |
| 163 | self.add_hiddenSSID_and_connect(self.open_hidden_5g) |