1 # Copyright 2018 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 import logging 5 import os 6 import time 7 8 from autotest_lib.client.common_lib import error 9 from autotest_lib.client.common_lib.cros import chrome 10 from autotest_lib.client.cros.input_playback import keyboard 11 from autotest_lib.client.cros.power import power_test 12 13 class power_Display(power_test.power_Test): 14 """class for power_Display test. 15 """ 16 version = 1 17 18 # TODO(tbroch) find more patterns that typical display vendors use to show 19 # average and worstcase display power. 20 PAGES = ['checker1', 'black', 'white', 'red', 'green', 'blue'] 21 def run_once(self, pages=None, secs_per_page=60, brightness=''): 22 """run_once method. 23 24 @param pages: list of pages names that must be in 25 <testdir>/html/<name>.html 26 @param secs_per_page: time in seconds to display page and measure power. 27 @param brightness: flag for brightness setting to use for testing. 28 possible value are 'max' (100%) and 'all' (all manual 29 brightness steps in Chrome OS) 30 """ 31 if pages is None: 32 pages = self.PAGES 33 34 with chrome.Chrome(init_network_controller=True) as self.cr: 35 http_path = os.path.join(self.job.testdir, 'power_Display', 'html') 36 self.cr.browser.platform.SetHTTPServerDirectories(http_path) 37 tab = self.cr.browser.tabs.New() 38 tab.Activate() 39 40 # Just measure power in full-screen. 41 fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen') 42 if not fullscreen: 43 with keyboard.Keyboard() as keys: 44 keys.press_key('f4') 45 46 if brightness not in ['', 'all', 'max']: 47 raise error.TestFail( 48 'Invalid brightness flag: %s' % (brightness)) 49 50 if brightness == 'max': 51 self.backlight.set_percent(100) 52 53 brightnesses = [] 54 if brightness == 'all': 55 self.backlight.set_percent(100) 56 for step in range(16, 0, -1): 57 nonlinear = step * 6.25 58 linear = self.backlight.nonlinear_to_linear(nonlinear) 59 brightnesses.append((nonlinear, linear)) 60 else: 61 linear = self.backlight.get_percent() 62 nonlinear = self.backlight.linear_to_nonlinear(linear) 63 brightnesses.append((nonlinear, linear)) 64 65 self.start_measurements() 66 67 loop = 0 68 for name in pages: 69 url = os.path.join(http_path, name + '.html') 70 logging.info('Navigating to url: %s', url) 71 tab.Navigate(self.cr.browser.platform.http_server.UrlOf(url)) 72 tab.WaitForDocumentReadyStateToBeComplete() 73 74 for nonlinear, linear in brightnesses: 75 self.backlight.set_percent(linear) 76 tagname = '%s_%s' % (self.tagged_testname, name) 77 if len(brightnesses) > 1: 78 tagname += '_%.2f' % (nonlinear) 79 loop_start = time.time() 80 self.loop_sleep(loop, secs_per_page) 81 self.checkpoint_measurements(tagname, loop_start) 82 loop += 1 83