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 17import time 18from acts.test_decorators import test_tracker_info 19from acts_contrib.test_utils.power import PowerWiFiBaseTest as PWBT 20from acts_contrib.test_utils.wifi import wifi_test_utils as wutils 21from acts_contrib.test_utils.wifi.wifi_power_test_utils import CHRE_WIFI_SCAN_TYPE 22from acts_contrib.test_utils.wifi.wifi_power_test_utils import CHRE_WIFI_RADIO_CHAIN 23from acts_contrib.test_utils.wifi.wifi_power_test_utils import CHRE_WIFI_CHANNEL_SET 24 25UNLOCK_SCREEN = 'input keyevent 82' 26LOCATION_ON = 'settings put secure location_mode 3' 27ENABLE_WIFI_SCANNING = 'cmd wifi enable-scanning enabled' 28DISABLE_WIFI_SCANNING = 'cmd wifi enable-scanning disabled' 29CHRE_POWER_TEST_CLIENT = 'chre_power_test_client' 30UNLOAD_ALL_CHRE_PRODUCTION_APP = CHRE_POWER_TEST_CLIENT + ' unloadall' 31LOAD_CHRE_TEST_NANOAPP = CHRE_POWER_TEST_CLIENT + ' load' 32DISABLE_CHRE_WIFI_SCAN = CHRE_POWER_TEST_CLIENT + ' wifi disable' 33CHRE_SCAN_INTERVAL = 5 34NS = 1000000000 35 36class PowerWiFiscanTest(PWBT.PowerWiFiBaseTest): 37 def setup_class(self): 38 super().setup_class() 39 # Setup scan command 40 SINGLE_SHOT_SCAN = ( 41 'nohup am instrument -w -r -e min_scan_count \"700\"' 42 ' -e WifiScanTest-testWifiSingleShotScan %d' 43 ' -e class com.google.android.platform.powertests.' 44 'WifiScanTest#testWifiSingleShotScan' 45 ' com.google.android.platform.powertests/' 46 'androidx.test.runner.AndroidJUnitRunner > /dev/null &' % 47 (self.mon_duration + self.mon_offset + 10)) 48 self.APK_SCAN_CMDS = { 49 'singleshot': SINGLE_SHOT_SCAN 50 } 51 52 def setup_test(self): 53 super().setup_test() 54 # Reset attenuation to minimum 55 self.set_attenuation([0, 0, 0, 0]) 56 # Turn on location for WiFi Scans 57 self.dut.adb.shell(LOCATION_ON) 58 59 def scan_setup(self): 60 """Setup for scan based on the type of scan. 61 62 Trigger the desired scan. 63 """ 64 self.log.info('Trigger {} scans'.format(self.test_configs.scan_mode)) 65 if self.test_configs.scan_type == 'apk': 66 atten_setting = self.test_configs.wifi_band + '_' + self.test_configs.rssi 67 self.set_attenuation(self.atten_level[atten_setting]) 68 self.dut.adb.shell_nb( 69 self.APK_SCAN_CMDS[self.test_configs.scan_mode]) 70 else: 71 self.mon_info.offset = 0 72 if self.test_configs.scan_mode == 'pno': 73 self.log.info('Set attenuation to trigger PNO scan') 74 self.set_attenuation(self.atten_level['max_atten']) 75 elif self.test_configs.scan_mode == 'connectivity': 76 self.dut.droid.wakeUpNow() 77 self.log.info( 78 'Now turn on screen to trigger connectivity scans') 79 self.dut.adb.shell(UNLOCK_SCREEN) 80 elif self.test_configs.scan_mode == 'roaming': 81 atten_setting = self.test_configs.wifi_band + '_roaming' 82 self.set_attenuation(self.atten_level[atten_setting]) 83 84 def chre_scan_setup(self): 85 self.dut.adb.shell("cmd wifi force-country-code enabled US") 86 time.sleep(1) 87 country_code = self.dut.adb.shell("cmd wifi get-country-code") 88 if "US" in country_code: 89 self.log.info("Country-Code is set to US") 90 else: 91 self.log.warning("Country Code is : " + str(country_code)) 92 self.dut.adb.shell(DISABLE_WIFI_SCANNING) 93 self.dut.adb.shell(UNLOAD_ALL_CHRE_PRODUCTION_APP) 94 self.dut.adb.shell(LOAD_CHRE_TEST_NANOAPP) 95 chre_wifi_scan_trigger_cmd = CHRE_POWER_TEST_CLIENT + ' wifi enable ' + \ 96 str(CHRE_SCAN_INTERVAL*NS) + \ 97 " " + CHRE_WIFI_SCAN_TYPE[self.test_configs.wifi_scan_type] + " " + \ 98 CHRE_WIFI_RADIO_CHAIN[self.test_configs.wifi_radio_chain] + " " + \ 99 CHRE_WIFI_CHANNEL_SET[self.test_configs.wifi_channel_set] 100 self.dut.log.info(chre_wifi_scan_trigger_cmd) 101 self.dut.adb.shell(chre_wifi_scan_trigger_cmd) 102 103 def wifi_scan_test_func(self): 104 105 attrs = [ 106 'screen_status', 'wifi_status', 'wifi_band', 'rssi', 'scan_type', 107 'scan_mode' 108 ] 109 indices = [2, 4, 6, 8, 10, 11] 110 self.decode_test_configs(attrs, indices) 111 if self.test_configs.wifi_status == 'Disconnected': 112 self.setup_ap_connection( 113 self.main_network[self.test_configs.wifi_band], connect=False) 114 elif self.test_configs.wifi_status == 'Connected': 115 self.setup_ap_connection( 116 self.main_network[self.test_configs.wifi_band]) 117 else: 118 wutils.wifi_toggle_state(self.dut, True) 119 if self.test_configs.screen_status == 'OFF': 120 self.dut.droid.goToSleepNow() 121 self.dut.log.info('Screen is OFF') 122 time.sleep(2) 123 self.scan_setup() 124 self.measure_power_and_validate() 125 126 def chre_wifi_scan_test_func(self): 127 attrs = [ 128 'screen_status', 'wifi_scan_type', 'wifi_radio_chain', 'wifi_channel_set' 129 ] 130 indices = [2, 6, 7, 8] 131 self.decode_test_configs(attrs, indices) 132 wutils.wifi_toggle_state(self.dut, True) 133 if self.test_configs.screen_status == 'OFF': 134 self.dut.droid.goToSleepNow() 135 self.dut.log.info('Screen is OFF') 136 time.sleep(5) 137 self.chre_scan_setup() 138 self.measure_power_and_validate() 139 self.dut.adb.shell(DISABLE_CHRE_WIFI_SCAN) 140 self.dut.adb.shell(ENABLE_WIFI_SCANNING) 141 142 # Test cases 143 # Power.apk triggered singleshot scans 144 @test_tracker_info(uuid='e5539b01-e208-43c6-bebf-6f1e73d8d8cb') 145 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_high_scan_apk_singleshot( 146 self): 147 self.wifi_scan_test_func() 148 149 @test_tracker_info(uuid='14c5a762-95bc-40ea-9fd4-27126df7d86c') 150 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_low_scan_apk_singleshot( 151 self): 152 self.wifi_scan_test_func() 153 154 @test_tracker_info(uuid='a6506600-c567-43b5-9c25-86b505099b97') 155 def test_screen_OFF_WiFi_Disconnected_band_2g_RSSI_none_scan_apk_singleshot( 156 self): 157 self.wifi_scan_test_func() 158 159 @test_tracker_info(uuid='1a458248-1159-4c8e-a39f-92fc9e69c4dd') 160 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_high_scan_apk_singleshot( 161 self): 162 self.wifi_scan_test_func() 163 164 @test_tracker_info(uuid='bd4da426-a621-4131-9f89-6e5a77f321d2') 165 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_low_scan_apk_singleshot( 166 self): 167 self.wifi_scan_test_func() 168 169 @test_tracker_info(uuid='288b3add-8925-4803-81c0-53debf157ffc') 170 def test_screen_OFF_WiFi_Disconnected_band_5g_RSSI_none_scan_apk_singleshot( 171 self): 172 self.wifi_scan_test_func() 173 174 # Firmware/framework scans 175 @test_tracker_info(uuid='ff5ea952-ee31-4968-a190-82935ce7a8cb') 176 def test_screen_OFF_WiFi_ON_band_5g_RSSI_high_scan_system_connectivity( 177 self): 178 """WiFi disconected, turn on Screen to trigger connectivity scans. 179 180 """ 181 self.wifi_scan_test_func() 182 183 @test_tracker_info(uuid='9a836e5b-8128-4dd2-8e96-e79177810bdd') 184 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_connectivity( 185 self): 186 """WiFi connected to 2g, turn on screen to trigger connectivity scans. 187 188 """ 189 self.wifi_scan_test_func() 190 191 @test_tracker_info(uuid='51e3c4f1-742b-45af-afd5-ae3552a03272') 192 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_roaming( 193 self): 194 """WiFi connected to 2g, low RSSI to be below roaming threshold. 195 196 """ 197 self.wifi_scan_test_func() 198 199 @test_tracker_info(uuid='a16ae337-326f-4d09-990f-42232c3c0dc4') 200 def test_screen_OFF_WiFi_Connected_band_2g_RSSI_high_scan_system_pno(self): 201 """WiFi connected to 2g, trigger pno scan. 202 203 """ 204 self.wifi_scan_test_func() 205 206 def test_screen_OFF_CHRE_wifi_scan_activePassiveDfs_highAccuracy_all(self): 207 """ 208 Trigger CHRE based scan for the following parameters : 209 wifi_scan_type : activePassiveDfs 210 wifi_radio_chain : highAccuracy 211 wifi_channel_set : all 212 """ 213 self.chre_wifi_scan_test_func() 214 215 216 def test_screen_OFF_CHRE_wifi_scan_activePassiveDfs_lowLatency_all(self): 217 """ 218 Trigger CHRE based scan for the following parameters : 219 wifi_scan_type : activePassiveDfs 220 wifi_radio_chain : lowLatency 221 wifi_channel_set : all 222 """ 223 self.chre_wifi_scan_test_func() 224 225 226 def test_screen_OFF_CHRE_wifi_scan_noPreference_lowPower_all(self): 227 """ 228 Trigger CHRE based scan for the following parameters : 229 wifi_scan_type : noPreference 230 wifi_radio_chain : lowPower 231 wifi_channel_set : all 232 """ 233 self.chre_wifi_scan_test_func() 234 235 236 def test_screen_OFF_CHRE_wifi_scan_passive_lowLatency_all(self): 237 """ 238 Trigger CHRE based scan for the following parameters : 239 wifi_scan_type : passive 240 wifi_radio_chain : lowLatency 241 wifi_channel_set : all 242 """ 243 self.chre_wifi_scan_test_func() 244 245 246 def test_screen_OFF_CHRE_wifi_scan_passive_highAccuracy_all(self): 247 """ 248 Trigger CHRE based scan for the following parameters : 249 wifi_scan_type : passive 250 wifi_radio_chain : highAccuracy 251 wifi_channel_set : all 252 """ 253 self.chre_wifi_scan_test_func()