• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import time
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.server import autotest, test
10from autotest_lib.server.cros.servo import chrome_cr50
11from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
12
13
14class firmware_Cr50DeepSleepStress(FirmwareTest):
15    """Verify cr50 deep sleep after running power_SuspendStress.
16
17    Cr50 should enter deep sleep every suspend. Verify that by checking the
18    idle deep sleep count.
19
20    @param duration: Total time to spend running power_SuspendStress.
21            suspend_iterations will take priority if it is set to some
22            non-zero value.
23    @param suspend_iterations: The number of iterations to run for
24            power_SuspendStress.
25    """
26    version = 1
27
28    SLEEP_DELAY = 20
29    MIN_RESUME = 15
30    MIN_SUSPEND = 15
31    MEM = "mem"
32
33    def initialize(self, host, cmdline_args):
34        super(firmware_Cr50DeepSleepStress, self).initialize(host, cmdline_args)
35        if not hasattr(self, "cr50"):
36          raise error.TestError('Test needs to be run through CCD')
37
38    def check_deep_sleep_count(self):
39        self.cr50.ccd_enable()
40        count = self.cr50.get_deep_sleep_count()
41        logging.debug("Cr50 resumed from sleep %d times", count)
42        return count
43
44    def cleanup(self):
45        self.check_deep_sleep_count()
46        super(firmware_Cr50DeepSleepStress, self).cleanup()
47
48    def run_once(self, host, duration=600, suspend_iterations=0):
49        self.cr50.send_command('sysrst pulse')
50
51        if self.MIN_SUSPEND + self.MIN_RESUME < self.SLEEP_DELAY:
52            logging.info("Minimum suspend-resume cycle is %ds. This is " \
53                         "shorter than the Cr50 idle timeout. Cr50 may not " \
54                         "enter deep sleep every cycle",
55                         self.MIN_SUSPEND + self.MIN_RESUME)
56
57        # Clear the deep sleep count
58        logging.info("Clear Cr50 deep sleep count")
59        self.cr50.clear_deep_sleep_count()
60        # Disable CCD so Cr50 can enter deep sleep
61        logging.info("Disable CCD")
62        self.cr50.ccd_disable()
63
64        self.client_at = autotest.Autotest(host)
65        suspend_iterations = suspend_iterations if suspend_iterations else None
66
67        self.client_at.run_test('power_SuspendStress', tag="idle",
68                                duration=duration,
69                                min_suspend=self.MIN_SUSPEND,
70                                min_resume=self.MIN_RESUME,
71                                check_connection=False,
72                                iterations=suspend_iterations,
73                                suspend_state=self.MEM)
74
75        count = self.check_deep_sleep_count()
76        if suspend_iterations:
77            logging.info("After %d suspend-resume cycles Cr50 entered deep " \
78                         "sleep %d times." % (suspend_iterations, count))
79            if count != suspend_iterations:
80                raise error.TestFail("Cr50 deep sleep count, %d, did not " \
81                                     "match suspend count, %d" %
82                                     (count, suspend_iterations))
83        else:
84            logging.info("During the %ds test Cr50 entered deep sleep %d " \
85                         "times" % (duration, count))
86