Home | History | Annotate | Download | only in live
      1 #!/usr/bin/env python3.4
      2 #
      3 # Copyright 2016 - 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 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     18 from acts.test_utils.tel.tel_atten_utils import set_rssi
     19 from acts.test_utils.tel.tel_defines import MAX_RSSI_RESERVED_VALUE
     20 from acts.test_utils.tel.tel_defines import MIN_RSSI_RESERVED_VALUE
     21 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
     22 from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
     23 from acts.test_utils.tel.tel_defines import GEN_4G
     24 from acts.test_utils.tel.tel_test_utils import ensure_network_generation
     25 from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
     26 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
     27 from acts.test_utils.tel.tel_test_utils import verify_http_connection
     28 from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
     29 from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
     30 
     31 # Attenuator name
     32 ATTEN_NAME_FOR_WIFI = 'wifi0'
     33 ATTEN_NAME_FOR_CELL = 'cell0'
     34 
     35 
     36 class TelWifiDataTest(TelephonyBaseTest):
     37     def __init__(self, controllers):
     38         TelephonyBaseTest.__init__(self, controllers)
     39         self.tests = ("test_wifi_cell_switching_stress", )
     40         self.stress_test_number = int(self.user_params["stress_test_number"])
     41         self.live_network_ssid = self.user_params["wifi_network_ssid"]
     42         try:
     43             self.live_network_pwd = self.user_params["wifi_network_pass"]
     44         except KeyError:
     45             self.live_network_pwd = None
     46 
     47         self.attens = {}
     48         for atten in self.attenuators:
     49             self.attens[atten.path] = atten
     50 
     51     @TelephonyBaseTest.tel_test_wrap
     52     def test_wifi_cell_switching_stress(self):
     53         """Test for data switch between WiFi and Cell. DUT go in and out WiFi
     54         coverage for multiple times.
     55 
     56         Steps:
     57         1. Set WiFi and Cellular signal to good (attenuation value to MIN).
     58         2. Make sure DUT get Cell data coverage (LTE) and WiFi connected.
     59         3. Set WiFi RSSI to MAX (WiFi attenuator value to MIN).
     60         4. Verify DUT report WiFi connected and Internet access OK.
     61         5. Set WiFi RSSI to MIN (WiFi attenuator value to MAX).
     62         6. Verify DUT report Cellular Data connected and Internet access OK.
     63         7. Repeat Step 3~6 for stress number.
     64 
     65         Expected Results:
     66         4. DUT report WiFi connected and Internet access OK.
     67         6. DUT report Cellular Data connected and Internet access OK.
     68         7. Stress test should pass.
     69 
     70         Returns:
     71         True if Pass. False if fail.
     72         """
     73         WIFI_RSSI_CHANGE_STEP_SIZE = 2
     74         WIFI_RSSI_CHANGE_DELAY_PER_STEP = 1
     75         # Set Attenuator Value for WiFi and Cell to 0.
     76         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
     77                  MAX_RSSI_RESERVED_VALUE)
     78         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL], 0,
     79                  MAX_RSSI_RESERVED_VALUE)
     80 
     81         # Make sure DUT get Cell Data coverage (LTE).
     82         toggle_airplane_mode(self.log, self.android_devices[0], False)
     83         if not ensure_network_generation(self.log, self.android_devices[0],
     84                                          GEN_4G, NETWORK_SERVICE_DATA):
     85             return False
     86 
     87         # Make sure DUT WiFi is connected.
     88         if not ensure_wifi_connected(self.log, self.android_devices[0],
     89                                      self.live_network_ssid,
     90                                      self.live_network_pwd):
     91             self.log.error("{} connect WiFI failed".format(
     92                 self.android_devices[0].serial))
     93             return False
     94 
     95         total_iteration = self.stress_test_number
     96         self.log.info("Stress test. Total iteration = {}.".format(
     97             total_iteration))
     98         current_iteration = 1
     99         while (current_iteration <= total_iteration):
    100             self.log.info(">----Current iteration = {}/{}----<".format(
    101                 current_iteration, total_iteration))
    102 
    103             # Set WiFi RSSI to MAX.
    104             set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
    105                      MAX_RSSI_RESERVED_VALUE, WIFI_RSSI_CHANGE_STEP_SIZE,
    106                      WIFI_RSSI_CHANGE_DELAY_PER_STEP)
    107             # Wait for DUT report WiFi connected and Internet access OK.
    108             if (not wait_for_wifi_data_connection(
    109                     self.log, self.android_devices[0], True) or
    110                     not verify_http_connection(self.log,
    111                                                self.android_devices[0])):
    112                 self.log.error("Data not on WiFi")
    113                 break
    114 
    115             # Set WiFi RSSI to MIN (DUT lose WiFi coverage).
    116             set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI], 0,
    117                      MIN_RSSI_RESERVED_VALUE, WIFI_RSSI_CHANGE_STEP_SIZE,
    118                      WIFI_RSSI_CHANGE_DELAY_PER_STEP)
    119             # Wait for DUT report Cellular Data connected and Internet access OK.
    120             if (not wait_for_cell_data_connection(
    121                     self.log, self.android_devices[0], True) or
    122                     not verify_http_connection(self.log,
    123                                                self.android_devices[0])):
    124                 self.log.error("Data not on Cell")
    125                 break
    126 
    127             self.log.info(">----Iteration : {}/{} succeed.----<".format(
    128                 current_iteration, total_iteration))
    129             current_iteration += 1
    130         if current_iteration <= total_iteration:
    131             self.log.info(">----Iteration : {}/{} failed.----<".format(
    132                 current_iteration, total_iteration))
    133             return False
    134         else:
    135             return True
    136 
    137 
    138 if __name__ == "__main__":
    139     raise Exception("Cannot run this class directly")
    140