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