Use device-independent text for nvprmsaa4/16 in nanobench and dm
[platform/upstream/libSkiaSharp.git] / tools / buildbot_spec.py
1 #
2 # Copyright 2015 Google Inc.
3 #
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 #
7
8 #!/usr/bin/env python
9
10 usage = '''
11 Write buildbot spec to outfile based on the bot name:
12   $ python buildbot_spec.py outfile Test-Ubuntu-GCC-GCE-CPU-AVX2-x86-Debug
13 Or run self-tests:
14   $ python buildbot_spec.py test
15 '''
16
17 import inspect
18 import json
19 import os
20 import sys
21
22 import builder_name_schema
23 import dm_flags
24 import nanobench_flags
25
26
27 CONFIG_DEBUG = 'Debug'
28 CONFIG_RELEASE = 'Release'
29
30
31 def lineno():
32   caller = inspect.stack()[1]  # Up one level to our caller.
33   return inspect.getframeinfo(caller[0]).lineno
34
35 # Since we don't actually start coverage until we're in the self-test,
36 # some function def lines aren't reported as covered. Add them to this
37 # list so that we can ignore them.
38 cov_skip = []
39
40 cov_start = lineno()+1   # We care about coverage starting just past this def.
41 def gyp_defines(builder_dict):
42   gyp_defs = {}
43
44   # skia_arch_type.
45   if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
46     arch = builder_dict['target_arch']
47   elif builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
48     arch = None
49   else:
50     arch = builder_dict['arch']
51
52   arch_types = {
53     'x86':      'x86',
54     'x86_64':   'x86_64',
55     'Arm7':     'arm',
56     'Arm64':    'arm64',
57     'Mips':     'mips32',
58     'Mips64':   'mips64',
59     'MipsDSP2': 'mips32',
60   }
61   if arch in arch_types:
62     gyp_defs['skia_arch_type']  = arch_types[arch]
63
64   # housekeeper: build shared lib.
65   if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
66     gyp_defs['skia_shared_lib'] = '1'
67
68   # skia_gpu.
69   if builder_dict.get('cpu_or_gpu') == 'CPU':
70     gyp_defs['skia_gpu'] = '0'
71
72   # skia_warnings_as_errors.
73   werr = False
74   if builder_dict['role'] == builder_name_schema.BUILDER_ROLE_BUILD:
75     if 'Win' in builder_dict.get('os', ''):
76       if not ('GDI' in builder_dict.get('extra_config', '') or
77               'Exceptions' in builder_dict.get('extra_config', '')):
78         werr = True
79     elif ('Mac' in builder_dict.get('os', '') and
80           'Android' in builder_dict.get('extra_config', '')):
81       werr = False
82     else:
83       werr = True
84   gyp_defs['skia_warnings_as_errors'] = str(int(werr))  # True/False -> '1'/'0'
85
86   # Win debugger.
87   if 'Win' in builder_dict.get('os', ''):
88     gyp_defs['skia_win_debuggers_path'] = 'c:/DbgHelp'
89
90   # Qt SDK (Win).
91   if 'Win' in builder_dict.get('os', ''):
92     if builder_dict.get('os') == 'Win8':
93       gyp_defs['qt_sdk'] = 'C:/Qt/Qt5.1.0/5.1.0/msvc2012_64/'
94     else:
95       gyp_defs['qt_sdk'] = 'C:/Qt/4.8.5/'
96
97   # ANGLE.
98   if builder_dict.get('extra_config') == 'ANGLE':
99     gyp_defs['skia_angle'] = '1'
100     if builder_dict.get('os', '') in ('Ubuntu', 'Linux'):
101       gyp_defs['use_x11'] = '1'
102       gyp_defs['chromeos'] = '0'
103
104   # GDI.
105   if builder_dict.get('extra_config') == 'GDI':
106     gyp_defs['skia_gdi'] = '1'
107
108   # Build with Exceptions on Windows.
109   if ('Win' in builder_dict.get('os', '') and
110       builder_dict.get('extra_config') == 'Exceptions'):
111     gyp_defs['skia_win_exceptions'] = '1'
112
113   # iOS.
114   if (builder_dict.get('os') == 'iOS' or
115       builder_dict.get('extra_config') == 'iOS'):
116     gyp_defs['skia_os'] = 'ios'
117
118   # Shared library build.
119   if builder_dict.get('extra_config') == 'Shared':
120     gyp_defs['skia_shared_lib'] = '1'
121
122   # PDF viewer in GM.
123   if (builder_dict.get('os') == 'Mac10.8' and
124       builder_dict.get('arch') == 'x86_64' and
125       builder_dict.get('configuration') == 'Release'):
126     gyp_defs['skia_run_pdfviewer_in_gm'] = '1'
127
128   # Clang.
129   if builder_dict.get('compiler') == 'Clang':
130     gyp_defs['skia_clang_build'] = '1'
131
132   # Valgrind.
133   if 'Valgrind' in builder_dict.get('extra_config', ''):
134     gyp_defs['skia_release_optimization_level'] = '1'
135
136   # Link-time code generation just wastes time on compile-only bots.
137   if (builder_dict.get('role') == builder_name_schema.BUILDER_ROLE_BUILD and
138       builder_dict.get('compiler') == 'MSVC'):
139     gyp_defs['skia_win_ltcg'] = '0'
140
141   # Mesa.
142   if (builder_dict.get('extra_config') == 'Mesa' or
143       builder_dict.get('cpu_or_gpu_value') == 'Mesa'):
144     gyp_defs['skia_mesa'] = '1'
145
146   # VisualBench
147   if builder_dict.get('extra_config') == 'VisualBench':
148     gyp_defs['skia_use_sdl'] = '1'
149
150   # skia_use_android_framework_defines.
151   if builder_dict.get('extra_config') == 'Android_FrameworkDefs':
152     gyp_defs['skia_use_android_framework_defines'] = '1'
153
154   # Skia dump stats for perf tests and gpu
155   if (builder_dict.get('cpu_or_gpu') == 'GPU' and
156       builder_dict.get('role') == 'Perf'):
157       gyp_defs['skia_dump_stats'] = '1'
158
159   return gyp_defs
160
161
162 cov_skip.extend([lineno(), lineno() + 1])
163 def get_extra_env_vars(builder_dict):
164   env = {}
165   if builder_dict.get('configuration') == 'Coverage':
166     # We have to use Clang 3.6 because earlier versions do not support the
167     # compile flags we use and 3.7 and 3.8 hit asserts during compilation.
168     env['CC'] = '/usr/bin/clang-3.6'
169     env['CXX'] = '/usr/bin/clang++-3.6'
170   elif builder_dict.get('compiler') == 'Clang':
171     env['CC'] = '/usr/bin/clang'
172     env['CXX'] = '/usr/bin/clang++'
173
174   # SKNX_NO_SIMD, SK_USE_DISCARDABLE_SCALEDIMAGECACHE, etc.
175   extra_config = builder_dict.get('extra_config', '')
176   if extra_config.startswith('SK') and extra_config.isupper():
177     env['CPPFLAGS'] = '-D' + extra_config
178
179   return env
180
181
182 cov_skip.extend([lineno(), lineno() + 1])
183 def build_targets_from_builder_dict(builder_dict, do_test_steps, do_perf_steps):
184   """Return a list of targets to build, depending on the builder type."""
185   if builder_dict['role'] in ('Test', 'Perf') and builder_dict['os'] == 'iOS':
186     return ['iOSShell']
187   if builder_dict.get('extra_config') == 'Appurify':
188     return ['VisualBenchTest_APK']
189   t = []
190   if do_test_steps:
191     t.append('dm')
192   if do_perf_steps and builder_dict.get('extra_config') == 'VisualBench':
193       t.append('visualbench')
194   elif do_perf_steps:
195       t.append('nanobench')
196   if t:
197     return t
198   else:
199     return ['most']
200
201
202 cov_skip.extend([lineno(), lineno() + 1])
203 def device_cfg(builder_dict):
204   # Android.
205   if 'Android' in builder_dict.get('extra_config', ''):
206     if 'NoNeon' in builder_dict['extra_config']:
207       return 'arm_v7'
208     return {
209       'Arm64': 'arm64',
210       'x86': 'x86',
211       'x86_64': 'x86_64',
212       'Mips': 'mips',
213       'Mips64': 'mips64',
214       'MipsDSP2': 'mips_dsp2',
215     }.get(builder_dict['target_arch'], 'arm_v7_neon')
216   elif builder_dict.get('os') == 'Android':
217     return {
218       'AndroidOne': 'arm_v7_neon',
219       'GalaxyS3': 'arm_v7_neon',
220       'GalaxyS4': 'arm_v7_neon',
221       'Nexus5': 'arm_v7', # This'd be 'nexus_5', but we simulate no-NEON Clank.
222       'Nexus6': 'arm_v7_neon',
223       'Nexus7': 'nexus_7',
224       'Nexus9': 'nexus_9',
225       'Nexus10': 'nexus_10',
226       'NexusPlayer': 'x86',
227       'NVIDIA_Shield': 'arm64',
228     }[builder_dict['model']]
229
230   # ChromeOS.
231   if 'CrOS' in builder_dict.get('extra_config', ''):
232     if 'Link' in builder_dict['extra_config']:
233       return 'link'
234     if 'Daisy' in builder_dict['extra_config']:
235       return 'daisy'
236   elif builder_dict.get('os') == 'ChromeOS':
237     return {
238       'Link': 'link',
239       'Daisy': 'daisy',
240     }[builder_dict['model']]
241
242   return None
243
244
245 cov_skip.extend([lineno(), lineno() + 1])
246 def get_builder_spec(builder_name):
247   builder_dict = builder_name_schema.DictForBuilderName(builder_name)
248   env = get_extra_env_vars(builder_dict)
249   gyp_defs = gyp_defines(builder_dict)
250   gyp_defs_list = ['%s=%s' % (k, v) for k, v in gyp_defs.iteritems()]
251   gyp_defs_list.sort()
252   env['GYP_DEFINES'] = ' '.join(gyp_defs_list)
253   rv = {
254     'builder_cfg': builder_dict,
255     'dm_flags': dm_flags.get_args(builder_name),
256     'env': env,
257     'nanobench_flags': nanobench_flags.get_args(builder_name),
258   }
259   device = device_cfg(builder_dict)
260   if device:
261     rv['device_cfg'] = device
262
263   role = builder_dict['role']
264   if role == builder_name_schema.BUILDER_ROLE_HOUSEKEEPER:
265     configuration = CONFIG_RELEASE
266   else:
267     configuration = builder_dict.get(
268         'configuration', CONFIG_DEBUG)
269   arch = (builder_dict.get('arch') or builder_dict.get('target_arch'))
270   if ('Win' in builder_dict.get('os', '') and arch == 'x86_64'):
271     configuration += '_x64'
272   rv['configuration'] = configuration
273   rv['do_test_steps'] = role == builder_name_schema.BUILDER_ROLE_TEST
274   rv['do_perf_steps'] = (role == builder_name_schema.BUILDER_ROLE_PERF or
275                          (role == builder_name_schema.BUILDER_ROLE_TEST and
276                           configuration == CONFIG_DEBUG))
277   if 'Valgrind' in builder_name:
278     rv['do_perf_steps'] = True
279   if 'GalaxyS4' in builder_name:
280     rv['do_perf_steps'] = False
281
282   rv['build_targets'] = build_targets_from_builder_dict(
283         builder_dict, rv['do_test_steps'], rv['do_perf_steps'])
284
285   # Do we upload perf results?
286   upload_perf_results = False
287   if role == builder_name_schema.BUILDER_ROLE_PERF:
288     upload_perf_results = True
289   rv['upload_perf_results'] = upload_perf_results
290
291   # Do we upload correctness results?
292   skip_upload_bots = [
293     'ASAN',
294     'Coverage',
295     'TSAN',
296     'UBSAN',
297     'Valgrind',
298   ]
299   upload_dm_results = True
300   for s in skip_upload_bots:
301     if s in builder_name:
302       upload_dm_results = False
303       break
304   rv['upload_dm_results'] = upload_dm_results
305
306   return rv
307
308
309 cov_end = lineno()   # Don't care about code coverage past here.
310
311
312 def self_test():
313   import coverage  # This way the bots don't need coverage.py to be installed.
314   args = {}
315   cases = [
316         'Build-Mac10.8-Clang-Arm7-Debug-Android',
317         'Build-Win-MSVC-x86-Debug',
318         'Build-Win-MSVC-x86-Debug-GDI',
319         'Build-Win-MSVC-x86-Debug-Exceptions',
320         'Build-Ubuntu-GCC-Arm7-Debug-Android_FrameworkDefs',
321         'Build-Ubuntu-GCC-Arm7-Debug-Android_NoNeon',
322         'Build-Ubuntu-GCC-Arm7-Debug-CrOS_Daisy',
323         'Build-Ubuntu-GCC-x86_64-Debug-CrOS_Link',
324         'Build-Ubuntu-GCC-x86_64-Release-Mesa',
325         'Build-Ubuntu-GCC-x86_64-Release-ANGLE',
326         'Housekeeper-PerCommit',
327         'Perf-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Release-Trybot',
328         'Perf-Ubuntu-GCC-ShuttleA-GPU-GTX660-x86_64-Release-VisualBench',
329         'Test-Android-GCC-GalaxyS4-GPU-SGX544-Arm7-Debug',
330         'Perf-Android-GCC-Nexus5-GPU-Adreno330-Arm7-Release-Appurify',
331         'Test-Android-GCC-Nexus6-GPU-Adreno420-Arm7-Debug',
332         'Test-ChromeOS-GCC-Link-CPU-AVX-x86_64-Debug',
333         'Test-iOS-Clang-iPad4-GPU-SGX554-Arm7-Debug',
334         'Test-Mac10.8-Clang-MacMini4.1-GPU-GeForce320M-x86_64-Release',
335         'Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Coverage',
336         ('Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-'
337          'SK_USE_DISCARDABLE_SCALEDIMAGECACHE'),
338         'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD',
339         'Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-Shared',
340         'Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind',
341         'Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86-Release-ANGLE',
342         'Test-Win8-MSVC-ShuttleA-CPU-AVX-x86_64-Debug',
343   ]
344
345   cov = coverage.coverage()
346   cov.start()
347   for case in cases:
348     args[case] = get_builder_spec(case)
349   cov.stop()
350
351   this_file = os.path.basename(__file__)
352   _, _, not_run, _ = cov.analysis(this_file)
353   filtered = [line for line in not_run if
354               line > cov_start and line < cov_end and line not in cov_skip]
355   if filtered:
356     print 'Lines not covered by test cases: ', filtered
357     sys.exit(1)
358
359   golden = this_file.replace('.py', '.json')
360   with open(os.path.join(os.path.dirname(__file__), golden), 'w') as f:
361     json.dump(args, f, indent=2, sort_keys=True)
362
363
364 if __name__ == '__main__':
365   if len(sys.argv) == 2 and sys.argv[1] == 'test':
366     self_test()
367     sys.exit(0)
368
369   if len(sys.argv) != 3:
370     print usage
371     sys.exit(1)
372
373   with open(sys.argv[1], 'w') as out:
374     json.dump(get_builder_spec(sys.argv[2]), out)