settings_factory.py revision ef4ca8a8cfe05ec09447896db42fb220d07834f8
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("chrome_src", 63 description="The path to the source of chrome. " 64 "This is used to run telemetry benchmarks. " 65 "The default one is the src inside chroot.", 66 required=False, default="")) 67 self.AddField(TextField("build", 68 description="The xbuddy specification for an " 69 "official or trybot image to use for tests. " 70 "'/remote' is assumed, and the board is given " 71 "elsewhere, so omit the '/remote/<board>/' xbuddy" 72 "prefix.", 73 required=False, default="")) 74 75 76class GlobalSettings(Settings): 77 def __init__(self, name): 78 super(GlobalSettings, self).__init__(name, "global") 79 self.AddField(TextField("name", 80 description="The name of the experiment. Just an " 81 "identifier.")) 82 self.AddField(TextField("board", description="The target " 83 "board for running experiments on, e.g. x86-alex.")) 84 self.AddField(ListField("remote", 85 description="A comma-separated list of ip's of " 86 "chromeos devices to run experiments on.")) 87 self.AddField(BooleanField("rerun_if_failed", description="Whether to " 88 "re-run failed test runs or not.", 89 default=False)) 90 self.AddField(BooleanField("rm_chroot_tmp", default=False, 91 description="Whether to remove the test_that" 92 "result in the chroot")) 93 self.AddField(ListField("email", description="Space-seperated" 94 "list of email addresses to send email to.")) 95 self.AddField(BooleanField("rerun", description="Whether to ignore the " 96 "cache and for tests to be re-run.", 97 default=False)) 98 self.AddField(BooleanField("same_specs", default=True, 99 description="Ensure cached runs are run on the " 100 "same kind of devices which are specified as a " 101 "remote.")) 102 self.AddField(BooleanField("same_machine", default=False, 103 description="Ensure cached runs are run on the " 104 "exact the same remote")) 105 self.AddField(BooleanField("use_file_locks", default=False, 106 description="Whether to use the file locks " 107 "mechanism (deprecated) instead of the AFE " 108 "server lock mechanism.")) 109 self.AddField(IntegerField("iterations", default=1, 110 description="Number of iterations to run all " 111 "tests.")) 112 self.AddField(TextField("chromeos_root", 113 description="The path to a chromeos checkout which " 114 "contains a src/scripts directory. Defaults to " 115 "the chromeos checkout which contains the " 116 "chromeos_image.")) 117 self.AddField(TextField("logging_level", default="average", 118 description="The level of logging desired. " 119 "Options are 'quiet', 'average', and 'verbose'.")) 120 self.AddField(IntegerField("acquire_timeout", default=0, 121 description="Number of seconds to wait for " 122 "machine before exit if all the machines in " 123 "the experiment file are busy. Default is 0")) 124 self.AddField(TextField("perf_args", default="", 125 description="The optional profile command. It " 126 "enables perf commands to record perforamance " 127 "related counters. It must start with perf " 128 "command record or stat followed by arguments.")) 129 self.AddField(TextField("cache_dir", default="", 130 description="The abs path of cache dir. " 131 "Default is /home/$(whoami)/cros_scratch.")) 132 self.AddField(BooleanField("cache_only", default=False, 133 description="Whether to use only cached " 134 "results (do not rerun failed tests).")) 135 self.AddField(BooleanField("no_email", default=False, 136 description="Whether to disable the email to " 137 "user after crosperf finishes.")) 138 self.AddField(BooleanField("json_report", default=False, 139 description="Whether to generate a json version" 140 " of the report, for archiving.")) 141 self.AddField(BooleanField("show_all_results", default=False, 142 description="When running Telemetry tests, " 143 "whether to all the results, instead of just " 144 "the default (summary) results.")) 145 self.AddField(TextField("share_cache", default="", 146 description="Path to alternate cache whose data " 147 "you want to use. It accepts multiples directories" 148 " separated by a \",\"")) 149 self.AddField(TextField("results_dir", default="", 150 description="The results dir")) 151 self.AddField(TextField("locks_dir", default="", 152 description="An alternate directory to use for " 153 "storing/checking machine locks. Using this field " 154 "automatically sets use_file_locks to True.\n" 155 "WARNING: If you use your own locks directory, " 156 "there is no guarantee that someone else might not " 157 "hold a lock on the same machine in a different " 158 "locks directory.")) 159 self.AddField(TextField("chrome_src", 160 description="The path to the source of chrome. " 161 "This is used to run telemetry benchmarks. " 162 "The default one is the src inside chroot.", 163 required=False, default="")) 164 self.AddField(IntegerField("retries", default=0, 165 description="Number of times to retry a " 166 "benchmark run.")) 167 168class SettingsFactory(object): 169 """Factory class for building different types of Settings objects. 170 171 This factory is currently hardcoded to produce settings for ChromeOS 172 experiment files. The idea is that in the future, other types 173 of settings could be produced. 174 """ 175 176 def GetSettings(self, name, settings_type): 177 if settings_type == "label" or not settings_type: 178 return LabelSettings(name) 179 if settings_type == "global": 180 return GlobalSettings(name) 181 if settings_type == "benchmark": 182 return BenchmarkSettings(name) 183 184 raise Exception("Invalid settings type: '%s'." % settings_type) 185