| 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 import logging | 5 import logging |
| 6 import re | 6 import re |
| 7 import time | 7 import time |
| 8 | 8 |
| 9 from pylib import flag_changer | 9 from pylib import flag_changer |
| 10 from pylib.base import base_test_result | 10 from pylib.base import base_test_result |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 #override | 123 #override |
| 124 def _GetTests(self): | 124 def _GetTests(self): |
| 125 return self._test_instance.GetTests() | 125 return self._test_instance.GetTests() |
| 126 | 126 |
| 127 #override | 127 #override |
| 128 def _GetTestName(self, test): | 128 def _GetTestName(self, test): |
| 129 return '%s#%s' % (test['class'], test['method']) | 129 return '%s#%s' % (test['class'], test['method']) |
| 130 | 130 |
| 131 #override | 131 #override |
| 132 def _RunTest(self, device, test): | 132 def _RunTest(self, device, test): |
| 133 extras = self._test_instance.GetHttpServerEnvironmentVars() | 133 test_name = self._GetTestName(test) |
| 134 logging.info('preparing to run %s: %s' % (test_name, test)) |
| 134 | 135 |
| 135 if isinstance(test, list): | 136 extras = { |
| 136 if not self._test_instance.driver_apk: | 137 'class': test_name, |
| 137 raise Exception('driver_apk does not exist. ' | 138 'org.chromium.chrome.test.ChromeInstrumentationTestRunner' |
| 138 'Please build it and try again.') | 139 '.EnableTestHttpServer': '', |
| 139 | 140 } |
| 140 def name_and_timeout(t): | 141 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name) |
| 141 n = self._GetTestName(t) | |
| 142 i = self._GetTimeoutFromAnnotations(t['annotations'], n) | |
| 143 return (n, i) | |
| 144 | |
| 145 test_names, timeouts = zip(*(name_and_timeout(t) for t in test)) | |
| 146 | |
| 147 test_name = ','.join(test_names) | |
| 148 target = '%s/%s' % ( | |
| 149 self._test_instance.driver_package, | |
| 150 self._test_instance.driver_name) | |
| 151 extras.update( | |
| 152 self._test_instance.GetDriverEnvironmentVars( | |
| 153 test_list=test_names)) | |
| 154 timeout = sum(timeouts) | |
| 155 else: | |
| 156 test_name = self._GetTestName(test) | |
| 157 target = '%s/%s' % ( | |
| 158 self._test_instance.test_package, self._test_instance.test_runner) | |
| 159 extras['class'] = test_name | |
| 160 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name) | |
| 161 | |
| 162 logging.info('preparing to run %s: %s' % (test_name, test)) | |
| 163 | 142 |
| 164 time_ms = lambda: int(time.time() * 1e3) | 143 time_ms = lambda: int(time.time() * 1e3) |
| 165 start_ms = time_ms() | 144 start_ms = time_ms() |
| 166 output = device.StartInstrumentation( | 145 output = device.StartInstrumentation( |
| 167 target, raw=True, extras=extras, timeout=timeout, retries=0) | 146 '%s/%s' % (self._test_instance.test_package, |
| 147 self._test_instance.test_runner), |
| 148 raw=True, extras=extras, timeout=timeout, retries=0) |
| 168 duration_ms = time_ms() - start_ms | 149 duration_ms = time_ms() - start_ms |
| 169 | 150 |
| 170 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 151 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
| 171 # doesn't have to parse the output. | 152 # doesn't have to parse the output. |
| 172 logging.debug('output from %s:', test_name) | 153 logging.debug('output from %s:', test_name) |
| 173 for l in output: | 154 for l in output: |
| 174 logging.debug(' %s', l) | 155 logging.debug(' %s', l) |
| 175 | 156 |
| 176 result_code, result_bundle, statuses = ( | 157 result_code, result_bundle, statuses = ( |
| 177 self._test_instance.ParseAmInstrumentRawOutput(output)) | 158 self._test_instance.ParseAmInstrumentRawOutput(output)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 198 | 179 |
| 199 try: | 180 try: |
| 200 scale = int(annotations.get('TimeoutScale', 1)) | 181 scale = int(annotations.get('TimeoutScale', 1)) |
| 201 except ValueError as e: | 182 except ValueError as e: |
| 202 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) | 183 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) |
| 203 scale = 1 | 184 scale = 1 |
| 204 timeout *= scale | 185 timeout *= scale |
| 205 | 186 |
| 206 return timeout | 187 return timeout |
| 207 | 188 |
| OLD | NEW |