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

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

Issue 988693005: Chromium roll (https://codereview.chromium.org/976353002) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fixed bad android build patch Created 5 years, 9 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 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 5
6 import logging 6 import logging
7 import os 7 import os
8 8
9 from pylib import constants 9 from pylib import constants
10 from pylib import ports 10 from pylib import ports
11 from pylib.base import test_run 11 from pylib.base import test_run
12 from pylib.device import device_errors 12 from pylib.device import device_errors
13 from pylib.gtest import gtest_test_instance 13 from pylib.gtest import gtest_test_instance
14 14
15 from pylib.local import local_test_server_spawner 15 from pylib.local import local_test_server_spawner
16 from pylib.local.device import local_device_environment 16 from pylib.local.device import local_device_environment
17 from pylib.local.device import local_device_test_run 17 from pylib.local.device import local_device_test_run
18 from pylib.utils import apk_helper 18 from pylib.utils import apk_helper
19 from pylib.utils import device_temp_file 19 from pylib.utils import device_temp_file
20 20
21 _COMMAND_LINE_FLAGS_SUPPORTED = True 21 _COMMAND_LINE_FLAGS_SUPPORTED = True
22 22
23 _EXTRA_COMMAND_LINE_FILE = ( 23 _EXTRA_COMMAND_LINE_FILE = (
24 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile') 24 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile')
25 _EXTRA_COMMAND_LINE_FLAGS = ( 25 _EXTRA_COMMAND_LINE_FLAGS = (
26 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags') 26 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags')
27 _EXTRA_ENABLE_TEST_SERVER_SPAWNER = (
28 'org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner'
29 '.EnableTestServerSpawner')
30 27
31 _MAX_SHARD_SIZE = 256 28 _MAX_SHARD_SIZE = 256
32 29
33 # TODO(jbudorick): Move this up to the test instance if the net test server is 30 # 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. 31 # handled outside of the APK for the remote_device environment.
35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ 32 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
36 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests' 33 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests'
37 ] 34 ]
38 35
39 class _ApkDelegate(object): 36 class _ApkDelegate(object):
40 def __init__(self, apk): 37 def __init__(self, apk):
41 self._apk = apk 38 self._apk = apk
42 self._package = apk_helper.GetPackageName(self._apk) 39 self._package = apk_helper.GetPackageName(self._apk)
43 self._runner = apk_helper.GetInstrumentationName(self._apk) 40 self._runner = apk_helper.GetInstrumentationName(self._apk)
44 self._component = '%s/%s' % (self._package, self._runner) 41 self._component = '%s/%s' % (self._package, self._runner)
45 self._enable_test_server_spawner = False 42 self._enable_test_server_spawner = False
46 43
47 def EnableTestServerSpawner(self):
48 self._enable_test_server_spawner = True
49
50 def Install(self, device): 44 def Install(self, device):
51 device.Install(self._apk) 45 device.Install(self._apk)
52 46
53 def RunWithFlags(self, device, flags, **kwargs): 47 def RunWithFlags(self, device, flags, **kwargs):
54 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: 48 with device_temp_file.DeviceTempFile(device.adb) as command_line_file:
55 device.WriteFile(command_line_file.name, '_ %s' % flags) 49 device.WriteFile(command_line_file.name, '_ %s' % flags)
56 50
57 extras = { 51 extras = {
58 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, 52 _EXTRA_COMMAND_LINE_FILE: command_line_file.name,
59 } 53 }
60 if self._enable_test_server_spawner:
61 extras[_EXTRA_ENABLE_TEST_SERVER_SPAWNER] = '1'
62 54
63 return device.StartInstrumentation( 55 return device.StartInstrumentation(
64 self._component, extras=extras, raw=False, **kwargs) 56 self._component, extras=extras, raw=False, **kwargs)
65 57
66 def Clear(self, device): 58 def Clear(self, device):
67 device.ClearApplicationState(self._package) 59 device.ClearApplicationState(self._package)
68 60
69 61
70 class _ExeDelegate(object): 62 class _ExeDelegate(object):
71 def __init__(self, exe, tr): 63 def __init__(self, exe, tr):
72 self._exe_host_path = exe 64 self._exe_host_path = exe
73 self._exe_file_name = os.path.split(exe)[-1] 65 self._exe_file_name = os.path.split(exe)[-1]
74 self._exe_device_path = '%s/%s' % ( 66 self._exe_device_path = '%s/%s' % (
75 constants.TEST_EXECUTABLE_DIR, self._exe_file_name) 67 constants.TEST_EXECUTABLE_DIR, self._exe_file_name)
76 deps_host_path = self._exe_host_path + '_deps' 68 deps_host_path = self._exe_host_path + '_deps'
77 if os.path.exists(deps_host_path): 69 if os.path.exists(deps_host_path):
78 self._deps_host_path = deps_host_path 70 self._deps_host_path = deps_host_path
79 self._deps_device_path = self._exe_device_path + '_deps' 71 self._deps_device_path = self._exe_device_path + '_deps'
80 else: 72 else:
81 self._deps_host_path = None 73 self._deps_host_path = None
82 self._test_run = tr 74 self._test_run = tr
83 75
84 def EnableTestServerSpawner(self):
85 pass
86
87 def Install(self, device): 76 def Install(self, device):
88 # TODO(jbudorick): Look into merging this with normal data deps pushing if 77 # TODO(jbudorick): Look into merging this with normal data deps pushing if
89 # executables become supported on nonlocal environments. 78 # executables become supported on nonlocal environments.
90 host_device_tuples = [(self._exe_host_path, self._exe_device_path)] 79 host_device_tuples = [(self._exe_host_path, self._exe_device_path)]
91 if self._deps_host_path: 80 if self._deps_host_path:
92 host_device_tuples.append((self._deps_host_path, self._deps_device_path)) 81 host_device_tuples.append((self._deps_host_path, self._deps_device_path))
93 device.PushChangedFiles(host_device_tuples) 82 device.PushChangedFiles(host_device_tuples)
94 83
95 def RunWithFlags(self, device, flags, **kwargs): 84 def RunWithFlags(self, device, flags, **kwargs):
96 cmd = [ 85 cmd = [
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 def __init__(self, env, test_instance): 125 def __init__(self, env, test_instance):
137 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) 126 assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
138 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) 127 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
139 super(LocalDeviceGtestRun, self).__init__(env, test_instance) 128 super(LocalDeviceGtestRun, self).__init__(env, test_instance)
140 129
141 if self._test_instance.apk: 130 if self._test_instance.apk:
142 self._delegate = _ApkDelegate(self._test_instance.apk) 131 self._delegate = _ApkDelegate(self._test_instance.apk)
143 elif self._test_instance.exe: 132 elif self._test_instance.exe:
144 self._delegate = _ExeDelegate(self, self._test_instance.exe) 133 self._delegate = _ExeDelegate(self, self._test_instance.exe)
145 134
135 self._servers = {}
136
146 #override 137 #override
147 def TestPackage(self): 138 def TestPackage(self):
148 return self._test_instance._suite 139 return self._test_instance._suite
149 140
150 #override 141 #override
151 def SetUp(self): 142 def SetUp(self):
152 143
153 def individual_device_set_up(dev, host_device_tuples): 144 def individual_device_set_up(dev, host_device_tuples):
154 # Install test APK. 145 # Install test APK.
155 self._delegate.Install(dev) 146 self._delegate.Install(dev)
156 147
157 # Push data dependencies. 148 # Push data dependencies.
158 external_storage = dev.GetExternalStoragePath() 149 external_storage = dev.GetExternalStoragePath()
159 host_device_tuples = [ 150 host_device_tuples = [
160 (h, d if d is not None else external_storage) 151 (h, d if d is not None else external_storage)
161 for h, d in host_device_tuples] 152 for h, d in host_device_tuples]
162 dev.PushChangedFiles(host_device_tuples) 153 dev.PushChangedFiles(host_device_tuples)
163 154
155 self._servers[str(dev)] = []
164 if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER: 156 if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER:
165 self._delegate.EnableTestServerSpawner() 157 self._servers[str(dev)].append(
158 local_test_server_spawner.LocalTestServerSpawner(
159 ports.AllocateTestServerPort(), dev, self.GetTool(dev)))
160
161 for s in self._servers[str(dev)]:
162 s.SetUp()
166 163
167 self._env.parallel_devices.pMap(individual_device_set_up, 164 self._env.parallel_devices.pMap(individual_device_set_up,
168 self._test_instance.GetDataDependencies()) 165 self._test_instance.GetDataDependencies())
169 166
170 #override 167 #override
171 def _ShouldShard(self): 168 def _ShouldShard(self):
172 return True 169 return True
173 170
174 #override 171 #override
175 def _CreateShards(self, tests): 172 def _CreateShards(self, tests):
(...skipping 11 matching lines...) Expand all
187 self._env.devices[0], '--gtest_list_tests') 184 self._env.devices[0], '--gtest_list_tests')
188 tests = gtest_test_instance.ParseGTestListTests(tests) 185 tests = gtest_test_instance.ParseGTestListTests(tests)
189 tests = self._test_instance.FilterTests(tests) 186 tests = self._test_instance.FilterTests(tests)
190 return tests 187 return tests
191 188
192 #override 189 #override
193 def _RunTest(self, device, test): 190 def _RunTest(self, device, test):
194 # Run the test. 191 # Run the test.
195 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test, 192 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test,
196 timeout=900, retries=0) 193 timeout=900, retries=0)
194 for s in self._servers[str(device)]:
195 s.Reset()
197 self._delegate.Clear(device) 196 self._delegate.Clear(device)
198 197
199 # Parse the output. 198 # Parse the output.
200 # TODO(jbudorick): Transition test scripts away from parsing stdout. 199 # TODO(jbudorick): Transition test scripts away from parsing stdout.
201 results = self._test_instance.ParseGTestOutput(output) 200 results = self._test_instance.ParseGTestOutput(output)
202 return results 201 return results
203 202
204 #override 203 #override
205 def TearDown(self): 204 def TearDown(self):
206 pass 205 def individual_device_tear_down(dev):
206 for s in self._servers[str(dev)]:
207 s.TearDown()
207 208
209 self._env.parallel_devices.pMap(individual_device_tear_down)
210
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/filter/content_browsertests_disabled ('k') | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698