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