Home | History | Annotate | Download | only in wifi
      1 #!/usr/bin/env python3.4
      2 
      3 import queue
      4 import time
      5 
      6 import acts.base_test
      7 import acts.test_utils.wifi.wifi_test_utils as wifi_utils
      8 import acts.test_utils.tel.tel_test_utils as tele_utils
      9 import acts.utils
     10 
     11 from acts import asserts
     12 from acts import signals
     13 from acts.test_decorators import test_tracker_info
     14 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     15 from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_general
     16 from acts.test_utils.tel.tel_voice_utils import two_phone_call_short_seq
     17 
     18 WifiEnums = wifi_utils.WifiEnums
     19 
     20 ATTENUATORS = "attenuators"
     21 WIFI_SSID = "wifi_network_ssid"
     22 WIFI_PWD = "wifi_network_pass"
     23 STRESS_COUNT = "stress_iteration"
     24 
     25 class WifiTeleCoexTest(TelephonyBaseTest):
     26     """Tests for WiFi, Celular Co-existance."""
     27 
     28 
     29     def __init__(self, controllers):
     30         TelephonyBaseTest.__init__(self, controllers)
     31 
     32 
     33     def setup_class(self):
     34         TelephonyBaseTest.setup_class(self)
     35         self.dut = self.android_devices[0]
     36         wifi_utils.wifi_test_device_init(self.dut)
     37         # Set attenuation to 0 on all channels.
     38         if getattr(self, ATTENUATORS, []):
     39             for a in self.attenuators:
     40                 a.set_atten(0)
     41         self.ads = self.android_devices
     42         self.dut = self.android_devices[0]
     43         self.wifi_network_ssid = self.user_params.get(WIFI_SSID)
     44         self.wifi_network_pass = self.user_params.get(WIFI_PWD)
     45         self.network = { WifiEnums.SSID_KEY : self.wifi_network_ssid,
     46                          WifiEnums.PWD_KEY : self.wifi_network_pass
     47                        }
     48         self.stress_count = self.user_params.get(STRESS_COUNT)
     49 
     50 
     51     def setup_test(self):
     52         wifi_utils.wifi_toggle_state(self.dut, True)
     53 
     54 
     55     def teardown_test(self):
     56         wifi_utils.reset_wifi(self.dut)
     57 
     58 
     59     """Helper Functions"""
     60 
     61 
     62     def connect_to_wifi(self, ad, network):
     63         """Connection logic for open and psk wifi networks.
     64 
     65         Args:
     66             ad: Android device object.
     67             network: A JSON dict of the WiFi network configuration.
     68 
     69         """
     70         ad.ed.clear_all_events()
     71         wifi_utils.start_wifi_connection_scan(ad)
     72         scan_results = ad.droid.wifiGetScanResults()
     73         wifi_utils.assert_network_in_list({WifiEnums.SSID_KEY:
     74                 self.wifi_network_ssid}, scan_results)
     75         wifi_utils.wifi_connect(ad, network)
     76         self.log.debug("Connected to %s network on %s device" % (
     77                 network[WifiEnums.SSID_KEY], ad.serial))
     78 
     79 
     80     def stress_toggle_wifi(self, stress_count):
     81         """Toggle WiFi in a loop.
     82 
     83         Args:
     84             stress_count: Number of times to toggle WiFi OFF and ON.
     85 
     86         """
     87         for count in range(stress_count):
     88             self.log.debug("stress_toggle_wifi: Iteration %d" % count)
     89             wifi_utils.toggle_wifi_off_and_on(self.dut)
     90 
     91         if not self.dut.droid.wifiGetisWifiEnabled():
     92             raise signals.TestFailure("WiFi did not turn on after toggling it"
     93                                       " %d times" % self.stress_count)
     94 
     95 
     96     def stress_toggle_airplane(self, stress_count):
     97         """Toggle Airplane mode in a loop.
     98 
     99         Args:
    100             stress_count: Number of times to toggle Airplane mode OFF and ON.
    101 
    102         """
    103         for count in range(stress_count):
    104             self.log.debug("stress_toggle_airplane: Iteration %d" % count)
    105             wifi_utils.toggle_airplane_mode_on_and_off(self.dut)
    106 
    107         if not self.dut.droid.wifiGetisWifiEnabled():
    108             raise signals.TestFailure("WiFi did not turn on after toggling it"
    109                                       " %d times" % self.stress_count)
    110 
    111 
    112     def stress_toggle_airplane_and_wifi(self, stress_count):
    113         """Toggle Airplane and WiFi modes in a loop.
    114 
    115         Args:
    116             stress_count: Number of times to perform Airplane mode ON, WiFi ON,
    117                           Airplane mode OFF, in a sequence.
    118 
    119         """
    120         self.log.debug("Toggling Airplane mode ON")
    121 
    122         asserts.assert_true(
    123             acts.utils.force_airplane_mode(self.dut, True),
    124             "Can not turn on airplane mode on: %s" % self.dut.serial)
    125         # Sleep for atleast 500ms so that, call to enable wifi is not deferred.
    126         time.sleep(1)
    127 
    128         self.log.debug("Toggling wifi ON")
    129         wifi_utils.wifi_toggle_state(self.dut, True)
    130         # Sleep for 1s before getting new WiFi state.
    131         time.sleep(1)
    132         if not self.dut.droid.wifiGetisWifiEnabled():
    133             raise signals.TestFailure("WiFi did not turn on after turning ON"
    134                                       " Airplane mode")
    135         asserts.assert_true(
    136             acts.utils.force_airplane_mode(self.dut, False),
    137             "Can not turn on airplane mode on: %s" % self.dut.serial)
    138 
    139         if not self.dut.droid.wifiGetisWifiEnabled():
    140             raise signals.TestFailure("WiFi did not turn on after toggling it"
    141                                       " %d times" % self.stress_count)
    142 
    143 
    144     def setup_cellular_voice_calling(self):
    145         """Setup phone for voice general calling and make sure phone is
    146            attached to voice."""
    147         # Make sure Phone A and B are attached to voice network.
    148         for ad in self.ads:
    149             if not phone_setup_voice_general(self.log, ad):
    150                 raise signals.TestFailure("Phone failed to setup for voice"
    151                                           " calling serial:%s" % ad.serial)
    152         self.log.debug("Finished setting up phones for voice calling")
    153 
    154 
    155     def validate_cellular_and_wifi(self):
    156         """Validate WiFi, make some cellular calls.
    157 
    158         Steps:
    159             1. Check if device is still connected to the WiFi network.
    160             2. If WiFi looks good, check if deivce is attached to voice.
    161             3. Make a short sequence voice call between Phone A and B.
    162 
    163         """
    164         # Sleep for 5s before getting new WiFi state.
    165         time.sleep(5)
    166         wifi_info = self.dut.droid.wifiGetConnectionInfo()
    167         if wifi_info[WifiEnums.SSID_KEY] != self.wifi_network_ssid:
    168             raise signals.TestFailure("Phone failed to connect to %s network on"
    169                                       " %s" % (self.wifi_network_ssid,
    170                                       self.dut.serial))
    171 
    172         # Make short call sequence between Phone A and Phone B.
    173         two_phone_call_short_seq(self.log, self.ads[0], None, None, self.ads[1],
    174                                  None, None)
    175 
    176     """Tests"""
    177 
    178 
    179     @test_tracker_info(uuid="8b9b6fb9-964b-43e7-b75f-675774ee346f")
    180     @TelephonyBaseTest.tel_test_wrap
    181     def test_toggle_wifi_call(self):
    182         """Test to toggle WiFi and then perform WiFi connection and
    183            cellular calls.
    184 
    185         Steps:
    186             1. Attach device to voice subscription network.
    187             2. Connect to a WiFi network.
    188             3. Toggle WiFi OFF and ON.
    189             4. Verify device auto-connects to the WiFi network.
    190             5. Verify device is attached to voice network.
    191             6. Make short sequence voice calls.
    192 
    193         """
    194         self.setup_cellular_voice_calling()
    195         self.connect_to_wifi(self.dut, self.network)
    196         wifi_utils.toggle_wifi_off_and_on(self.dut)
    197         self.validate_cellular_and_wifi()
    198         return True
    199 
    200 
    201     @test_tracker_info(uuid="caf22447-6354-4a2e-99e5-0ff235fc8f20")
    202     @TelephonyBaseTest.tel_test_wrap
    203     def test_toggle_airplane_call(self):
    204         """Test to toggle Airplane mode and perform WiFi connection and
    205            cellular calls.
    206 
    207         Steps:
    208             1. Attach device to voice subscription network.
    209             2. Connect to a WiFi network.
    210             3. Toggle Airplane mode OFF and ON.
    211             4. Verify device auto-connects to the WiFi network.
    212             5. Verify device is attached to voice network.
    213             6. Make short sequence voice calls.
    214 
    215         """
    216         self.setup_cellular_voice_calling()
    217         self.connect_to_wifi(self.dut, self.network)
    218         wifi_utils.toggle_airplane_mode_on_and_off(self.dut)
    219         self.validate_cellular_and_wifi()
    220         return True
    221 
    222 
    223     @test_tracker_info(uuid="dd888b35-f820-409a-89af-4b0f6551e4d6")
    224     @TelephonyBaseTest.tel_test_wrap
    225     def test_toggle_airplane_and_wifi_call(self):
    226         """Test to toggle WiFi in a loop and perform WiFi connection and
    227            cellular calls.
    228 
    229         Steps:
    230             1. Attach device to voice subscription network.
    231             2. Connect to a WiFi network.
    232             3. Toggle Airplane mode ON.
    233             4. Turn WiFi ON.
    234             5. Toggle Airplane mode OFF.
    235             3. Verify device auto-connects to the WiFi network.
    236             4. Verify device is attached to voice network.
    237             5. Make short sequence voice calls.
    238 
    239         """
    240         self.setup_cellular_voice_calling()
    241         self.connect_to_wifi(self.dut, self.network)
    242         self.stress_toggle_airplane_and_wifi(1)
    243         self.validate_cellular_and_wifi()
    244         return True
    245 
    246 
    247     @test_tracker_info(uuid="15db5b7e-827e-4bc8-8e77-7fcce343a323")
    248     @TelephonyBaseTest.tel_test_wrap
    249     def test_stress_toggle_wifi_call(self):
    250         """Stress test to toggle WiFi in a loop, then perform WiFi connection
    251            and cellular calls.
    252 
    253         Steps:
    254             1. Attach device to voice subscription network.
    255             2. Connect to a WiFi network.
    256             3. Toggle WiFi OFF and ON in a loop.
    257             4. Verify device auto-connects to the WiFi network.
    258             5. Verify device is attached to voice network.
    259             6. Make short sequence voice calls.
    260 
    261         """
    262         self.setup_cellular_voice_calling()
    263         self.connect_to_wifi(self.dut, self.network)
    264         self.stress_toggle_wifi(self.stress_count)
    265         self.validate_cellular_and_wifi()
    266         return True
    267 
    268 
    269     @test_tracker_info(uuid="80a2f1bf-5e41-453a-9b8e-be3b41d4d313")
    270     @TelephonyBaseTest.tel_test_wrap
    271     def test_stress_toggle_airplane_call(self):
    272         """Stress test to toggle Airplane mode in a loop, then perform WiFi and
    273            cellular calls.
    274 
    275         Steps:
    276             1. Attach device to voice subscription network.
    277             2. Connect to a WiFi network.
    278             3. Toggle Airplane mode OFF and ON in a loop.
    279             4. Verify device auto-connects to the WiFi network.
    280             5. Verify device is attached to voice network.
    281             6. Make short sequence voice calls.
    282 
    283         """
    284         self.setup_cellular_voice_calling()
    285         self.connect_to_wifi(self.dut, self.network)
    286         self.stress_toggle_airplane(self.stress_count)
    287         self.validate_cellular_and_wifi()
    288         return True
    289 
    290 
    291     @test_tracker_info(uuid="b88ad3e7-6462-4280-ad57-22d0ac91fdd8")
    292     @TelephonyBaseTest.tel_test_wrap
    293     def test_stress_toggle_airplane_and_wifi_call(self):
    294         """Stress test to toggle Airplane and WiFi mode in a loop, then perform
    295            WiFi connection and cellular calls.
    296 
    297         Steps:
    298             1. Attach device to voice subscription network.
    299             2. Connect to a WiFi network.
    300             3. Toggle Airplane mode ON.
    301             4. Turn WiFi ON.
    302             5. Toggle Airplane mode OFF.
    303             6. Repeat 3, 4 & 5, in a loop.
    304             7. Verify device auto-connects to the WiFi network.
    305             8. Verify device is attached to voice network.
    306             9. Make short sequence voice calls.
    307 
    308         """
    309         self.setup_cellular_voice_calling()
    310         self.connect_to_wifi(self.dut, self.network)
    311         self.stress_toggle_airplane_and_wifi(self.stress_count)
    312         self.validate_cellular_and_wifi()
    313         return True
    314