1#!/usr/bin/env python3
2#
3#   Copyright 2019 - 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 acts.test_utils.power.PowerGnssBaseTest as GBT
18from acts.test_utils.gnss import dut_log_test_utils as diaglog
19from acts.test_utils.gnss import gnss_test_utils as gutil
20import time
21import os
22from acts import utils
23MDLOG_RUNNING_TIME = 300
24DUT_ACTION_WAIT_TIME = 2
25
26class PowerGnssDpoSimTest(GBT.PowerGnssBaseTest):
27    """Power baseline tests for rockbottom state.
28    Rockbottom for GNSS on/off, screen on/off, everything else turned off
29
30    """
31
32    def measure_gnsspower_test_func(self):
33        """Test function for baseline rockbottom tests.
34
35        Decode the test config from the test name, set device to desired state.
36        Measure power and plot results.
37        """
38        result = self.collect_power_data()
39        self.pass_fail_check(result.average_current)
40
41    # Test cases
42    def test_gnss_dpoOFF_measurement(self):
43        utils.set_location_service(self.dut, True)
44        time.sleep(DUT_ACTION_WAIT_TIME)
45        gutil.start_gnss_by_gtw_gpstool(self.dut, state=True, type="gnss", bgdisplay=True)
46        self.dut.send_keycode("SLEEP")
47        time.sleep(DUT_ACTION_WAIT_TIME)
48        self.measure_gnsspower_test_func()
49        diaglog.start_diagmdlog_background(self.dut, maskfile=self.maskfile)
50        self.disconnect_usb(self.dut, MDLOG_RUNNING_TIME)
51        qxdm_log_path = os.path.join(self.log_path, 'QXDM')
52        diaglog.stop_background_diagmdlog(self.dut, qxdm_log_path)
53        gutil.start_gnss_by_gtw_gpstool(self.dut, state=False)
54
55    def test_gnss_dpoON_measurement(self):
56        utils.set_location_service(self.dut, True)
57        time.sleep(DUT_ACTION_WAIT_TIME)
58        gutil.start_gnss_by_gtw_gpstool(self.dut, state=True, type="gnss", bgdisplay=True)
59        self.dut.send_keycode("SLEEP")
60        time.sleep(DUT_ACTION_WAIT_TIME)
61        self.measure_gnsspower_test_func()
62        diaglog.start_diagmdlog_background(self.dut, maskfile=self.maskfile)
63        self.disconnect_usb(self.dut, MDLOG_RUNNING_TIME)
64        qxdm_log_path = os.path.join(self.log_path, 'QXDM')
65        diaglog.stop_background_diagmdlog(self.dut, qxdm_log_path)
66        gutil.start_gnss_by_gtw_gpstool(self.dut, state=False)
67
68    def test_gnss_rockbottom(self):
69        self.dut.send_keycode("SLEEP")
70        time.sleep(120)
71        self.measure_gnsspower_test_func()
72