1# Copyright (c) 2014 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.common_lib import error 6from autotest_lib.server import autotest, test 7 8 9class power_BrightnessResetAfterReboot(test.test): 10 """Tests for default brightness level after rebooting the device. 11 """ 12 version = 1 13 14 GET_BRIGHTNESS_FLAG = '--get_brightness_percent' 15 SET_BRIGHTNESS_FLAG = '--set_brightness_percent' 16 17 def run_once(self, host, client_autotest): 18 """This test verify that user should get default brightness 19 after rebooting the device with maximum brigntness level. 20 """ 21 if host.has_internal_display() is None: 22 raise error.TestNAError('Test can not processed on ' 23 'devices without internal display') 24 autotest_client = autotest.Autotest(host) 25 host.reboot() 26 autotest_client.run_test(client_autotest, 27 exit_without_logout=True) 28 29 initial_bright = self.backlight_control(self.GET_BRIGHTNESS_FLAG, 30 host) 31 32 if initial_bright < 10.0 or initial_bright > 90.0: 33 raise error.TestFail('Default brightness level is out ' 34 'of scope(10% - 90%): %f' 35 %(initial_bright)) 36 37 self.backlight_control('%s=0' % (self.SET_BRIGHTNESS_FLAG), host) 38 if not self.backlight_control(self.GET_BRIGHTNESS_FLAG, host) == 0: 39 raise error.TestFail('Not able to change the brightness ' 40 'to minum(0%) level') 41 self.backlight_control('%s=100' % (self.SET_BRIGHTNESS_FLAG), host) 42 if not self.backlight_control(self.GET_BRIGHTNESS_FLAG, host) == 100: 43 raise error.TestFail('Not able to change the brightness ' 44 'to maximum(100%) level') 45 46 host.reboot() 47 autotest_client.run_test(client_autotest, 48 exit_without_logout=True) 49 bright_after_reboot = self.backlight_control(self.GET_BRIGHTNESS_FLAG, 50 host) 51 if not initial_bright == bright_after_reboot: 52 raise error.TestFail('Not able to reset default brightness\n' 53 'Previous boot default brightness: %f\n' 54 'Current boot default brightness: %f' 55 % (initial_bright, bright_after_reboot)) 56 57 58 def backlight_control(self, arg_str, host): 59 """Executes backlight_tool with arguments passed through arg_str. 60 Two functions are used: 61 - sets the brightness percentage to a given level 62 - gets the brightness percentage and returns a float value 63 @param arg_str: Command argument to set/get the backlight. 64 @param host: host object representing the DUT. 65 """ 66 cmd = 'backlight_tool %s' % (arg_str) 67 try: 68 result = host.run(cmd).stdout.rstrip() 69 except error.CmdError: 70 raise error.TestFail(cmd) 71 if result: 72 return float(result) 73