OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 | 5 |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 import os | 8 import os |
9 import pexpect | 9 import pexpect |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 """ | 32 """ |
33 | 33 |
34 def __init__(self, adb, device, test_suite, timeout, rebaseline, | 34 def __init__(self, adb, device, test_suite, timeout, rebaseline, |
35 performance_test, cleanup_test_files, tool, dump_debug_info): | 35 performance_test, cleanup_test_files, tool, dump_debug_info): |
36 self.adb = adb | 36 self.adb = adb |
37 self.device = device | 37 self.device = device |
38 self.test_suite_full = test_suite | 38 self.test_suite_full = test_suite |
39 self.test_suite = os.path.splitext(test_suite)[0] | 39 self.test_suite = os.path.splitext(test_suite)[0] |
40 self.test_suite_basename = self._GetTestSuiteBaseName() | 40 self.test_suite_basename = self._GetTestSuiteBaseName() |
41 self.test_suite_dirname = os.path.dirname( | 41 self.test_suite_dirname = os.path.dirname( |
42 self.test_suite.split(self.test_suite_basename)[0]); | 42 self.test_suite.split(self.test_suite_basename)[0]) |
43 self.rebaseline = rebaseline | 43 self.rebaseline = rebaseline |
44 self.performance_test = performance_test | 44 self.performance_test = performance_test |
45 self.cleanup_test_files = cleanup_test_files | 45 self.cleanup_test_files = cleanup_test_files |
46 self.tool = tool | 46 self.tool = tool |
47 if timeout == 0: | 47 if timeout == 0: |
48 timeout = 60 | 48 timeout = 60 |
49 # On a VM (e.g. chromium buildbots), this timeout is way too small. | 49 # On a VM (e.g. chromium buildbots), this timeout is way too small. |
50 if os.environ.get('BUILDBOT_SLAVENAME'): | 50 if os.environ.get('BUILDBOT_SLAVENAME'): |
51 timeout = timeout * 2 | 51 timeout = timeout * 2 |
52 self.timeout = timeout * self.tool.GetTimeoutScale() | 52 self.timeout = timeout * self.tool.GetTimeoutScale() |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 """Watches the test output. | 137 """Watches the test output. |
138 Args: | 138 Args: |
139 p: the process generating output as created by pexpect.spawn. | 139 p: the process generating output as created by pexpect.spawn. |
140 """ | 140 """ |
141 ok_tests = [] | 141 ok_tests = [] |
142 failed_tests = [] | 142 failed_tests = [] |
143 crashed_tests = [] | 143 crashed_tests = [] |
144 timed_out = False | 144 timed_out = False |
145 overall_fail = False | 145 overall_fail = False |
146 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | 146 re_run = re.compile('\[ RUN \] ?(.*)\r\n') |
147 # APK tests rely on the END tag. | 147 # APK tests rely on the PASSED tag. |
148 re_end = re.compile('\[ END \] ?(.*)\r\n') | 148 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') |
149 # Signal handlers are installed before starting tests | 149 # Signal handlers are installed before starting tests |
150 # to output the CRASHED marker when a crash happens. | 150 # to output the CRASHED marker when a crash happens. |
151 re_crash = re.compile('\[ CRASHED \](.*)\r\n') | 151 re_crash = re.compile('\[ CRASHED \](.*)\r\n') |
152 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | 152 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') |
153 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | 153 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') |
154 re_ok = re.compile('\[ OK \] ?(.*)\r\n') | 154 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') |
155 io_stats_before = self._BeginGetIOStats() | 155 io_stats_before = self._BeginGetIOStats() |
156 try: | 156 try: |
157 while True: | 157 while True: |
158 found = p.expect([re_run, re_end, re_runner_fail], timeout=self.timeout) | 158 found = p.expect([re_run, re_passed, re_runner_fail], |
159 if found == 1: # matched END. | 159 timeout=self.timeout) |
| 160 if found == 1: # matched PASSED. |
160 break | 161 break |
161 if found == 2: # RUNNER_FAILED | 162 if found == 2: # RUNNER_FAILED |
162 logging.error('RUNNER_FAILED') | 163 logging.error('RUNNER_FAILED') |
163 overall_fail = True | 164 overall_fail = True |
164 break | 165 break |
165 if self.dump_debug_info: | 166 if self.dump_debug_info: |
166 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') | 167 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') |
167 full_test_name = p.match.group(1).replace('\r', '') | 168 full_test_name = p.match.group(1).replace('\r', '') |
168 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) | 169 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) |
169 if found == 0: # re_ok | 170 if found == 0: # re_ok |
170 ok_tests += [BaseTestResult(full_test_name, p.before)] | 171 if full_test_name == p.match.group(1).replace('\r', ''): |
171 continue | 172 ok_tests += [BaseTestResult(full_test_name, p.before)] |
| 173 continue |
172 if found == 2: # re_crash | 174 if found == 2: # re_crash |
173 crashed_tests += [BaseTestResult(full_test_name, p.before)] | 175 crashed_tests += [BaseTestResult(full_test_name, p.before)] |
174 overall_fail = True | 176 overall_fail = True |
175 break | 177 break |
176 # The test failed. | 178 # The test failed. |
177 failed_tests += [BaseTestResult(full_test_name, p.before)] | 179 failed_tests += [BaseTestResult(full_test_name, p.before)] |
178 except pexpect.EOF: | 180 except pexpect.EOF: |
179 logging.error('Test terminated - EOF') | 181 logging.error('Test terminated - EOF') |
180 except pexpect.TIMEOUT: | 182 except pexpect.TIMEOUT: |
181 logging.error('Test terminated after %d second timeout.', | 183 logging.error('Test terminated after %d second timeout.', |
182 self.timeout) | 184 self.timeout) |
183 timed_out = True | 185 timed_out = True |
184 finally: | 186 finally: |
185 p.close() | 187 p.close() |
186 if not self.rebaseline: | 188 if not self.rebaseline: |
187 ok_tests += self._EndGetIOStats(io_stats_before) | 189 ok_tests += self._EndGetIOStats(io_stats_before) |
188 ret_code = self._GetGTestReturnCode() | 190 ret_code = self._GetGTestReturnCode() |
189 if ret_code: | 191 if ret_code: |
190 failed_tests += [BaseTestResult('gtest exit code: %d' % ret_code, | 192 failed_tests += [BaseTestResult('gtest exit code: %d' % ret_code, |
191 'pexpect.before: %s' | 193 'pexpect.before: %s' |
192 '\npexpect.after: %s' | 194 '\npexpect.after: %s' |
193 % (p.before, | 195 % (p.before, |
194 p.after))] | 196 p.after))] |
195 # Create TestResults and return | 197 # Create TestResults and return |
196 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, | 198 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, |
197 crashed=crashed_tests, timed_out=timed_out, | 199 crashed=crashed_tests, timed_out=timed_out, |
198 overall_fail=overall_fail) | 200 overall_fail=overall_fail) |
OLD | NEW |