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

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

Issue 12263024: Android: Add test runner scripts to run content_browsertests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused browsertests/test_sharder.py 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) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 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 copy 5 import copy
6 import fnmatch 6 import fnmatch
7 import logging 7 import logging
8 import os 8 import os
9 9
10 from pylib import android_commands 10 from pylib import android_commands
11 from pylib import cmd_helper 11 from pylib import cmd_helper
12 from pylib import constants
12 from pylib import ports 13 from pylib import ports
13 from pylib.base import shard 14 from pylib.base import shard
14 from pylib.base import test_result
15 from pylib.utils import emulator 15 from pylib.utils import emulator
16 from pylib.utils import xvfb 16 from pylib.utils import xvfb
17 17
18 import gtest_config 18 import gtest_config
19 import test_runner 19 import test_runner
20 20
21 21
22 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): 22 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type):
23 """Get a list of absolute paths to test suite targets. 23 """Get a list of absolute paths to test suite targets.
24 24
(...skipping 25 matching lines...) Expand all
50 for t in all_test_suites] 50 for t in all_test_suites]
51 for t, q in zip(all_test_suites, qualified_test_suites): 51 for t, q in zip(all_test_suites, qualified_test_suites):
52 if not os.path.exists(q): 52 if not os.path.exists(q):
53 raise Exception('Test suite %s not found in %s.\n' 53 raise Exception('Test suite %s not found in %s.\n'
54 'Supported test suites:\n %s\n' 54 'Supported test suites:\n %s\n'
55 'Ensure it has been built.\n' % 55 'Ensure it has been built.\n' %
56 (t, q, gtest_config.STABLE_TEST_SUITES)) 56 (t, q, gtest_config.STABLE_TEST_SUITES))
57 return zip(all_test_suites, qualified_test_suites) 57 return zip(all_test_suites, qualified_test_suites)
58 58
59 59
60 def _GetTestsFromDevice(runner): 60 def GetTestsFromDevice(runner):
61 """Get a list of tests from a device, excluding disabled tests. 61 """Get a list of tests from a device, excluding disabled tests.
62 62
63 Args: 63 Args:
64 runner: a TestRunner. 64 runner: a TestRunner.
65 """ 65 """
66 # The executable/apk needs to be copied before we can call GetAllTests. 66 # The executable/apk needs to be copied before we can call GetAllTests.
67 runner.test_package.StripAndCopyExecutable() 67 runner.test_package.StripAndCopyExecutable()
68 all_tests = runner.test_package.GetAllTests() 68 all_tests = runner.test_package.GetAllTests()
69 # Only includes tests that do not have any match in the disabled list. 69 # Only includes tests that do not have any match in the disabled list.
70 disabled_list = runner.GetDisabledTests() 70 disabled_list = runner.GetDisabledTests()
71 return filter(lambda t: not any([fnmatch.fnmatch(t, disabled_pattern) 71 return filter(lambda t: not any([fnmatch.fnmatch(t, disabled_pattern)
72 for disabled_pattern in disabled_list]), 72 for disabled_pattern in disabled_list]),
73 all_tests) 73 all_tests)
74 74
75 75
76 def _GetAllEnabledTests(runner_factory, devices): 76 def GetAllEnabledTests(runner_factory, devices):
77 """Get all enabled tests. 77 """Get all enabled tests.
78 78
79 Obtains a list of enabled tests from the test package on the device, 79 Obtains a list of enabled tests from the test package on the device,
80 then filters it again using the disabled list on the host. 80 then filters it again using the disabled list on the host.
81 81
82 Args: 82 Args:
83 runner_factory: callable that takes a devices and returns a TestRunner. 83 runner_factory: callable that takes a devices and returns a TestRunner.
84 devices: list of devices. 84 devices: list of devices.
85 85
86 Returns: 86 Returns:
87 List of all enabled tests. 87 List of all enabled tests.
88 88
89 Raises Exception if all devices failed. 89 Raises Exception if all devices failed.
90 """ 90 """
91 for device in devices: 91 for device in devices:
92 try: 92 try:
93 logging.info('Obtaining tests from %s', device) 93 logging.info('Obtaining tests from %s', device)
94 runner = runner_factory(device) 94 runner = runner_factory(device)
95 return _GetTestsFromDevice(runner) 95 return GetTestsFromDevice(runner)
96 except Exception as e: 96 except Exception as e:
97 logging.warning('Failed obtaining tests from %s with exception: %s', 97 logging.warning('Failed obtaining tests from %s with exception: %s',
98 device, e) 98 device, e)
99 raise Exception('No device available to get the list of tests.') 99 raise Exception('No device available to get the list of tests.')
100 100
101 101
102 def _RunATestSuite(options, suite_name): 102 def _RunATestSuite(options, suite_name):
103 """Run a single test suite. 103 """Run a single test suite.
104 104
105 Helper for Dispatch() to allow stop/restart of the emulator across 105 Helper for Dispatch() to allow stop/restart of the emulator across
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 # Constructs a new TestRunner with the current options. 138 # Constructs a new TestRunner with the current options.
139 def RunnerFactory(device): 139 def RunnerFactory(device):
140 return test_runner.TestRunner( 140 return test_runner.TestRunner(
141 device, 141 device,
142 options.test_suite, 142 options.test_suite,
143 options.test_arguments, 143 options.test_arguments,
144 options.timeout, 144 options.timeout,
145 options.cleanup_test_files, 145 options.cleanup_test_files,
146 options.tool, 146 options.tool,
147 options.build_type, 147 options.build_type,
148 options.webkit) 148 options.webkit,
149 constants.GTEST_TEST_PACKAGE_NAME,
150 constants.GTEST_TEST_ACTIVITY_NAME,
151 constants.GTEST_COMMAND_LINE_FILE)
149 152
150 # Get tests and split them up based on the number of devices. 153 # Get tests and split them up based on the number of devices.
151 if options.gtest_filter: 154 if options.gtest_filter:
152 all_tests = [t for t in options.gtest_filter.split(':') if t] 155 all_tests = [t for t in options.gtest_filter.split(':') if t]
153 else: 156 else:
154 all_tests = _GetAllEnabledTests(RunnerFactory, attached_devices) 157 all_tests = GetAllEnabledTests(RunnerFactory, attached_devices)
155 num_devices = len(attached_devices) 158 num_devices = len(attached_devices)
156 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] 159 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)]
157 tests = [t for t in tests if t] 160 tests = [t for t in tests if t]
158 161
159 # Run tests. 162 # Run tests.
160 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, tests, 163 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, tests,
161 options.build_type) 164 options.build_type)
162 165
163 test_results.LogFull( 166 test_results.LogFull(
164 test_type='Unit test', 167 test_type='Unit test',
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 failures = 0 208 failures = 0
206 for suite_name, suite_path in all_test_suites: 209 for suite_name, suite_path in all_test_suites:
207 # Give each test suite its own copy of options. 210 # Give each test suite its own copy of options.
208 test_options = copy.deepcopy(options) 211 test_options = copy.deepcopy(options)
209 test_options.test_suite = suite_path 212 test_options.test_suite = suite_path
210 failures += _RunATestSuite(test_options, suite_name) 213 failures += _RunATestSuite(test_options, suite_name)
211 214
212 if options.use_xvfb: 215 if options.use_xvfb:
213 framebuffer.Stop() 216 framebuffer.Stop()
214 return failures 217 return failures
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698