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 | 9 |
10 from pylib import constants | 10 from pylib import constants |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 def _WatchTestOutput(self, p): | 116 def _WatchTestOutput(self, p): |
117 """Watches the test output. | 117 """Watches the test output. |
118 Args: | 118 Args: |
119 p: the process generating output as created by pexpect.spawn. | 119 p: the process generating output as created by pexpect.spawn. |
120 """ | 120 """ |
121 ok_tests = [] | 121 ok_tests = [] |
122 failed_tests = [] | 122 failed_tests = [] |
123 crashed_tests = [] | 123 crashed_tests = [] |
124 timed_out_tests = [] | 124 timed_out_tests = [] |
125 overall_fail = False | |
126 overall_timed_out = False | |
127 | 125 |
128 # Test case statuses. | 126 # Test case statuses. |
129 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | 127 re_run = re.compile('\[ RUN \] ?(.*)\r\n') |
130 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | 128 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') |
131 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') | 129 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') |
132 | 130 |
133 # Test run statuses. | 131 # Test run statuses. |
134 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') | 132 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') |
135 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | 133 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') |
136 # Signal handlers are installed before starting tests | 134 # Signal handlers are installed before starting tests |
137 # to output the CRASHED marker when a crash happens. | 135 # to output the CRASHED marker when a crash happens. |
138 re_crash = re.compile('\[ CRASHED \](.*)\r\n') | 136 re_crash = re.compile('\[ CRASHED \](.*)\r\n') |
139 | 137 |
140 try: | 138 try: |
141 while True: | 139 while True: |
142 full_test_name = None | 140 full_test_name = None |
143 | 141 |
144 found = p.expect([re_run, re_passed, re_runner_fail], | 142 found = p.expect([re_run, re_passed, re_runner_fail], |
145 timeout=self.timeout) | 143 timeout=self.timeout) |
146 if found == 1: # re_passed | 144 if found == 1: # re_passed |
147 break | 145 break |
148 elif found == 2: # re_runner_fail | 146 elif found == 2: # re_runner_fail |
149 overall_fail = True | |
150 break | 147 break |
151 else: # re_run | 148 else: # re_run |
152 if self.dump_debug_info: | 149 if self.dump_debug_info: |
153 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') | 150 self.dump_debug_info.TakeScreenshot('_Test_Start_Run_') |
154 | 151 |
155 full_test_name = p.match.group(1).replace('\r', '') | 152 full_test_name = p.match.group(1).replace('\r', '') |
156 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) | 153 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) |
157 if found == 0: # re_ok | 154 if found == 0: # re_ok |
158 if full_test_name == p.match.group(1).replace('\r', ''): | 155 if full_test_name == p.match.group(1).replace('\r', ''): |
159 ok_tests += [BaseTestResult(full_test_name, p.before)] | 156 ok_tests += [BaseTestResult(full_test_name, p.before)] |
160 elif found == 2: # re_crash | 157 elif found == 2: # re_crash |
161 crashed_tests += [BaseTestResult(full_test_name, p.before)] | 158 crashed_tests += [BaseTestResult(full_test_name, p.before)] |
162 overall_fail = True | |
163 break | 159 break |
164 else: # re_fail | 160 else: # re_fail |
165 failed_tests += [BaseTestResult(full_test_name, p.before)] | 161 failed_tests += [BaseTestResult(full_test_name, p.before)] |
166 except pexpect.EOF: | 162 except pexpect.EOF: |
167 logging.error('Test terminated - EOF') | 163 logging.error('Test terminated - EOF') |
168 raise errors.DeviceUnresponsiveError('Device may be offline') | 164 raise errors.DeviceUnresponsiveError('Device may be offline') |
169 except pexpect.TIMEOUT: | 165 except pexpect.TIMEOUT: |
170 logging.error('Test terminated after %d second timeout.', | 166 logging.error('Test terminated after %d second timeout.', |
171 self.timeout) | 167 self.timeout) |
172 overall_timed_out = True | |
173 if full_test_name: | 168 if full_test_name: |
174 timed_out_tests += [BaseTestResult(full_test_name, p.before)] | 169 timed_out_tests += [BaseTestResult(full_test_name, p.before)] |
175 finally: | 170 finally: |
176 p.close() | 171 p.close() |
177 | 172 |
178 ret_code = self._GetGTestReturnCode() | 173 ret_code = self._GetGTestReturnCode() |
179 if ret_code: | 174 if ret_code: |
180 logging.critical( | 175 logging.critical( |
181 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', | 176 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', |
182 ret_code, p.before, p.after) | 177 ret_code, p.before, p.after) |
183 overall_fail = True | |
184 | 178 |
185 # Create TestResults and return | 179 # Create TestResults and return |
186 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, | 180 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, |
187 crashed=crashed_tests, timed_out=timed_out_tests, | 181 crashed=crashed_tests, timed_out=timed_out_tests) |
188 overall_fail=overall_fail, | |
189 overall_timed_out=overall_timed_out) | |
OLD | NEW |