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 | |
Kuo-Hsin Yang | 4a00617 | 2018-04-25 14:44:55 +0800 | [diff] [blame] | 5 | import json |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 6 | import logging |
| 7 | import os |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 8 | import StringIO |
| 9 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 10 | from autotest_lib.client.common_lib import error, utils |
| 11 | from autotest_lib.client.common_lib.cros import dev_server |
| 12 | |
| 13 | |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 14 | TELEMETRY_RUN_BENCHMARKS_SCRIPT = 'tools/perf/run_benchmark' |
Ilja H. Friedel | 086bc3f | 2014-02-27 22:17:55 -0800 | [diff] [blame] | 15 | TELEMETRY_RUN_TESTS_SCRIPT = 'tools/telemetry/run_tests' |
Gurchetan Singh | faf75e9 | 2017-04-17 18:09:44 -0700 | [diff] [blame] | 16 | TELEMETRY_RUN_GPU_TESTS_SCRIPT = 'content/test/gpu/run_gpu_integration_test.py' |
Mao Huang | c9642d7 | 2017-09-28 16:50:02 +0800 | [diff] [blame] | 17 | TELEMETRY_TIMEOUT_MINS = 150 |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 18 | |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 19 | DUT_CHROME_ROOT = '/usr/local/telemetry/src' |
| 20 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 21 | # Result Statuses |
| 22 | SUCCESS_STATUS = 'SUCCESS' |
| 23 | WARNING_STATUS = 'WARNING' |
| 24 | FAILED_STATUS = 'FAILED' |
| 25 | |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 26 | # A list of benchmarks with that the telemetry test harness can run on dut. |
wutao | 5a6dedd | 2018-03-01 18:15:31 -0800 | [diff] [blame] | 27 | ON_DUT_WHITE_LIST = ['cros_ui_smoothness', |
| 28 | 'dromaeo.domcoreattr', |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 29 | 'dromaeo.domcoremodify', |
| 30 | 'dromaeo.domcorequery', |
| 31 | 'dromaeo.domcoretraverse', |
| 32 | 'image_decoding.image_decoding_measurement', |
| 33 | 'jetstream', |
| 34 | 'kraken', |
| 35 | 'memory.top_7_stress', |
| 36 | 'octane', |
| 37 | 'page_cycler.typical_25', |
Chung-yih Wang | 80ba581 | 2017-01-20 17:22:11 +0800 | [diff] [blame] | 38 | 'page_cycler_v2.typical_25', |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 39 | 'robohornet_pro', |
Chung-yih Wang | 4667232 | 2018-03-30 16:28:57 +0800 | [diff] [blame] | 40 | 'smoothness.top_25_smooth', |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 41 | 'smoothness.tough_animation_cases', |
| 42 | 'smoothness.tough_canvas_cases', |
| 43 | 'smoothness.tough_filters_cases', |
| 44 | 'smoothness.tough_pinch_zoom_cases', |
| 45 | 'smoothness.tough_scrolling_cases', |
| 46 | 'smoothness.tough_webgl_cases', |
| 47 | 'speedometer', |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 48 | 'sunspider', |
| 49 | 'tab_switching.top_10', |
Chung-yih Wang | 80ba581 | 2017-01-20 17:22:11 +0800 | [diff] [blame] | 50 | 'tab_switching.typical_25', |
Patrik Höglund | 2ef2e17 | 2016-11-16 10:07:29 +0100 | [diff] [blame] | 51 | 'webrtc.peerconnection', |
| 52 | 'webrtc.stress'] |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 53 | |
| 54 | # BLACK LIST |
| 55 | # 'session_restore.cold.typical_25', # profile generator not implemented on |
| 56 | # CrOS. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 57 | |
| 58 | class TelemetryResult(object): |
| 59 | """Class to represent the results of a telemetry run. |
| 60 | |
| 61 | This class represents the results of a telemetry run, whether it ran |
| 62 | successful, failed or had warnings. |
| 63 | """ |
| 64 | |
| 65 | |
| 66 | def __init__(self, exit_code=0, stdout='', stderr=''): |
| 67 | """Initializes this TelemetryResultObject instance. |
| 68 | |
| 69 | @param status: Status of the telemtry run. |
| 70 | @param stdout: Stdout of the telemetry run. |
| 71 | @param stderr: Stderr of the telemetry run. |
| 72 | """ |
| 73 | if exit_code == 0: |
| 74 | self.status = SUCCESS_STATUS |
| 75 | else: |
| 76 | self.status = FAILED_STATUS |
| 77 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 78 | self._stdout = stdout |
| 79 | self._stderr = stderr |
| 80 | self.output = '\n'.join([stdout, stderr]) |
| 81 | |
| 82 | |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 83 | class TelemetryRunner(object): |
| 84 | """Class responsible for telemetry for a given build. |
| 85 | |
| 86 | This class will extract and install telemetry on the devserver and is |
| 87 | responsible for executing the telemetry benchmarks and returning their |
| 88 | output to the caller. |
| 89 | """ |
| 90 | |
Ting-Yuan Huang | 85dcde8 | 2016-04-08 17:41:32 +0800 | [diff] [blame] | 91 | def __init__(self, host, local=False, telemetry_on_dut=True): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 92 | """Initializes this telemetry runner instance. |
| 93 | |
| 94 | If telemetry is not installed for this build, it will be. |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 95 | |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 96 | Basically, the following commands on the local pc on which test_that |
| 97 | will be executed, depending on the 4 possible combinations of |
| 98 | local x telemetry_on_dut: |
| 99 | |
| 100 | local=True, telemetry_on_dut=False: |
| 101 | run_benchmark --browser=cros-chrome --remote=[dut] [test] |
| 102 | |
| 103 | local=True, telemetry_on_dut=True: |
| 104 | ssh [dut] run_benchmark --browser=system [test] |
| 105 | |
| 106 | local=False, telemetry_on_dut=False: |
| 107 | ssh [devserver] run_benchmark --browser=cros-chrome --remote=[dut] [test] |
| 108 | |
| 109 | local=False, telemetry_on_dut=True: |
| 110 | ssh [devserver] ssh [dut] run_benchmark --browser=system [test] |
| 111 | |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 112 | @param host: Host where the test will be run. |
| 113 | @param local: If set, no devserver will be used, test will be run |
| 114 | locally. |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 115 | If not set, "ssh [devserver] " will be appended to test |
| 116 | commands. |
| 117 | @param telemetry_on_dut: If set, telemetry itself (the test harness) |
| 118 | will run on dut. |
| 119 | It decides browser=[system|cros-chrome] |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 120 | """ |
| 121 | self._host = host |
Ilja H. Friedel | c7bf310 | 2014-05-13 17:31:25 -0700 | [diff] [blame] | 122 | self._devserver = None |
| 123 | self._telemetry_path = None |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 124 | self._telemetry_on_dut = telemetry_on_dut |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 125 | # TODO (llozano crbug.com/324964). Remove conditional code. |
| 126 | # Use a class hierarchy instead. |
| 127 | if local: |
| 128 | self._setup_local_telemetry() |
| 129 | else: |
| 130 | self._setup_devserver_telemetry() |
| 131 | |
| 132 | logging.debug('Telemetry Path: %s', self._telemetry_path) |
| 133 | |
| 134 | |
| 135 | def _setup_devserver_telemetry(self): |
| 136 | """Setup Telemetry to use the devserver.""" |
| 137 | logging.debug('Setting up telemetry for devserver testing') |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 138 | logging.debug('Grabbing build from AFE.') |
Prathmesh Prabhu | cfff58a | 2017-02-06 10:07:43 -0800 | [diff] [blame] | 139 | info = self._host.host_info_store.get() |
| 140 | if not info.build: |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 141 | logging.error('Unable to locate build label for host: %s.', |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 142 | self._host.host_port) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 143 | raise error.AutotestError('Failed to grab build for host %s.' % |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 144 | self._host.host_port) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 145 | |
Prathmesh Prabhu | cfff58a | 2017-02-06 10:07:43 -0800 | [diff] [blame] | 146 | logging.debug('Setting up telemetry for build: %s', info.build) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 147 | |
Prathmesh Prabhu | cfff58a | 2017-02-06 10:07:43 -0800 | [diff] [blame] | 148 | self._devserver = dev_server.ImageServer.resolve( |
| 149 | info.build, hostname=self._host.hostname) |
| 150 | self._devserver.stage_artifacts(info.build, ['autotest_packages']) |
| 151 | self._telemetry_path = self._devserver.setup_telemetry(build=info.build) |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 152 | |
| 153 | |
| 154 | def _setup_local_telemetry(self): |
| 155 | """Setup Telemetry to use local path to its sources. |
| 156 | |
| 157 | First look for chrome source root, either externally mounted, or inside |
| 158 | the chroot. Prefer chrome-src-internal source tree to chrome-src. |
| 159 | """ |
| 160 | TELEMETRY_DIR = 'src' |
| 161 | CHROME_LOCAL_SRC = '/var/cache/chromeos-cache/distfiles/target/' |
Josh Triplett | 05208c9 | 2014-07-17 13:21:29 -0700 | [diff] [blame] | 162 | CHROME_EXTERNAL_SRC = os.path.expanduser('~/chrome_root/') |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 163 | |
| 164 | logging.debug('Setting up telemetry for local testing') |
| 165 | |
| 166 | sources_list = ('chrome-src-internal', 'chrome-src') |
Josh Triplett | 05208c9 | 2014-07-17 13:21:29 -0700 | [diff] [blame] | 167 | dir_list = [CHROME_EXTERNAL_SRC] |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 168 | dir_list.extend( |
| 169 | [os.path.join(CHROME_LOCAL_SRC, x) for x in sources_list]) |
| 170 | if 'CHROME_ROOT' in os.environ: |
| 171 | dir_list.insert(0, os.environ['CHROME_ROOT']) |
| 172 | |
| 173 | telemetry_src = '' |
| 174 | for dir in dir_list: |
| 175 | if os.path.exists(dir): |
| 176 | telemetry_src = os.path.join(dir, TELEMETRY_DIR) |
| 177 | break |
| 178 | else: |
| 179 | raise error.TestError('Telemetry source directory not found.') |
| 180 | |
| 181 | self._devserver = None |
| 182 | self._telemetry_path = telemetry_src |
| 183 | |
| 184 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 185 | def _get_telemetry_cmd(self, script, test_or_benchmark, *args): |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 186 | """Build command to execute telemetry based on script and benchmark. |
| 187 | |
| 188 | @param script: Telemetry script we want to run. For example: |
| 189 | [path_to_telemetry_src]/src/tools/telemetry/run_tests. |
| 190 | @param test_or_benchmark: Name of the test or benchmark we want to run, |
| 191 | with the page_set (if required) as part of |
| 192 | the string. |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 193 | @param args: additional list of arguments to pass to the script. |
| 194 | |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 195 | @returns Full telemetry command to execute the script. |
| 196 | """ |
| 197 | telemetry_cmd = [] |
| 198 | if self._devserver: |
Allen Li | a5cfb97 | 2016-12-27 17:17:22 -0800 | [diff] [blame] | 199 | devserver_hostname = self._devserver.hostname |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 200 | telemetry_cmd.extend(['ssh', devserver_hostname]) |
| 201 | |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 202 | if self._telemetry_on_dut: |
| 203 | telemetry_cmd.extend( |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 204 | [self._host.ssh_command(alive_interval=900, |
| 205 | connection_attempts=4), |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 206 | 'python', |
| 207 | script, |
| 208 | '--verbose', |
| 209 | '--output-format=chartjson', |
| 210 | '--output-dir=%s' % DUT_CHROME_ROOT, |
| 211 | '--browser=system']) |
| 212 | else: |
| 213 | telemetry_cmd.extend( |
| 214 | ['python', |
| 215 | script, |
| 216 | '--verbose', |
| 217 | '--browser=cros-chrome', |
| 218 | '--output-format=chartjson', |
| 219 | '--output-dir=%s' % self._telemetry_path, |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 220 | '--remote=%s' % self._host.host_port]) |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 221 | telemetry_cmd.extend(args) |
| 222 | telemetry_cmd.append(test_or_benchmark) |
| 223 | |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 224 | return ' '.join(telemetry_cmd) |
| 225 | |
| 226 | |
| 227 | def _scp_telemetry_results_cmd(self, perf_results_dir): |
| 228 | """Build command to copy the telemetry results from the devserver. |
| 229 | |
| 230 | @param perf_results_dir: directory path where test output is to be |
| 231 | collected. |
| 232 | @returns SCP command to copy the results json to the specified directory. |
| 233 | """ |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 234 | if not perf_results_dir: |
| 235 | return '' |
| 236 | |
| 237 | scp_cmd = ['scp'] |
| 238 | if self._telemetry_on_dut: |
| 239 | scp_cmd.append(self._host.make_ssh_options(alive_interval=900, |
| 240 | connection_attempts=4)) |
| 241 | if not self._host.is_default_port: |
| 242 | scp_cmd.append('-P %d' % self._host.port) |
| 243 | src = 'root@%s:%s/results-chart.json' % (self._host.hostname, |
| 244 | DUT_CHROME_ROOT) |
| 245 | else: |
| 246 | devserver_hostname = '' |
Ricky Liang | d186f3e | 2016-03-15 16:50:55 +0800 | [diff] [blame] | 247 | if self._devserver: |
Allen Li | a5cfb97 | 2016-12-27 17:17:22 -0800 | [diff] [blame] | 248 | devserver_hostname = self._devserver.hostname + ':' |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 249 | src = '%s%s/results-chart.json' % (devserver_hostname, |
| 250 | self._telemetry_path) |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 251 | |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 252 | scp_cmd.extend([src, perf_results_dir]) |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 253 | return ' '.join(scp_cmd) |
| 254 | |
| 255 | |
| 256 | def _run_cmd(self, cmd): |
| 257 | """Execute an command in a external shell and capture the output. |
| 258 | |
| 259 | @param cmd: String of is a valid shell command. |
| 260 | |
| 261 | @returns The standard out, standard error and the integer exit code of |
| 262 | the executed command. |
| 263 | """ |
| 264 | logging.debug('Running: %s', cmd) |
| 265 | |
| 266 | output = StringIO.StringIO() |
| 267 | error_output = StringIO.StringIO() |
| 268 | exit_code = 0 |
| 269 | try: |
| 270 | result = utils.run(cmd, stdout_tee=output, |
| 271 | stderr_tee=error_output, |
| 272 | timeout=TELEMETRY_TIMEOUT_MINS*60) |
| 273 | exit_code = result.exit_status |
| 274 | except error.CmdError as e: |
| 275 | logging.debug('Error occurred executing.') |
| 276 | exit_code = e.result_obj.exit_status |
| 277 | |
| 278 | stdout = output.getvalue() |
| 279 | stderr = error_output.getvalue() |
| 280 | logging.debug('Completed with exit code: %d.\nstdout:%s\n' |
| 281 | 'stderr:%s', exit_code, stdout, stderr) |
| 282 | return stdout, stderr, exit_code |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 283 | |
| 284 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 285 | def _run_telemetry(self, script, test_or_benchmark, *args): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 286 | """Runs telemetry on a dut. |
| 287 | |
| 288 | @param script: Telemetry script we want to run. For example: |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 289 | [path_to_telemetry_src]/src/tools/telemetry/run_tests. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 290 | @param test_or_benchmark: Name of the test or benchmark we want to run, |
| 291 | with the page_set (if required) as part of the |
| 292 | string. |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 293 | @param args: additional list of arguments to pass to the script. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 294 | |
| 295 | @returns A TelemetryResult Instance with the results of this telemetry |
| 296 | execution. |
| 297 | """ |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 298 | # TODO (sbasi crbug.com/239933) add support for incognito mode. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 299 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 300 | telemetry_cmd = self._get_telemetry_cmd(script, |
| 301 | test_or_benchmark, |
| 302 | *args) |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 303 | logging.debug('Running Telemetry: %s', telemetry_cmd) |
Luis Lozano | 23ae319 | 2013-11-08 16:22:46 -0800 | [diff] [blame] | 304 | |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 305 | stdout, stderr, exit_code = self._run_cmd(telemetry_cmd) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 306 | |
| 307 | return TelemetryResult(exit_code=exit_code, stdout=stdout, |
| 308 | stderr=stderr) |
| 309 | |
| 310 | |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 311 | def _run_scp(self, perf_results_dir): |
| 312 | """Runs telemetry on a dut. |
| 313 | |
| 314 | @param perf_results_dir: The local directory that results are being |
| 315 | collected. |
| 316 | """ |
| 317 | scp_cmd = self._scp_telemetry_results_cmd(perf_results_dir) |
| 318 | logging.debug('Retrieving Results: %s', scp_cmd) |
Dean Liao | e4773c7 | 2017-11-09 16:15:38 +0800 | [diff] [blame] | 319 | _, _, exit_code = self._run_cmd(scp_cmd) |
| 320 | if exit_code != 0: |
| 321 | raise error.TestFail('Unable to retrieve results.') |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 322 | |
| 323 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 324 | def _run_test(self, script, test, *args): |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 325 | """Runs a telemetry test on a dut. |
| 326 | |
| 327 | @param script: Which telemetry test script we want to run. Can be |
| 328 | telemetry's base test script or the Chrome OS specific |
| 329 | test script. |
| 330 | @param test: Telemetry test we want to run. |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 331 | @param args: additional list of arguments to pass to the script. |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 332 | |
| 333 | @returns A TelemetryResult Instance with the results of this telemetry |
| 334 | execution. |
| 335 | """ |
| 336 | logging.debug('Running telemetry test: %s', test) |
| 337 | telemetry_script = os.path.join(self._telemetry_path, script) |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 338 | result = self._run_telemetry(telemetry_script, test, *args) |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 339 | if result.status is FAILED_STATUS: |
Ilja H. Friedel | c7bf310 | 2014-05-13 17:31:25 -0700 | [diff] [blame] | 340 | raise error.TestFail('Telemetry test %s failed.' % test) |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 341 | return result |
| 342 | |
| 343 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 344 | def run_telemetry_test(self, test, *args): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 345 | """Runs a telemetry test on a dut. |
| 346 | |
| 347 | @param test: Telemetry test we want to run. |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 348 | @param args: additional list of arguments to pass to the telemetry |
| 349 | execution script. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 350 | |
| 351 | @returns A TelemetryResult Instance with the results of this telemetry |
| 352 | execution. |
| 353 | """ |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 354 | return self._run_test(TELEMETRY_RUN_TESTS_SCRIPT, test, *args) |
Simran Basi | 1dbfc13 | 2013-05-02 10:11:02 -0700 | [diff] [blame] | 355 | |
| 356 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 357 | def run_telemetry_benchmark(self, benchmark, perf_value_writer=None, |
| 358 | *args): |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 359 | """Runs a telemetry benchmark on a dut. |
| 360 | |
| 361 | @param benchmark: Benchmark we want to run. |
Fang Deng | e689e71 | 2013-11-13 18:27:06 -0800 | [diff] [blame] | 362 | @param perf_value_writer: Should be an instance with the function |
| 363 | output_perf_value(), if None, no perf value |
| 364 | will be written. Typically this will be the |
| 365 | job object from an autotest test. |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 366 | @param args: additional list of arguments to pass to the telemetry |
| 367 | execution script. |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 368 | |
| 369 | @returns A TelemetryResult Instance with the results of this telemetry |
| 370 | execution. |
| 371 | """ |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 372 | logging.debug('Running telemetry benchmark: %s', benchmark) |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 373 | |
| 374 | if benchmark not in ON_DUT_WHITE_LIST: |
| 375 | self._telemetry_on_dut = False |
| 376 | |
| 377 | if self._telemetry_on_dut: |
| 378 | telemetry_script = os.path.join(DUT_CHROME_ROOT, |
| 379 | TELEMETRY_RUN_BENCHMARKS_SCRIPT) |
| 380 | self._ensure_deps(self._host, benchmark) |
| 381 | else: |
| 382 | telemetry_script = os.path.join(self._telemetry_path, |
| 383 | TELEMETRY_RUN_BENCHMARKS_SCRIPT) |
| 384 | |
Luis Lozano | 814c718 | 2015-09-08 11:20:47 -0700 | [diff] [blame] | 385 | result = self._run_telemetry(telemetry_script, benchmark, *args) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 386 | |
| 387 | if result.status is WARNING_STATUS: |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 388 | raise error.TestWarn('Telemetry Benchmark: %s' |
| 389 | ' exited with Warnings.' % benchmark) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 390 | if result.status is FAILED_STATUS: |
Dave Tu | 6a404e6 | 2013-11-05 15:54:48 -0800 | [diff] [blame] | 391 | raise error.TestFail('Telemetry Benchmark: %s' |
| 392 | ' failed to run.' % benchmark) |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 393 | if perf_value_writer: |
| 394 | self._run_scp(perf_value_writer.resultsdir) |
Simran Basi | 833814b | 2013-01-29 13:13:43 -0800 | [diff] [blame] | 395 | return result |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 396 | |
Gurchetan Singh | faf75e9 | 2017-04-17 18:09:44 -0700 | [diff] [blame] | 397 | |
| 398 | def run_gpu_integration_test(self, test, *args): |
| 399 | """Runs a gpu test on a dut. |
| 400 | |
| 401 | @param test: Gpu test we want to run. |
| 402 | @param args: additional list of arguments to pass to the telemetry |
| 403 | execution script. |
| 404 | |
| 405 | @returns A TelemetryResult instance with the results of this telemetry |
| 406 | execution. |
| 407 | """ |
| 408 | script = os.path.join(DUT_CHROME_ROOT, |
| 409 | TELEMETRY_RUN_GPU_TESTS_SCRIPT) |
| 410 | cmd = [] |
| 411 | if self._devserver: |
| 412 | devserver_hostname = self._devserver.hostname |
| 413 | cmd.extend(['ssh', devserver_hostname]) |
| 414 | |
| 415 | cmd.extend( |
Dean Liao | e3e75f6 | 2017-11-14 10:36:43 +0800 | [diff] [blame] | 416 | [self._host.ssh_command(alive_interval=900, connection_attempts=4), |
| 417 | 'python', script]) |
Gurchetan Singh | faf75e9 | 2017-04-17 18:09:44 -0700 | [diff] [blame] | 418 | cmd.extend(args) |
| 419 | cmd.append(test) |
| 420 | cmd = ' '.join(cmd) |
| 421 | stdout, stderr, exit_code = self._run_cmd(cmd) |
| 422 | |
| 423 | return TelemetryResult(exit_code=exit_code, stdout=stdout, |
| 424 | stderr=stderr) |
| 425 | |
| 426 | |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 427 | def _ensure_deps(self, dut, test_name): |
| 428 | """ |
| 429 | Ensure the dependencies are locally available on DUT. |
| 430 | |
| 431 | @param dut: The autotest host object representing DUT. |
| 432 | @param test_name: Name of the telemetry test. |
| 433 | """ |
| 434 | # Get DEPs using host's telemetry. |
Kuo-Hsin Yang | 4a00617 | 2018-04-25 14:44:55 +0800 | [diff] [blame] | 435 | # Example output, fetch_benchmark_deps.py --output-deps=deps octane: |
| 436 | # {'octane': ['tools/perf/page_sets/data/octane_002.wprgo']} |
| 437 | perf_path = os.path.join(self._telemetry_path, 'tools', 'perf') |
| 438 | deps_path = os.path.join(perf_path, 'fetch_benchmark_deps_result.json') |
| 439 | fetch_path = os.path.join(perf_path, 'fetch_benchmark_deps.py') |
| 440 | format_fetch = ('python %s --output-deps=%s %s') |
| 441 | command_fetch = format_fetch % (fetch_path, deps_path, test_name) |
| 442 | command_get = 'cat %s' % deps_path |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 443 | |
| 444 | if self._devserver: |
| 445 | devserver_hostname = self._devserver.url().split( |
| 446 | 'http://')[1].split(':')[0] |
Kuo-Hsin Yang | 4a00617 | 2018-04-25 14:44:55 +0800 | [diff] [blame] | 447 | command_fetch = 'ssh %s %s' % (devserver_hostname, command_fetch) |
| 448 | command_get = 'ssh %s %s' % (devserver_hostname, command_get) |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 449 | |
Kuo-Hsin Yang | 4a00617 | 2018-04-25 14:44:55 +0800 | [diff] [blame] | 450 | logging.info('Getting DEPs: %s', command_fetch) |
| 451 | _, _, exit_code = self._run_cmd(command_fetch) |
| 452 | if exit_code != 0: |
| 453 | raise error.TestFail('Error occurred while fetching DEPs.') |
| 454 | stdout, _, exit_code = self._run_cmd(command_get) |
| 455 | if exit_code != 0: |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 456 | raise error.TestFail('Error occurred while getting DEPs.') |
| 457 | |
| 458 | # Download DEPs to DUT. |
| 459 | # send_file() relies on rsync over ssh. Couldn't be better. |
Kuo-Hsin Yang | 4a00617 | 2018-04-25 14:44:55 +0800 | [diff] [blame] | 460 | deps = json.loads(stdout) |
| 461 | for dep in deps[test_name]: |
Ting-Yuan Huang | e5b1913 | 2016-03-22 13:02:41 +0800 | [diff] [blame] | 462 | src = os.path.join(self._telemetry_path, dep) |
| 463 | dst = os.path.join(DUT_CHROME_ROOT, dep) |
Ting-Yuan Huang | 8a2c7f7 | 2016-03-28 22:01:07 +0800 | [diff] [blame] | 464 | if self._devserver: |
| 465 | logging.info('Copying: %s -> %s', src, dst) |
Chung-yih Wang | fd8eb24 | 2017-12-09 19:23:04 +0800 | [diff] [blame] | 466 | rsync_cmd = utils.sh_escape('rsync %s %s %s:%s' % |
| 467 | (self._host.rsync_options(), src, |
| 468 | self._host.hostname, dst)) |
| 469 | utils.run('ssh %s "%s"' % (devserver_hostname, rsync_cmd)) |
Ting-Yuan Huang | 8a2c7f7 | 2016-03-28 22:01:07 +0800 | [diff] [blame] | 470 | else: |
| 471 | if not os.path.isfile(src): |
| 472 | raise error.TestFail('Error occurred while saving DEPs.') |
| 473 | logging.info('Copying: %s -> %s', src, dst) |
| 474 | dut.send_file(src, dst) |