Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright 2017 - The Android Open Source Project |
| 4 | # |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 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 |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 12 | # distributed under the License is distributed on an 'AS IS' BASIS, |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 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 | |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 17 | import logging |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 18 | import os |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 19 | from acts import base_test |
Qi Jiang | c64e51b | 2018-02-09 04:02:47 +0000 | [diff] [blame] | 20 | from acts import utils |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 21 | from acts.test_utils.wifi import wifi_test_utils as wutils |
| 22 | from acts.test_utils.wifi import wifi_power_test_utils as wputils |
| 23 | from acts.test_decorators import test_tracker_info |
| 24 | |
| 25 | |
| 26 | class 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 Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 35 | |
| 36 | def setup_class(self): |
| 37 | |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 38 | self.log = logging.getLogger() |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 39 | self.dut = self.android_devices[0] |
Qi Jiang | 9bbaee6 | 2018-03-23 00:03:18 +0000 | [diff] [blame] | 40 | req_params = ['baselinetest_params', 'custom_files'] |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 41 | self.unpack_userparams(req_params) |
| 42 | self.unpack_testparams(self.baselinetest_params) |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 43 | self.mon_data_path = os.path.join(self.log_path, 'Monsoon') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 44 | self.mon = self.monsoons[0] |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 45 | self.mon.set_max_current(8.0) |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 46 | self.mon.set_voltage(4.2) |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 47 | self.mon.attach_device(self.dut) |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 48 | self.mon_info = wputils.create_monsoon_info(self) |
Qi Jiang | 9bbaee6 | 2018-03-23 00:03:18 +0000 | [diff] [blame] | 49 | for file in self.custom_files: |
Qi Jiang | 6441fb2 | 2018-04-19 20:26:27 +0000 | [diff] [blame] | 50 | if 'pass_fail_threshold' in file: |
Qi Jiang | 9bbaee6 | 2018-03-23 00:03:18 +0000 | [diff] [blame] | 51 | self.threshold_file = file |
| 52 | self.threshold = wputils.unpack_custom_file(self.threshold_file, |
| 53 | self.TAG) |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 54 | |
| 55 | def teardown_class(self): |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 56 | """Tearing down the entire test class. |
Qi Jiang | 7f6dc98 | 2018-02-24 01:29:29 +0000 | [diff] [blame] | 57 | |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 58 | """ |
| 59 | self.log.info('Tearing down the test class') |
| 60 | self.mon.usb('on') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 61 | |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 62 | def teardown_test(self): |
| 63 | """Tearing down the test case. |
Qi Jiang | 7f6dc98 | 2018-02-24 01:29:29 +0000 | [diff] [blame] | 64 | |
Qi Jiang | 9279b9a | 2018-02-07 04:50:29 +0000 | [diff] [blame] | 65 | """ |
| 66 | self.log.info('Tearing down the test') |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 67 | self.mon.usb('on') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 68 | |
| 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 Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 78 | 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 Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 87 | if wifi_status == 'ON': |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 88 | wutils.wifi_toggle_state(self.dut, True) |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 89 | if screen_status == 'OFF': |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 90 | self.dut.droid.goToSleepNow() |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 91 | self.dut.log.info('Screen is OFF') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 92 | # Collecting current measurement data and plot |
Qi Jiang | c64e51b | 2018-02-09 04:02:47 +0000 | [diff] [blame] | 93 | begin_time = utils.get_current_epoch_time() |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 94 | file_path, avg_current = wputils.monsoon_data_collect_save( |
Qi Jiang | c64e51b | 2018-02-09 04:02:47 +0000 | [diff] [blame] | 95 | self.dut, self.mon_info, self.current_test_name) |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 96 | wputils.monsoon_data_plot(self.mon_info, file_path) |
Qi Jiang | c64e51b | 2018-02-09 04:02:47 +0000 | [diff] [blame] | 97 | # Take Bugreport |
| 98 | if bool(self.bug_report) == True: |
| 99 | self.dut.take_bug_report(self.test_name, begin_time) |
Qi Jiang | a4fcfdc | 2017-09-18 20:05:26 +0000 | [diff] [blame] | 100 | wputils.pass_fail_check(self, avg_current) |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 101 | |
| 102 | # Test cases |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 103 | @test_tracker_info(uuid='e7ab71f4-1e14-40d2-baec-cde19a3ac859') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 104 | def test_rockbottom_screenoff_wifidisabled(self): |
| 105 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 106 | self.rockbottom_test_func('OFF', 'OFF') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 107 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 108 | @test_tracker_info(uuid='167c847d-448f-4c7c-900f-82c552d7d9bb') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 109 | def test_rockbottom_screenoff_wifidisconnected(self): |
| 110 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 111 | self.rockbottom_test_func('OFF', 'ON') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 112 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 113 | @test_tracker_info(uuid='2cd25820-8548-4e60-b0e3-63727b3c952c') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 114 | def test_rockbottom_screenon_wifidisabled(self): |
| 115 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 116 | self.rockbottom_test_func('ON', 'OFF') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 117 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 118 | @test_tracker_info(uuid='d7d90a1b-231a-47c7-8181-23814c8ff9b6') |
Qi Jiang | 73b2535 | 2017-08-02 19:56:31 +0000 | [diff] [blame] | 119 | def test_rockbottom_screenon_wifidisconnected(self): |
| 120 | |
Qi Jiang | 0f280b0 | 2017-10-12 01:31:41 +0000 | [diff] [blame] | 121 | self.rockbottom_test_func('ON', 'ON') |