settings_factory.py revision c39917fe61858e884d06656122cf88a8c66fd825
1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""Setting files for global, benchmark and labels."""
5
6from __future__ import print_function
7
8from field import BooleanField
9from field import IntegerField
10from field import ListField
11from field import TextField
12from settings import Settings
13
14
15class BenchmarkSettings(Settings):
16  """Settings used to configure individual benchmarks."""
17
18  def __init__(self, name):
19    super(BenchmarkSettings, self).__init__(name, 'benchmark')
20    self.AddField(
21        TextField(
22            'test_name',
23            description='The name of the test to run. '
24            'Defaults to the name of the benchmark.'))
25    self.AddField(
26        TextField(
27            'test_args', description='Arguments to be passed to the '
28            'test.'))
29    self.AddField(
30        IntegerField(
31            'iterations',
32            default=1,
33            description='Number of iterations to run the '
34            'test.'))
35    self.AddField(
36        TextField(
37            'suite', default='', description='The type of the benchmark.'))
38    self.AddField(
39        IntegerField(
40            'retries',
41            default=0,
42            description='Number of times to retry a '
43            'benchmark run.'))
44    self.AddField(
45        BooleanField(
46            'run_local',
47            description='Run benchmark harness on the DUT. '
48            'Currently only compatible with the suite: '
49            'telemetry_Crosperf.',
50            required=False,
51            default=True))
52
53
54class LabelSettings(Settings):
55  """Settings for each label."""
56
57  def __init__(self, name):
58    super(LabelSettings, self).__init__(name, 'label')
59    self.AddField(
60        TextField(
61            'chromeos_image',
62            required=False,
63            description='The path to the image to run tests '
64            'on, for local/custom-built images. See the '
65            "'build' option for official or trybot images."))
66    self.AddField(
67        TextField(
68            'chromeos_root',
69            description='The path to a chromeos checkout which '
70            'contains a src/scripts directory. Defaults to '
71            'the chromeos checkout which contains the '
72            'chromeos_image.'))
73    self.AddField(
74        ListField(
75            'remote',
76            description='A comma-separated list of IPs of chromeos'
77            'devices to run experiments on.'))
78    self.AddField(
79        TextField(
80            'image_args',
81            required=False,
82            default='',
83            description='Extra arguments to pass to '
84            'image_chromeos.py.'))
85    self.AddField(
86        TextField(
87            'cache_dir',
88            default='',
89            description='The cache dir for this image.'))
90    self.AddField(
91        TextField(
92            'compiler',
93            default='gcc',
94            description='The compiler used to build the '
95            'ChromeOS image (gcc or llvm).'))
96    self.AddField(
97        TextField(
98            'chrome_src',
99            description='The path to the source of chrome. '
100            'This is used to run telemetry benchmarks. '
101            'The default one is the src inside chroot.',
102            required=False,
103            default=''))
104    self.AddField(
105        TextField(
106            'build',
107            description='The xbuddy specification for an '
108            'official or trybot image to use for tests. '
109            "'/remote' is assumed, and the board is given "
110            "elsewhere, so omit the '/remote/<board>/' xbuddy "
111            'prefix.',
112            required=False,
113            default=''))
114
115
116class GlobalSettings(Settings):
117  """Settings that apply per-experiment."""
118
119  def __init__(self, name):
120    super(GlobalSettings, self).__init__(name, 'global')
121    self.AddField(
122        TextField(
123            'name',
124            description='The name of the experiment. Just an '
125            'identifier.'))
126    self.AddField(
127        TextField(
128            'board',
129            description='The target board for running '
130            'experiments on, e.g. x86-alex.'))
131    self.AddField(
132        ListField(
133            'remote',
134            description='A comma-separated list of IPs of '
135            'chromeos devices to run experiments on.'))
136    self.AddField(
137        BooleanField(
138            'rerun_if_failed',
139            description='Whether to re-run failed test runs '
140            'or not.',
141            default=False))
142    self.AddField(
143        BooleanField(
144            'rm_chroot_tmp',
145            default=False,
146            description='Whether to remove the test_that '
147            'result in the chroot.'))
148    self.AddField(
149        ListField(
150            'email',
151            description='Space-separated list of email '
152            'addresses to send email to.'))
153    self.AddField(
154        BooleanField(
155            'rerun',
156            description='Whether to ignore the cache and '
157            'for tests to be re-run.',
158            default=False))
159    self.AddField(
160        BooleanField(
161            'same_specs',
162            default=True,
163            description='Ensure cached runs are run on the '
164            'same kind of devices which are specified as a '
165            'remote.'))
166    self.AddField(
167        BooleanField(
168            'same_machine',
169            default=False,
170            description='Ensure cached runs are run on the '
171            'same remote.'))
172    self.AddField(
173        BooleanField(
174            'use_file_locks',
175            default=False,
176            description='Whether to use the file locks '
177            'mechanism (deprecated) instead of the AFE '
178            'server lock mechanism.'))
179    self.AddField(
180        IntegerField(
181            'iterations',
182            default=1,
183            description='Number of iterations to run all '
184            'tests.'))
185    self.AddField(
186        TextField(
187            'chromeos_root',
188            description='The path to a chromeos checkout which '
189            'contains a src/scripts directory. Defaults to '
190            'the chromeos checkout which contains the '
191            'chromeos_image.'))
192    self.AddField(
193        TextField(
194            'logging_level',
195            default='average',
196            description='The level of logging desired. '
197            "Options are 'quiet', 'average', and 'verbose'."))
198    self.AddField(
199        IntegerField(
200            'acquire_timeout',
201            default=0,
202            description='Number of seconds to wait for '
203            'machine before exit if all the machines in '
204            'the experiment file are busy. Default is 0.'))
205    self.AddField(
206        TextField(
207            'perf_args',
208            default='',
209            description='The optional profile command. It '
210            'enables perf commands to record perforamance '
211            'related counters. It must start with perf '
212            'command record or stat followed by arguments.'))
213    self.AddField(
214        TextField(
215            'cache_dir',
216            default='',
217            description='The abs path of cache dir. '
218            'Default is /home/$(whoami)/cros_scratch.'))
219    self.AddField(
220        BooleanField(
221            'cache_only',
222            default=False,
223            description='Whether to use only cached '
224            'results (do not rerun failed tests).'))
225    self.AddField(
226        BooleanField(
227            'no_email',
228            default=False,
229            description='Whether to disable the email to '
230            'user after crosperf finishes.'))
231    self.AddField(
232        BooleanField(
233            'json_report',
234            default=False,
235            description='Whether to generate a json version '
236            'of the report, for archiving.'))
237    self.AddField(
238        BooleanField(
239            'show_all_results',
240            default=False,
241            description='When running Telemetry tests, '
242            'whether to all the results, instead of just '
243            'the default (summary) results.'))
244    self.AddField(
245        TextField(
246            'share_cache',
247            default='',
248            description='Path to alternate cache whose data '
249            'you want to use. It accepts multiple directories '
250            'separated by a ",".'))
251    self.AddField(
252        TextField(
253            'results_dir', default='', description='The results dir.'))
254    self.AddField(
255        TextField(
256            'locks_dir',
257            default='',
258            description='An alternate directory to use for '
259            'storing/checking machine locks. Using this field '
260            'automatically sets use_file_locks to True.\n'
261            'WARNING: If you use your own locks directory, '
262            'there is no guarantee that someone else might not '
263            'hold a lock on the same machine in a different '
264            'locks directory.'))
265    self.AddField(
266        TextField(
267            'chrome_src',
268            description='The path to the source of chrome. '
269            'This is used to run telemetry benchmarks. '
270            'The default one is the src inside chroot.',
271            required=False,
272            default=''))
273    self.AddField(
274        IntegerField(
275            'retries',
276            default=0,
277            description='Number of times to retry a '
278            'benchmark run.'))
279
280
281class SettingsFactory(object):
282  """Factory class for building different types of Settings objects.
283
284  This factory is currently hardcoded to produce settings for ChromeOS
285  experiment files. The idea is that in the future, other types
286  of settings could be produced.
287  """
288
289  def GetSettings(self, name, settings_type):
290    if settings_type == 'label' or not settings_type:
291      return LabelSettings(name)
292    if settings_type == 'global':
293      return GlobalSettings(name)
294    if settings_type == 'benchmark':
295      return BenchmarkSettings(name)
296
297    raise TypeError("Invalid settings type: '%s'." % settings_type)
298