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

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

Issue 1186513002: Revert of [Android] Refactor browser test execution. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 itertools 5 import itertools
6 import logging 6 import logging
7 import os 7 import os
8 import posixpath 8 import posixpath
9 9
10 from pylib import constants 10 from pylib import constants
11 from pylib import ports 11 from pylib import ports
12 from pylib.base import test_run 12 from pylib.base import test_run
13 from pylib.device import device_errors 13 from pylib.device import device_errors
14 from pylib.gtest import gtest_test_instance 14 from pylib.gtest import gtest_test_instance
15 15
16 from pylib.local import local_test_server_spawner 16 from pylib.local import local_test_server_spawner
17 from pylib.local.device import local_device_environment 17 from pylib.local.device import local_device_environment
18 from pylib.local.device import local_device_test_run 18 from pylib.local.device import local_device_test_run
19 from pylib.utils import apk_helper
19 from pylib.utils import device_temp_file 20 from pylib.utils import device_temp_file
20 21
21 _COMMAND_LINE_FLAGS_SUPPORTED = True 22 _COMMAND_LINE_FLAGS_SUPPORTED = True
22 23
23 _EXTRA_COMMAND_LINE_FILE = ( 24 _EXTRA_COMMAND_LINE_FILE = (
24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') 25 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
25 _EXTRA_COMMAND_LINE_FLAGS = ( 26 _EXTRA_COMMAND_LINE_FLAGS = (
26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') 27 'org.chromium.native_test.NativeTestActivity.CommandLineFlags')
27 _EXTRA_TEST_LIST = ( 28 _EXTRA_NATIVE_TEST_ACTIVITY = (
28 'org.chromium.native_test.NativeTestInstrumentationTestRunner' 29 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
29 '.TestList') 30 '.NativeTestActivity')
30 31
31 _MAX_SHARD_SIZE = 256 32 _MAX_SHARD_SIZE = 256
32 33
33 # TODO(jbudorick): Move this up to the test instance if the net test server is 34 # TODO(jbudorick): Move this up to the test instance if the net test server is
34 # handled outside of the APK for the remote_device environment. 35 # handled outside of the APK for the remote_device environment.
35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ 36 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
36 'components_browsertests', 'content_unittests', 'content_browsertests', 37 'components_browsertests', 'content_unittests', 'content_browsertests',
37 'net_unittests', 'unit_tests' 38 'net_unittests', 'unit_tests'
38 ] 39 ]
39 40
40 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone. 41 # TODO(jbudorick): Move this inside _ApkDelegate once TestPackageApk is gone.
41 def PullAppFilesImpl(device, package, files, directory): 42 def PullAppFilesImpl(device, package, files, directory):
42 device_dir = device.GetApplicationDataDirectory(package) 43 device_dir = device.GetApplicationDataDirectory(package)
43 host_dir = os.path.join(directory, str(device)) 44 host_dir = os.path.join(directory, str(device))
44 for f in files: 45 for f in files:
45 device_file = posixpath.join(device_dir, f) 46 device_file = posixpath.join(device_dir, f)
46 host_file = os.path.join(host_dir, *f.split(posixpath.sep)) 47 host_file = os.path.join(host_dir, *f.split(posixpath.sep))
47 host_file_base, ext = os.path.splitext(host_file) 48 host_file_base, ext = os.path.splitext(host_file)
48 for i in itertools.count(): 49 for i in itertools.count():
49 host_file = '%s_%d%s' % (host_file_base, i, ext) 50 host_file = '%s_%d%s' % (host_file_base, i, ext)
50 if not os.path.exists(host_file): 51 if not os.path.exists(host_file):
51 break 52 break
52 device.PullFile(device_file, host_file) 53 device.PullFile(device_file, host_file)
53 54
54 class _ApkDelegate(object): 55 class _ApkDelegate(object):
55 def __init__(self, test_instance): 56 def __init__(self, apk):
56 self._activity = test_instance.activity 57 self._apk = apk
57 self._apk = test_instance.apk
58 self._package = test_instance.package
59 self._runner = test_instance.runner
60 58
59 helper = apk_helper.ApkHelper(self._apk)
60 self._activity = helper.GetActivityName()
61 self._package = helper.GetPackageName()
62 self._runner = helper.GetInstrumentationName()
61 self._component = '%s/%s' % (self._package, self._runner) 63 self._component = '%s/%s' % (self._package, self._runner)
62 self._extras = test_instance.extras 64 self._enable_test_server_spawner = False
63 65
64 def Install(self, device): 66 def Install(self, device):
65 device.Install(self._apk) 67 device.Install(self._apk)
66 68
67 def Run(self, test, device, flags=None, **kwargs): 69 def RunWithFlags(self, device, flags, **kwargs):
68 extras = dict(self._extras) 70 with device_temp_file.DeviceTempFile(device.adb) as command_line_file:
71 device.WriteFile(command_line_file.name, '_ %s' % flags)
69 72
70 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: 73 extras = {
71 device.WriteFile(command_line_file.name, '_ %s' % flags if flags else '_') 74 _EXTRA_COMMAND_LINE_FILE: command_line_file.name,
72 extras[_EXTRA_COMMAND_LINE_FILE] = command_line_file.name 75 _EXTRA_NATIVE_TEST_ACTIVITY: self._activity,
76 }
73 77
74 with device_temp_file.DeviceTempFile(device.adb) as test_list_file: 78 return device.StartInstrumentation(
75 if test: 79 self._component, extras=extras, raw=False, **kwargs)
76 device.WriteFile(test_list_file.name, '\n'.join(test))
77 extras[_EXTRA_TEST_LIST] = test_list_file.name
78
79 return device.StartInstrumentation(
80 self._component, extras=extras, raw=False, **kwargs)
81 80
82 def PullAppFiles(self, device, files, directory): 81 def PullAppFiles(self, device, files, directory):
83 PullAppFilesImpl(device, self._package, files, directory) 82 PullAppFilesImpl(device, self._package, files, directory)
84 83
85 def Clear(self, device): 84 def Clear(self, device):
86 device.ClearApplicationState(self._package) 85 device.ClearApplicationState(self._package)
87 86
88 87
89 class _ExeDelegate(object): 88 class _ExeDelegate(object):
90 def __init__(self, tr, exe): 89 def __init__(self, exe, tr):
91 self._exe_host_path = exe 90 self._exe_host_path = exe
92 self._exe_file_name = os.path.split(exe)[-1] 91 self._exe_file_name = os.path.split(exe)[-1]
93 self._exe_device_path = '%s/%s' % ( 92 self._exe_device_path = '%s/%s' % (
94 constants.TEST_EXECUTABLE_DIR, self._exe_file_name) 93 constants.TEST_EXECUTABLE_DIR, self._exe_file_name)
95 deps_host_path = self._exe_host_path + '_deps' 94 deps_host_path = self._exe_host_path + '_deps'
96 if os.path.exists(deps_host_path): 95 if os.path.exists(deps_host_path):
97 self._deps_host_path = deps_host_path 96 self._deps_host_path = deps_host_path
98 self._deps_device_path = self._exe_device_path + '_deps' 97 self._deps_device_path = self._exe_device_path + '_deps'
99 else: 98 else:
100 self._deps_host_path = None 99 self._deps_host_path = None
101 self._test_run = tr 100 self._test_run = tr
102 101
103 def Install(self, device): 102 def Install(self, device):
104 # TODO(jbudorick): Look into merging this with normal data deps pushing if 103 # TODO(jbudorick): Look into merging this with normal data deps pushing if
105 # executables become supported on nonlocal environments. 104 # executables become supported on nonlocal environments.
106 host_device_tuples = [(self._exe_host_path, self._exe_device_path)] 105 host_device_tuples = [(self._exe_host_path, self._exe_device_path)]
107 if self._deps_host_path: 106 if self._deps_host_path:
108 host_device_tuples.append((self._deps_host_path, self._deps_device_path)) 107 host_device_tuples.append((self._deps_host_path, self._deps_device_path))
109 device.PushChangedFiles(host_device_tuples) 108 device.PushChangedFiles(host_device_tuples)
110 109
111 def Run(self, test, device, flags=None, **kwargs): 110 def RunWithFlags(self, device, flags, **kwargs):
112 cmd = [ 111 cmd = [
113 self._test_run.GetTool(device).GetTestWrapper(), 112 self._test_run.GetTool(device).GetTestWrapper(),
114 self._exe_device_path, 113 self._exe_device_path,
114 flags,
115 ] 115 ]
116 if test:
117 cmd.append('--gtest_filter=%s' % ':'.join(test))
118 if flags:
119 cmd.append(flags)
120 cwd = constants.TEST_EXECUTABLE_DIR 116 cwd = constants.TEST_EXECUTABLE_DIR
121 117
122 env = { 118 env = {
123 'LD_LIBRARY_PATH': 119 'LD_LIBRARY_PATH':
124 '%s/%s_deps' % (constants.TEST_EXECUTABLE_DIR, self._exe_file_name), 120 '%s/%s_deps' % (constants.TEST_EXECUTABLE_DIR, self._exe_file_name),
125 } 121 }
126 try: 122 try:
127 gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] 123 gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
128 external = device.GetExternalStoragePath() 124 external = device.GetExternalStoragePath()
129 env['GCOV_PREFIX'] = '%s/gcov' % external 125 env['GCOV_PREFIX'] = '%s/gcov' % external
(...skipping 19 matching lines...) Expand all
149 145
150 146
151 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun): 147 class LocalDeviceGtestRun(local_device_test_run.LocalDeviceTestRun):
152 148
153 def __init__(self, env, test_instance): 149 def __init__(self, env, test_instance):
154 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) 150 assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
155 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) 151 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
156 super(LocalDeviceGtestRun, self).__init__(env, test_instance) 152 super(LocalDeviceGtestRun, self).__init__(env, test_instance)
157 153
158 if self._test_instance.apk: 154 if self._test_instance.apk:
159 self._delegate = _ApkDelegate(self._test_instance) 155 self._delegate = _ApkDelegate(self._test_instance.apk)
160 elif self._test_instance.exe: 156 elif self._test_instance.exe:
161 self._delegate = _ExeDelegate(self, self._test_instance.exe) 157 self._delegate = _ExeDelegate(self, self._test_instance.exe)
162 158
163 self._servers = {} 159 self._servers = {}
164 160
165 #override 161 #override
166 def TestPackage(self): 162 def TestPackage(self):
167 return self._test_instance.suite 163 return self._test_instance.suite
168 164
169 #override 165 #override
(...skipping 21 matching lines...) Expand all
191 187
192 self._env.parallel_devices.pMap(individual_device_set_up, 188 self._env.parallel_devices.pMap(individual_device_set_up,
193 self._test_instance.GetDataDependencies()) 189 self._test_instance.GetDataDependencies())
194 190
195 #override 191 #override
196 def _ShouldShard(self): 192 def _ShouldShard(self):
197 return True 193 return True
198 194
199 #override 195 #override
200 def _CreateShards(self, tests): 196 def _CreateShards(self, tests):
201 device_count = len(self._env.devices) 197 if self._test_instance.suite in gtest_test_instance.BROWSER_TEST_SUITES:
202 shards = [] 198 return tests
203 for i in xrange(0, device_count): 199 else:
204 unbounded_shard = tests[i::device_count] 200 device_count = len(self._env.devices)
205 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] 201 shards = []
206 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] 202 for i in xrange(0, device_count):
207 return shards 203 unbounded_shard = tests[i::device_count]
204 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE]
205 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)]
206 return [':'.join(s) for s in shards]
208 207
209 #override 208 #override
210 def _GetTests(self): 209 def _GetTests(self):
211 tests = self._delegate.Run( 210 tests = self._delegate.RunWithFlags(
212 None, self._env.devices[0], flags='--gtest_list_tests') 211 self._env.devices[0], '--gtest_list_tests')
213 tests = gtest_test_instance.ParseGTestListTests(tests) 212 tests = gtest_test_instance.ParseGTestListTests(tests)
214 tests = self._test_instance.FilterTests(tests) 213 tests = self._test_instance.FilterTests(tests)
215 return tests 214 return tests
216 215
217 #override 216 #override
218 def _RunTest(self, device, test): 217 def _RunTest(self, device, test):
219 # Run the test. 218 # Run the test.
220 output = self._delegate.Run( 219 output = self._delegate.RunWithFlags(
221 test, device, timeout=900, retries=0) 220 device, '--gtest_filter=%s' % test, timeout=900, retries=0)
222 for s in self._servers[str(device)]: 221 for s in self._servers[str(device)]:
223 s.Reset() 222 s.Reset()
224 if self._test_instance.app_files: 223 if self._test_instance.app_files:
225 self._delegate.PullAppFiles(device, self._test_instance.app_files, 224 self._delegate.PullAppFiles(device, self._test_instance.app_files,
226 self._test_instance.app_file_dir) 225 self._test_instance.app_file_dir)
227 self._delegate.Clear(device) 226 self._delegate.Clear(device)
228 227
229 # Parse the output. 228 # Parse the output.
230 # TODO(jbudorick): Transition test scripts away from parsing stdout. 229 # TODO(jbudorick): Transition test scripts away from parsing stdout.
231 results = self._test_instance.ParseGTestOutput(output) 230 results = self._test_instance.ParseGTestOutput(output)
232 return results 231 return results
233 232
234 #override 233 #override
235 def TearDown(self): 234 def TearDown(self):
236 def individual_device_tear_down(dev): 235 def individual_device_tear_down(dev):
237 for s in self._servers[str(dev)]: 236 for s in self._servers[str(dev)]:
238 s.TearDown() 237 s.TearDown()
239 238
240 self._env.parallel_devices.pMap(individual_device_tear_down) 239 self._env.parallel_devices.pMap(individual_device_tear_down)
241 240
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698