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

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

Issue 12317059: [Andoid] Threaded TestRunner creation and SetUp and TearDown calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clear data and kill process between tests Created 7 years, 10 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 | Annotate | Revision Log
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 glob 5 import glob
6 import logging 6 import logging
7 import os 7 import os
8 8
9 from pylib import android_commands 9 from pylib import android_commands
10 from pylib import constants 10 from pylib import constants
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 def __init__(self, device, test_suite, test_arguments, timeout, 157 def __init__(self, device, test_suite, test_arguments, timeout,
158 cleanup_test_files, tool_name, build_type, 158 cleanup_test_files, tool_name, build_type,
159 in_webkit_checkout, test_apk_package_name=None, 159 in_webkit_checkout, test_apk_package_name=None,
160 test_activity_name=None, command_line_file=None): 160 test_activity_name=None, command_line_file=None):
161 super(TestRunner, self).__init__(device, tool_name, build_type) 161 super(TestRunner, self).__init__(device, tool_name, build_type)
162 self._running_on_emulator = self.device.startswith('emulator') 162 self._running_on_emulator = self.device.startswith('emulator')
163 self._test_arguments = test_arguments 163 self._test_arguments = test_arguments
164 self.in_webkit_checkout = in_webkit_checkout 164 self.in_webkit_checkout = in_webkit_checkout
165 self._cleanup_test_files = cleanup_test_files 165 self._cleanup_test_files = cleanup_test_files
166 self._test_apk_package_name = test_apk_package_name
166 167
167 logging.warning('Test suite: ' + test_suite) 168 logging.warning('Test suite: ' + test_suite)
168 if os.path.splitext(test_suite)[1] == '.apk': 169 if os.path.splitext(test_suite)[1] == '.apk':
169 self.test_package = test_package_apk.TestPackageApk( 170 self.test_package = test_package_apk.TestPackageApk(
170 self.adb, 171 self.adb,
171 device, 172 device,
172 test_suite, 173 test_suite,
173 timeout, 174 timeout,
174 self._cleanup_test_files, 175 self._cleanup_test_files,
175 self.tool, 176 self.tool,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 'filter', 234 'filter',
234 self.test_package.test_suite_basename) 235 self.test_package.test_suite_basename)
235 disabled_tests = run_tests_helper.GetExpectations( 236 disabled_tests = run_tests_helper.GetExpectations(
236 gtest_filter_base_path + '_disabled') 237 gtest_filter_base_path + '_disabled')
237 if self._running_on_emulator: 238 if self._running_on_emulator:
238 # Append emulator's filter file. 239 # Append emulator's filter file.
239 disabled_tests.extend(run_tests_helper.GetExpectations( 240 disabled_tests.extend(run_tests_helper.GetExpectations(
240 gtest_filter_base_path + '_emulator_additional_disabled')) 241 gtest_filter_base_path + '_emulator_additional_disabled'))
241 return disabled_tests 242 return disabled_tests
242 243
244 def _ClearApplicationState(self):
245 """Kill the test process and clear application state."""
246 if self._test_apk_package_name:
247 self.adb.ClearApplicationState(self._test_apk_package_name)
nilesh 2013/02/23 01:24:10 I think the killAllblocking can be in else: Or e
craigdh 2013/02/25 20:05:14 Done.
248 self.adb.KillAllBlocking(self.test_package.test_suite_basename, 30)
249
243 def RunTest(self, test): 250 def RunTest(self, test):
244 """Runs a test on a single device. 251 """Runs a test on a single device.
245 252
246 Args: 253 Args:
247 test: a gtest filter string to run. 254 test: a gtest filter string to run.
248 255
249 Returns: 256 Returns:
250 Tuple: (TestResults, test to retry or None) 257 Tuple: (TestResults, test to retry or None)
251 """ 258 """
252 test_results = test_result.TestResults() 259 test_results = test_result.TestResults()
253 if not test: 260 if not test:
254 return test_results, None 261 return test_results, None
255 262
256 try: 263 try:
264 self._ClearApplicationState()
257 self.test_package.CreateTestRunnerScript(test, self._test_arguments) 265 self.test_package.CreateTestRunnerScript(test, self._test_arguments)
258 test_results = self.test_package.RunTestsAndListResults() 266 test_results = self.test_package.RunTestsAndListResults()
259 except errors.DeviceUnresponsiveError as e: 267 except errors.DeviceUnresponsiveError as e:
260 # Make sure this device is not attached 268 # Make sure this device is not attached
261 logging.warning(e) 269 logging.warning(e)
262 if android_commands.IsDeviceAttached(self.device): 270 if android_commands.IsDeviceAttached(self.device):
263 raise 271 raise
264 test_results.device_exception = device_exception 272 test_results.device_exception = device_exception
265 # Calculate unknown test results. 273 # Calculate unknown test results.
266 # TODO(frankf): Do not break TestResults encapsulation. 274 # TODO(frankf): Do not break TestResults encapsulation.
267 all_tests = set(test.split(':')) 275 all_tests = set(test.split(':'))
268 all_tests_ran = set([t.name for t in test_results.GetAll()]) 276 all_tests_ran = set([t.name for t in test_results.GetAll()])
269 unknown_tests = all_tests - all_tests_ran 277 unknown_tests = all_tests - all_tests_ran
270 test_results.unknown = [test_result.BaseTestResult(t, '') for t in 278 test_results.unknown = [test_result.BaseTestResult(t, '') for t in
271 unknown_tests] 279 unknown_tests]
272 retry = ':'.join([t.name for t in test_results.GetAllBroken()]) 280 retry = ':'.join([t.name for t in test_results.GetAllBroken()])
273 return test_results, retry 281 return test_results, retry
274 282
275 def SetUp(self): 283 def SetUp(self):
276 """Sets up necessary test enviroment for the test suite.""" 284 """Sets up necessary test enviroment for the test suite."""
277 super(TestRunner, self).SetUp() 285 super(TestRunner, self).SetUp()
278 self.adb.ClearApplicationState(constants.CHROME_PACKAGE) 286 self._ClearApplicationState()
nilesh 2013/02/23 01:24:10 I dont think we need it here now. The next line (S
craigdh 2013/02/25 20:05:14 Done.
279 self.StripAndCopyFiles() 287 self.StripAndCopyFiles()
280 if _TestSuiteRequiresMockTestServer(self.test_package.test_suite_basename): 288 if _TestSuiteRequiresMockTestServer(self.test_package.test_suite_basename):
281 self.LaunchChromeTestServerSpawner() 289 self.LaunchChromeTestServerSpawner()
282 self.tool.SetupEnvironment() 290 self.tool.SetupEnvironment()
283 291
284 def TearDown(self): 292 def TearDown(self):
285 """Cleans up the test enviroment for the test suite.""" 293 """Cleans up the test enviroment for the test suite."""
286 self.tool.CleanUpEnvironment() 294 self.tool.CleanUpEnvironment()
287 if self._cleanup_test_files: 295 if self._cleanup_test_files:
288 self.adb.RemovePushedFiles() 296 self.adb.RemovePushedFiles()
289 super(TestRunner, self).TearDown() 297 super(TestRunner, self).TearDown()
OLDNEW
« no previous file with comments | « build/android/pylib/base/shard_unittest.py ('k') | build/android/pylib/utils/reraiser_thread.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698