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 os |
7 import re | 8 import re |
8 import os | |
9 | 9 |
10 from pylib import constants | 10 from pylib import constants |
11 from pylib import pexpect | 11 from pylib import pexpect |
12 from pylib.android_commands import errors | 12 from pylib.android_commands import errors |
13 from pylib.base.test_result import BaseTestResult, TestResults | 13 from pylib.base import base_test_result |
14 from pylib.perf_tests_helper import PrintPerfResult | 14 from pylib.perf_tests_helper import PrintPerfResult |
15 | 15 |
16 | 16 |
17 class TestPackage(object): | 17 class TestPackage(object): |
18 """A helper base class for both APK and stand-alone executables. | 18 """A helper base class for both APK and stand-alone executables. |
19 | 19 |
20 Args: | 20 Args: |
21 adb: ADB interface the tests are using. | 21 adb: ADB interface the tests are using. |
22 device: Device to run the tests. | 22 device: Device to run the tests. |
23 test_suite: A specific test suite to run, empty to run all. | 23 test_suite: A specific test suite to run, empty to run all. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 self.test_suite_dirname + '/linux_dumper_unittest_helper', | 116 self.test_suite_dirname + '/linux_dumper_unittest_helper', |
117 constants.TEST_EXECUTABLE_DIR + '/linux_dumper_unittest_helper') | 117 constants.TEST_EXECUTABLE_DIR + '/linux_dumper_unittest_helper') |
118 if self.test_suite_basename == 'content_browsertests': | 118 if self.test_suite_basename == 'content_browsertests': |
119 self.adb.PushIfNeeded( | 119 self.adb.PushIfNeeded( |
120 self.test_suite_dirname + | 120 self.test_suite_dirname + |
121 '/../content_shell/assets/content_shell.pak', | 121 '/../content_shell/assets/content_shell.pak', |
122 external_storage + '/paks/content_shell.pak') | 122 external_storage + '/paks/content_shell.pak') |
123 | 123 |
124 def _WatchTestOutput(self, p): | 124 def _WatchTestOutput(self, p): |
125 """Watches the test output. | 125 """Watches the test output. |
| 126 |
126 Args: | 127 Args: |
127 p: the process generating output as created by pexpect.spawn. | 128 p: the process generating output as created by pexpect.spawn. |
| 129 |
| 130 Returns: |
| 131 A TestRunResults object. |
128 """ | 132 """ |
129 ok_tests = [] | 133 results = base_test_result.TestRunResults() |
130 failed_tests = [] | |
131 crashed_tests = [] | |
132 timed_out_tests = [] | |
133 | 134 |
134 # Test case statuses. | 135 # Test case statuses. |
135 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | 136 re_run = re.compile('\[ RUN \] ?(.*)\r\n') |
136 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | 137 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') |
137 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') | 138 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') |
138 | 139 |
139 # Test run statuses. | 140 # Test run statuses. |
140 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') | 141 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') |
141 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | 142 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') |
142 # Signal handlers are installed before starting tests | 143 # Signal handlers are installed before starting tests |
143 # to output the CRASHED marker when a crash happens. | 144 # to output the CRASHED marker when a crash happens. |
144 re_crash = re.compile('\[ CRASHED \](.*)\r\n') | 145 re_crash = re.compile('\[ CRASHED \](.*)\r\n') |
145 | 146 |
146 try: | 147 try: |
147 while True: | 148 while True: |
148 full_test_name = None | 149 full_test_name = None |
149 | |
150 found = p.expect([re_run, re_passed, re_runner_fail], | 150 found = p.expect([re_run, re_passed, re_runner_fail], |
151 timeout=self.timeout) | 151 timeout=self.timeout) |
152 if found == 1: # re_passed | 152 if found == 1: # re_passed |
153 break | 153 break |
154 elif found == 2: # re_runner_fail | 154 elif found == 2: # re_runner_fail |
155 break | 155 break |
156 else: # re_run | 156 else: # re_run |
157 full_test_name = p.match.group(1).replace('\r', '') | 157 full_test_name = p.match.group(1).replace('\r', '') |
158 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) | 158 found = p.expect([re_ok, re_fail, re_crash], timeout=self.timeout) |
159 if found == 0: # re_ok | 159 if found == 0: # re_ok |
160 if full_test_name == p.match.group(1).replace('\r', ''): | 160 if full_test_name == p.match.group(1).replace('\r', ''): |
161 ok_tests += [BaseTestResult(full_test_name, p.before)] | 161 results.AddResult(base_test_result.BaseTestResult( |
| 162 full_test_name, base_test_result.ResultType.PASS, |
| 163 log=p.before)) |
162 elif found == 2: # re_crash | 164 elif found == 2: # re_crash |
163 crashed_tests += [BaseTestResult(full_test_name, p.before)] | 165 results.AddResult(base_test_result.BaseTestResult( |
| 166 full_test_name, base_test_result.ResultType.CRASH, |
| 167 log=p.before)) |
164 break | 168 break |
165 else: # re_fail | 169 else: # re_fail |
166 failed_tests += [BaseTestResult(full_test_name, p.before)] | 170 results.AddResult(base_test_result.BaseTestResult( |
| 171 full_test_name, base_test_result.ResultType.FAIL, log=p.before)) |
167 except pexpect.EOF: | 172 except pexpect.EOF: |
168 logging.error('Test terminated - EOF') | 173 logging.error('Test terminated - EOF') |
169 # We're here because either the device went offline, or the test harness | 174 # We're here because either the device went offline, or the test harness |
170 # crashed without outputting the CRASHED marker (crbug.com/175538). | 175 # crashed without outputting the CRASHED marker (crbug.com/175538). |
171 if not self.adb.IsOnline(): | 176 if not self.adb.IsOnline(): |
172 raise errors.DeviceUnresponsiveError('Device %s went offline.' % | 177 raise errors.DeviceUnresponsiveError('Device %s went offline.' % |
173 self.device) | 178 self.device) |
174 elif full_test_name: | 179 if full_test_name: |
175 crashed_tests += [BaseTestResult(full_test_name, p.before)] | 180 results.AddResult(base_test_result.BaseTestResult( |
| 181 full_test_name, base_test_result.ResultType.CRASH, log=p.before)) |
176 except pexpect.TIMEOUT: | 182 except pexpect.TIMEOUT: |
177 logging.error('Test terminated after %d second timeout.', | 183 logging.error('Test terminated after %d second timeout.', |
178 self.timeout) | 184 self.timeout) |
179 if full_test_name: | 185 if full_test_name: |
180 timed_out_tests += [BaseTestResult(full_test_name, p.before)] | 186 results.AddResult(base_test_result.BaseTestResult( |
| 187 full_test_name, base_test_result.ResultType.TIMEOUT, log=p.before)) |
181 finally: | 188 finally: |
182 p.close() | 189 p.close() |
183 | 190 |
184 ret_code = self._GetGTestReturnCode() | 191 ret_code = self._GetGTestReturnCode() |
185 if ret_code: | 192 if ret_code: |
186 logging.critical( | 193 logging.critical( |
187 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', | 194 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', |
188 ret_code, p.before, p.after) | 195 ret_code, p.before, p.after) |
189 | 196 |
190 # Create TestResults and return | 197 return results |
191 return TestResults.FromRun(ok=ok_tests, failed=failed_tests, | |
192 crashed=crashed_tests, timed_out=timed_out_tests) | |
OLD | NEW |