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_decorators import test_tracker_info
     18 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     19 from acts.test_utils.tel.tel_atten_utils import set_rssi
     20 from acts.test_utils.tel.tel_defines import MAX_RSSI_RESERVED_VALUE
     21 from acts.test_utils.tel.tel_defines import MIN_RSSI_RESERVED_VALUE
     22 from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_NW_SELECTION
     23 from acts.test_utils.tel.tel_defines import NETWORK_SERVICE_DATA
     24 from acts.test_utils.tel.tel_defines import GEN_4G
     25 from acts.test_utils.tel.tel_test_utils import ensure_network_generation
     26 from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
     27 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
     28 from acts.test_utils.tel.tel_test_utils import verify_http_connection
     29 from acts.test_utils.tel.tel_test_utils import wait_for_cell_data_connection
     30 from acts.test_utils.tel.tel_test_utils import wait_for_wifi_data_connection
     31 from acts.test_utils.tel.tel_test_utils import run_multithread_func
     32 from acts.test_utils.tel.tel_test_utils import active_file_download_test
     33 from acts.utils import adb_shell_ping
     34 
     35 # Attenuator name
     36 ATTEN_NAME_FOR_WIFI_2G = 'wifi0'
     37 ATTEN_NAME_FOR_WIFI_5G = 'wifi1'
     38 ATTEN_NAME_FOR_CELL_3G = 'cell0'
     39 ATTEN_NAME_FOR_CELL_4G = 'cell1'
     40 
     41 DEFAULT_PING_DURATION = 120
     42 DEFAULT_IRAT_DURATION = 60
     43 
     44 
     45 class TelWifiDataTest(TelephonyBaseTest):
     46     def __init__(self, controllers):
     47         TelephonyBaseTest.__init__(self, controllers)
     48 
     49         self.stress_test_number = self.get_stress_test_number()
     50         self.live_network_ssid = self.user_params["wifi_network_ssid"]
     51         self.live_network_pwd = self.user_params.get("wifi_network_pass")
     52 
     53         self.attens = {}
     54         for atten in self.attenuators:
     55             self.attens[atten.path] = atten
     56         attentuator_name_list = [
     57             ATTEN_NAME_FOR_WIFI_2G, ATTEN_NAME_FOR_WIFI_5G,
     58             ATTEN_NAME_FOR_CELL_3G, ATTEN_NAME_FOR_CELL_4G
     59         ]
     60         for atten_name in attentuator_name_list:
     61             set_rssi(self.log, self.attens[atten_name], 0,
     62                      MAX_RSSI_RESERVED_VALUE)
     63 
     64     def teardown_test(self):
     65         super().teardown_test()
     66         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
     67                  MAX_RSSI_RESERVED_VALUE)
     68         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
     69                  MAX_RSSI_RESERVED_VALUE)
     70         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
     71                  MAX_RSSI_RESERVED_VALUE)
     72         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
     73                  MAX_RSSI_RESERVED_VALUE)
     74         return True
     75 
     76     def _basic_connectivity_check(self):
     77         """
     78         Set Attenuator Value for WiFi and Cell to 0
     79         Make sure DUT get Cell Data coverage (LTE)
     80         Make sure DUT WiFi is connected
     81         """
     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         if not ensure_wifi_connected(self.log, self.android_devices[0],
     88                                      self.live_network_ssid,
     89                                      self.live_network_pwd):
     90             ad.log.error("%s connect WiFI failed")
     91             return False
     92         return True
     93 
     94     def _atten_setup_wifi_cell(self):
     95         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
     96                  MAX_RSSI_RESERVED_VALUE)
     97         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
     98                  MAX_RSSI_RESERVED_VALUE)
     99         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
    100                  MAX_RSSI_RESERVED_VALUE)
    101         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
    102                  MAX_RSSI_RESERVED_VALUE)
    103 
    104     def _atten_setup_cell_only(self):
    105         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
    106                  MIN_RSSI_RESERVED_VALUE)
    107         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
    108                  MIN_RSSI_RESERVED_VALUE)
    109         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
    110                  MAX_RSSI_RESERVED_VALUE)
    111         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
    112                  MAX_RSSI_RESERVED_VALUE)
    113 
    114     def _atten_setup_lte_only(self):
    115         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
    116                  MIN_RSSI_RESERVED_VALUE)
    117         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
    118                  MIN_RSSI_RESERVED_VALUE)
    119         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
    120                  MIN_RSSI_RESERVED_VALUE)
    121         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
    122                  MAX_RSSI_RESERVED_VALUE)
    123 
    124     def _atten_setup_wcdma_only(self):
    125         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
    126                  MIN_RSSI_RESERVED_VALUE)
    127         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
    128                  MIN_RSSI_RESERVED_VALUE)
    129         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
    130                  MAX_RSSI_RESERVED_VALUE)
    131         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
    132                  MIN_RSSI_RESERVED_VALUE)
    133 
    134     def _atten_setup_wifi_only(self):
    135         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_2G], 0,
    136                  MAX_RSSI_RESERVED_VALUE)
    137         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_WIFI_5G], 0,
    138                  MAX_RSSI_RESERVED_VALUE)
    139         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_3G], 0,
    140                  MIN_RSSI_RESERVED_VALUE)
    141         set_rssi(self.log, self.attens[ATTEN_NAME_FOR_CELL_4G], 0,
    142                  MIN_RSSI_RESERVED_VALUE)
    143 
    144     @TelephonyBaseTest.tel_test_wrap
    145     def _wifi_cell_irat_task(self, ad, irat_wait_time=60):
    146         """
    147         Atten only WiFi to MIN and MAX
    148         WiFi --> Cellular
    149         """
    150         self._atten_setup_wifi_cell()
    151         if (not wait_for_wifi_data_connection(self.log, ad, True,
    152                                               irat_wait_time) or
    153                 not verify_http_connection(self.log, ad)):
    154             ad.log.error("Data not on WiFi")
    155             return False
    156 
    157         ad.log.info("Triggering WiFi to Cellular IRAT")
    158         self._atten_setup_cell_only()
    159         if (not wait_for_cell_data_connection(self.log, ad, True,
    160                                               irat_wait_time) or
    161                 not verify_http_connection(self.log, ad)):
    162             ad.log.error("Data not on Cell")
    163             return False
    164         return True
    165 
    166     @test_tracker_info(uuid="b223f74b-59f4-4eec-8785-67420bd96bd1")
    167     @TelephonyBaseTest.tel_test_wrap
    168     def test_wifi_cell_irat_stress_ping_continuous(self):
    169         """Test for data switch between WiFi and Cell. DUT go in and out WiFi
    170         coverage for multiple times.
    171 
    172         Steps:
    173         1. Set WiFi and Cellular signal to good (attenuation value to MIN).
    174         2. Make sure DUT get Cell data coverage (LTE) and WiFi connected.
    175         3. Set WiFi RSSI to MAX (WiFi attenuator value to MIN).
    176         4. Verify DUT report WiFi connected and Internet access OK.
    177         5. Set WiFi RSSI to MIN (WiFi attenuator value to MAX).
    178         6. Verify DUT report Cellular Data connected and Internet access OK.
    179         7. Repeat Step 3~6 for stress number.
    180 
    181         Expected Results:
    182         4. DUT report WiFi connected and Internet access OK.
    183         6. DUT report Cellular Data connected and Internet access OK.
    184         7. Stress test should pass.
    185 
    186         Returns:
    187         True if Pass. False if fail.
    188         """
    189         if not self._basic_connectivity_check():
    190             self.log.error("Basic Connectivity Check Failed")
    191             return False
    192 
    193         total_iteration = self.stress_test_number
    194         ad = self.android_devices[0]
    195         ping_task = (adb_shell_ping, (ad, DEFAULT_PING_DURATION,
    196                                       "www.google.com", 200, 40))
    197         irat_task = (self._wifi_cell_irat_task, (ad, DEFAULT_IRAT_DURATION))
    198         current_iteration = 1
    199         while (current_iteration <= total_iteration):
    200             self.log.info(">----Current iteration = %d/%d----<",
    201                           current_iteration, total_iteration)
    202             results = run_multithread_func(self.log, [ping_task, irat_task])
    203             if not results[1]:
    204                 ad.log.error("Data IRAT failed in active ICMP transfer")
    205                 break
    206             if results[0]:
    207                 ad.log.info("ICMP transfer succeeded with parallel IRAT")
    208             else:
    209                 ad.log.error("ICMP transfer failed with parallel IRAT")
    210                 break
    211             self.log.info(">----Iteration : %d/%d succeed.----<",
    212                           current_iteration, total_iteration)
    213             current_iteration += 1
    214         if current_iteration <= total_iteration:
    215             self.log.info(">----Iteration : %d/%d failed.----<",
    216                           current_iteration, total_iteration)
    217             return False
    218         else:
    219             return True
    220 
    221     @test_tracker_info(uuid="72d2aa4d-c395-417e-99c5-12dc22ea90a1")
    222     @TelephonyBaseTest.tel_test_wrap
    223     def test_wifi_cell_irat_stress_http_dl(self):
    224         """Test for data switch between WiFi and Cell. DUT go in and out WiFi
    225         coverage for multiple times.
    226 
    227         Steps:
    228         1. Set WiFi and Cellular signal to good (attenuation value to MIN).
    229         2. Make sure DUT get Cell data coverage (LTE) and WiFi connected.
    230         3. Set WiFi RSSI to MAX (WiFi attenuator value to MIN).
    231         4. Verify DUT report WiFi connected and able to download file
    232         5. Set WiFi RSSI to MIN (WiFi attenuator value to MAX).
    233         6. Verify DUT report Cellular Data connected and able to download file
    234         7. Repeat Step 3~6 for stress number.
    235 
    236         Expected Results:
    237         4. DUT report WiFi connected and able to download file
    238         6. DUT report Cellular Data connected and able to download file
    239         7. Stress test should pass.
    240 
    241         Returns:
    242         True if Pass. False if fail.
    243         """
    244         ad = self.android_devices[0]
    245         if not self._basic_connectivity_check():
    246             self.log.error("Basic Connectivity Check Failed")
    247             return False
    248 
    249         total_iteration = self.stress_test_number
    250         self.log.info("Stress test. Total iteration = %d.", total_iteration)
    251         current_iteration = 1
    252         while (current_iteration <= total_iteration):
    253             self.log.info(">----Current iteration = %d/%d----<",
    254                           current_iteration, total_iteration)
    255 
    256             self._atten_setup_wifi_cell()
    257             if (not wait_for_wifi_data_connection(self.log, ad, True)):
    258                 ad.log.error("Data not on WiFi")
    259                 break
    260             if not active_file_download_test(self.log, ad):
    261                 ad.log.error("HTTP file download failed on WiFi")
    262                 break
    263 
    264             self._atten_setup_cell_only()
    265             if (not wait_for_cell_data_connection(self.log, ad, True)):
    266                 ad.log.error("Data not on Cell")
    267                 break
    268             if not active_file_download_test(self.log, ad):
    269                 ad.log.error("HTTP file download failed on cell")
    270                 break
    271 
    272             self.log.info(">----Iteration : %d/%d succeed.----<",
    273                           current_iteration, total_iteration)
    274             current_iteration += 1
    275 
    276         if current_iteration <= total_iteration:
    277             self.log.info(">----Iteration : %d/%d failed.----<",
    278                           current_iteration, total_iteration)
    279             return False
    280         else:
    281             return True
    282 
    283     @test_tracker_info(uuid="bce71469-114c-489f-b9c4-26c53c29a553")
    284     @TelephonyBaseTest.tel_test_wrap
    285     def test_wifi_cell_irat_stress_ping(self):
    286         """Test for data switch between WiFi and Cell. DUT go in and out WiFi
    287         coverage for multiple times.
    288 
    289         Steps:
    290         1. Set WiFi and Cellular signal to good (attenuation value to MIN).
    291         2. Make sure DUT get Cell data coverage (LTE) and WiFi connected.
    292         3. Set WiFi RSSI to MAX (WiFi attenuator value to MIN).
    293         4. Verify DUT report WiFi connected and Internet access OK.
    294         5. Set WiFi RSSI to MIN (WiFi attenuator value to MAX).
    295         6. Verify DUT report Cellular Data connected and Internet access OK.
    296         7. Repeat Step 3~6 for stress number.
    297 
    298         Expected Results:
    299         4. DUT report WiFi connected and Internet access OK.
    300         6. DUT report Cellular Data connected and Internet access OK.
    301         7. Stress test should pass.
    302 
    303         Returns:
    304         True if Pass. False if fail.
    305         """
    306         ad = self.android_devices[0]
    307         if not self._basic_connectivity_check():
    308             self.log.error("Basic Connectivity Check Failed")
    309             return False
    310 
    311         total_iteration = self.stress_test_number
    312         self.log.info("Stress test. Total iteration = %d.", total_iteration)
    313         current_iteration = 1
    314         while (current_iteration <= total_iteration):
    315             self.log.info(">----Current iteration = %d/%d----<",
    316                           current_iteration, total_iteration)
    317 
    318             self._atten_setup_wifi_cell()
    319             if (not wait_for_wifi_data_connection(self.log, ad, True) or
    320                     not verify_http_connection(self.log, ad)):
    321                 ad.log.error("Data not on WiFi")
    322                 break
    323 
    324             self._atten_setup_cell_only()
    325             if (not wait_for_cell_data_connection(self.log, ad, True) or
    326                     not verify_http_connection(self.log, ad)):
    327                 ad.log.error("Data not on Cell")
    328                 break
    329             self.log.info(">----Iteration : %d/%d succeed.----<",
    330                           current_iteration, total_iteration)
    331             current_iteration += 1
    332         if current_iteration <= total_iteration:
    333             self.log.info(">----Iteration : %d/%d failed.----<",
    334                           current_iteration, total_iteration)
    335             return False
    336         else:
    337             return True
    338 
    339     @test_tracker_info(uuid="696f22ef-39cd-4e15-bbb2-f836d2ee47f1")
    340     @TelephonyBaseTest.tel_test_wrap
    341     def test_wifi_only_http_dl(self):
    342         """Test for 10MB file download on WiFi Only
    343 
    344         Steps:
    345         1. Set WiFi atten to MIN and Cellular to MAX
    346         2. Start downloading 1GB file from net
    347         3. Verify is the download is successfull
    348 
    349         Expected Results:
    350         1. File should download over WiFi
    351 
    352         Returns:
    353         True if Pass. False if fail.
    354         """
    355         ad = self.android_devices[0]
    356         if not self._basic_connectivity_check():
    357             self.log.error("Basic Connectivity Check Failed")
    358             return False
    359         self._atten_setup_wifi_only()
    360         if (not wait_for_wifi_data_connection(self.log, ad, True) or
    361                 not verify_http_connection(self.log, ad)):
    362             ad.log.error("Data not on WiFi")
    363             return False
    364         if not active_file_download_test(self.log, ad, "10MB"):
    365             ad.log.error("HTTP file download failed on WiFi")
    366             return False
    367         return True
    368 
    369     @test_tracker_info(uuid="6c9bf89b-5469-4b08-acf4-0ef651b1a318")
    370     @TelephonyBaseTest.tel_test_wrap
    371     def test_lte_only_http_dl(self):
    372         """Test for 1GB file download on WiFi Only
    373 
    374         Steps:
    375         1. Set WiFi atten to MIN and Cellular to MAX
    376         2. Start downloading 1GB file from net
    377         3. Verify is the download is successfull
    378 
    379         Expected Results:
    380         1. File should download over WiFi
    381 
    382         Returns:
    383         True if Pass. False if fail.
    384         """
    385         ad = self.android_devices[0]
    386         if not self._basic_connectivity_check():
    387             self.log.error("Basic Connectivity Check Failed")
    388             return False
    389         self._atten_setup_lte_only()
    390         if (not wait_for_cell_data_connection(self.log, ad, True) or
    391                 not verify_http_connection(self.log, ad)):
    392             ad.log.error("Data not on LTE")
    393             return False
    394         if not active_file_download_test(self.log, ad, "1GB"):
    395             ad.log.error("HTTP file download failed on LTE")
    396             return False
    397         return True
    398 
    399 
    400 if __name__ == "__main__":
    401     raise Exception("Cannot run this class directly")
    402