Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: build/android/pylib/remote/device/remote_device_test_run.py

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Run specific test on specific environment.""" 5 """Run specific test on specific environment."""
6 6
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
(...skipping 11 matching lines...) Expand all
22 class RemoteDeviceTestRun(test_run.TestRun): 22 class RemoteDeviceTestRun(test_run.TestRun):
23 """Run tests on a remote device.""" 23 """Run tests on a remote device."""
24 24
25 _TEST_RUN_KEY = 'test_run' 25 _TEST_RUN_KEY = 'test_run'
26 _TEST_RUN_ID_KEY = 'test_run_id' 26 _TEST_RUN_ID_KEY = 'test_run_id'
27 27
28 WAIT_TIME = 5 28 WAIT_TIME = 5
29 COMPLETE = 'complete' 29 COMPLETE = 'complete'
30 HEARTBEAT_INTERVAL = 300 30 HEARTBEAT_INTERVAL = 300
31 31
32 _RESULTS_FILE = 'appurify_results/result.txt'
33
32 def __init__(self, env, test_instance): 34 def __init__(self, env, test_instance):
33 """Constructor. 35 """Constructor.
34 36
35 Args: 37 Args:
36 env: Environment the tests will run in. 38 env: Environment the tests will run in.
37 test_instance: The test that will be run. 39 test_instance: The test that will be run.
38 """ 40 """
39 super(RemoteDeviceTestRun, self).__init__(env, test_instance) 41 super(RemoteDeviceTestRun, self).__init__(env, test_instance)
40 self._env = env 42 self._env = env
41 self._test_instance = test_instance 43 self._test_instance = test_instance
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 for test in test_list_res.json()['response']: 168 for test in test_list_res.json()['response']:
167 if test['test_type'] == test_name: 169 if test['test_type'] == test_name:
168 return test['test_id'] 170 return test['test_id']
169 raise remote_device_helper.RemoteDeviceError( 171 raise remote_device_helper.RemoteDeviceError(
170 'No test found with name %s' % (test_name)) 172 'No test found with name %s' % (test_name))
171 173
172 def _DownloadTestResults(self, results_path): 174 def _DownloadTestResults(self, results_path):
173 """Download the test results from remote device service. 175 """Download the test results from remote device service.
174 176
175 Args: 177 Args:
176 results_path: path to download results to. 178 results_path: Path to download appurify results zipfile.
177 """ 179 """
178 if results_path: 180 if results_path:
179 logging.info('Downloading results to %s.' % results_path) 181 logging.info('Downloading results to %s.' % results_path)
180 if not os.path.exists(os.path.dirname(results_path)): 182 if not os.path.exists(os.path.dirname(results_path)):
181 os.makedirs(os.path.dirname(results_path)) 183 os.makedirs(os.path.dirname(results_path))
182 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, 184 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
183 logging.WARNING): 185 logging.WARNING):
184 appurify_sanitized.utils.wget(self._results['results']['url'], 186 appurify_sanitized.utils.wget(self._results['results']['url'],
185 results_path) 187 results_path)
186 188
189 def _GetRawTestOutput(self):
190 """Returns the test output."""
191 # TODO(mikecase): Remove getting results from zip when b/18981674 is fixed.
192 results_zipfile = self._env.results_path
193 if results_zipfile and os.path.exists(results_zipfile):
194 with zipfile.ZipFile(results_zipfile) as z:
195 with z.open(self._RESULTS_FILE, 'r') as r:
196 return r.read()
197 else:
198 logging.warning(
199 'If the test output is too long, some test results may get cut off.')
200 logging.warning(
201 'Use the --results-path option to ensure you get the full results.')
202 return self._results['results']['output']
203
187 def _GetTestStatus(self, test_run_id): 204 def _GetTestStatus(self, test_run_id):
188 """Checks the state of the test, and sets self._results 205 """Checks the state of the test, and sets self._results
189 206
190 Args: 207 Args:
191 test_run_id: Id of test on on remote service. 208 test_run_id: Id of test on on remote service.
192 """ 209 """
193 210
194 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, 211 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
195 logging.WARNING): 212 logging.WARNING):
196 test_check_res = appurify_sanitized.api.tests_check_result( 213 test_check_res = appurify_sanitized.api.tests_check_result(
197 self._env.token, test_run_id) 214 self._env.token, test_run_id)
198 remote_device_helper.TestHttpResponse(test_check_res, 215 remote_device_helper.TestHttpResponse(test_check_res,
199 'Unable to get test status.') 216 'Unable to get test status.')
200 self._results = test_check_res.json()['response'] 217 self._results = test_check_res.json()['response']
201 return self._results['status'] 218 return self._results['status']
202 219
203 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package, 220 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package,
204 environment_variables): 221 environment_variables, extra_apks=None):
205 config = {'runner': runner_package} 222 config = {'runner': runner_package}
206 if environment_variables: 223 if environment_variables:
207 config['environment_vars'] = ','.join( 224 config['environment_vars'] = ','.join(
208 '%s=%s' % (k, v) for k, v in environment_variables.iteritems()) 225 '%s=%s' % (k, v) for k, v in environment_variables.iteritems())
209 226
210 self._app_id = self._UploadAppToDevice(app_path) 227 self._app_id = self._UploadAppToDevice(app_path)
211 228
212 data_deps = self._test_instance.GetDataDependencies() 229 data_deps = self._test_instance.GetDataDependencies()
213 if data_deps: 230 if data_deps:
214 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: 231 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps:
215 sdcard_files = [] 232 sdcard_files = []
233 additional_apks = []
216 host_test = os.path.basename(test_path) 234 host_test = os.path.basename(test_path)
217 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: 235 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file:
218 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) 236 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED)
219 for h, _ in data_deps: 237 for h, _ in data_deps:
220 if os.path.isdir(h): 238 if os.path.isdir(h):
221 zip_utils.WriteToZipFile(zip_file, h, '.') 239 zip_utils.WriteToZipFile(zip_file, h, '.')
222 sdcard_files.extend(os.listdir(h)) 240 sdcard_files.extend(os.listdir(h))
223 else: 241 else:
224 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) 242 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h))
225 sdcard_files.append(os.path.basename(h)) 243 sdcard_files.append(os.path.basename(h))
244 for a in extra_apks or ():
245 zip_utils.WriteToZipFile(zip_file, a, os.path.basename(a));
246 additional_apks.append(os.path.basename(a))
247
226 config['sdcard_files'] = ','.join(sdcard_files) 248 config['sdcard_files'] = ','.join(sdcard_files)
227 config['host_test'] = host_test 249 config['host_test'] = host_test
250 if additional_apks:
251 config['additional_apks'] = ','.join(additional_apks)
228 self._test_id = self._UploadTestToDevice( 252 self._test_id = self._UploadTestToDevice(
229 'robotium', test_with_deps.name, app_id=self._app_id) 253 'robotium', test_with_deps.name, app_id=self._app_id)
230 else: 254 else:
231 self._test_id = self._UploadTestToDevice('robotium', test_path) 255 self._test_id = self._UploadTestToDevice('robotium', test_path)
232 256
233 logging.info('Setting config: %s' % config) 257 logging.info('Setting config: %s' % config)
234 appurify_configs = {} 258 appurify_configs = {}
235 if self._env.network_config: 259 if self._env.network_config:
236 appurify_configs['network'] = self._env.network_config 260 appurify_configs['network'] = self._env.network_config
237 self._SetTestConfig('robotium', config, **appurify_configs) 261 self._SetTestConfig('robotium', config, **appurify_configs)
238 262
239 def _UploadAppToDevice(self, app_path): 263 def _UploadAppToDevice(self, app_path):
240 """Upload app to device.""" 264 """Upload app to device."""
241 logging.info('Uploading %s to remote service.', app_path) 265 logging.info('Uploading %s to remote service as %s.', app_path,
266 self._test_instance.suite)
242 with open(app_path, 'rb') as apk_src: 267 with open(app_path, 'rb') as apk_src:
243 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, 268 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
244 logging.WARNING): 269 logging.WARNING):
245 upload_results = appurify_sanitized.api.apps_upload( 270 upload_results = appurify_sanitized.api.apps_upload(
246 self._env.token, apk_src, 'raw', name=self._test_instance.suite) 271 self._env.token, apk_src, 'raw', name=self._test_instance.suite)
247 remote_device_helper.TestHttpResponse( 272 remote_device_helper.TestHttpResponse(
248 upload_results, 'Unable to upload %s.' % app_path) 273 upload_results, 'Unable to upload %s.' % app_path)
249 return upload_results.json()['response']['app_id'] 274 return upload_results.json()['response']['app_id']
250 275
251 def _UploadTestToDevice(self, test_type, test_path, app_id=None): 276 def _UploadTestToDevice(self, test_type, test_path, app_id=None):
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 config_data.extend( 315 config_data.extend(
291 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) 316 '%s=%s' % (k, v) for k, v in runner_configs.iteritems())
292 config.write(''.join('%s\n' % l for l in config_data)) 317 config.write(''.join('%s\n' % l for l in config_data))
293 config.flush() 318 config.flush()
294 config.seek(0) 319 config.seek(0)
295 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, 320 with appurify_sanitized.SanitizeLogging(self._env.verbose_count,
296 logging.WARNING): 321 logging.WARNING):
297 config_response = appurify_sanitized.api.config_upload( 322 config_response = appurify_sanitized.api.config_upload(
298 self._env.token, config, self._test_id) 323 self._env.token, config, self._test_id)
299 remote_device_helper.TestHttpResponse( 324 remote_device_helper.TestHttpResponse(
300 config_response, 'Unable to upload test config.') 325 config_response, 'Unable to upload test config.')
OLDNEW
« no previous file with comments | « build/android/pylib/remote/device/remote_device_instrumentation_test_run.py ('k') | build/android/pylib/utils/emulator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698