blob: 2e507256c838fa40b049e216c293efbce6dcaea2 [file] [log] [blame]
Simran Basi833814b2013-01-29 13:13:43 -08001# 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 Yang4a006172018-04-25 14:44:55 +08005import json
Simran Basi833814b2013-01-29 13:13:43 -08006import logging
7import os
Simran Basi833814b2013-01-29 13:13:43 -08008import StringIO
9
Simran Basi833814b2013-01-29 13:13:43 -080010from autotest_lib.client.common_lib import error, utils
11from autotest_lib.client.common_lib.cros import dev_server
12
13
Dave Tu6a404e62013-11-05 15:54:48 -080014TELEMETRY_RUN_BENCHMARKS_SCRIPT = 'tools/perf/run_benchmark'
Ilja H. Friedel086bc3f2014-02-27 22:17:55 -080015TELEMETRY_RUN_TESTS_SCRIPT = 'tools/telemetry/run_tests'
Gurchetan Singhfaf75e92017-04-17 18:09:44 -070016TELEMETRY_RUN_GPU_TESTS_SCRIPT = 'content/test/gpu/run_gpu_integration_test.py'
Mao Huangc9642d72017-09-28 16:50:02 +080017TELEMETRY_TIMEOUT_MINS = 150
Simran Basi833814b2013-01-29 13:13:43 -080018
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080019DUT_CHROME_ROOT = '/usr/local/telemetry/src'
20
Simran Basi833814b2013-01-29 13:13:43 -080021# Result Statuses
22SUCCESS_STATUS = 'SUCCESS'
23WARNING_STATUS = 'WARNING'
24FAILED_STATUS = 'FAILED'
25
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080026# A list of benchmarks with that the telemetry test harness can run on dut.
Kuo-Hsin Yange0a2c062018-06-20 15:08:22 +080027ON_DUT_WHITE_LIST = ['cros_tab_switching.typical_24',
28 'cros_ui_smoothness',
wutao5a6dedd2018-03-01 18:15:31 -080029 'dromaeo.domcoreattr',
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080030 'dromaeo.domcoremodify',
31 'dromaeo.domcorequery',
32 'dromaeo.domcoretraverse',
33 'image_decoding.image_decoding_measurement',
34 'jetstream',
35 'kraken',
36 'memory.top_7_stress',
37 'octane',
38 'page_cycler.typical_25',
Chung-yih Wang80ba5812017-01-20 17:22:11 +080039 'page_cycler_v2.typical_25',
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080040 'robohornet_pro',
Chung-yih Wang46672322018-03-30 16:28:57 +080041 'smoothness.top_25_smooth',
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080042 'smoothness.tough_animation_cases',
43 'smoothness.tough_canvas_cases',
44 'smoothness.tough_filters_cases',
45 'smoothness.tough_pinch_zoom_cases',
46 'smoothness.tough_scrolling_cases',
47 'smoothness.tough_webgl_cases',
48 'speedometer',
Hsu-Cheng Tsaied1d6b32018-05-17 17:28:28 +080049 'speedometer2',
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080050 'sunspider',
51 'tab_switching.top_10',
Chung-yih Wang80ba5812017-01-20 17:22:11 +080052 'tab_switching.typical_25',
Patrik Höglund2ef2e172016-11-16 10:07:29 +010053 'webrtc.peerconnection',
54 'webrtc.stress']
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080055
56# BLACK LIST
57# 'session_restore.cold.typical_25', # profile generator not implemented on
58 # CrOS.
Simran Basi833814b2013-01-29 13:13:43 -080059
60class TelemetryResult(object):
61 """Class to represent the results of a telemetry run.
62
63 This class represents the results of a telemetry run, whether it ran
64 successful, failed or had warnings.
65 """
66
67
68 def __init__(self, exit_code=0, stdout='', stderr=''):
69 """Initializes this TelemetryResultObject instance.
70
71 @param status: Status of the telemtry run.
72 @param stdout: Stdout of the telemetry run.
73 @param stderr: Stderr of the telemetry run.
74 """
75 if exit_code == 0:
76 self.status = SUCCESS_STATUS
77 else:
78 self.status = FAILED_STATUS
79
Simran Basi833814b2013-01-29 13:13:43 -080080 self._stdout = stdout
81 self._stderr = stderr
82 self.output = '\n'.join([stdout, stderr])
83
84
Simran Basi833814b2013-01-29 13:13:43 -080085class TelemetryRunner(object):
86 """Class responsible for telemetry for a given build.
87
88 This class will extract and install telemetry on the devserver and is
89 responsible for executing the telemetry benchmarks and returning their
90 output to the caller.
91 """
92
Ting-Yuan Huang85dcde82016-04-08 17:41:32 +080093 def __init__(self, host, local=False, telemetry_on_dut=True):
Simran Basi833814b2013-01-29 13:13:43 -080094 """Initializes this telemetry runner instance.
95
96 If telemetry is not installed for this build, it will be.
Luis Lozano23ae3192013-11-08 16:22:46 -080097
Ting-Yuan Huange5b19132016-03-22 13:02:41 +080098 Basically, the following commands on the local pc on which test_that
99 will be executed, depending on the 4 possible combinations of
100 local x telemetry_on_dut:
101
102 local=True, telemetry_on_dut=False:
103 run_benchmark --browser=cros-chrome --remote=[dut] [test]
104
105 local=True, telemetry_on_dut=True:
106 ssh [dut] run_benchmark --browser=system [test]
107
108 local=False, telemetry_on_dut=False:
109 ssh [devserver] run_benchmark --browser=cros-chrome --remote=[dut] [test]
110
111 local=False, telemetry_on_dut=True:
112 ssh [devserver] ssh [dut] run_benchmark --browser=system [test]
113
Luis Lozano23ae3192013-11-08 16:22:46 -0800114 @param host: Host where the test will be run.
115 @param local: If set, no devserver will be used, test will be run
116 locally.
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800117 If not set, "ssh [devserver] " will be appended to test
118 commands.
119 @param telemetry_on_dut: If set, telemetry itself (the test harness)
120 will run on dut.
121 It decides browser=[system|cros-chrome]
Simran Basi833814b2013-01-29 13:13:43 -0800122 """
123 self._host = host
Ilja H. Friedelc7bf3102014-05-13 17:31:25 -0700124 self._devserver = None
125 self._telemetry_path = None
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800126 self._telemetry_on_dut = telemetry_on_dut
Luis Lozano23ae3192013-11-08 16:22:46 -0800127 # TODO (llozano crbug.com/324964). Remove conditional code.
128 # Use a class hierarchy instead.
129 if local:
130 self._setup_local_telemetry()
131 else:
132 self._setup_devserver_telemetry()
133
134 logging.debug('Telemetry Path: %s', self._telemetry_path)
135
136
137 def _setup_devserver_telemetry(self):
138 """Setup Telemetry to use the devserver."""
139 logging.debug('Setting up telemetry for devserver testing')
Simran Basi833814b2013-01-29 13:13:43 -0800140 logging.debug('Grabbing build from AFE.')
Prathmesh Prabhucfff58a2017-02-06 10:07:43 -0800141 info = self._host.host_info_store.get()
142 if not info.build:
Simran Basi833814b2013-01-29 13:13:43 -0800143 logging.error('Unable to locate build label for host: %s.',
Dean Liaoe3e75f62017-11-14 10:36:43 +0800144 self._host.host_port)
Simran Basi833814b2013-01-29 13:13:43 -0800145 raise error.AutotestError('Failed to grab build for host %s.' %
Dean Liaoe3e75f62017-11-14 10:36:43 +0800146 self._host.host_port)
Simran Basi833814b2013-01-29 13:13:43 -0800147
Prathmesh Prabhucfff58a2017-02-06 10:07:43 -0800148 logging.debug('Setting up telemetry for build: %s', info.build)
Simran Basi833814b2013-01-29 13:13:43 -0800149
Prathmesh Prabhucfff58a2017-02-06 10:07:43 -0800150 self._devserver = dev_server.ImageServer.resolve(
151 info.build, hostname=self._host.hostname)
152 self._devserver.stage_artifacts(info.build, ['autotest_packages'])
153 self._telemetry_path = self._devserver.setup_telemetry(build=info.build)
Luis Lozano23ae3192013-11-08 16:22:46 -0800154
155
156 def _setup_local_telemetry(self):
157 """Setup Telemetry to use local path to its sources.
158
159 First look for chrome source root, either externally mounted, or inside
160 the chroot. Prefer chrome-src-internal source tree to chrome-src.
161 """
162 TELEMETRY_DIR = 'src'
163 CHROME_LOCAL_SRC = '/var/cache/chromeos-cache/distfiles/target/'
Josh Triplett05208c92014-07-17 13:21:29 -0700164 CHROME_EXTERNAL_SRC = os.path.expanduser('~/chrome_root/')
Luis Lozano23ae3192013-11-08 16:22:46 -0800165
166 logging.debug('Setting up telemetry for local testing')
167
168 sources_list = ('chrome-src-internal', 'chrome-src')
Josh Triplett05208c92014-07-17 13:21:29 -0700169 dir_list = [CHROME_EXTERNAL_SRC]
Luis Lozano23ae3192013-11-08 16:22:46 -0800170 dir_list.extend(
171 [os.path.join(CHROME_LOCAL_SRC, x) for x in sources_list])
172 if 'CHROME_ROOT' in os.environ:
173 dir_list.insert(0, os.environ['CHROME_ROOT'])
174
175 telemetry_src = ''
176 for dir in dir_list:
177 if os.path.exists(dir):
178 telemetry_src = os.path.join(dir, TELEMETRY_DIR)
179 break
180 else:
181 raise error.TestError('Telemetry source directory not found.')
182
183 self._devserver = None
184 self._telemetry_path = telemetry_src
185
186
Luis Lozano814c7182015-09-08 11:20:47 -0700187 def _get_telemetry_cmd(self, script, test_or_benchmark, *args):
Luis Lozano23ae3192013-11-08 16:22:46 -0800188 """Build command to execute telemetry based on script and benchmark.
189
190 @param script: Telemetry script we want to run. For example:
191 [path_to_telemetry_src]/src/tools/telemetry/run_tests.
192 @param test_or_benchmark: Name of the test or benchmark we want to run,
193 with the page_set (if required) as part of
194 the string.
Luis Lozano814c7182015-09-08 11:20:47 -0700195 @param args: additional list of arguments to pass to the script.
196
Luis Lozano23ae3192013-11-08 16:22:46 -0800197 @returns Full telemetry command to execute the script.
198 """
199 telemetry_cmd = []
200 if self._devserver:
Allen Lia5cfb972016-12-27 17:17:22 -0800201 devserver_hostname = self._devserver.hostname
Luis Lozano23ae3192013-11-08 16:22:46 -0800202 telemetry_cmd.extend(['ssh', devserver_hostname])
203
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800204 if self._telemetry_on_dut:
205 telemetry_cmd.extend(
Dean Liaoe3e75f62017-11-14 10:36:43 +0800206 [self._host.ssh_command(alive_interval=900,
207 connection_attempts=4),
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800208 'python',
209 script,
210 '--verbose',
211 '--output-format=chartjson',
212 '--output-dir=%s' % DUT_CHROME_ROOT,
213 '--browser=system'])
214 else:
215 telemetry_cmd.extend(
216 ['python',
217 script,
218 '--verbose',
219 '--browser=cros-chrome',
220 '--output-format=chartjson',
221 '--output-dir=%s' % self._telemetry_path,
Dean Liaoe3e75f62017-11-14 10:36:43 +0800222 '--remote=%s' % self._host.host_port])
Luis Lozano814c7182015-09-08 11:20:47 -0700223 telemetry_cmd.extend(args)
224 telemetry_cmd.append(test_or_benchmark)
225
Keith Haddow1e5c7012016-03-09 16:05:37 -0800226 return ' '.join(telemetry_cmd)
227
228
229 def _scp_telemetry_results_cmd(self, perf_results_dir):
230 """Build command to copy the telemetry results from the devserver.
231
232 @param perf_results_dir: directory path where test output is to be
233 collected.
234 @returns SCP command to copy the results json to the specified directory.
235 """
Dean Liaoe3e75f62017-11-14 10:36:43 +0800236 if not perf_results_dir:
237 return ''
238
239 scp_cmd = ['scp']
240 if self._telemetry_on_dut:
241 scp_cmd.append(self._host.make_ssh_options(alive_interval=900,
242 connection_attempts=4))
243 if not self._host.is_default_port:
244 scp_cmd.append('-P %d' % self._host.port)
245 src = 'root@%s:%s/results-chart.json' % (self._host.hostname,
246 DUT_CHROME_ROOT)
247 else:
248 devserver_hostname = ''
Ricky Liangd186f3e2016-03-15 16:50:55 +0800249 if self._devserver:
Allen Lia5cfb972016-12-27 17:17:22 -0800250 devserver_hostname = self._devserver.hostname + ':'
Dean Liaoe3e75f62017-11-14 10:36:43 +0800251 src = '%s%s/results-chart.json' % (devserver_hostname,
252 self._telemetry_path)
Keith Haddow1e5c7012016-03-09 16:05:37 -0800253
Dean Liaoe3e75f62017-11-14 10:36:43 +0800254 scp_cmd.extend([src, perf_results_dir])
Keith Haddow1e5c7012016-03-09 16:05:37 -0800255 return ' '.join(scp_cmd)
256
257
258 def _run_cmd(self, cmd):
259 """Execute an command in a external shell and capture the output.
260
261 @param cmd: String of is a valid shell command.
262
263 @returns The standard out, standard error and the integer exit code of
264 the executed command.
265 """
266 logging.debug('Running: %s', cmd)
267
268 output = StringIO.StringIO()
269 error_output = StringIO.StringIO()
270 exit_code = 0
271 try:
272 result = utils.run(cmd, stdout_tee=output,
273 stderr_tee=error_output,
274 timeout=TELEMETRY_TIMEOUT_MINS*60)
275 exit_code = result.exit_status
276 except error.CmdError as e:
277 logging.debug('Error occurred executing.')
278 exit_code = e.result_obj.exit_status
279
280 stdout = output.getvalue()
281 stderr = error_output.getvalue()
282 logging.debug('Completed with exit code: %d.\nstdout:%s\n'
283 'stderr:%s', exit_code, stdout, stderr)
284 return stdout, stderr, exit_code
Simran Basi833814b2013-01-29 13:13:43 -0800285
286
Luis Lozano814c7182015-09-08 11:20:47 -0700287 def _run_telemetry(self, script, test_or_benchmark, *args):
Simran Basi833814b2013-01-29 13:13:43 -0800288 """Runs telemetry on a dut.
289
290 @param script: Telemetry script we want to run. For example:
Luis Lozano23ae3192013-11-08 16:22:46 -0800291 [path_to_telemetry_src]/src/tools/telemetry/run_tests.
Simran Basi833814b2013-01-29 13:13:43 -0800292 @param test_or_benchmark: Name of the test or benchmark we want to run,
293 with the page_set (if required) as part of the
294 string.
Luis Lozano814c7182015-09-08 11:20:47 -0700295 @param args: additional list of arguments to pass to the script.
Simran Basi833814b2013-01-29 13:13:43 -0800296
297 @returns A TelemetryResult Instance with the results of this telemetry
298 execution.
299 """
Simran Basi1dbfc132013-05-02 10:11:02 -0700300 # TODO (sbasi crbug.com/239933) add support for incognito mode.
Simran Basi833814b2013-01-29 13:13:43 -0800301
Luis Lozano814c7182015-09-08 11:20:47 -0700302 telemetry_cmd = self._get_telemetry_cmd(script,
303 test_or_benchmark,
304 *args)
Keith Haddow1e5c7012016-03-09 16:05:37 -0800305 logging.debug('Running Telemetry: %s', telemetry_cmd)
Luis Lozano23ae3192013-11-08 16:22:46 -0800306
Keith Haddow1e5c7012016-03-09 16:05:37 -0800307 stdout, stderr, exit_code = self._run_cmd(telemetry_cmd)
Simran Basi833814b2013-01-29 13:13:43 -0800308
309 return TelemetryResult(exit_code=exit_code, stdout=stdout,
310 stderr=stderr)
311
312
Keith Haddow1e5c7012016-03-09 16:05:37 -0800313 def _run_scp(self, perf_results_dir):
314 """Runs telemetry on a dut.
315
316 @param perf_results_dir: The local directory that results are being
317 collected.
318 """
319 scp_cmd = self._scp_telemetry_results_cmd(perf_results_dir)
320 logging.debug('Retrieving Results: %s', scp_cmd)
Dean Liaoe4773c72017-11-09 16:15:38 +0800321 _, _, exit_code = self._run_cmd(scp_cmd)
322 if exit_code != 0:
323 raise error.TestFail('Unable to retrieve results.')
Keith Haddow1e5c7012016-03-09 16:05:37 -0800324
325
Luis Lozano814c7182015-09-08 11:20:47 -0700326 def _run_test(self, script, test, *args):
Simran Basi1dbfc132013-05-02 10:11:02 -0700327 """Runs a telemetry test on a dut.
328
329 @param script: Which telemetry test script we want to run. Can be
330 telemetry's base test script or the Chrome OS specific
331 test script.
332 @param test: Telemetry test we want to run.
Luis Lozano814c7182015-09-08 11:20:47 -0700333 @param args: additional list of arguments to pass to the script.
Simran Basi1dbfc132013-05-02 10:11:02 -0700334
335 @returns A TelemetryResult Instance with the results of this telemetry
336 execution.
337 """
338 logging.debug('Running telemetry test: %s', test)
339 telemetry_script = os.path.join(self._telemetry_path, script)
Luis Lozano814c7182015-09-08 11:20:47 -0700340 result = self._run_telemetry(telemetry_script, test, *args)
Simran Basi1dbfc132013-05-02 10:11:02 -0700341 if result.status is FAILED_STATUS:
Ilja H. Friedelc7bf3102014-05-13 17:31:25 -0700342 raise error.TestFail('Telemetry test %s failed.' % test)
Simran Basi1dbfc132013-05-02 10:11:02 -0700343 return result
344
345
Luis Lozano814c7182015-09-08 11:20:47 -0700346 def run_telemetry_test(self, test, *args):
Simran Basi833814b2013-01-29 13:13:43 -0800347 """Runs a telemetry test on a dut.
348
349 @param test: Telemetry test we want to run.
Luis Lozano814c7182015-09-08 11:20:47 -0700350 @param args: additional list of arguments to pass to the telemetry
351 execution script.
Simran Basi833814b2013-01-29 13:13:43 -0800352
353 @returns A TelemetryResult Instance with the results of this telemetry
354 execution.
355 """
Luis Lozano814c7182015-09-08 11:20:47 -0700356 return self._run_test(TELEMETRY_RUN_TESTS_SCRIPT, test, *args)
Simran Basi1dbfc132013-05-02 10:11:02 -0700357
358
Luis Lozano814c7182015-09-08 11:20:47 -0700359 def run_telemetry_benchmark(self, benchmark, perf_value_writer=None,
360 *args):
Simran Basi833814b2013-01-29 13:13:43 -0800361 """Runs a telemetry benchmark on a dut.
362
363 @param benchmark: Benchmark we want to run.
Fang Denge689e712013-11-13 18:27:06 -0800364 @param perf_value_writer: Should be an instance with the function
365 output_perf_value(), if None, no perf value
366 will be written. Typically this will be the
367 job object from an autotest test.
Luis Lozano814c7182015-09-08 11:20:47 -0700368 @param args: additional list of arguments to pass to the telemetry
369 execution script.
Simran Basi833814b2013-01-29 13:13:43 -0800370
371 @returns A TelemetryResult Instance with the results of this telemetry
372 execution.
373 """
Dave Tu6a404e62013-11-05 15:54:48 -0800374 logging.debug('Running telemetry benchmark: %s', benchmark)
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800375
376 if benchmark not in ON_DUT_WHITE_LIST:
377 self._telemetry_on_dut = False
378
379 if self._telemetry_on_dut:
380 telemetry_script = os.path.join(DUT_CHROME_ROOT,
381 TELEMETRY_RUN_BENCHMARKS_SCRIPT)
382 self._ensure_deps(self._host, benchmark)
383 else:
384 telemetry_script = os.path.join(self._telemetry_path,
385 TELEMETRY_RUN_BENCHMARKS_SCRIPT)
386
Luis Lozano814c7182015-09-08 11:20:47 -0700387 result = self._run_telemetry(telemetry_script, benchmark, *args)
Simran Basi833814b2013-01-29 13:13:43 -0800388
389 if result.status is WARNING_STATUS:
Dave Tu6a404e62013-11-05 15:54:48 -0800390 raise error.TestWarn('Telemetry Benchmark: %s'
391 ' exited with Warnings.' % benchmark)
Simran Basi833814b2013-01-29 13:13:43 -0800392 if result.status is FAILED_STATUS:
Dave Tu6a404e62013-11-05 15:54:48 -0800393 raise error.TestFail('Telemetry Benchmark: %s'
394 ' failed to run.' % benchmark)
Keith Haddow1e5c7012016-03-09 16:05:37 -0800395 if perf_value_writer:
396 self._run_scp(perf_value_writer.resultsdir)
Simran Basi833814b2013-01-29 13:13:43 -0800397 return result
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800398
Gurchetan Singhfaf75e92017-04-17 18:09:44 -0700399
400 def run_gpu_integration_test(self, test, *args):
401 """Runs a gpu test on a dut.
402
403 @param test: Gpu test we want to run.
404 @param args: additional list of arguments to pass to the telemetry
405 execution script.
406
407 @returns A TelemetryResult instance with the results of this telemetry
408 execution.
409 """
410 script = os.path.join(DUT_CHROME_ROOT,
411 TELEMETRY_RUN_GPU_TESTS_SCRIPT)
412 cmd = []
413 if self._devserver:
414 devserver_hostname = self._devserver.hostname
415 cmd.extend(['ssh', devserver_hostname])
416
417 cmd.extend(
Dean Liaoe3e75f62017-11-14 10:36:43 +0800418 [self._host.ssh_command(alive_interval=900, connection_attempts=4),
419 'python', script])
Gurchetan Singhfaf75e92017-04-17 18:09:44 -0700420 cmd.extend(args)
421 cmd.append(test)
422 cmd = ' '.join(cmd)
423 stdout, stderr, exit_code = self._run_cmd(cmd)
424
425 return TelemetryResult(exit_code=exit_code, stdout=stdout,
426 stderr=stderr)
427
428
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800429 def _ensure_deps(self, dut, test_name):
430 """
431 Ensure the dependencies are locally available on DUT.
432
433 @param dut: The autotest host object representing DUT.
434 @param test_name: Name of the telemetry test.
435 """
436 # Get DEPs using host's telemetry.
Kuo-Hsin Yang4a006172018-04-25 14:44:55 +0800437 # Example output, fetch_benchmark_deps.py --output-deps=deps octane:
438 # {'octane': ['tools/perf/page_sets/data/octane_002.wprgo']}
439 perf_path = os.path.join(self._telemetry_path, 'tools', 'perf')
440 deps_path = os.path.join(perf_path, 'fetch_benchmark_deps_result.json')
441 fetch_path = os.path.join(perf_path, 'fetch_benchmark_deps.py')
442 format_fetch = ('python %s --output-deps=%s %s')
443 command_fetch = format_fetch % (fetch_path, deps_path, test_name)
444 command_get = 'cat %s' % deps_path
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800445
446 if self._devserver:
447 devserver_hostname = self._devserver.url().split(
448 'http://')[1].split(':')[0]
Kuo-Hsin Yang4a006172018-04-25 14:44:55 +0800449 command_fetch = 'ssh %s %s' % (devserver_hostname, command_fetch)
450 command_get = 'ssh %s %s' % (devserver_hostname, command_get)
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800451
Kuo-Hsin Yang4a006172018-04-25 14:44:55 +0800452 logging.info('Getting DEPs: %s', command_fetch)
453 _, _, exit_code = self._run_cmd(command_fetch)
454 if exit_code != 0:
455 raise error.TestFail('Error occurred while fetching DEPs.')
456 stdout, _, exit_code = self._run_cmd(command_get)
457 if exit_code != 0:
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800458 raise error.TestFail('Error occurred while getting DEPs.')
459
460 # Download DEPs to DUT.
461 # send_file() relies on rsync over ssh. Couldn't be better.
Kuo-Hsin Yang4a006172018-04-25 14:44:55 +0800462 deps = json.loads(stdout)
463 for dep in deps[test_name]:
Ting-Yuan Huange5b19132016-03-22 13:02:41 +0800464 src = os.path.join(self._telemetry_path, dep)
465 dst = os.path.join(DUT_CHROME_ROOT, dep)
Ting-Yuan Huang8a2c7f72016-03-28 22:01:07 +0800466 if self._devserver:
467 logging.info('Copying: %s -> %s', src, dst)
Chung-yih Wangfd8eb242017-12-09 19:23:04 +0800468 rsync_cmd = utils.sh_escape('rsync %s %s %s:%s' %
469 (self._host.rsync_options(), src,
470 self._host.hostname, dst))
471 utils.run('ssh %s "%s"' % (devserver_hostname, rsync_cmd))
Ting-Yuan Huang8a2c7f72016-03-28 22:01:07 +0800472 else:
473 if not os.path.isfile(src):
474 raise error.TestFail('Error occurred while saving DEPs.')
475 logging.info('Copying: %s -> %s', src, dst)
476 dut.send_file(src, dst)