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 sys | 7 import sys |
8 | 8 |
9 from base_test_runner import BaseTestRunner | 9 from base_test_runner import BaseTestRunner |
10 import debug_info | 10 import debug_info |
11 import run_tests_helper | 11 import run_tests_helper |
12 from test_package_executable import TestPackageExecutable | 12 from test_package_executable import TestPackageExecutable |
13 from test_result import TestResults | 13 from test_result import TestResults |
14 | 14 |
15 | 15 |
16 class SingleTestRunner(BaseTestRunner): | 16 class SingleTestRunner(BaseTestRunner): |
17 """Single test suite attached to a single device. | 17 """Single test suite attached to a single device. |
18 | 18 |
19 Args: | 19 Args: |
20 device: Device to run the tests. | 20 device: Device to run the tests. |
21 test_suite: A specific test suite to run, empty to run all. | 21 test_suite: A specific test suite to run, empty to run all. |
22 gtest_filter: A gtest_filter flag. | 22 gtest_filter: A gtest_filter flag. |
23 test_arguments: Additional arguments to pass to the test binary. | 23 test_arguments: Additional arguments to pass to the test binary. |
24 timeout: Timeout for each test. | 24 timeout: Timeout for each test. |
25 rebaseline: Whether or not to run tests in isolation and update the filter. | 25 rebaseline: Whether or not to run tests in isolation and update the filter. |
26 performance_test: Whether or not performance test(s). | 26 performance_test: Whether or not performance test(s). |
27 cleanup_test_files: Whether or not to cleanup test files on device. | 27 cleanup_test_files: Whether or not to cleanup test files on device. |
28 tool: Name of the Valgrind tool. | 28 tool: Name of the Valgrind tool. |
| 29 shard_index: index number of the shard on which the test suite will run. |
29 dump_debug_info: Whether or not to dump debug information. | 30 dump_debug_info: Whether or not to dump debug information. |
30 """ | 31 """ |
31 | 32 |
32 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, | 33 def __init__(self, device, test_suite, gtest_filter, test_arguments, timeout, |
33 rebaseline, performance_test, cleanup_test_files, tool, | 34 rebaseline, performance_test, cleanup_test_files, tool, |
34 dump_debug_info=False, | 35 shard_index, dump_debug_info=False, |
35 fast_and_loose=False): | 36 fast_and_loose=False): |
36 BaseTestRunner.__init__(self, device) | 37 BaseTestRunner.__init__(self, device, shard_index) |
37 self._running_on_emulator = self.device.startswith('emulator') | 38 self._running_on_emulator = self.device.startswith('emulator') |
38 self._gtest_filter = gtest_filter | 39 self._gtest_filter = gtest_filter |
39 self._test_arguments = test_arguments | 40 self._test_arguments = test_arguments |
40 self.test_results = TestResults() | 41 self.test_results = TestResults() |
41 if dump_debug_info: | 42 if dump_debug_info: |
42 self.dump_debug_info = debug_info.GTestDebugInfo(self.adb, device, | 43 self.dump_debug_info = debug_info.GTestDebugInfo(self.adb, device, |
43 os.path.basename(test_suite), gtest_filter) | 44 os.path.basename(test_suite), gtest_filter) |
44 else: | 45 else: |
45 self.dump_debug_info = None | 46 self.dump_debug_info = None |
46 self.fast_and_loose = fast_and_loose | 47 self.fast_and_loose = fast_and_loose |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 str([f.name for f in failed_results])) | 259 str([f.name for f in failed_results])) |
259 logging.info('Remaining: ' + str(len(all_tests - executed_names)) + ' ' + | 260 logging.info('Remaining: ' + str(len(all_tests - executed_names)) + ' ' + |
260 str(all_tests - executed_names)) | 261 str(all_tests - executed_names)) |
261 logging.info('*' * 80) | 262 logging.info('*' * 80) |
262 if executed_names == all_tests: | 263 if executed_names == all_tests: |
263 break | 264 break |
264 self.test_results = TestResults.FromOkAndFailed(list(executed_results - | 265 self.test_results = TestResults.FromOkAndFailed(list(executed_results - |
265 failed_results), | 266 failed_results), |
266 list(failed_results)) | 267 list(failed_results)) |
267 | 268 |
268 def _RunTestsForSuiteInternal(self): | 269 def RunTests(self): |
269 """Runs all tests (in rebaseline mode, run each test in isolation). | 270 """Runs all tests (in rebaseline mode, runs each test in isolation). |
270 | 271 |
271 Returns: | 272 Returns: |
272 A TestResults object. | 273 A TestResults object. |
273 """ | 274 """ |
274 if self.test_package.rebaseline: | 275 if self.test_package.rebaseline: |
275 self.RebaselineTests() | 276 self.RebaselineTests() |
276 else: | 277 else: |
277 if not self._gtest_filter: | 278 if not self._gtest_filter: |
278 self._gtest_filter = ('-' + ':'.join(self.GetDisabledTests()) + ':' + | 279 self._gtest_filter = ('-' + ':'.join(self.GetDisabledTests()) + ':' + |
279 ':'.join(['*.' + x + '*' for x in | 280 ':'.join(['*.' + x + '*' for x in |
280 self.test_package.GetDisabledPrefixes()])) | 281 self.test_package.GetDisabledPrefixes()])) |
281 self.RunTestsWithFilter() | 282 self.RunTestsWithFilter() |
| 283 return self.test_results |
282 | 284 |
283 def SetUp(self): | 285 def SetUp(self): |
284 """Sets up necessary test enviroment for the test suite.""" | 286 """Sets up necessary test enviroment for the test suite.""" |
285 super(SingleTestRunner, self).SetUp() | 287 super(SingleTestRunner, self).SetUp() |
286 if self.test_package.performance_test: | 288 if self.test_package.performance_test: |
287 if run_tests_helper.IsRunningAsBuildbot(): | 289 if run_tests_helper.IsRunningAsBuildbot(): |
288 self.adb.SetJavaAssertsEnabled(enable=False) | 290 self.adb.SetJavaAssertsEnabled(enable=False) |
289 self.adb.Reboot(full_reboot=False) | 291 self.adb.Reboot(full_reboot=False) |
290 self.adb.SetupPerformanceTest() | 292 self.adb.SetupPerformanceTest() |
291 if self.dump_debug_info: | 293 if self.dump_debug_info: |
292 self.dump_debug_info.StartRecordingLog(True) | 294 self.dump_debug_info.StartRecordingLog(True) |
293 self.StripAndCopyFiles() | 295 self.StripAndCopyFiles() |
294 self.LaunchHelperToolsForTestSuite() | 296 self.LaunchHelperToolsForTestSuite() |
295 self.test_package.tool.SetupEnvironment() | 297 self.test_package.tool.SetupEnvironment() |
296 | 298 |
297 def TearDown(self): | 299 def TearDown(self): |
298 """Cleans up the test enviroment for the test suite.""" | 300 """Cleans up the test enviroment for the test suite.""" |
299 super(SingleTestRunner, self).TearDown() | |
300 self.test_package.tool.CleanUpEnvironment() | 301 self.test_package.tool.CleanUpEnvironment() |
301 if self.test_package.cleanup_test_files: | 302 if self.test_package.cleanup_test_files: |
302 self.adb.RemovePushedFiles() | 303 self.adb.RemovePushedFiles() |
303 if self.dump_debug_info: | 304 if self.dump_debug_info: |
304 self.dump_debug_info.StopRecordingLog() | 305 self.dump_debug_info.StopRecordingLog() |
305 if self.test_package.performance_test: | 306 if self.test_package.performance_test: |
306 self.adb.TearDownPerformanceTest() | 307 self.adb.TearDownPerformanceTest() |
307 | 308 super(SingleTestRunner, self).TearDown() |
308 def RunTests(self): | |
309 """Runs the tests and cleans up the files once finished. | |
310 | |
311 Returns: | |
312 A TestResults object. | |
313 """ | |
314 self.SetUp() | |
315 try: | |
316 self._RunTestsForSuiteInternal() | |
317 finally: | |
318 self.TearDown() | |
319 return self.test_results | |
OLD | NEW |