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

Side by Side Diff: mojo/tools/mojob.py

Issue 728783003: Add infrastructure to run tests on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Do not introduce IsInitialzed() Created 6 years, 1 month 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # This a simple script to make building/testing Mojo components easier. 6 # This a simple script to make building/testing Mojo components easier.
7 7
8 import argparse 8 import argparse
9 import os 9 import os
10 import platform 10 import platform
11 import re 11 import re
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 14
15 import mopy.paths 15 import mopy.paths
16 16
17 17
18 def call(args, command, shell=False):
19 if args.dry_run:
20 if isinstance(command, list):
21 command = ' '.join(command)
22 print command
23 else:
24 return subprocess.call(command, shell=shell)
25
26
18 def get_out_dir(args): 27 def get_out_dir(args):
19 out_dir = "out" 28 out_dir = "out"
20 prefix = '' 29 prefix = ''
21 if args.android: 30 if args.android:
22 prefix = 'android_' 31 prefix = 'android_'
23 elif args.chromeos: 32 elif args.chromeos:
24 prefix = 'chromeos_' 33 prefix = 'chromeos_'
25 subdir = prefix + ('Debug' if args.debug else 'Release') 34 subdir = prefix + ('Debug' if args.debug else 'Release')
26 return os.path.join(out_dir, subdir) 35 return os.path.join(out_dir, subdir)
27 36
28 37
29 def sync(args): 38 def sync(args):
30 # pylint: disable=W0613 39 # pylint: disable=W0613
31 return subprocess.call(['gclient', 'sync']) 40 return call(args, ['gclient', 'sync'])
32 41
33 42
34 def gn(args): 43 def gn(args):
35 command = ['gn', 'gen'] 44 command = ['gn', 'gen']
36 45
37 gn_args = [] 46 gn_args = []
38 gn_args.append('is_debug=' + ('true' if args.debug else 'false')) 47 gn_args.append('is_debug=' + ('true' if args.debug else 'false'))
39 gn_args.append('is_asan=' + ('true' if args.asan else 'false')) 48 gn_args.append('is_asan=' + ('true' if args.asan else 'false'))
40 gn_args.append('is_clang=' + ('true' if args.clang else 'false')) 49 gn_args.append('is_clang=' + ('true' if args.clang else 'false'))
41 50
(...skipping 19 matching lines...) Expand all
61 gn_args.append(r'''os=\"android\" cpu_arch=\"arm\"''') 70 gn_args.append(r'''os=\"android\" cpu_arch=\"arm\"''')
62 elif args.chromeos: 71 elif args.chromeos:
63 gn_args.append(r'''os=\"chromeos\" ui_base_build_ime=false 72 gn_args.append(r'''os=\"chromeos\" ui_base_build_ime=false
64 use_system_harfbuzz=false''') 73 use_system_harfbuzz=false''')
65 74
66 out_dir = get_out_dir(args) 75 out_dir = get_out_dir(args)
67 command.append(out_dir) 76 command.append(out_dir)
68 command.append('--args="%s"' % ' '.join(gn_args)) 77 command.append('--args="%s"' % ' '.join(gn_args))
69 78
70 print 'Running %s ...' % ' '.join(command) 79 print 'Running %s ...' % ' '.join(command)
71 return subprocess.call(' '.join(command), shell=True) 80 return call(args, ' '.join(command), shell=True)
72 81
73 82
74 def get_gn_arg_value(out_dir, arg): 83 def get_gn_arg_value(out_dir, arg):
75 args_file_path = os.path.join(out_dir, "args.gn") 84 args_file_path = os.path.join(out_dir, "args.gn")
76 if os.path.isfile(args_file_path): 85 if os.path.isfile(args_file_path):
77 key_value_regex = re.compile(r'^%s = (.+)$' % arg) 86 key_value_regex = re.compile(r'^%s = (.+)$' % arg)
78 with open(args_file_path, "r") as args_file: 87 with open(args_file_path, "r") as args_file:
79 for line in args_file.readlines(): 88 for line in args_file.readlines():
80 m = key_value_regex.search(line) 89 m = key_value_regex.search(line)
81 if m: 90 if m:
82 return m.group(1).strip('"') 91 return m.group(1).strip('"')
83 return '' 92 return ''
84 93
85 94
86 def build(args): 95 def build(args):
87 out_dir = get_out_dir(args) 96 out_dir = get_out_dir(args)
88 print 'Building in %s ...' % out_dir 97 print 'Building in %s ...' % out_dir
89 if get_gn_arg_value(out_dir, 'use_goma') == 'true': 98 if get_gn_arg_value(out_dir, 'use_goma') == 'true':
90 # Use the configured goma directory. 99 # Use the configured goma directory.
91 local_goma_dir = get_gn_arg_value(out_dir, 'goma_dir') 100 local_goma_dir = get_gn_arg_value(out_dir, 'goma_dir')
92 print 'Ensuring goma (in %s) started ...' % local_goma_dir 101 print 'Ensuring goma (in %s) started ...' % local_goma_dir
93 command = ['python', 102 command = ['python',
94 os.path.join(local_goma_dir, 'goma_ctl.py'), 103 os.path.join(local_goma_dir, 'goma_ctl.py'),
95 'ensure_start'] 104 'ensure_start']
96 exit_code = subprocess.call(command) 105 exit_code = call(args, command)
97 if exit_code: 106 if exit_code:
98 return exit_code 107 return exit_code
99 108
100 return subprocess.call(['ninja', '-j', '1000', '-l', '100', '-C', out_dir, 109 return call(args, ['ninja', '-j', '1000', '-l', '100', '-C', out_dir,
101 'root']) 110 'root'])
102 else: 111 else:
103 return subprocess.call(['ninja', '-C', out_dir, 'root']) 112 return call(args, ['ninja', '-C', out_dir, 'root'])
104 113
105 114
106 def run_unittests(args): 115 def run_unittests(args):
107 out_dir = get_out_dir(args) 116 out_dir = get_out_dir(args)
108 print 'Running unit tests in %s ...' % out_dir 117 print 'Running unit tests in %s ...' % out_dir
109 command = ['python'] 118 command = ['python']
110 if platform.system() == 'Linux': 119 if platform.system() == 'Linux' and not args.android:
111 command.append('./testing/xvfb.py') 120 command.append('./testing/xvfb.py')
112 command.append(out_dir) 121 command.append(out_dir)
113 122
114 command.append(os.path.join('mojo', 'tools', 'test_runner.py')) 123 command.append(os.path.join('mojo', 'tools', 'test_runner.py'))
115 command.append(os.path.join('mojo', 'tools', 'data', 'unittests')) 124 if args.android:
125 command.append('--android')
126 command.append(os.path.join('mojo', 'tools', 'data', 'android_unittests'))
127 else:
128 command.append(os.path.join('mojo', 'tools', 'data', 'unittests'))
116 command.append(out_dir) 129 command.append(out_dir)
117 command.append('mojob_test_successes') 130 command.append('mojob_test_successes')
118 return subprocess.call(command) 131 return call(args, command)
119 132
120 133
121 def run_skytests(args): 134 def run_skytests(args):
122 out_dir = get_out_dir(args) 135 out_dir = get_out_dir(args)
123 if platform.system() != 'Linux': 136 if platform.system() != 'Linux' or args.android:
124 return 0 137 return 0
125 138
126 command = [] 139 command = []
127 command.append('./testing/xvfb.py') 140 command.append('./testing/xvfb.py')
128 command.append(out_dir) 141 command.append(out_dir)
129 command.append('sky/tools/test_sky') 142 command.append('sky/tools/test_sky')
130 command.append('-t') 143 command.append('-t')
131 command.append('Debug' if args.debug else 'Release') 144 command.append('Debug' if args.debug else 'Release')
132 command.append('--no-new-test-results') 145 command.append('--no-new-test-results')
133 command.append('--no-show-results') 146 command.append('--no-show-results')
134 command.append('--verbose') 147 command.append('--verbose')
135 return subprocess.call(command) 148 return call(args, command)
136 149
137 150
138 def run_pytests(args): 151 def run_pytests(args):
139 out_dir = get_out_dir(args) 152 out_dir = get_out_dir(args)
140 print 'Running python tests in %s ...' % out_dir 153 print 'Running python tests in %s ...' % out_dir
141 command = ['python'] 154 command = ['python']
142 command.append(os.path.join('mojo', 'tools', 'run_mojo_python_tests.py')) 155 command.append(os.path.join('mojo', 'tools', 'run_mojo_python_tests.py'))
143 exit_code = subprocess.call(command) 156 exit_code = call(args, command)
144 if exit_code: 157 if exit_code:
145 return exit_code 158 return exit_code
146 159
147 if platform.system() != 'Linux': 160 if platform.system() != 'Linux' or args.android:
148 print ('Python bindings tests are only supported on Linux.') 161 print ('Python bindings tests are only supported on Linux.')
149 return 162 return
150 163
151 command = ['python'] 164 command = ['python']
152 command.append(os.path.join('mojo', 'tools', 165 command.append(os.path.join('mojo', 'tools',
153 'run_mojo_python_bindings_tests.py')) 166 'run_mojo_python_bindings_tests.py'))
154 command.append('--build-dir=' + out_dir) 167 command.append('--build-dir=' + out_dir)
155 return subprocess.call(command) 168 return call(args, command)
156 169
157 170
158 def test(args): 171 def test(args):
159 exit_code = run_unittests(args) 172 exit_code = run_unittests(args)
160 if exit_code: 173 if exit_code:
161 return exit_code 174 return exit_code
162 exit_code = run_pytests(args) 175 exit_code = run_pytests(args)
163 if exit_code: 176 if exit_code:
164 return exit_code 177 return exit_code
165 return run_skytests(args) 178 return run_skytests(args)
166 179
167 180
168 def perftest(args): 181 def perftest(args):
169 out_dir = get_out_dir(args) 182 out_dir = get_out_dir(args)
170 print 'Running perf tests in %s ...' % out_dir 183 print 'Running perf tests in %s ...' % out_dir
171 command = [] 184 command = []
172 command.append(os.path.join(out_dir, 'mojo_public_system_perftests')) 185 command.append(os.path.join(out_dir, 'mojo_public_system_perftests'))
173 return subprocess.call(command) 186 return call(args, command)
174 187
175 188
176 def pytest(args): 189 def pytest(args):
177 return run_pytests(args) 190 return run_pytests(args)
178 191
179 192
180 def darttest(args): 193 def darttest(args):
181 out_dir = get_out_dir(args) 194 out_dir = get_out_dir(args)
182 print 'Running Dart tests in %s ...' % out_dir 195 print 'Running Dart tests in %s ...' % out_dir
183 command = [] 196 command = []
184 command.append('dart') 197 command.append('dart')
185 command.append(os.path.join('mojo', 'tools', 'dart_test_runner.dart')) 198 command.append(os.path.join('mojo', 'tools', 'dart_test_runner.dart'))
186 command.append(os.path.join(out_dir, 'gen')) 199 command.append(os.path.join(out_dir, 'gen'))
187 return subprocess.call(command) 200 return call(args, command)
188 201
189 202
190 def main(): 203 def main():
191 os.chdir(mopy.paths.Paths().src_root) 204 os.chdir(mopy.paths.Paths().src_root)
192 205
193 parser = argparse.ArgumentParser(description='A script to make building' 206 parser = argparse.ArgumentParser(description='A script to make building'
194 '/testing Mojo components easier.') 207 '/testing Mojo components easier.')
195 208
196 parent_parser = argparse.ArgumentParser(add_help=False) 209 parent_parser = argparse.ArgumentParser(add_help=False)
197 debug_group = parent_parser.add_mutually_exclusive_group() 210 debug_group = parent_parser.add_mutually_exclusive_group()
198 debug_group.add_argument('--debug', help='Debug build (default)', 211 debug_group.add_argument('--debug', help='Debug build (default)',
199 default=True, action='store_true') 212 default=True, action='store_true')
200 debug_group.add_argument('--release', help='Release build', default=False, 213 debug_group.add_argument('--release', help='Release build', default=False,
201 dest='debug', action='store_false') 214 dest='debug', action='store_false')
202 215
203 os_group = parent_parser.add_mutually_exclusive_group() 216 os_group = parent_parser.add_mutually_exclusive_group()
204 os_group.add_argument('--android', help='Build for Android', 217 os_group.add_argument('--android', help='Build for Android',
205 action='store_true') 218 action='store_true')
206 os_group.add_argument('--chromeos', help='Build for ChromeOS', 219 os_group.add_argument('--chromeos', help='Build for ChromeOS',
207 action='store_true') 220 action='store_true')
208 221
222 parent_parser.add_argument('--dry-run', help='Print commands',
223 action='store_true')
224
209 subparsers = parser.add_subparsers() 225 subparsers = parser.add_subparsers()
210 226
211 sync_parser = subparsers.add_parser('sync', parents=[parent_parser], 227 sync_parser = subparsers.add_parser('sync', parents=[parent_parser],
212 help='Sync using gclient (does not run gn).') 228 help='Sync using gclient (does not run gn).')
213 sync_parser.set_defaults(func=sync) 229 sync_parser.set_defaults(func=sync)
214 230
215 gn_parser = subparsers.add_parser('gn', parents=[parent_parser], 231 gn_parser = subparsers.add_parser('gn', parents=[parent_parser],
216 help='Run gn for mojo (does not sync).') 232 help='Run gn for mojo (does not sync).')
217 gn_parser.set_defaults(func=gn) 233 gn_parser.set_defaults(func=gn)
218 gn_parser.add_argument('--asan', help='Uses Address Sanitizer', 234 gn_parser.add_argument('--asan', help='Uses Address Sanitizer',
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 args.clang = False 276 args.clang = False
261 277
262 if platform.system() == 'Windows': 278 if platform.system() == 'Windows':
263 args.clang = False 279 args.clang = False
264 280
265 return args.func(args) 281 return args.func(args)
266 282
267 283
268 if __name__ == '__main__': 284 if __name__ == '__main__':
269 sys.exit(main()) 285 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698