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