| OLD | NEW |
| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 194 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 195 logging.WARNING): | 195 logging.WARNING): |
| 196 test_check_res = appurify_sanitized.api.tests_check_result( | 196 test_check_res = appurify_sanitized.api.tests_check_result( |
| 197 self._env.token, test_run_id) | 197 self._env.token, test_run_id) |
| 198 remote_device_helper.TestHttpResponse(test_check_res, | 198 remote_device_helper.TestHttpResponse(test_check_res, |
| 199 'Unable to get test status.') | 199 'Unable to get test status.') |
| 200 self._results = test_check_res.json()['response'] | 200 self._results = test_check_res.json()['response'] |
| 201 return self._results['status'] | 201 return self._results['status'] |
| 202 | 202 |
| 203 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package, | 203 def _AmInstrumentTestSetup(self, app_path, test_path, runner_package, |
| 204 environment_variables): | 204 environment_variables, extra_apks=None): |
| 205 config = {'runner': runner_package} | 205 config = {'runner': runner_package} |
| 206 if environment_variables: | 206 if environment_variables: |
| 207 config['environment_vars'] = ','.join( | 207 config['environment_vars'] = ','.join( |
| 208 '%s=%s' % (k, v) for k, v in environment_variables.iteritems()) | 208 '%s=%s' % (k, v) for k, v in environment_variables.iteritems()) |
| 209 | 209 |
| 210 self._app_id = self._UploadAppToDevice(app_path) | 210 self._app_id = self._UploadAppToDevice(app_path) |
| 211 | 211 |
| 212 data_deps = self._test_instance.GetDataDependencies() | 212 data_deps = self._test_instance.GetDataDependencies() |
| 213 if data_deps: | 213 if data_deps: |
| 214 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: | 214 with tempfile.NamedTemporaryFile(suffix='.zip') as test_with_deps: |
| 215 sdcard_files = [] | 215 sdcard_files = [] |
| 216 additional_apks = [] |
| 216 host_test = os.path.basename(test_path) | 217 host_test = os.path.basename(test_path) |
| 217 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: | 218 with zipfile.ZipFile(test_with_deps.name, 'w') as zip_file: |
| 218 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) | 219 zip_file.write(test_path, host_test, zipfile.ZIP_DEFLATED) |
| 219 for h, _ in data_deps: | 220 for h, _ in data_deps: |
| 220 if os.path.isdir(h): | 221 if os.path.isdir(h): |
| 221 zip_utils.WriteToZipFile(zip_file, h, '.') | 222 zip_utils.WriteToZipFile(zip_file, h, '.') |
| 222 sdcard_files.extend(os.listdir(h)) | 223 sdcard_files.extend(os.listdir(h)) |
| 223 else: | 224 else: |
| 224 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | 225 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) |
| 225 sdcard_files.append(os.path.basename(h)) | 226 sdcard_files.append(os.path.basename(h)) |
| 227 for a in extra_apks or (): |
| 228 zip_utils.WriteToZipFile(zip_file, a, os.path.basename(a)); |
| 229 additional_apks.append(os.path.basename(a)) |
| 230 |
| 226 config['sdcard_files'] = ','.join(sdcard_files) | 231 config['sdcard_files'] = ','.join(sdcard_files) |
| 227 config['host_test'] = host_test | 232 config['host_test'] = host_test |
| 233 if additional_apks: |
| 234 config['additional_apks'] = ','.join(additional_apks) |
| 228 self._test_id = self._UploadTestToDevice( | 235 self._test_id = self._UploadTestToDevice( |
| 229 'robotium', test_with_deps.name, app_id=self._app_id) | 236 'robotium', test_with_deps.name, app_id=self._app_id) |
| 230 else: | 237 else: |
| 231 self._test_id = self._UploadTestToDevice('robotium', test_path) | 238 self._test_id = self._UploadTestToDevice('robotium', test_path) |
| 232 | 239 |
| 233 logging.info('Setting config: %s' % config) | 240 logging.info('Setting config: %s' % config) |
| 234 appurify_configs = {} | 241 appurify_configs = {} |
| 235 if self._env.network_config: | 242 if self._env.network_config: |
| 236 appurify_configs['network'] = self._env.network_config | 243 appurify_configs['network'] = self._env.network_config |
| 237 self._SetTestConfig('robotium', config, **appurify_configs) | 244 self._SetTestConfig('robotium', config, **appurify_configs) |
| 238 | 245 |
| 239 def _UploadAppToDevice(self, app_path): | 246 def _UploadAppToDevice(self, app_path): |
| 240 """Upload app to device.""" | 247 """Upload app to device.""" |
| 241 logging.info('Uploading %s to remote service.', app_path) | 248 logging.info('Uploading %s to remote service as %s.', app_path, |
| 249 self._test_instance.suite) |
| 242 with open(app_path, 'rb') as apk_src: | 250 with open(app_path, 'rb') as apk_src: |
| 243 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 251 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 244 logging.WARNING): | 252 logging.WARNING): |
| 245 upload_results = appurify_sanitized.api.apps_upload( | 253 upload_results = appurify_sanitized.api.apps_upload( |
| 246 self._env.token, apk_src, 'raw', name=self._test_instance.suite) | 254 self._env.token, apk_src, 'raw', name=self._test_instance.suite) |
| 247 remote_device_helper.TestHttpResponse( | 255 remote_device_helper.TestHttpResponse( |
| 248 upload_results, 'Unable to upload %s.' % app_path) | 256 upload_results, 'Unable to upload %s.' % app_path) |
| 249 return upload_results.json()['response']['app_id'] | 257 return upload_results.json()['response']['app_id'] |
| 250 | 258 |
| 251 def _UploadTestToDevice(self, test_type, test_path, app_id=None): | 259 def _UploadTestToDevice(self, test_type, test_path, app_id=None): |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 config_data.extend( | 298 config_data.extend( |
| 291 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) | 299 '%s=%s' % (k, v) for k, v in runner_configs.iteritems()) |
| 292 config.write(''.join('%s\n' % l for l in config_data)) | 300 config.write(''.join('%s\n' % l for l in config_data)) |
| 293 config.flush() | 301 config.flush() |
| 294 config.seek(0) | 302 config.seek(0) |
| 295 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, | 303 with appurify_sanitized.SanitizeLogging(self._env.verbose_count, |
| 296 logging.WARNING): | 304 logging.WARNING): |
| 297 config_response = appurify_sanitized.api.config_upload( | 305 config_response = appurify_sanitized.api.config_upload( |
| 298 self._env.token, config, self._test_id) | 306 self._env.token, config, self._test_id) |
| 299 remote_device_helper.TestHttpResponse( | 307 remote_device_helper.TestHttpResponse( |
| 300 config_response, 'Unable to upload test config.') | 308 config_response, 'Unable to upload test config.') |
| OLD | NEW |