Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 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 | |
| 5 | import logging |
| 6 | import os |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 7 | import pprint |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 8 | import re |
| 9 | import StringIO |
| 10 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 11 | from autotest_lib.client.common_lib import error, utils |
| 12 | from autotest_lib.client.common_lib.cros import dev_server |
| 13 | |
| 14 | |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 15 | TELEMETRY_RUN_BENCHMARKS_SCRIPT = 'tools/perf/run_benchmark' |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 16 | TELEMETRY_RUN_CROS_TESTS_SCRIPT = 'chrome/test/telemetry/run_cros_tests' |
Ilja Friedel | f247380 | 2014-03-28 17:54:34 -0700 | [diff] [blame] | 17 | TELEMETRY_RUN_GPU_TESTS_SCRIPT = 'content/test/gpu/run_gpu_test.py' |
Ilja H. Friedel | 086bc3f | 2014-02-27 22:17:55 -0800 | [diff] [blame] | 18 | TELEMETRY_RUN_TESTS_SCRIPT = 'tools/telemetry/run_tests' |
Achuith Bhandarkar | 124e473 | 2014-01-21 15:27:54 -0800 | [diff] [blame] | 19 | TELEMETRY_TIMEOUT_MINS = 120 |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 20 | |
| 21 | # Result Statuses |
| 22 | SUCCESS_STATUS = 'SUCCESS' |
| 23 | WARNING_STATUS = 'WARNING' |
| 24 | FAILED_STATUS = 'FAILED' |
| 25 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 26 | # Regex for the RESULT output lines understood by chrome buildbot. |
| 27 | # Keep in sync with chromium/tools/build/scripts/slave/process_log_utils.py. |
| 28 | RESULTS_REGEX = re.compile(r'(?P<IMPORTANT>\*)?RESULT ' |
| 29 | '(?P<GRAPH>[^:]*): (?P<TRACE>[^=]*)= ' |
| 30 | '(?P<VALUE>[\{\[]?[-\d\., ]+[\}\]]?)(' |
| 31 | ' ?(?P<UNITS>.+))?') |
| 32 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 33 | |
| 34 | class TelemetryResult(object): |
| 35 | """Class to represent the results of a telemetry run. |
| 36 | |
| 37 | This class represents the results of a telemetry run, whether it ran |
| 38 | successful, failed or had warnings. |
| 39 | """ |
| 40 | |
| 41 | |
| 42 | def __init__(self, exit_code=0, stdout='', stderr=''): |
| 43 | """Initializes this TelemetryResultObject instance. |
| 44 | |
| 45 | @param status: Status of the telemtry run. |
| 46 | @param stdout: Stdout of the telemetry run. |
| 47 | @param stderr: Stderr of the telemetry run. |
| 48 | """ |
| 49 | if exit_code == 0: |
| 50 | self.status = SUCCESS_STATUS |
| 51 | else: |
| 52 | self.status = FAILED_STATUS |
| 53 | |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 54 | # A list of perf values, e.g. |
| 55 | # [{'graph': 'graphA', 'trace': 'page_load_time', |
| 56 | # 'units': 'secs', 'value':0.5}, ...] |
| 57 | self.perf_data = [] |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 58 | self._stdout = stdout |
| 59 | self._stderr = stderr |
| 60 | self.output = '\n'.join([stdout, stderr]) |
| 61 | |
| 62 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 63 | def _cleanup_perf_string(self, str): |
| 64 | """Clean up a perf-related string by removing illegal characters. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 65 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 66 | Perf keys stored in the chromeOS database may contain only letters, |
| 67 | numbers, underscores, periods, and dashes. Transform an inputted |
| 68 | string so that any illegal characters are replaced by underscores. |
| 69 | |
| 70 | @param str: The perf string to clean up. |
| 71 | |
| 72 | @return The cleaned-up perf string. |
| 73 | """ |
| 74 | return re.sub(r'[^\w.-]', '_', str) |
| 75 | |
| 76 | |
| 77 | def _cleanup_units_string(self, units): |
| 78 | """Cleanup a units string. |
| 79 | |
| 80 | Given a string representing units for a perf measurement, clean it up |
| 81 | by replacing certain illegal characters with meaningful alternatives. |
| 82 | Any other illegal characters should then be replaced with underscores. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 83 | |
| 84 | Examples: |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 85 | count/time -> count_per_time |
| 86 | % -> percent |
| 87 | units! --> units_ |
| 88 | score (bigger is better) -> score__bigger_is_better_ |
| 89 | score (runs/s) -> score__runs_per_s_ |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 90 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 91 | @param units: The units string to clean up. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 92 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 93 | @return The cleaned-up units string. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 94 | """ |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 95 | if '%' in units: |
| 96 | units = units.replace('%', 'percent') |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 97 | if '/' in units: |
| 98 | units = units.replace('/','_per_') |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 99 | return self._cleanup_perf_string(units) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 100 | |
| 101 | |
| 102 | def parse_benchmark_results(self): |
| 103 | """Parse the results of a telemetry benchmark run. |
| 104 | |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 105 | Stdout has the output in RESULT block format below. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 106 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 107 | The lines of interest start with the substring "RESULT". These are |
| 108 | specially-formatted perf data lines that are interpreted by chrome |
| 109 | builbot (when the Telemetry tests run for chrome desktop) and are |
| 110 | parsed to extract perf data that can then be displayed on a perf |
| 111 | dashboard. This format is documented in the docstring of class |
| 112 | GraphingLogProcessor in this file in the chrome tree: |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 113 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 114 | chromium/tools/build/scripts/slave/process_log_utils.py |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 115 | |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 116 | Example RESULT output lines: |
| 117 | RESULT average_commit_time_by_url: http___www.ebay.com= 8.86528 ms |
| 118 | RESULT CodeLoad: CodeLoad= 6343 score (bigger is better) |
| 119 | RESULT ai-astar: ai-astar= [614,527,523,471,530,523,577,625,614,538] ms |
| 120 | |
| 121 | Currently for chromeOS, we can only associate a single perf key (string) |
| 122 | with a perf value. That string can only contain letters, numbers, |
| 123 | dashes, periods, and underscores, as defined by write_keyval() in: |
| 124 | |
| 125 | chromeos/src/third_party/autotest/files/client/common_lib/ |
| 126 | base_utils.py |
| 127 | |
| 128 | We therefore parse each RESULT line, clean up the strings to remove any |
| 129 | illegal characters not accepted by chromeOS, and construct a perf key |
| 130 | string based on the parsed components of the RESULT line (with each |
| 131 | component separated by a special delimiter). We prefix the perf key |
| 132 | with the substring "TELEMETRY" to identify it as a telemetry-formatted |
| 133 | perf key. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 134 | |
| 135 | Stderr has the format of Warnings/Tracebacks. There is always a default |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 136 | warning of the display enviornment setting, followed by warnings of |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 137 | page timeouts or a traceback. |
| 138 | |
| 139 | If there are any other warnings we flag the test as warning. If there |
| 140 | is a traceback we consider this test a failure. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 141 | """ |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 142 | if not self._stdout: |
| 143 | # Nothing in stdout implies a test failure. |
| 144 | logging.error('No stdout, test failed.') |
| 145 | self.status = FAILED_STATUS |
| 146 | return |
| 147 | |
| 148 | stdout_lines = self._stdout.splitlines() |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 149 | for line in stdout_lines: |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 150 | results_match = RESULTS_REGEX.search(line) |
| 151 | if not results_match: |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 152 | continue |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 153 | |
| 154 | match_dict = results_match.groupdict() |
| 155 | graph_name = self._cleanup_perf_string(match_dict['GRAPH'].strip()) |
| 156 | trace_name = self._cleanup_perf_string(match_dict['TRACE'].strip()) |
| 157 | units = self._cleanup_units_string( |
| 158 | (match_dict['UNITS'] or 'units').strip()) |
| 159 | value = match_dict['VALUE'].strip() |
| 160 | unused_important = match_dict['IMPORTANT'] or False # Unused now. |
| 161 | |
| 162 | if value.startswith('['): |
| 163 | # A list of values, e.g., "[12,15,8,7,16]". Extract just the |
| 164 | # numbers, compute the average and use that. In this example, |
| 165 | # we'd get 12+15+8+7+16 / 5 --> 11.6. |
| 166 | value_list = [float(x) for x in value.strip('[],').split(',')] |
| 167 | value = float(sum(value_list)) / len(value_list) |
| 168 | elif value.startswith('{'): |
| 169 | # A single value along with a standard deviation, e.g., |
| 170 | # "{34.2,2.15}". Extract just the value itself and use that. |
| 171 | # In this example, we'd get 34.2. |
| 172 | value_list = [float(x) for x in value.strip('{},').split(',')] |
| 173 | value = value_list[0] # Position 0 is the value. |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 174 | elif re.search('^\d+$', value): |
| 175 | value = int(value) |
| 176 | else: |
| 177 | value = float(value) |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 178 | |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 179 | self.perf_data.append({'graph':graph_name, 'trace': trace_name, |
| 180 | 'units': units, 'value': value}) |
Dennis Jeffrey | c42fd30 | 2013-04-17 11:57:51 -0700 | [diff] [blame] | 181 | |
| 182 | pp = pprint.PrettyPrinter(indent=2) |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 183 | logging.debug('Perf values: %s', pp.pformat(self.perf_data)) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 184 | |
| 185 | if self.status is SUCCESS_STATUS: |
| 186 | return |
| 187 | |
| 188 | # Otherwise check if simply a Warning occurred or a Failure, |
| 189 | # i.e. a Traceback is listed. |
| 190 | self.status = WARNING_STATUS |
| 191 | for line in self._stderr.splitlines(): |
| 192 | if line.startswith('Traceback'): |
| 193 | self.status = FAILED_STATUS |
| 194 | |
| 195 | |
| 196 | class TelemetryRunner(object): |
| 197 | """Class responsible for telemetry for a given build. |
| 198 | |
| 199 | This class will extract and install telemetry on the devserver and is |
| 200 | responsible for executing the telemetry benchmarks and returning their |
| 201 | output to the caller. |
| 202 | """ |
| 203 | |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 204 | def __init__(self, host, local=False): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 205 | """Initializes this telemetry runner instance. |
| 206 | |
| 207 | If telemetry is not installed for this build, it will be. |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 208 | |
| 209 | @param host: Host where the test will be run. |
| 210 | @param local: If set, no devserver will be used, test will be run |
| 211 | locally. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 212 | """ |
| 213 | self._host = host |
Ilja H. Friedel | c7bf310 | 2014-05-13 17:31:25 -0700 | [diff] [blame] | 214 | self._devserver = None |
| 215 | self._telemetry_path = None |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 216 | # TODO (llozano crbug.com/324964). Remove conditional code. |
| 217 | # Use a class hierarchy instead. |
| 218 | if local: |
| 219 | self._setup_local_telemetry() |
| 220 | else: |
| 221 | self._setup_devserver_telemetry() |
| 222 | |
| 223 | logging.debug('Telemetry Path: %s', self._telemetry_path) |
| 224 | |
| 225 | |
| 226 | def _setup_devserver_telemetry(self): |
| 227 | """Setup Telemetry to use the devserver.""" |
| 228 | logging.debug('Setting up telemetry for devserver testing') |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 229 | logging.debug('Grabbing build from AFE.') |
| 230 | |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 231 | build = self._host.get_build() |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 232 | if not build: |
| 233 | logging.error('Unable to locate build label for host: %s.', |
| 234 | self._host.hostname) |
| 235 | raise error.AutotestError('Failed to grab build for host %s.' % |
| 236 | self._host.hostname) |
| 237 | |
| 238 | logging.debug('Setting up telemetry for build: %s', build) |
| 239 | |
| 240 | self._devserver = dev_server.ImageServer.resolve(build) |
| 241 | self._telemetry_path = self._devserver.setup_telemetry(build=build) |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 242 | |
| 243 | |
| 244 | def _setup_local_telemetry(self): |
| 245 | """Setup Telemetry to use local path to its sources. |
| 246 | |
| 247 | First look for chrome source root, either externally mounted, or inside |
| 248 | the chroot. Prefer chrome-src-internal source tree to chrome-src. |
| 249 | """ |
| 250 | TELEMETRY_DIR = 'src' |
| 251 | CHROME_LOCAL_SRC = '/var/cache/chromeos-cache/distfiles/target/' |
| 252 | CHROME_EXTERNAL_SRC = '~/chrome_root/' |
| 253 | |
| 254 | logging.debug('Setting up telemetry for local testing') |
| 255 | |
| 256 | sources_list = ('chrome-src-internal', 'chrome-src') |
| 257 | dir_list = [os.path.join(CHROME_EXTERNAL_SRC, x) for x in sources_list] |
| 258 | dir_list.extend( |
| 259 | [os.path.join(CHROME_LOCAL_SRC, x) for x in sources_list]) |
| 260 | if 'CHROME_ROOT' in os.environ: |
| 261 | dir_list.insert(0, os.environ['CHROME_ROOT']) |
| 262 | |
| 263 | telemetry_src = '' |
| 264 | for dir in dir_list: |
| 265 | if os.path.exists(dir): |
| 266 | telemetry_src = os.path.join(dir, TELEMETRY_DIR) |
| 267 | break |
| 268 | else: |
| 269 | raise error.TestError('Telemetry source directory not found.') |
| 270 | |
| 271 | self._devserver = None |
| 272 | self._telemetry_path = telemetry_src |
| 273 | |
| 274 | |
| 275 | def _get_telemetry_cmd(self, script, test_or_benchmark): |
| 276 | """Build command to execute telemetry based on script and benchmark. |
| 277 | |
| 278 | @param script: Telemetry script we want to run. For example: |
| 279 | [path_to_telemetry_src]/src/tools/telemetry/run_tests. |
| 280 | @param test_or_benchmark: Name of the test or benchmark we want to run, |
| 281 | with the page_set (if required) as part of |
| 282 | the string. |
| 283 | @returns Full telemetry command to execute the script. |
| 284 | """ |
| 285 | telemetry_cmd = [] |
| 286 | if self._devserver: |
| 287 | devserver_hostname = self._devserver.url().split( |
| 288 | 'http://')[1].split(':')[0] |
| 289 | telemetry_cmd.extend(['ssh', devserver_hostname]) |
| 290 | |
| 291 | telemetry_cmd.extend( |
| 292 | ['python', |
| 293 | script, |
Ilja H. Friedel | 6965bd8 | 2014-05-20 18:29:15 -0700 | [diff] [blame] | 294 | '--verbose', |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 295 | '--browser=cros-chrome', |
| 296 | '--remote=%s' % self._host.hostname, |
| 297 | test_or_benchmark]) |
| 298 | return telemetry_cmd |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 299 | |
| 300 | |
| 301 | def _run_telemetry(self, script, test_or_benchmark): |
| 302 | """Runs telemetry on a dut. |
| 303 | |
| 304 | @param script: Telemetry script we want to run. For example: |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 305 | [path_to_telemetry_src]/src/tools/telemetry/run_tests. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 306 | @param test_or_benchmark: Name of the test or benchmark we want to run, |
| 307 | with the page_set (if required) as part of the |
| 308 | string. |
| 309 | |
| 310 | @returns A TelemetryResult Instance with the results of this telemetry |
| 311 | execution. |
| 312 | """ |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 313 | # TODO (sbasi crbug.com/239933) add support for incognito mode. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 314 | |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 315 | telemetry_cmd = self._get_telemetry_cmd(script, test_or_benchmark) |
| 316 | logging.debug('Running Telemetry: %s', ' '.join(telemetry_cmd)) |
| 317 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 318 | output = StringIO.StringIO() |
| 319 | error_output = StringIO.StringIO() |
| 320 | exit_code = 0 |
| 321 | try: |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 322 | result = utils.run(' '.join(telemetry_cmd), stdout_tee=output, |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 323 | stderr_tee=error_output, |
| 324 | timeout=TELEMETRY_TIMEOUT_MINS*60) |
| 325 | exit_code = result.exit_status |
| 326 | except error.CmdError as e: |
| 327 | # Telemetry returned a return code of not 0; for benchmarks this |
| 328 | # can be due to a timeout on one of the pages of the page set and |
| 329 | # we may still have data on the rest. For a test however this |
| 330 | # indicates failure. |
| 331 | logging.debug('Error occurred executing telemetry.') |
| 332 | exit_code = e.result_obj.exit_status |
| 333 | |
| 334 | stdout = output.getvalue() |
| 335 | stderr = error_output.getvalue() |
| 336 | logging.debug('Telemetry completed with exit code: %d.\nstdout:%s\n' |
| 337 | 'stderr:%s', exit_code, stdout, stderr) |
| 338 | |
| 339 | return TelemetryResult(exit_code=exit_code, stdout=stdout, |
| 340 | stderr=stderr) |
| 341 | |
| 342 | |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 343 | def _run_test(self, script, test): |
| 344 | """Runs a telemetry test on a dut. |
| 345 | |
| 346 | @param script: Which telemetry test script we want to run. Can be |
| 347 | telemetry's base test script or the Chrome OS specific |
| 348 | test script. |
| 349 | @param test: Telemetry test we want to run. |
| 350 | |
| 351 | @returns A TelemetryResult Instance with the results of this telemetry |
| 352 | execution. |
| 353 | """ |
| 354 | logging.debug('Running telemetry test: %s', test) |
| 355 | telemetry_script = os.path.join(self._telemetry_path, script) |
| 356 | result = self._run_telemetry(telemetry_script, test) |
| 357 | if result.status is FAILED_STATUS: |
Ilja H. Friedel | c7bf310 | 2014-05-13 17:31:25 -0700 | [diff] [blame] | 358 | raise error.TestFail('Telemetry test %s failed.' % test) |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 359 | return result |
| 360 | |
| 361 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 362 | def run_telemetry_test(self, test): |
| 363 | """Runs a telemetry test on a dut. |
| 364 | |
| 365 | @param test: Telemetry test we want to run. |
| 366 | |
| 367 | @returns A TelemetryResult Instance with the results of this telemetry |
| 368 | execution. |
| 369 | """ |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 370 | return self._run_test(TELEMETRY_RUN_TESTS_SCRIPT, test) |
| 371 | |
| 372 | |
| 373 | def run_cros_telemetry_test(self, test): |
| 374 | """Runs a cros specific telemetry test on a dut. |
| 375 | |
| 376 | @param test: Telemetry test we want to run. |
| 377 | |
| 378 | @returns A TelemetryResult instance with the results of this telemetry |
| 379 | execution. |
| 380 | """ |
| 381 | return self._run_test(TELEMETRY_RUN_CROS_TESTS_SCRIPT, test) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 382 | |
| 383 | |
Ilja H. Friedel | 086bc3f | 2014-02-27 22:17:55 -0800 | [diff] [blame] | 384 | def run_gpu_test(self, test): |
| 385 | """Runs a gpu test on a dut. |
| 386 | |
| 387 | @param test: Gpu test we want to run. |
| 388 | |
| 389 | @returns A TelemetryResult instance with the results of this telemetry |
| 390 | execution. |
| 391 | """ |
| 392 | return self._run_test(TELEMETRY_RUN_GPU_TESTS_SCRIPT, test) |
| 393 | |
| 394 | |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 395 | @staticmethod |
| 396 | def _output_perf_value(perf_value_writer, perf_data): |
| 397 | """Output perf values to result dir. |
| 398 | |
| 399 | The perf values will be output to the result dir and |
| 400 | be subsequently uploaded to perf dashboard. |
| 401 | |
| 402 | @param perf_value_writer: Should be an instance with the function |
| 403 | output_perf_value(), if None, no perf value |
| 404 | will be written. Typically this will be the |
| 405 | job object from an autotest test. |
| 406 | @param perf_data: A list of perf values, each value is |
| 407 | a dictionary that looks like |
| 408 | {'graph':'GraphA', 'trace':'metric1', |
| 409 | 'units':'secs', 'value':0.5} |
| 410 | """ |
| 411 | for perf_value in perf_data: |
| 412 | perf_value_writer.output_perf_value( |
| 413 | description=perf_value['trace'], |
| 414 | value=perf_value['value'], |
| 415 | units=perf_value['units'], |
| 416 | graph=perf_value['graph']) |
| 417 | |
| 418 | |
| 419 | def run_telemetry_benchmark(self, benchmark, perf_value_writer=None): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 420 | """Runs a telemetry benchmark on a dut. |
| 421 | |
| 422 | @param benchmark: Benchmark we want to run. |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 423 | @param perf_value_writer: Should be an instance with the function |
| 424 | output_perf_value(), if None, no perf value |
| 425 | will be written. Typically this will be the |
| 426 | job object from an autotest test. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 427 | |
| 428 | @returns A TelemetryResult Instance with the results of this telemetry |
| 429 | execution. |
| 430 | """ |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 431 | logging.debug('Running telemetry benchmark: %s', benchmark) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 432 | telemetry_script = os.path.join(self._telemetry_path, |
| 433 | TELEMETRY_RUN_BENCHMARKS_SCRIPT) |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 434 | result = self._run_telemetry(telemetry_script, benchmark) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 435 | result.parse_benchmark_results() |
| 436 | |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 437 | if perf_value_writer: |
| 438 | self._output_perf_value(perf_value_writer, result.perf_data) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 439 | |
| 440 | if result.status is WARNING_STATUS: |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 441 | raise error.TestWarn('Telemetry Benchmark: %s' |
| 442 | ' exited with Warnings.' % benchmark) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 443 | if result.status is FAILED_STATUS: |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 444 | raise error.TestFail('Telemetry Benchmark: %s' |
| 445 | ' failed to run.' % benchmark) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 446 | |
| 447 | return result |