1# Copyright (c) 2017 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.cros.power import power_dashboard 6 7class ServerTestDashboard(power_dashboard.BaseDashboard): 8 """Dashboard class for autotests that run on server side. 9 """ 10 11 def __init__(self, logger, testname, host, start_ts=None, resultsdir=None, 12 uploadurl=None, note=''): 13 """Create ServerTestDashboard objects. 14 15 Args: 16 logger: object that store the log. This will get convert to 17 dictionary by self._convert() 18 testname: name of current test 19 resultsdir: directory to save the power json 20 uploadurl: url to upload power data 21 host: autotest_lib.server.hosts.cros_host.CrosHost object of DUT 22 note: note for current test run 23 """ 24 25 self._host = host 26 self._note = note 27 super(ServerTestDashboard, self).__init__(logger, testname, start_ts, 28 resultsdir, uploadurl) 29 30 def _create_dut_info_dict(self, power_rails): 31 """Create a dictionary that contain information of the DUT. 32 33 Args: 34 power_rails: list of measured power rails 35 36 Returns: 37 DUT info dictionary 38 """ 39 40 board = self._host.get_board().replace('board:', '') 41 platform = self._host.get_platform() 42 43 if not platform.startswith(board): 44 board += '_' + platform 45 46 if self._host.has_hammer(): 47 board += '_hammer' 48 49 dut_info_dict = { 50 'board': board, 51 'version': { 52 'hw': self._host.get_hardware_revision(), 53 'milestone': self._host.get_chromeos_release_milestone(), 54 'os': self._host.get_release_version(), 55 'channel': self._host.get_channel(), 56 'firmware': self._host.get_firmware_version(), 57 'ec': self._host.get_ec_version(), 58 'kernel': self._host.get_kernel_version(), 59 }, 60 'sku' : { 61 'cpu': self._host.get_cpu_name(), 62 'memory_size': self._host.get_mem_total_gb(), 63 'storage_size': self._host.get_disk_size_gb(), 64 'display_resolution': self._host.get_screen_resolution(), 65 }, 66 'ina': { 67 'version': 0, 68 'ina': power_rails, 69 }, 70 'note': self._note, 71 } 72 73 if self._host.has_battery(): 74 # Round the battery size to nearest tenth because it is fluctuated 75 # for platform without battery nominal voltage data. 76 dut_info_dict['sku']['battery_size'] = round( 77 self._host.get_battery_size(), 1) 78 dut_info_dict['sku']['battery_shutdown_percent'] = \ 79 self._host.get_low_battery_shutdown_percent() 80 return dut_info_dict 81 82class PowerTelemetryLoggerDashboard(ServerTestDashboard): 83 """Dashboard class for power_telemetry_logger.PowerTelemetryLogger class. 84 """ 85 86 def __init__(self, logger, testname, host, start_ts, checkpoint_logger, 87 resultsdir=None, uploadurl=None, note=''): 88 if uploadurl is None: 89 uploadurl = 'http://chrome-power.appspot.com' 90 self._checkpoint_logger = checkpoint_logger 91 super(PowerTelemetryLoggerDashboard, self).__init__( 92 logger, testname, host, start_ts, resultsdir, uploadurl, note) 93 94 def _create_checkpoint_dict(self): 95 """Create dictionary for checkpoint. 96 """ 97 return self._checkpoint_logger.convert_relative(self._start_ts) 98 99 def _convert(self): 100 """ 101 self._logger is already in correct format, so just return it. 102 103 Returns: 104 raw measurement dictionary 105 """ 106 self._tag_with_checkpoint(self._logger) 107 return self._logger 108