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 import logging | 5 import logging |
6 import os | 6 import os |
7 import re | 7 import re |
8 | 8 |
9 from pylib import pexpect | 9 from pylib import pexpect |
10 from pylib import ports | 10 from pylib import ports |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 Args: | 72 Args: |
73 p: An instance of pexpect spawn class. | 73 p: An instance of pexpect spawn class. |
74 | 74 |
75 Returns: | 75 Returns: |
76 A TestRunResults object. | 76 A TestRunResults object. |
77 """ | 77 """ |
78 results = base_test_result.TestRunResults() | 78 results = base_test_result.TestRunResults() |
79 | 79 |
80 # Test case statuses. | 80 # Test case statuses. |
81 re_run = re.compile('\[ RUN \] ?(.*)\r\n') | 81 re_run = re.compile('\[ RUN \] ?(.*)\r\n') |
82 re_fail = re.compile('\[ FAILED \] ?(.*)\r\n') | 82 re_fail = re.compile('\[ FAILED \] ?(.*?)( \((\d+) ms\))?\r\r\n') |
83 re_ok = re.compile('\[ OK \] ?(.*?) .*\r\n') | 83 re_ok = re.compile('\[ OK \] ?(.*?)( \((\d+) ms\))?\r\r\n') |
84 | 84 |
85 # Test run statuses. | 85 # Test run statuses. |
86 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') | 86 re_passed = re.compile('\[ PASSED \] ?(.*)\r\n') |
87 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') | 87 re_runner_fail = re.compile('\[ RUNNER_FAILED \] ?(.*)\r\n') |
88 # Signal handlers are installed before starting tests | 88 # Signal handlers are installed before starting tests |
89 # to output the CRASHED marker when a crash happens. | 89 # to output the CRASHED marker when a crash happens. |
90 re_crash = re.compile('\[ CRASHED \](.*)\r\n') | 90 re_crash = re.compile('\[ CRASHED \](.*)\r\n') |
91 | 91 |
92 log = '' | 92 log = '' |
93 try: | 93 try: |
94 while True: | 94 while True: |
95 full_test_name = None | 95 full_test_name = None |
| 96 |
96 found = p.expect([re_run, re_passed, re_runner_fail], | 97 found = p.expect([re_run, re_passed, re_runner_fail], |
97 timeout=self._timeout) | 98 timeout=self._timeout) |
98 if found == 1: # re_passed | 99 if found == 1: # re_passed |
99 break | 100 break |
100 elif found == 2: # re_runner_fail | 101 elif found == 2: # re_runner_fail |
101 break | 102 break |
102 else: # re_run | 103 else: # re_run |
103 full_test_name = p.match.group(1).replace('\r', '') | 104 full_test_name = p.match.group(1).replace('\r', '') |
104 found = p.expect([re_ok, re_fail, re_crash], timeout=self._timeout) | 105 found = p.expect([re_ok, re_fail, re_crash], timeout=self._timeout) |
105 log = p.before.replace('\r', '') | 106 log = p.before.replace('\r', '') |
106 if found == 0: # re_ok | 107 if found == 0: # re_ok |
107 if full_test_name == p.match.group(1).replace('\r', ''): | 108 if full_test_name == p.match.group(1).replace('\r', ''): |
| 109 duration_ms = int(p.match.group(3)) if p.match.group(3) else 0 |
108 results.AddResult(base_test_result.BaseTestResult( | 110 results.AddResult(base_test_result.BaseTestResult( |
109 full_test_name, base_test_result.ResultType.PASS, | 111 full_test_name, base_test_result.ResultType.PASS, |
110 log=log)) | 112 duration=duration_ms, log=log)) |
111 elif found == 2: # re_crash | 113 elif found == 2: # re_crash |
112 results.AddResult(base_test_result.BaseTestResult( | 114 results.AddResult(base_test_result.BaseTestResult( |
113 full_test_name, base_test_result.ResultType.CRASH, | 115 full_test_name, base_test_result.ResultType.CRASH, |
114 log=log)) | 116 log=log)) |
115 break | 117 break |
116 else: # re_fail | 118 else: # re_fail |
| 119 duration_ms = int(p.match.group(3)) if p.match.group(3) else 0 |
117 results.AddResult(base_test_result.BaseTestResult( | 120 results.AddResult(base_test_result.BaseTestResult( |
118 full_test_name, base_test_result.ResultType.FAIL, log=log)) | 121 full_test_name, base_test_result.ResultType.FAIL, |
| 122 duration=duration_ms, log=log)) |
119 except pexpect.EOF: | 123 except pexpect.EOF: |
120 logging.error('Test terminated - EOF') | 124 logging.error('Test terminated - EOF') |
121 # We're here because either the device went offline, or the test harness | 125 # We're here because either the device went offline, or the test harness |
122 # crashed without outputting the CRASHED marker (crbug.com/175538). | 126 # crashed without outputting the CRASHED marker (crbug.com/175538). |
123 if not self.device.IsOnline(): | 127 if not self.device.IsOnline(): |
124 raise device_errors.DeviceUnreachableError( | 128 raise device_errors.DeviceUnreachableError( |
125 'Device %s went offline.' % str(self.device)) | 129 'Device %s went offline.' % str(self.device)) |
126 if full_test_name: | 130 if full_test_name: |
127 results.AddResult(base_test_result.BaseTestResult( | 131 results.AddResult(base_test_result.BaseTestResult( |
128 full_test_name, base_test_result.ResultType.CRASH, | 132 full_test_name, base_test_result.ResultType.CRASH, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 #override | 187 #override |
184 def TearDown(self): | 188 def TearDown(self): |
185 """Cleans up the test enviroment for the test suite.""" | 189 """Cleans up the test enviroment for the test suite.""" |
186 for s in self._servers: | 190 for s in self._servers: |
187 s.TearDown() | 191 s.TearDown() |
188 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name): | 192 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name): |
189 self._perf_controller.SetDefaultPerfMode() | 193 self._perf_controller.SetDefaultPerfMode() |
190 self.test_package.ClearApplicationState(self.device) | 194 self.test_package.ClearApplicationState(self.device) |
191 self.tool.CleanUpEnvironment() | 195 self.tool.CleanUpEnvironment() |
192 super(TestRunner, self).TearDown() | 196 super(TestRunner, self).TearDown() |
OLD | NEW |