• 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
5from autotest_lib.client.bin import test
6from autotest_lib.client.common_lib import error
7from autotest_lib.client.cros.power import power_utils, sys_power
8
9
10class power_BacklightSuspend(test.test):
11    """class power_BacklightSuspend."""
12
13    version = 1
14
15    def run_once(self, resume_percent=70, suspend_state='mem'):
16        results = {}
17        backlight = power_utils.Backlight()
18
19        results['initial_brightness'] = backlight.get_level()
20        max_level = backlight.get_max_level()
21        resume_level = int(round(max_level * resume_percent / 100))
22
23        # If the current brightness is the same as the requested brightness,
24        # request 100 - |resume_brightness| instead.
25        if resume_level == results['initial_brightness']:
26            resume_level = max_level - resume_level
27        backlight.set_resume_level(resume_level)
28
29        sys_power.kernel_suspend(seconds=10, state=suspend_state)
30
31        final_level = backlight.get_level()
32        if final_level != resume_level:
33            raise error.TestFail(
34                ('Brightness level after resume did not match requested ' + \
35                 'brightness: %d vs %d') % (final_level, resume_level))
36
37        results['resume_brightness'] = resume_level
38        self.write_perf_keyval(results)
39