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