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