| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 ret += [current + test_name] | 122 ret += [current + test_name] |
| 123 return ret | 123 return ret |
| 124 | 124 |
| 125 def _WatchTestOutput(self, p): | 125 def _WatchTestOutput(self, p): |
| 126 """Watches the test output. | 126 """Watches the test output. |
| 127 Args: | 127 Args: |
| 128 p: the process generating output as created by pexpect.spawn. | 128 p: the process generating output as created by pexpect.spawn. |
| 129 """ | 129 """ |
| 130 ok_tests = [] | 130 ok_tests = [] |
| 131 failed_tests = [] | 131 failed_tests = [] |
| 132 crashed_tests = [] |
| 132 timed_out = False | 133 timed_out = False |
| 133 overall_fail = False | 134 overall_fail = False |
| 134 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | 135 re_run = re.compile('\[ RUN \] ?(.*)\r\n') |
| 135 # APK tests rely on the END tag. | 136 # APK tests rely on the END tag. |
| 136 re_end = re.compile('\[ END \] ?(.*)\r\n') | 137 re_end = re.compile('\[ END \] ?(.*)\r\n') |
| 138 # Signal handlers are installed before starting tests |
| 139 # to output the CRASHED marker when a crash happens. |
| 140 re_crash = re.compile('\[ CRASHED \](.*)\r\n') |
| 137 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | 141 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') |
| 138 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | 142 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') |
| 139 re_ok = re.compile('\[ OK \] ?(.*)\r\n') | 143 re_ok = re.compile('\[ OK \] ?(.*)\r\n') |
| 140 (io_stats_before, ready_to_continue) = self._BeginGetIOStats() | 144 (io_stats_before, ready_to_continue) = self._BeginGetIOStats() |
| 141 while ready_to_continue: | 145 while ready_to_continue: |
| 142 found = p.expect([re_run, pexpect.EOF, re_end, re_runner_fail], | 146 found = p.expect([re_run, pexpect.EOF, re_end, re_runner_fail], |
| 143 timeout=self.timeout) | 147 timeout=self.timeout) |
| 144 if found == 1: # matched pexpect.EOF | 148 if found == 1: # matched pexpect.EOF |
| 145 break | 149 break |
| 146 if found == 2: # matched END. | 150 if found == 2: # matched END. |
| 147 break | 151 break |
| 148 if found == 3: # RUNNER_FAILED | 152 if found == 3: # RUNNER_FAILED |
| 149 logging.error('RUNNER_FAILED') | 153 logging.error('RUNNER_FAILED') |
| 150 overall_fail = True | 154 overall_fail = True |
| 151 break | 155 break |
| 152 if self.dump_debug_info: | 156 if self.dump_debug_info: |
| 153 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') | 157 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') |
| 154 full_test_name = p.match.group(1) | 158 full_test_name = p.match.group(1) |
| 155 found = p.expect([re_ok, re_fail, pexpect.EOF, pexpect.TIMEOUT], | 159 found = p.expect([re_ok, re_fail, re_crash, pexpect.EOF, pexpect.TIMEOUT], |
| 156 timeout=self.timeout) | 160 timeout=self.timeout) |
| 157 if found == 0: # re_ok | 161 if found == 0: # re_ok |
| 158 ok_tests += [BaseTestResult(full_test_name.replace('\r', ''), | 162 ok_tests += [BaseTestResult(full_test_name.replace('\r', ''), |
| 159 p.before)] | 163 p.before)] |
| 160 continue | 164 continue |
| 165 if found == 2: # re_crash |
| 166 crashed_tests += [BaseTestResult(full_test_name.replace('\r', ''), |
| 167 p.before)] |
| 168 overall_fail = True |
| 169 break |
| 170 # The test failed. |
| 161 failed_tests += [BaseTestResult(full_test_name.replace('\r', ''), | 171 failed_tests += [BaseTestResult(full_test_name.replace('\r', ''), |
| 162 p.before)] | 172 p.before)] |
| 163 if found >= 2: | 173 if found >= 3: |
| 164 # The test crashed / bailed out (i.e., didn't print OK or FAIL). | 174 # The test bailed out (i.e., didn't print OK or FAIL). |
| 165 if found == 3: # pexpect.TIMEOUT | 175 if found == 3: # pexpect.TIMEOUT |
| 166 logging.error('Test terminated after %d second timeout.', | 176 logging.error('Test terminated after %d second timeout.', |
| 167 self.timeout) | 177 self.timeout) |
| 168 timed_out = True | 178 timed_out = True |
| 169 break | 179 break |
| 170 p.close() | 180 p.close() |
| 171 if not self.rebaseline and ready_to_continue: | 181 if not self.rebaseline and ready_to_continue: |
| 172 ok_tests += self._EndGetIOStats(io_stats_before) | 182 ok_tests += self._EndGetIOStats(io_stats_before) |
| 173 ret_code = self._GetGTestReturnCode() | 183 ret_code = self._GetGTestReturnCode() |
| 174 if ret_code: | 184 if ret_code: |
| 175 failed_tests += [BaseTestResult('gtest exit code: %d' % ret_code, | 185 failed_tests += [BaseTestResult('gtest exit code: %d' % ret_code, |
| 176 'pexpect.before: %s' | 186 'pexpect.before: %s' |
| 177 '\npexpect.after: %s' | 187 '\npexpect.after: %s' |
| 178 % (p.before, | 188 % (p.before, |
| 179 p.after))] | 189 p.after))] |
| 180 return TestResults.FromOkAndFailed(ok_tests, failed_tests, | 190 # Create TestResults and return |
| 181 timed_out, overall_fail) | 191 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, |
| 192 crashed=crashed_tests, timed_out=timed_out, |
| 193 overall_fail=overall_fail) |
| OLD | NEW |