• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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 random, time
6
7from autotest_lib.client.bin import test
8from autotest_lib.client.cros import sys_power
9
10
11# Suspend tests need to allow time for the kernel to settle.
12MIN_ALLOWED_SUSPEND_S = 10
13
14
15class power_CheckAfterSuspend(test.test):
16    """Checks capabilities by running tests after suspend/resume cycle.
17
18    This can easily run multiple iterations with the built in Autotest
19    iterations parameter to run_test():
20
21      test_that -b <board> --iterations=3 ${MACHINE_IP} \
22          f:client/site_tests/power_CheckAfterSuspend/control
23    """
24    version = 1
25
26
27    def initialize(self, tests=[], min_suspend_s=2, enable_baseline=False):
28        """
29        @param tests: list of client tests to run before/after suspend.
30        @param min_suspend_s: suspend durations (in seconds).
31        @param enable_baseline: If True, run one pass of tests before suspend,
32                                otherwise only run tests after suspend.
33        """
34        self._tests = tests
35        self._min_suspend_s = min_suspend_s
36        self._enable_baseline = enable_baseline
37
38
39    def run_once(self):
40        """Run a series of tests supplied by the control file.
41
42        Handles iterations by adding tags with the iteration#.
43
44        Normally runs each test once after each suspend.  If enable_baseline
45        is True then run an initial pass through the tests before any suspend.
46
47        The test runs a series
48        """
49        if self.iteration is not None and self.iteration > 1:
50            test_tag = '%03d' % self.iteration
51        else:
52            test_tag = ''
53            if self._enable_baseline:
54                for t in self._tests:
55                    self.job.run_test(t, tag=test_tag+'preSuspend', disable_sysinfo=True)
56
57        time.sleep(random.randint(0, 3))
58        sys_power.do_suspend(max(self._min_suspend_s, MIN_ALLOWED_SUSPEND_S))
59
60        for t in self._tests:
61            self.job.run_test(t, tag=test_tag+'postSuspend', disable_sysinfo=True)
62