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
10usage = '''
11Write extra flags to outfile for nanobench based on the bot name:
12  $ python nanobench_flags.py outfile Perf-Android-GCC-GalaxyS3-GPU-Mali400-Arm7-Release
13Or run self-tests:
14  $ python nanobench_flags.py test
15'''
16
17import inspect
18import json
19import os
20import sys
21
22
23def lineno():
24  caller = inspect.stack()[1]  # Up one level to our caller.
25  return inspect.getframeinfo(caller[0]).lineno
26
27
28cov_start = lineno()+1   # We care about coverage starting just past this def.
29def get_args(bot):
30  args = []
31
32  args.extend(['--scales', '1.0', '1.1'])
33
34  config = ['565', '8888', 'gpu', 'nonrendering', 'angle', 'hwui']
35  # The S4 crashes and the NP produces a long error stream when we run with
36  # MSAA.
37  if ('GalaxyS4'    not in bot and
38      'NexusPlayer' not in bot):
39    if 'Android' in bot:
40      config.extend(['msaa4', 'nvprmsaa4'])
41    else:
42      config.extend(['msaa16', 'nvprmsaa16'])
43  args.append('--config')
44  args.extend(config)
45
46  if 'Valgrind' in bot:
47    # Don't care about Valgrind performance.
48    args.extend(['--loops',   '1'])
49    args.extend(['--samples', '1'])
50
51  if 'HD2000' in bot:
52    args.extend(['--benchTileW', '256'])
53    args.extend(['--benchTileH', '256'])
54
55  match = []
56  if 'Android' in bot:
57    # Segfaults when run as GPU bench. Very large texture?
58    match.append('~blurroundrect')
59    match.append('~patch_grid')  # skia:2847
60    match.append('~desk_carsvg')
61  if 'HD2000' in bot:
62    match.extend(['~gradient', '~etc1bitmap'])  # skia:2895
63  if 'Nexus7' in bot:
64    match = ['skp']  # skia:2774
65  if 'NexusPlayer' in bot:
66    match.append('~desk_unicodetable')
67
68  if match:
69    args.append('--match')
70    args.extend(match)
71
72  return args
73cov_end = lineno()   # Don't care about code coverage past here.
74
75
76def self_test():
77  import coverage  # This way the bots don't need coverage.py to be installed.
78  args = {}
79  cases = [
80    'Perf-Android-Nexus7-Tegra3-Arm7-Release',
81    'Perf-Android-GCC-NexusPlayer-GPU-PowerVR-x86-Release',
82    'Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind',
83    'Test-Win7-MSVC-ShuttleA-GPU-HD2000-x86-Debug-ANGLE',
84  ]
85
86  cov = coverage.coverage()
87  cov.start()
88  for case in cases:
89    args[case] = get_args(case)
90  cov.stop()
91
92  this_file = os.path.basename(__file__)
93  _, _, not_run, _ = cov.analysis(this_file)
94  filtered = [line for line in not_run if line > cov_start and line < cov_end]
95  if filtered:
96    print 'Lines not covered by test cases: ', filtered
97    sys.exit(1)
98
99  golden = this_file.replace('.py', '.json')
100  with open(os.path.join(os.path.dirname(__file__), golden), 'w') as f:
101    json.dump(args, f, indent=2, sort_keys=True)
102
103
104if __name__ == '__main__':
105  if len(sys.argv) == 2 and sys.argv[1] == 'test':
106    self_test()
107    sys.exit(0)
108
109  if len(sys.argv) != 3:
110    print usage
111    sys.exit(1)
112
113  with open(sys.argv[1], 'w') as out:
114    json.dump(get_args(sys.argv[2]), out)
115