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_power_test_utils as wputils 21from acts.controllers.adb_lib.error import AdbCommandError 22 23 24class PowerWiFidtimTest(PWBT.PowerWiFiBaseTest): 25 def dtim_test_func(self, dtim_max=10): 26 """A reusable function for DTIM test. 27 Covering different DTIM value, with screen ON or OFF and 2g/5g network 28 29 Args: 30 dtim: the value for DTIM set on the phone 31 screen_status: screen on or off 32 network: a dict of information for the network to connect 33 """ 34 attrs = ['screen_status', 'wifi_band', 'dtim'] 35 indices = [2, 4, 6] 36 self.decode_test_configs(attrs, indices) 37 38 # Starts from P21 device, the dtim setting method is changed to use adb. 39 # If no file match '/vendor/firmware/wlan/*/*.ini', use adb to change 40 # the dtim. 41 change_dtim_with_adb = False 42 try: 43 self.dut.adb.shell('ls /vendor/firmware/wlan/*/*.ini') 44 except AdbCommandError as e: 45 change_dtim_with_adb = True 46 47 if not change_dtim_with_adb: 48 # Initialize the dut to rock-bottom state 49 rebooted = wputils.change_dtim( 50 self.dut, 51 gEnableModulatedDTIM=int(self.test_configs.dtim), 52 gMaxLIModulatedDTIM=dtim_max) 53 if rebooted: 54 self.dut_rockbottom() 55 self.dut.log.info('DTIM value of the phone is now {}'.format( 56 self.test_configs.dtim)) 57 self.setup_ap_connection(self.main_network[self.test_configs.wifi_band]) 58 59 if change_dtim_with_adb: 60 self.dut.log.info('No ini file for dtim, change dtim with adb') 61 wputils.change_dtim_adb( 62 self.dut, 63 gEnableModulatedDTIM=int(self.test_configs.dtim)) 64 65 if self.test_configs.screen_status == 'OFF': 66 self.dut.droid.goToSleepNow() 67 self.dut.log.info('Screen is OFF') 68 time.sleep(5) 69 self.measure_power_and_validate() 70 71 # Test cases 72 @test_tracker_info(uuid='b6c4114d-984a-4269-9e77-2bec0e4b6e6f') 73 def test_screen_OFF_band_2g_dtim_2(self): 74 self.dtim_test_func() 75 76 @test_tracker_info(uuid='384d3b0f-4335-4b00-8363-308ec27a150c') 77 def test_screen_OFF_band_2g_dtim_8(self): 78 self.dtim_test_func() 79 80 def test_screen_OFF_band_2g_dtim_9(self): 81 self.dtim_test_func() 82 83 @test_tracker_info(uuid='017f57c3-e133-461d-80be-d025d1491d8a') 84 def test_screen_OFF_band_5g_dtim_2(self): 85 self.dtim_test_func() 86 87 @test_tracker_info(uuid='327af44d-d9e7-49e0-9bda-accad6241dc7') 88 def test_screen_OFF_band_5g_dtim_8(self): 89 self.dtim_test_func() 90 91 def test_screen_OFF_band_5g_dtim_9(self): 92 self.dtim_test_func() 93