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 time | 6 import time |
7 | 7 |
8 from pylib import flag_changer | 8 from pylib import flag_changer |
9 from pylib.base import base_test_result | 9 from pylib.base import base_test_result |
10 from pylib.base import test_run | 10 from pylib.base import test_run |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 def TearDown(self): | 86 def TearDown(self): |
87 def individual_device_tear_down(dev): | 87 def individual_device_tear_down(dev): |
88 if str(dev) in self._flag_changers: | 88 if str(dev) in self._flag_changers: |
89 self._flag_changers[str(dev)].Restore() | 89 self._flag_changers[str(dev)].Restore() |
90 | 90 |
91 self._env.parallel_devices.pMap(individual_device_tear_down) | 91 self._env.parallel_devices.pMap(individual_device_tear_down) |
92 | 92 |
93 #override | 93 #override |
94 def _CreateShards(self, tests): | 94 def _CreateShards(self, tests): |
95 return tests | 95 return [tests] |
96 | 96 |
97 #override | 97 #override |
98 def _GetTests(self): | 98 def _GetTests(self): |
99 return self._test_instance.GetTests() | 99 return self._test_instance.GetTests() |
100 | 100 |
101 #override | 101 #override |
102 def _GetTestName(self, test): | 102 def _GetTestName(self, test): |
103 return '%s#%s' % (test['class'], test['method']) | 103 return '%s#%s' % (test['class'], test['method']) |
104 | 104 |
105 #override | 105 #override |
106 def _RunTest(self, device, test): | 106 def _RunTest(self, device, test): |
107 test_name = self._GetTestName(test) | 107 extras = self._test_instance.GetHttpServerEnvironmentVars() |
| 108 |
| 109 if isinstance(test, list): |
| 110 if not self._test_instance.driver_apk: |
| 111 raise Exception('driver_apk does not exist. ' |
| 112 'Please build it and try again.') |
| 113 |
| 114 def name_and_timeout(t): |
| 115 n = self._GetTestName(t) |
| 116 i = self._GetTimeoutFromAnnotations(t['annotations'], n) |
| 117 return (n, i) |
| 118 |
| 119 test_names, timeouts = zip(*(name_and_timeout(t) for t in test)) |
| 120 |
| 121 test_name = ','.join(test_names) |
| 122 target = '%s/%s' % ( |
| 123 self._test_instance.driver_package, |
| 124 self._test_instance.driver_name) |
| 125 extras.update( |
| 126 self._test_instance.GetDriverEnvironmentVars( |
| 127 test_list=test_names)) |
| 128 timeout = sum(timeouts) |
| 129 else: |
| 130 test_name = self._GetTestName(test) |
| 131 target = '%s/%s' % ( |
| 132 self._test_instance.test_package, self._test_instance.test_runner) |
| 133 extras['class'] = test_name |
| 134 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name) |
| 135 |
108 logging.info('preparing to run %s: %s' % (test_name, test)) | 136 logging.info('preparing to run %s: %s' % (test_name, test)) |
109 | 137 |
110 extras = { | |
111 'class': test_name, | |
112 'org.chromium.chrome.test.ChromeInstrumentationTestRunner' | |
113 '.EnableTestHttpServer': '', | |
114 } | |
115 timeout = self._GetTimeoutFromAnnotations(test['annotations'], test_name) | |
116 | |
117 time_ms = lambda: int(time.time() * 1e3) | 138 time_ms = lambda: int(time.time() * 1e3) |
118 start_ms = time_ms() | 139 start_ms = time_ms() |
119 output = device.StartInstrumentation( | 140 output = device.StartInstrumentation( |
120 '%s/%s' % (self._test_instance.test_package, | 141 target, raw=True, extras=extras, timeout=timeout, retries=0) |
121 self._test_instance.test_runner), | |
122 raw=True, extras=extras, timeout=timeout, retries=0) | |
123 duration_ms = time_ms() - start_ms | 142 duration_ms = time_ms() - start_ms |
124 | 143 |
125 # TODO(jbudorick): Make instrumentation tests output a JSON so this | 144 # TODO(jbudorick): Make instrumentation tests output a JSON so this |
126 # doesn't have to parse the output. | 145 # doesn't have to parse the output. |
127 logging.debug('output from %s:', test_name) | 146 logging.debug('output from %s:', test_name) |
128 for l in output: | 147 for l in output: |
129 logging.debug(' %s', l) | 148 logging.debug(' %s', l) |
130 | 149 |
131 result_code, result_bundle, statuses = ( | 150 result_code, result_bundle, statuses = ( |
132 self._test_instance.ParseAmInstrumentRawOutput(output)) | 151 self._test_instance.ParseAmInstrumentRawOutput(output)) |
(...skipping 20 matching lines...) Expand all Loading... |
153 | 172 |
154 try: | 173 try: |
155 scale = int(annotations.get('TimeoutScale', 1)) | 174 scale = int(annotations.get('TimeoutScale', 1)) |
156 except ValueError as e: | 175 except ValueError as e: |
157 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) | 176 logging.warning("Non-integer value of TimeoutScale ignored. (%s)", str(e)) |
158 scale = 1 | 177 scale = 1 |
159 timeout *= scale | 178 timeout *= scale |
160 | 179 |
161 return timeout | 180 return timeout |
162 | 181 |
OLD | NEW |