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