 Chromium Code Reviews
 Chromium Code Reviews Issue 1414403002:
  Add CommandLineArgumentParameter and use it for WebView tests  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cr-526885-read-nested-annotations
    
  
    Issue 1414403002:
  Add CommandLineArgumentParameter and use it for WebView tests  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cr-526885-read-nested-annotations| 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 devil.android import device_errors | 9 from devil.android import device_errors | 
| 10 from pylib import flag_changer | 10 from pylib import flag_changer | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 return tests | 107 return tests | 
| 108 | 108 | 
| 109 #override | 109 #override | 
| 110 def _GetTests(self): | 110 def _GetTests(self): | 
| 111 return self._test_instance.GetTests() | 111 return self._test_instance.GetTests() | 
| 112 | 112 | 
| 113 #override | 113 #override | 
| 114 def _GetTestName(self, test): | 114 def _GetTestName(self, test): | 
| 115 return '%s#%s' % (test['class'], test['method']) | 115 return '%s#%s' % (test['class'], test['method']) | 
| 116 | 116 | 
| 117 def _GetFullTestName(self, test): | |
| 
jbudorick
2015/11/02 14:49:46
nit: I'd rather call this the display name or some
 
mnaganov (inactive)
2015/11/02 19:03:54
Done.
 | |
| 118 full_name = self._GetTestName(test) | |
| 119 flags = test['flags'] | |
| 120 if flags.add: | |
| 121 full_name = '%s with {%s}' % (full_name, ' '.join(flags.add)) | |
| 122 if flags.remove: | |
| 123 full_name = '%s without {%s}' % (full_name, ' '.join(flags.remove)) | |
| 124 return full_name | |
| 125 | |
| 117 #override | 126 #override | 
| 118 def _RunTest(self, device, test): | 127 def _RunTest(self, device, test): | 
| 119 extras = self._test_instance.GetHttpServerEnvironmentVars() | 128 extras = self._test_instance.GetHttpServerEnvironmentVars() | 
| 120 | 129 | 
| 130 flags = None | |
| 121 if isinstance(test, list): | 131 if isinstance(test, list): | 
| 122 if not self._test_instance.driver_apk: | 132 if not self._test_instance.driver_apk: | 
| 123 raise Exception('driver_apk does not exist. ' | 133 raise Exception('driver_apk does not exist. ' | 
| 124 'Please build it and try again.') | 134 'Please build it and try again.') | 
| 125 | 135 | 
| 126 def name_and_timeout(t): | 136 def name_and_timeout(t): | 
| 127 n = self._GetTestName(t) | 137 n = self._GetTestName(t) | 
| 128 i = self._GetTimeoutFromAnnotations(t['annotations'], n) | 138 i = self._GetTimeoutFromAnnotations(t['annotations'], n) | 
| 129 return (n, i) | 139 return (n, i) | 
| 130 | 140 | 
| 131 test_names, timeouts = zip(*(name_and_timeout(t) for t in test)) | 141 test_names, timeouts = zip(*(name_and_timeout(t) for t in test)) | 
| 132 | 142 | 
| 133 test_name = ','.join(test_names) | 143 test_name = ','.join(test_names) | 
| 144 full_test_name = test_name | |
| 134 target = '%s/%s' % ( | 145 target = '%s/%s' % ( | 
| 135 self._test_instance.driver_package, | 146 self._test_instance.driver_package, | 
| 136 self._test_instance.driver_name) | 147 self._test_instance.driver_name) | 
| 137 extras.update( | 148 extras.update( | 
| 138 self._test_instance.GetDriverEnvironmentVars( | 149 self._test_instance.GetDriverEnvironmentVars( | 
| 139 test_list=test_names)) | 150 test_list=test_names)) | 
| 140 timeout = sum(timeouts) | 151 timeout = sum(timeouts) | 
| 141 else: | 152 else: | 
| 142 test_name = self._GetTestName(test) | 153 test_name = self._GetTestName(test) | 
| 154 full_test_name = test_name | |
| 143 target = '%s/%s' % ( | 155 target = '%s/%s' % ( | 
| 144 self._test_instance.test_package, self._test_instance.test_runner) | 156 self._test_instance.test_package, self._test_instance.test_runner) | 
| 145 extras['class'] = test_name | 157 extras['class'] = test_name | 
| 146 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name) | 158 if 'flags' in test: | 
| 159 flags = test['flags'] | |
| 160 full_test_name = self._GetFullTestName(test) | |
| 161 timeout = self._GetTimeoutFromAnnotations( | |
| 162 test['annotations'], full_test_name) | |
| 147 | 163 | 
| 148 logging.info('preparing to run %s: %s', test_name, test) | 164 logging.info('preparing to run %s: %s', full_test_name, test) | 
| 165 | |
| 166 if flags: | |
| 167 self._flag_changers[str(device)].PushFlags( | |
| 
jbudorick
2015/11/02 14:49:46
Note that this flag changer may not have been crea
 
mnaganov (inactive)
2015/11/02 19:03:54
Good catch, fixed!
 | |
| 168 add=flags.add, remove=flags.remove) | |
| 149 | 169 | 
| 150 time_ms = lambda: int(time.time() * 1e3) | 170 time_ms = lambda: int(time.time() * 1e3) | 
| 151 start_ms = time_ms() | 171 start_ms = time_ms() | 
| 152 output = device.StartInstrumentation( | 172 output = device.StartInstrumentation( | 
| 153 target, raw=True, extras=extras, timeout=timeout, retries=0) | 173 target, raw=True, extras=extras, timeout=timeout, retries=0) | 
| 154 duration_ms = time_ms() - start_ms | 174 duration_ms = time_ms() - start_ms | 
| 155 | 175 | 
| 176 if flags: | |
| 177 self._flag_changers[str(device)].Restore() | |
| 
jbudorick
2015/11/02 14:49:46
This should be done in a finally block s.t. it get
 
mnaganov (inactive)
2015/11/02 19:03:54
Done.
 | |
| 178 | |
| 156 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 179 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 
| 157 # doesn't have to parse the output. | 180 # doesn't have to parse the output. | 
| 158 logging.debug('output from %s:', test_name) | 181 logging.debug('output from %s:', full_test_name) | 
| 159 for l in output: | 182 for l in output: | 
| 160 logging.debug(' %s', l) | 183 logging.debug(' %s', l) | 
| 161 | 184 | 
| 162 result_code, result_bundle, statuses = ( | 185 result_code, result_bundle, statuses = ( | 
| 163 self._test_instance.ParseAmInstrumentRawOutput(output)) | 186 self._test_instance.ParseAmInstrumentRawOutput(output)) | 
| 164 results = self._test_instance.GenerateTestResults( | 187 results = self._test_instance.GenerateTestResults( | 
| 165 result_code, result_bundle, statuses, start_ms, duration_ms) | 188 result_code, result_bundle, statuses, start_ms, duration_ms) | 
| 189 if flags: | |
| 
jbudorick
2015/11/02 14:49:46
This shouldn't have to be done, but I need to do s
 
mnaganov (inactive)
2015/11/02 19:03:54
Acknowledged.
 | |
| 190 for r in results: | |
| 191 if r.GetName() == test_name: | |
| 192 r.SetName(full_test_name) | |
| 166 if DidPackageCrashOnDevice(self._test_instance.test_package, device): | 193 if DidPackageCrashOnDevice(self._test_instance.test_package, device): | 
| 167 for r in results: | 194 for r in results: | 
| 168 if r.GetType() == base_test_result.ResultType.UNKNOWN: | 195 if r.GetType() == base_test_result.ResultType.UNKNOWN: | 
| 169 r.SetType(base_test_result.ResultType.CRASH) | 196 r.SetType(base_test_result.ResultType.CRASH) | 
| 170 # TODO(jbudorick): ClearApplicationState on failure before switching | 197 # TODO(jbudorick): ClearApplicationState on failure before switching | 
| 171 # instrumentation tests to platform mode. | 198 # instrumentation tests to platform mode. | 
| 172 return results | 199 return results | 
| 173 | 200 | 
| 174 #override | 201 #override | 
| 175 def _ShouldShard(self): | 202 def _ShouldShard(self): | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 187 | 214 | 
| 188 try: | 215 try: | 
| 189 scale = int(annotations.get('TimeoutScale', 1)) | 216 scale = int(annotations.get('TimeoutScale', 1)) | 
| 190 except ValueError as e: | 217 except ValueError as e: | 
| 191 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) | 218 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) | 
| 192 scale = 1 | 219 scale = 1 | 
| 193 timeout *= scale | 220 timeout *= scale | 
| 194 | 221 | 
| 195 return timeout | 222 return timeout | 
| 196 | 223 | 
| OLD | NEW |