Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: build/android/pylib/gtest/test_runner.py

Issue 221823011: [Android] Change object types from AndroidCommands to DeviceUtils in build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Frank's comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 android_commands
10 from pylib import constants 9 from pylib import constants
11 from pylib import pexpect 10 from pylib import pexpect
12 from pylib.base import base_test_result 11 from pylib.base import base_test_result
13 from pylib.base import base_test_runner 12 from pylib.base import base_test_runner
13 from pylib.device import adb_wrapper
14 from pylib.perf import perf_control 14 from pylib.perf import perf_control
15 15
16 16
17 def _TestSuiteRequiresMockTestServer(suite_name): 17 def _TestSuiteRequiresMockTestServer(suite_name):
18 """Returns True if the test suite requires mock test server.""" 18 """Returns True if the test suite requires mock test server."""
19 tests_require_net_test_server = ['unit_tests', 'net_unittests', 19 tests_require_net_test_server = ['unit_tests', 'net_unittests',
20 'content_unittests', 20 'content_unittests',
21 'content_browsertests'] 21 'content_browsertests']
22 return (suite_name in 22 return (suite_name in
23 tests_require_net_test_server) 23 tests_require_net_test_server)
(...skipping 22 matching lines...) Expand all
46 46
47 timeout = test_options.timeout 47 timeout = test_options.timeout
48 if timeout == 0: 48 if timeout == 0:
49 timeout = 60 49 timeout = 60
50 # On a VM (e.g. chromium buildbots), this timeout is way too small. 50 # On a VM (e.g. chromium buildbots), this timeout is way too small.
51 if os.environ.get('BUILDBOT_SLAVENAME'): 51 if os.environ.get('BUILDBOT_SLAVENAME'):
52 timeout = timeout * 2 52 timeout = timeout * 2
53 53
54 self._timeout = timeout * self.tool.GetTimeoutScale() 54 self._timeout = timeout * self.tool.GetTimeoutScale()
55 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name): 55 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name):
56 self._perf_controller = perf_control.PerfControl(self.adb) 56 self._perf_controller = perf_control.PerfControl(self.device)
57 57
58 #override 58 #override
59 def InstallTestPackage(self): 59 def InstallTestPackage(self):
60 self.test_package.Install(self.adb) 60 self.test_package.Install(self.device)
61 61
62 def GetAllTests(self): 62 def GetAllTests(self):
63 """Install test package and get a list of all tests.""" 63 """Install test package and get a list of all tests."""
64 self.test_package.Install(self.adb) 64 self.test_package.Install(self.device)
65 return self.test_package.GetAllTests(self.adb) 65 return self.test_package.GetAllTests(self.device)
66 66
67 #override 67 #override
68 def PushDataDeps(self): 68 def PushDataDeps(self):
69 self.adb.WaitForSdCardReady(20) 69 self.device.old_interface.WaitForSdCardReady(20)
70 self.tool.CopyFiles() 70 self.tool.CopyFiles()
71 if os.path.exists(constants.ISOLATE_DEPS_DIR): 71 if os.path.exists(constants.ISOLATE_DEPS_DIR):
72 device_dir = self.adb.GetExternalStorage() 72 device_dir = self.device.old_interface.GetExternalStorage()
73 # TODO(frankf): linux_dumper_unittest_helper needs to be in the same dir 73 # TODO(frankf): linux_dumper_unittest_helper needs to be in the same dir
74 # as breakpad_unittests exe. Find a better way to do this. 74 # as breakpad_unittests exe. Find a better way to do this.
75 if self.test_package.suite_name == 'breakpad_unittests': 75 if self.test_package.suite_name == 'breakpad_unittests':
76 device_dir = constants.TEST_EXECUTABLE_DIR 76 device_dir = constants.TEST_EXECUTABLE_DIR
77 for p in os.listdir(constants.ISOLATE_DEPS_DIR): 77 for p in os.listdir(constants.ISOLATE_DEPS_DIR):
78 self.adb.PushIfNeeded( 78 self.device.old_interface.PushIfNeeded(
79 os.path.join(constants.ISOLATE_DEPS_DIR, p), 79 os.path.join(constants.ISOLATE_DEPS_DIR, p),
80 os.path.join(device_dir, p)) 80 os.path.join(device_dir, p))
81 81
82 def _ParseTestOutput(self, p): 82 def _ParseTestOutput(self, p):
83 """Process the test output. 83 """Process the test output.
84 84
85 Args: 85 Args:
86 p: An instance of pexpect spawn class. 86 p: An instance of pexpect spawn class.
87 87
88 Returns: 88 Returns:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 full_test_name, base_test_result.ResultType.CRASH, 126 full_test_name, base_test_result.ResultType.CRASH,
127 log=log)) 127 log=log))
128 break 128 break
129 else: # re_fail 129 else: # re_fail
130 results.AddResult(base_test_result.BaseTestResult( 130 results.AddResult(base_test_result.BaseTestResult(
131 full_test_name, base_test_result.ResultType.FAIL, log=log)) 131 full_test_name, base_test_result.ResultType.FAIL, log=log))
132 except pexpect.EOF: 132 except pexpect.EOF:
133 logging.error('Test terminated - EOF') 133 logging.error('Test terminated - EOF')
134 # We're here because either the device went offline, or the test harness 134 # We're here because either the device went offline, or the test harness
135 # crashed without outputting the CRASHED marker (crbug.com/175538). 135 # crashed without outputting the CRASHED marker (crbug.com/175538).
136 if not self.adb.IsOnline(): 136 if not self.device.old_interface.IsOnline():
137 raise android_commands.errors.DeviceUnresponsiveError( 137 raise adb_wrapper.DeviceUnreachableError(
138 'Device %s went offline.' % self.device) 138 'Device %s went offline.' % str(self.device))
139 if full_test_name: 139 if full_test_name:
140 results.AddResult(base_test_result.BaseTestResult( 140 results.AddResult(base_test_result.BaseTestResult(
141 full_test_name, base_test_result.ResultType.CRASH, 141 full_test_name, base_test_result.ResultType.CRASH,
142 log=p.before.replace('\r', ''))) 142 log=p.before.replace('\r', '')))
143 except pexpect.TIMEOUT: 143 except pexpect.TIMEOUT:
144 logging.error('Test terminated after %d second timeout.', 144 logging.error('Test terminated after %d second timeout.',
145 self._timeout) 145 self._timeout)
146 if full_test_name: 146 if full_test_name:
147 results.AddResult(base_test_result.BaseTestResult( 147 results.AddResult(base_test_result.BaseTestResult(
148 full_test_name, base_test_result.ResultType.TIMEOUT, 148 full_test_name, base_test_result.ResultType.TIMEOUT,
149 log=p.before.replace('\r', ''))) 149 log=p.before.replace('\r', '')))
150 finally: 150 finally:
151 p.close() 151 p.close()
152 152
153 ret_code = self.test_package.GetGTestReturnCode(self.adb) 153 ret_code = self.test_package.GetGTestReturnCode(self.device)
154 if ret_code: 154 if ret_code:
155 logging.critical( 155 logging.critical(
156 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s', 156 'gtest exit code: %d\npexpect.before: %s\npexpect.after: %s',
157 ret_code, p.before, p.after) 157 ret_code, p.before, p.after)
158 158
159 return results 159 return results
160 160
161 #override 161 #override
162 def RunTest(self, test): 162 def RunTest(self, test):
163 test_results = base_test_result.TestRunResults() 163 test_results = base_test_result.TestRunResults()
164 if not test: 164 if not test:
165 return test_results, None 165 return test_results, None
166 166
167 try: 167 try:
168 self.test_package.ClearApplicationState(self.adb) 168 self.test_package.ClearApplicationState(self.device)
169 self.test_package.CreateCommandLineFileOnDevice( 169 self.test_package.CreateCommandLineFileOnDevice(
170 self.adb, test, self._test_arguments) 170 self.device, test, self._test_arguments)
171 test_results = self._ParseTestOutput( 171 test_results = self._ParseTestOutput(
172 self.test_package.SpawnTestProcess(self.adb)) 172 self.test_package.SpawnTestProcess(self.device))
173 finally: 173 finally:
174 self.CleanupSpawningServerState() 174 self.CleanupSpawningServerState()
175 # Calculate unknown test results. 175 # Calculate unknown test results.
176 all_tests = set(test.split(':')) 176 all_tests = set(test.split(':'))
177 all_tests_ran = set([t.GetName() for t in test_results.GetAll()]) 177 all_tests_ran = set([t.GetName() for t in test_results.GetAll()])
178 unknown_tests = all_tests - all_tests_ran 178 unknown_tests = all_tests - all_tests_ran
179 test_results.AddResults( 179 test_results.AddResults(
180 [base_test_result.BaseTestResult(t, base_test_result.ResultType.UNKNOWN) 180 [base_test_result.BaseTestResult(t, base_test_result.ResultType.UNKNOWN)
181 for t in unknown_tests]) 181 for t in unknown_tests])
182 retry = ':'.join([t.GetName() for t in test_results.GetNotPass()]) 182 retry = ':'.join([t.GetName() for t in test_results.GetNotPass()])
183 return test_results, retry 183 return test_results, retry
184 184
185 #override 185 #override
186 def SetUp(self): 186 def SetUp(self):
187 """Sets up necessary test enviroment for the test suite.""" 187 """Sets up necessary test enviroment for the test suite."""
188 super(TestRunner, self).SetUp() 188 super(TestRunner, self).SetUp()
189 if _TestSuiteRequiresMockTestServer(self.test_package.suite_name): 189 if _TestSuiteRequiresMockTestServer(self.test_package.suite_name):
190 self.LaunchChromeTestServerSpawner() 190 self.LaunchChromeTestServerSpawner()
191 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name): 191 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name):
192 self._perf_controller.SetHighPerfMode() 192 self._perf_controller.SetHighPerfMode()
193 self.tool.SetupEnvironment() 193 self.tool.SetupEnvironment()
194 194
195 #override 195 #override
196 def TearDown(self): 196 def TearDown(self):
197 """Cleans up the test enviroment for the test suite.""" 197 """Cleans up the test enviroment for the test suite."""
198 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name): 198 if _TestSuiteRequiresHighPerfMode(self.test_package.suite_name):
199 self._perf_controller.RestoreOriginalPerfMode() 199 self._perf_controller.RestoreOriginalPerfMode()
200 self.test_package.ClearApplicationState(self.adb) 200 self.test_package.ClearApplicationState(self.device)
201 self.tool.CleanUpEnvironment() 201 self.tool.CleanUpEnvironment()
202 super(TestRunner, self).TearDown() 202 super(TestRunner, self).TearDown()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698