Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import tempfile | 9 import tempfile |
| 10 import zipfile | |
| 10 | 11 |
| 12 from devil.utils import reraiser_thread | |
| 13 from devil.utils import tempdir | |
| 14 from devil.utils import zip_utils | |
| 11 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
| 12 from pylib.remote.device import remote_device_test_run | 16 from pylib.remote.device import remote_device_test_run |
| 13 | 17 |
| 14 | 18 |
| 15 class RemoteDeviceInstrumentationTestRun( | 19 class RemoteDeviceInstrumentationTestRun( |
| 16 remote_device_test_run.RemoteDeviceTestRun): | 20 remote_device_test_run.RemoteDeviceTestRun): |
| 17 """Run instrumentation tests on a remote device.""" | 21 """Run instrumentation tests on a remote device.""" |
| 18 | 22 |
| 19 #override | 23 #override |
| 20 def TestPackage(self): | 24 def TestPackage(self): |
| 21 return self._test_instance.test_package | 25 return self._test_instance.test_package |
| 22 | 26 |
| 23 #override | 27 #override |
| 24 def _TriggerSetUp(self): | 28 def _GetAppPath(self): |
| 25 """Set up the triggering of a test run.""" | 29 return self._test_instance.apk_under_test |
| 26 logging.info('Triggering test run.') | |
| 27 | |
| 28 # pylint: disable=protected-access | |
| 29 with tempfile.NamedTemporaryFile(suffix='.txt') as test_list_file: | |
| 30 tests = self._test_instance.GetTests() | |
| 31 logging.debug('preparing to run %d instrumentation tests remotely:', | |
| 32 len(tests)) | |
| 33 for t in tests: | |
| 34 test_name = '%s#%s' % (t['class'], t['method']) | |
| 35 logging.debug(' %s', test_name) | |
| 36 test_list_file.write('%s\n' % test_name) | |
| 37 test_list_file.flush() | |
| 38 self._test_instance._data_deps.append( | |
| 39 (os.path.abspath(test_list_file.name), None)) | |
| 40 | |
| 41 env_vars = self._test_instance.GetDriverEnvironmentVars( | |
| 42 test_list_file_path=test_list_file.name) | |
| 43 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars()) | |
| 44 | |
| 45 logging.debug('extras:') | |
| 46 for k, v in env_vars.iteritems(): | |
| 47 logging.debug(' %s: %s', k, v) | |
| 48 | |
| 49 self._AmInstrumentTestSetup( | |
| 50 self._test_instance.apk_under_test, | |
| 51 self._test_instance.driver_apk, | |
| 52 self._test_instance.driver_name, | |
| 53 environment_variables=env_vars, | |
| 54 extra_apks=([self._test_instance.test_apk] + | |
| 55 self._test_instance.additional_apks)) | |
| 56 | 30 |
| 57 #override | 31 #override |
| 58 def _ParseTestResults(self): | 32 def _GetTestFramework(self): |
| 33 if self._env.test_framework: | |
| 34 logging.warning('Ignoring configured test_framework "%s"', | |
| 35 self._env.test_framework) | |
| 36 return 'robotium' | |
| 37 | |
| 38 #override | |
| 39 def _ParseTestResults(self, test_output, results_zip): | |
| 59 logging.info('Parsing results from stdout.') | 40 logging.info('Parsing results from stdout.') |
| 60 r = base_test_result.TestRunResults() | 41 results = base_test_result.TestRunResults() |
| 61 result_code, result_bundle, statuses = ( | 42 result_code, result_bundle, statuses = ( |
| 62 self._test_instance.ParseAmInstrumentRawOutput( | 43 self._test_instance.ParseAmInstrumentRawOutput( |
| 63 self._results['results']['output'].splitlines())) | 44 test_output['results']['output'].splitlines())) |
| 64 result = self._test_instance.GenerateTestResults( | 45 result = self._test_instance.GenerateTestResults( |
| 65 result_code, result_bundle, statuses, 0, 0) | 46 result_code, result_bundle, statuses, 0, 0) |
| 66 | 47 |
| 67 if isinstance(result, base_test_result.BaseTestResult): | 48 if isinstance(result, base_test_result.BaseTestResult): |
| 68 r.AddResult(result) | 49 results.AddResult(result) |
| 69 elif isinstance(result, list): | 50 elif isinstance(result, list): |
| 70 r.AddResults(result) | 51 results.AddResults(result) |
| 71 else: | 52 else: |
| 72 raise Exception('Unexpected result type: %s' % type(result).__name__) | 53 raise Exception('Unexpected result type: %s' % type(result).__name__) |
| 73 | 54 |
| 74 self._DetectPlatformErrors(r) | 55 remote_device_test_run.DetectPlatformErrors( |
| 75 return r | 56 results, test_output, results_zip) |
| 57 return results | |
| 58 | |
| 59 #override | |
| 60 def _ShouldShard(self): | |
| 61 return True | |
| 62 | |
| 63 #override | |
| 64 def _SetupTestShards(self, num_shards): | |
| 65 test_ids = [] | |
| 66 | |
| 67 all_tests = self._test_instance.GetTests() | |
| 68 test_shards = [all_tests[i::num_shards] for i in range(num_shards)] | |
| 69 | |
| 70 test_list_files = [] | |
| 71 with tempdir.TempDir() as test_list_file_dir: | |
|
rnephew (Wrong account)
2015/11/04 22:22:03
Just a suggestion, feel free to ignore:
This seems
mikecase (-- gone --)
2015/11/05 23:17:41
Changed to test_list_dir.
| |
| 72 for i, tests in enumerate(test_shards): | |
| 73 test_list_file = tempfile.NamedTemporaryFile( | |
| 74 suffix='.txt', dir=test_list_file_dir, delete=False) | |
| 75 test_list_files.append(test_list_file) | |
| 76 for t in tests: | |
| 77 test_name = '%s#%s' % (t['class'], t['method']) | |
| 78 logging.debug('shard %s: %s', i, test_name) | |
| 79 test_list_file.write('%s\n' % test_name) | |
| 80 test_list_file.flush() | |
| 81 | |
| 82 with tempfile.NamedTemporaryFile(suffix='.zip') as test_package: | |
| 83 extra_apks = ([self._test_instance.test_apk] + | |
| 84 self._test_instance.additional_apks) | |
| 85 data_deps = (self._test_instance.GetDataDependencies() + | |
| 86 [(os.path.abspath(f.name), None) for f in test_list_files]) | |
| 87 | |
| 88 sdcard_files = [] | |
| 89 additional_apks = [] | |
| 90 host_test = os.path.basename(self._test_instance.driver_apk) | |
| 91 with zipfile.ZipFile(test_package.name, 'w') as zip_file: | |
| 92 zip_file.write( | |
| 93 self._test_instance.driver_apk, host_test, zipfile.ZIP_DEFLATED) | |
| 94 for h, _ in data_deps: | |
| 95 if os.path.isdir(h): | |
| 96 zip_utils.WriteToZipFile(zip_file, h, '.') | |
| 97 sdcard_files.extend(os.listdir(h)) | |
| 98 else: | |
| 99 zip_utils.WriteToZipFile(zip_file, h, os.path.basename(h)) | |
| 100 sdcard_files.append(os.path.basename(h)) | |
| 101 for a in extra_apks: | |
| 102 zip_utils.WriteToZipFile(zip_file, a, os.path.basename(a)) | |
| 103 additional_apks.append(os.path.basename(a)) | |
| 104 | |
| 105 framework_configs = { | |
| 106 'runner': self._test_instance.driver_name, | |
| 107 'sdcard_files': ','.join(sdcard_files), | |
| 108 'host_test': host_test, | |
| 109 'additional_apks': ','.join(additional_apks), | |
| 110 } | |
| 111 | |
| 112 def upload_test_shards(test_list_file): | |
| 113 shard_framework_config = dict(framework_configs) | |
| 114 env_vars = self._test_instance.GetDriverEnvironmentVars( | |
| 115 test_list_file_path=test_list_file.name) | |
| 116 env_vars.update(self._test_instance.GetHttpServerEnvironmentVars()) | |
| 117 shard_framework_config['environment_vars'] = ','.join( | |
| 118 '%s=%s' % (k, v) for k, v in env_vars.iteritems()) | |
| 119 | |
| 120 test_id = self._UploadTestToDevice(test_package.name) | |
| 121 self._UploadTestConfigToDevice( | |
| 122 test_id, shard_framework_config, self._appurify_configs) | |
| 123 test_ids.append(test_id) | |
| 124 | |
| 125 workers = reraiser_thread.ReraiserThreadGroup( | |
| 126 [reraiser_thread.ReraiserThread( | |
| 127 upload_test_shards, args=[test_list_file], | |
| 128 name='upload test shard %d' % i) | |
| 129 for i, test_list_file in enumerate(test_list_files)]) | |
| 130 workers.StartAll() | |
| 131 workers.JoinAll() | |
| 132 return test_ids | |
| OLD | NEW |