Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 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 | |
| 5 | '''Login with test account and display chart file using telemetry.''' |
| 6 | |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 7 | import argparse |
| 8 | import contextlib |
| 9 | import logging |
| 10 | import os |
| 11 | import signal |
| 12 | import time |
| 13 | |
Kuo Jen Wei | db663ea | 2020-03-13 16:39:15 +0800 | [diff] [blame^] | 14 | # Set chart process preferred logging format before overridden by importing |
| 15 | # common package. |
| 16 | logging.basicConfig( |
| 17 | level=logging.DEBUG, |
| 18 | format='%(asctime)s - %(levelname)s - %(message)s') |
| 19 | |
| 20 | # This sets up import paths for autotest. |
| 21 | import common |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 22 | from autotest_lib.client.bin import utils |
| 23 | from autotest_lib.client.common_lib.cros import chrome |
| 24 | from autotest_lib.client.cros.input_playback import keyboard |
| 25 | |
| 26 | DISPLAY_LEVEL = 96.0 |
| 27 | |
| 28 | |
| 29 | @contextlib.contextmanager |
| 30 | def set_display_brightness(display_level): |
| 31 | SET_BRIGHTNESS_CMD = 'backlight_tool --set_brightness_percent=%s' |
| 32 | |
| 33 | original_display_level = utils.system_output( |
| 34 | 'backlight_tool --get_brightness_percent') |
| 35 | logging.info('Save original display brightness %r ' |
| 36 | 'and fix display brightness to %r', original_display_level, |
| 37 | display_level) |
| 38 | utils.system(SET_BRIGHTNESS_CMD % display_level) |
| 39 | utils.system('stop powerd', ignore_status=True) |
| 40 | yield |
| 41 | logging.info('Restore display brightness %r', original_display_level) |
| 42 | utils.system('start powerd', ignore_status=True) |
| 43 | utils.system(SET_BRIGHTNESS_CMD % original_display_level) |
| 44 | |
| 45 | |
| 46 | def display(filepath): |
| 47 | """Display chart with filepath on device by using telemetry.""" |
| 48 | assert os.path.isfile(filepath), 'filepath %r not found.' % filepath |
| 49 | filepath = os.path.abspath(filepath) |
| 50 | |
| 51 | logging.info('Setup SIGINT listener for stop displaying.') |
| 52 | displaying = [True] |
| 53 | |
| 54 | def handler(signum, frame): |
| 55 | """Wait signal to clear running flag.""" |
| 56 | if signum == signal.SIGINT: |
| 57 | displaying.pop() |
| 58 | |
| 59 | signal.signal(signal.SIGINT, handler) |
| 60 | |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 61 | with chrome.Chrome(init_network_controller=True |
| 62 | ) as cr, set_display_brightness(DISPLAY_LEVEL): |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 63 | logging.info('Display chart file of path %r.', filepath) |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 64 | cr.browser.platform.SetHTTPServerDirectories(os.path.dirname(filepath)) |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 65 | tab = cr.browser.tabs[0] |
Kuo Jen Wei | 377e99b | 2020-02-25 16:39:42 +0800 | [diff] [blame] | 66 | tab.Navigate(cr.browser.platform.http_server.UrlOf(filepath)) |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 67 | |
| 68 | logging.info('Set chart tab fullscreen.') |
| 69 | kb = keyboard.Keyboard() |
| 70 | kb.press_key('f4') |
| 71 | kb.close() |
| 72 | |
Kuo Jen Wei | db663ea | 2020-03-13 16:39:15 +0800 | [diff] [blame^] | 73 | logging.info('Chart is ready.') |
Kuo Jen Wei | 7f00bb3 | 2018-11-01 15:35:24 +0800 | [diff] [blame] | 74 | while displaying: |
| 75 | time.sleep(1) |
| 76 | |
| 77 | |
| 78 | if __name__ == '__main__': |
| 79 | argparser = argparse.ArgumentParser( |
| 80 | description='Display chart file on chrome by using telemetry.' |
| 81 | ' Send SIGINT or keyboard interrupt to stop displaying.') |
| 82 | argparser.add_argument('filepath', help='Path of displayed chart file.') |
| 83 | |
| 84 | args = argparser.parse_args() |
| 85 | display(args.filepath) |