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