blob: f74f639c67d0046d336d31a0773883d9a362b0fa [file] [log] [blame]
Qi Jiang73b25352017-08-02 19:56:31 +00001#!/usr/bin/env python3.4
2#
3# Copyright 2017 - The Android Open Source Project
4#
Qi Jiang0f280b02017-10-12 01:31:41 +00005# Licensed under the Apache License, Version 2.0 (the 'License');
Qi Jiang73b25352017-08-02 19:56:31 +00006# 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
Qi Jiang0f280b02017-10-12 01:31:41 +000012# distributed under the License is distributed on an 'AS IS' BASIS,
Qi Jiang73b25352017-08-02 19:56:31 +000013# 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
Qi Jiang9279b9a2018-02-07 04:50:29 +000017import logging
Qi Jiang73b25352017-08-02 19:56:31 +000018import os
Qi Jiang73b25352017-08-02 19:56:31 +000019from acts import base_test
Qi Jiangc64e51b2018-02-09 04:02:47 +000020from acts import utils
Qi Jiang73b25352017-08-02 19:56:31 +000021from acts.test_utils.wifi import wifi_test_utils as wutils
22from acts.test_utils.wifi import wifi_power_test_utils as wputils
23from acts.test_decorators import test_tracker_info
24
25
26class PowerbaselineTest(base_test.BaseTestClass):
27 """Power baseline tests for rockbottom state.
28 Rockbottom for wifi on/off, screen on/off, everything else turned off
29
30 """
31
32 def __init__(self, controllers):
33
34 base_test.BaseTestClass.__init__(self, controllers)
Qi Jiang73b25352017-08-02 19:56:31 +000035
36 def setup_class(self):
37
Qi Jiang9279b9a2018-02-07 04:50:29 +000038 self.log = logging.getLogger()
Qi Jiang73b25352017-08-02 19:56:31 +000039 self.dut = self.android_devices[0]
Qi Jiang9bbaee62018-03-23 00:03:18 +000040 req_params = ['baselinetest_params', 'custom_files']
Qi Jiang73b25352017-08-02 19:56:31 +000041 self.unpack_userparams(req_params)
42 self.unpack_testparams(self.baselinetest_params)
Qi Jiang0f280b02017-10-12 01:31:41 +000043 self.mon_data_path = os.path.join(self.log_path, 'Monsoon')
Qi Jiang73b25352017-08-02 19:56:31 +000044 self.mon = self.monsoons[0]
Qi Jiang73b25352017-08-02 19:56:31 +000045 self.mon.set_max_current(8.0)
Qi Jiang0f280b02017-10-12 01:31:41 +000046 self.mon.set_voltage(4.2)
Qi Jiang73b25352017-08-02 19:56:31 +000047 self.mon.attach_device(self.dut)
Qi Jiang0f280b02017-10-12 01:31:41 +000048 self.mon_info = wputils.create_monsoon_info(self)
Qi Jiang9bbaee62018-03-23 00:03:18 +000049 for file in self.custom_files:
Qi Jiang6441fb22018-04-19 20:26:27 +000050 if 'pass_fail_threshold' in file:
Qi Jiang9bbaee62018-03-23 00:03:18 +000051 self.threshold_file = file
52 self.threshold = wputils.unpack_custom_file(self.threshold_file,
53 self.TAG)
Qi Jiang73b25352017-08-02 19:56:31 +000054
55 def teardown_class(self):
Qi Jiang9279b9a2018-02-07 04:50:29 +000056 """Tearing down the entire test class.
Qi Jiang7f6dc982018-02-24 01:29:29 +000057
Qi Jiang9279b9a2018-02-07 04:50:29 +000058 """
59 self.log.info('Tearing down the test class')
60 self.mon.usb('on')
Qi Jiang73b25352017-08-02 19:56:31 +000061
Qi Jiang9279b9a2018-02-07 04:50:29 +000062 def teardown_test(self):
63 """Tearing down the test case.
Qi Jiang7f6dc982018-02-24 01:29:29 +000064
Qi Jiang9279b9a2018-02-07 04:50:29 +000065 """
66 self.log.info('Tearing down the test')
Qi Jiang0f280b02017-10-12 01:31:41 +000067 self.mon.usb('on')
Qi Jiang73b25352017-08-02 19:56:31 +000068
69 def unpack_testparams(self, bulk_params):
70 """Unpack all the test specific parameters.
71
72 Args:
73 bulk_params: dict with all test specific params in the config file
74 """
75 for key in bulk_params.keys():
76 setattr(self, key, bulk_params[key])
77
Qi Jiang73b25352017-08-02 19:56:31 +000078 def rockbottom_test_func(self, screen_status, wifi_status):
79 """Test function for baseline rockbottom tests.
80
81 Args:
82 screen_status: screen on or off
83 wifi_status: wifi enable or disable, on/off, not connected even on
84 """
85 # Initialize the dut to rock-bottom state
86 wputils.dut_rockbottom(self.dut)
Qi Jiang0f280b02017-10-12 01:31:41 +000087 if wifi_status == 'ON':
Qi Jiang73b25352017-08-02 19:56:31 +000088 wutils.wifi_toggle_state(self.dut, True)
Qi Jiang0f280b02017-10-12 01:31:41 +000089 if screen_status == 'OFF':
Qi Jiang73b25352017-08-02 19:56:31 +000090 self.dut.droid.goToSleepNow()
Qi Jiang0f280b02017-10-12 01:31:41 +000091 self.dut.log.info('Screen is OFF')
Qi Jiang73b25352017-08-02 19:56:31 +000092 # Collecting current measurement data and plot
Qi Jiangc64e51b2018-02-09 04:02:47 +000093 begin_time = utils.get_current_epoch_time()
Qi Jiang73b25352017-08-02 19:56:31 +000094 file_path, avg_current = wputils.monsoon_data_collect_save(
Qi Jiangc64e51b2018-02-09 04:02:47 +000095 self.dut, self.mon_info, self.current_test_name)
Qi Jiang73b25352017-08-02 19:56:31 +000096 wputils.monsoon_data_plot(self.mon_info, file_path)
Qi Jiangc64e51b2018-02-09 04:02:47 +000097 # Take Bugreport
98 if bool(self.bug_report) == True:
99 self.dut.take_bug_report(self.test_name, begin_time)
Qi Jianga4fcfdc2017-09-18 20:05:26 +0000100 wputils.pass_fail_check(self, avg_current)
Qi Jiang73b25352017-08-02 19:56:31 +0000101
102 # Test cases
Qi Jiang0f280b02017-10-12 01:31:41 +0000103 @test_tracker_info(uuid='e7ab71f4-1e14-40d2-baec-cde19a3ac859')
Qi Jiang73b25352017-08-02 19:56:31 +0000104 def test_rockbottom_screenoff_wifidisabled(self):
105
Qi Jiang0f280b02017-10-12 01:31:41 +0000106 self.rockbottom_test_func('OFF', 'OFF')
Qi Jiang73b25352017-08-02 19:56:31 +0000107
Qi Jiang0f280b02017-10-12 01:31:41 +0000108 @test_tracker_info(uuid='167c847d-448f-4c7c-900f-82c552d7d9bb')
Qi Jiang73b25352017-08-02 19:56:31 +0000109 def test_rockbottom_screenoff_wifidisconnected(self):
110
Qi Jiang0f280b02017-10-12 01:31:41 +0000111 self.rockbottom_test_func('OFF', 'ON')
Qi Jiang73b25352017-08-02 19:56:31 +0000112
Qi Jiang0f280b02017-10-12 01:31:41 +0000113 @test_tracker_info(uuid='2cd25820-8548-4e60-b0e3-63727b3c952c')
Qi Jiang73b25352017-08-02 19:56:31 +0000114 def test_rockbottom_screenon_wifidisabled(self):
115
Qi Jiang0f280b02017-10-12 01:31:41 +0000116 self.rockbottom_test_func('ON', 'OFF')
Qi Jiang73b25352017-08-02 19:56:31 +0000117
Qi Jiang0f280b02017-10-12 01:31:41 +0000118 @test_tracker_info(uuid='d7d90a1b-231a-47c7-8181-23814c8ff9b6')
Qi Jiang73b25352017-08-02 19:56:31 +0000119 def test_rockbottom_screenon_wifidisconnected(self):
120
Qi Jiang0f280b02017-10-12 01:31:41 +0000121 self.rockbottom_test_func('ON', 'ON')