• 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.faft.firmware_test import FirmwareTest
11
12
13class firmware_Cr50DeepSleepStress(FirmwareTest):
14    """Verify cr50 deep sleep after running power_SuspendStress.
15
16    Cr50 should enter deep sleep every suspend. Verify that by checking the
17    idle deep sleep count.
18
19    @param duration: Total time to spend running power_SuspendStress.
20            suspend_iterations will take priority if it is set to some
21            non-zero value.
22    @param suspend_iterations: The number of iterations to run for
23            power_SuspendStress.
24    """
25    version = 1
26
27    SLEEP_DELAY = 20
28    MIN_RESUME = 15
29    MIN_SUSPEND = 15
30    MEM = "mem"
31
32    def initialize(self, host, cmdline_args):
33        super(firmware_Cr50DeepSleepStress, self).initialize(host, cmdline_args)
34        if not hasattr(self, "cr50"):
35            raise error.TestNAError('Test can only be run on devices with '
36                                    'access to the Cr50 console')
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 deep 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        self.cr50.ccd_disable()
62
63        self.client_at = autotest.Autotest(host)
64        suspend_iterations = suspend_iterations if suspend_iterations else None
65
66        self.client_at.run_test('power_SuspendStress', tag="idle",
67                                duration=duration,
68                                min_suspend=self.MIN_SUSPEND,
69                                min_resume=self.MIN_RESUME,
70                                check_connection=False,
71                                iterations=suspend_iterations,
72                                suspend_state=self.MEM)
73
74        count = self.check_deep_sleep_count()
75        if suspend_iterations:
76            logging.info("After %d suspend-resume cycles Cr50 entered deep " \
77                         "sleep %d times." % (suspend_iterations, count))
78            if count != suspend_iterations:
79                raise error.TestFail("Cr50 deep sleep count, %d, did not " \
80                                     "match suspend count, %d" %
81                                     (count, suspend_iterations))
82        else:
83            logging.info("During the %ds test Cr50 entered deep sleep %d " \
84                         "times" % (duration, count))
85