Home | History | Annotate | Download | only in power
      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 
     17 import logging
     18 import os
     19 import time
     20 from acts import base_test
     21 from acts.controllers.ap_lib import hostapd_constants as hc
     22 from acts.test_decorators import test_tracker_info
     23 from acts.test_utils.wifi import wifi_test_utils as wutils
     24 from acts.test_utils.wifi import wifi_power_test_utils as wputils
     25 
     26 UNLOCK_SCREEN = 'input keyevent 82'
     27 
     28 
     29 class PowerscanTest(base_test.BaseTestClass):
     30     def __init__(self, controllers):
     31 
     32         base_test.BaseTestClass.__init__(self, controllers)
     33         self.tests = ('test_single_shot_scan_2g_highRSSI',
     34                       'test_single_shot_scan_2g_lowRSSI',
     35                       'test_single_shot_scan_5g_highRSSI',
     36                       'test_single_shot_scan_5g_lowRSSI',
     37                       'test_background_scan'
     38                       'test_wifi_scan_2g', 'test_wifi_scan_5g',
     39                       'test_scan_wifidisconnected_turnonscreen',
     40                       'test_scan_wificonnected_turnonscreen',
     41                       'test_scan_screenoff_below_rssi_threshold',
     42                       'test_scan_screenoff_lost_wificonnection')
     43 
     44     def setup_class(self):
     45 
     46         self.log = logging.getLogger()
     47         self.dut = self.android_devices[0]
     48         self.access_point = self.access_points[0]
     49         req_params = ('main_network', 'scantest_params')
     50         self.unpack_userparams(req_params)
     51         self.unpack_testparams(self.scantest_params)
     52         self.mon_data_path = os.path.join(self.log_path, 'Monsoon')
     53         self.mon = self.monsoons[0]
     54         self.mon.set_max_current(8.0)
     55         self.mon.set_voltage(4.2)
     56         self.mon.attach_device(self.dut)
     57         self.mon_info = wputils.create_monsoon_info(self)
     58         self.num_atten = self.attenuators[0].instrument.num_atten
     59 
     60     def unpack_testparams(self, bulk_params):
     61         """Unpack all the test specific parameters.
     62 
     63         Args:
     64             bulk_params: dict with all test specific params in the config file
     65         """
     66         for key in bulk_params.keys():
     67             setattr(self, key, bulk_params[key])
     68 
     69     def setup_test(self):
     70 
     71         self.SINGLE_SHOT_SCAN = (
     72             'am instrument -w -r  -e min_scan_count \"700\"'
     73             ' -e WifiScanTest-testWifiSingleShotScan %d'
     74             ' -e class com.google.android.platform.powertests.'
     75             'WifiScanTest#testWifiSingleShotScan'
     76             ' com.google.android.platform.powertests/'
     77             'android.test.InstrumentationTestRunner > /dev/null &' %
     78             (self.mon_duration + self.mon_offset + 10))
     79         self.BACKGROUND_SCAN = (
     80             'am instrument -w -r -e min_scan_count \"1\" -e '
     81             'WifiScanTest-testWifiBackgroundScan %d -e class '
     82             'com.google.android.platform.powertests.WifiScan'
     83             'Test#testWifiBackgroundScan com.google.android.'
     84             'platform.powertests/android.test.Instrumentation'
     85             'TestRunner > /dev/null &' %
     86             (self.mon_duration + self.mon_offset + 10))
     87         self.WIFI_SCAN = (
     88             'am instrument -w -r -e min_scan_count \"1\" -e '
     89             'WifiScanTest-testWifiScan %d -e class '
     90             'com.google.android.platform.powertests.WifiScanTest#'
     91             'testWifiScan com.google.android.platform.powertests/'
     92             'android.test.InstrumentationTestRunner > /dev/null &' %
     93             (self.mon_duration + self.mon_offset + 10))
     94 
     95     def teardown_class(self):
     96 
     97         self.mon.usb('on')
     98 
     99     def powrapk_scan_test_func(self, scan_command):
    100         """Test function for power.apk triggered scans.
    101         Args:
    102             scan_command: the adb shell command to trigger scans
    103 
    104         """
    105         self.mon_info['offset'] == 0
    106         # Initialize the dut to rock-bottom state
    107         wputils.dut_rockbottom(self.dut)
    108         wutils.wifi_toggle_state(self.dut, True)
    109         self.log.info('Wait for {} seconds'.format(self.settle_wait_time))
    110         time.sleep(self.settle_wait_time)
    111         self.log.info('Running power apk command to trigger scans')
    112         self.dut.adb.shell_nb(scan_command)
    113         self.dut.droid.goToSleepNow()
    114         # Collect power data and plot
    115         file_path, avg_current = wputils.monsoon_data_collect_save(
    116             self.dut, self.mon_info, self.current_test_name, self.bug_report)
    117         wputils.monsoon_data_plot(self.mon_info, file_path)
    118         # Close AP controller
    119         self.access_point.close()
    120         # Path fail check
    121         wputils.pass_fail_check(self, avg_current)
    122 
    123     # Test cases
    124     @test_tracker_info(uuid='e5539b01-e208-43c6-bebf-6f1e73d8d8cb')
    125     def test_single_shot_scan_2g_highRSSI(self):
    126 
    127         network = self.main_network[hc.BAND_2G]
    128         wputils.ap_setup(self.access_point, network)
    129         self.log.info('Set attenuation to get high RSSI at 2g')
    130         [
    131             self.attenuators[i].set_atten(
    132                 self.atten_level[self.current_test_name][i])
    133             for i in range(self.num_atten)
    134         ]
    135         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    136 
    137     @test_tracker_info(uuid='14c5a762-95bc-40ea-9fd4-27126df7d86c')
    138     def test_single_shot_scan_2g_lowRSSI(self):
    139 
    140         network = self.main_network[hc.BAND_2G]
    141         wputils.ap_setup(self.access_point, network)
    142         self.log.info('Set attenuation to get low RSSI at 2g')
    143         [
    144             self.attenuators[i].set_atten(
    145                 self.atten_level[self.current_test_name][i])
    146             for i in range(self.num_atten)
    147         ]
    148         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    149 
    150     @test_tracker_info(uuid='a6506600-c567-43b5-9c25-86b505099b97')
    151     def test_single_shot_scan_2g_noAP(self):
    152 
    153         network = self.main_network[hc.BAND_2G]
    154         wputils.ap_setup(self.access_point, network)
    155         self.log.info('Set attenuation so all AP is out of reach ')
    156         [
    157             self.attenuators[i].set_atten(
    158                 self.atten_level[self.current_test_name][i])
    159             for i in range(self.num_atten)
    160         ]
    161         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    162 
    163     @test_tracker_info(uuid='1a458248-1159-4c8e-a39f-92fc9e69c4dd')
    164     def test_single_shot_scan_5g_highRSSI(self):
    165 
    166         network = self.main_network[hc.BAND_5G]
    167         wputils.ap_setup(self.access_point, network)
    168         self.log.info('Set attenuation to get high RSSI at 5g')
    169         [
    170             self.attenuators[i].set_atten(
    171                 self.atten_level[self.current_test_name][i])
    172             for i in range(self.num_atten)
    173         ]
    174         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    175 
    176     @test_tracker_info(uuid='bd4da426-a621-4131-9f89-6e5a77f321d2')
    177     def test_single_shot_scan_5g_lowRSSI(self):
    178 
    179         network = self.main_network[hc.BAND_5G]
    180         wputils.ap_setup(self.access_point, network)
    181         self.log.info('Set attenuation to get low RSSI at 5g')
    182         [
    183             self.attenuators[i].set_atten(
    184                 self.atten_level[self.current_test_name][i])
    185             for i in range(self.num_atten)
    186         ]
    187         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    188 
    189     @test_tracker_info(uuid='288b3add-8925-4803-81c0-53debf157ffc')
    190     def test_single_shot_scan_5g_noAP(self):
    191 
    192         network = self.main_network[hc.BAND_5G]
    193         wputils.ap_setup(self.access_point, network)
    194         self.log.info('Set attenuation so all AP is out of reach ')
    195         [
    196             self.attenuators[i].set_atten(
    197                 self.atten_level[self.current_test_name][i])
    198             for i in range(self.num_atten)
    199         ]
    200         self.powrapk_scan_test_func(self.SINGLE_SHOT_SCAN)
    201 
    202     @test_tracker_info(uuid='f401c66c-e515-4f51-8ef2-2a03470d8ff2')
    203     def test_background_scan(self):
    204 
    205         network = self.main_network[hc.BAND_2G]
    206         wputils.ap_setup(self.access_point, network)
    207         self.powrapk_scan_test_func(self.BACKGROUND_SCAN)
    208 
    209     @test_tracker_info(uuid='fe38c1c7-937c-42c0-9381-98356639df8f')
    210     def test_wifi_scan_2g(self):
    211 
    212         network = self.main_network[hc.BAND_2G]
    213         wputils.ap_setup(self.access_point, network)
    214         [
    215             self.attenuators[i].set_atten(
    216                 self.atten_level[self.current_test_name][i])
    217             for i in range(self.num_atten)
    218         ]
    219         self.powrapk_scan_test_func(self.WIFI_SCAN)
    220 
    221     @test_tracker_info(uuid='8eedefd1-3a08-4ac2-ba55-5eb438def3d4')
    222     def test_wifi_scan_5g(self):
    223 
    224         network = self.main_network[hc.BAND_2G]
    225         wputils.ap_setup(self.access_point, network)
    226         [
    227             self.attenuators[i].set_atten(
    228                 self.atten_level[self.current_test_name][i])
    229             for i in range(self.num_atten)
    230         ]
    231         self.powrapk_scan_test_func(self.WIFI_SCAN)
    232 
    233     @test_tracker_info(uuid='ff5ea952-ee31-4968-a190-82935ce7a8cb')
    234     def test_scan_wifidisconnected_turnonscreen(self):
    235 
    236         # Initialize the dut to rock-bottom state
    237         wputils.dut_rockbottom(self.dut)
    238         wutils.wifi_toggle_state(self.dut, True)
    239         self.dut.droid.goToSleepNow()
    240         self.log.info('Screen is OFF')
    241         time.sleep(5)
    242         self.dut.droid.wakeUpNow()
    243         self.log.info('Now turn on screen to trigger scans')
    244         self.dut.adb.shell(UNLOCK_SCREEN)
    245         file_path, avg_current = wputils.monsoon_data_collect_save(
    246             self.dut, self.mon_info, self.current_test_name, self.bug_report)
    247         wputils.monsoon_data_plot(self.mon_info, file_path)
    248         wputils.pass_fail_check(self, avg_current)
    249 
    250     @test_tracker_info(uuid='9a836e5b-8128-4dd2-8e96-e79177810bdd')
    251     def test_scan_wificonnected_turnonscreen(self):
    252 
    253         network = self.main_network[hc.BAND_2G]
    254         wputils.ap_setup(self.access_point, network)
    255         # Initialize the dut to rock-bottom state
    256         wputils.dut_rockbottom(self.dut)
    257         wutils.wifi_toggle_state(self.dut, True)
    258         # Set attenuators to connect main AP
    259         [
    260             self.attenuators[i].set_atten(
    261                 self.atten_level[self.current_test_name][i])
    262             for i in range(self.num_atten)
    263         ]
    264         wutils.wifi_connect(self.dut, network)
    265         time.sleep(10)
    266         self.dut.droid.goToSleepNow()
    267         self.log.info('Screen is OFF')
    268         time.sleep(5)
    269         self.dut.droid.wakeUpNow()
    270         self.log.info('Now turn on screen to trigger scans')
    271         self.dut.adb.shell(UNLOCK_SCREEN)
    272         file_path, avg_current = wputils.monsoon_data_collect_save(
    273             self.dut, self.mon_info, self.current_test_name, self.bug_report)
    274         wputils.monsoon_data_plot(self.mon_info, file_path)
    275         # Close AP controller
    276         self.access_point.close()
    277         # Path fail check
    278         wputils.pass_fail_check(self, avg_current)
    279 
    280     @test_tracker_info(uuid='51e3c4f1-742b-45af-afd5-ae3552a03272')
    281     def test_scan_screenoff_below_rssi_threshold(self):
    282 
    283         network = self.main_network[hc.BAND_2G]
    284         wputils.ap_setup(self.access_point, network)
    285         # Initialize the dut to rock-bottom state
    286         wputils.dut_rockbottom(self.dut)
    287         wutils.wifi_toggle_state(self.dut, True)
    288         # Set attenuator and add main network to the phone
    289         self.log.info('Set attenuation so device connection has medium RSSI')
    290         [
    291             self.attenuators[i].set_atten(self.atten_level['zero_atten'][i])
    292             for i in range(self.num_atten)
    293         ]
    294         wutils.wifi_connect(self.dut, network)
    295         self.dut.droid.goToSleepNow()
    296         time.sleep(20)
    297         # Set attenuator to make RSSI below threshold
    298         self.log.info('Set attenuation to drop RSSI below threhold')
    299         [
    300             self.attenuators[i].set_atten(
    301                 self.atten_level[self.current_test_name][i])
    302             for i in range(self.num_atten)
    303         ]
    304         file_path, avg_current = wputils.monsoon_data_collect_save(
    305             self.dut, self.mon_info, self.current_test_name, self.bug_report)
    306         wputils.monsoon_data_plot(self.mon_info, file_path)
    307         # Close AP controller
    308         self.access_point.close()
    309         # Path fail check
    310         wputils.pass_fail_check(self, avg_current)
    311 
    312     @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4')
    313     def test_scan_screenoff_lost_wificonnection(self):
    314 
    315         network = self.main_network[hc.BAND_5G]
    316         wputils.ap_setup(self.access_point, network)
    317         # Initialize the dut to rock-bottom state
    318         wputils.dut_rockbottom(self.dut)
    319         wutils.wifi_toggle_state(self.dut, True)
    320         # Set attenuator and add main network to the phone
    321         self.log.info('Set attenuation so device connection has medium RSSI')
    322         [
    323             self.attenuators[i].set_atten(self.atten_level['zero_atten'][i])
    324             for i in range(self.num_atten)
    325         ]
    326         wutils.wifi_connect(self.dut, network)
    327         self.dut.droid.goToSleepNow()
    328         time.sleep(5)
    329         # Set attenuator to make RSSI below threshold
    330         self.log.info('Set attenuation so device loses connection')
    331         [
    332             self.attenuators[i].set_atten(
    333                 self.atten_level[self.current_test_name][i])
    334             for i in range(self.num_atten)
    335         ]
    336         file_path, avg_current = wputils.monsoon_data_collect_save(
    337             self.dut, self.mon_info, self.current_test_name, self.bug_report)
    338         wputils.monsoon_data_plot(self.mon_info, file_path)
    339         # Close AP controller
    340         self.access_point.close()
    341         # Path fail check
    342         wputils.pass_fail_check(self, avg_current)
    343