settings_factory.py revision 585192fb87a05d0b2b24cc01d9a05b55c6b5849c
1e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov#!/usr/bin/python 2e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 3e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 4e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov# Use of this source code is governed by a BSD-style license that can be 5e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov# found in the LICENSE file. 6e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 7e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov"""Setting files for global, benchmark and labels.""" 8e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 9e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom field import BooleanField 10e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom field import FloatField 11e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom field import IntegerField 12e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom field import ListField 13e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom field import TextField 14e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovfrom settings import Settings 15e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 16e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 17e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovclass BenchmarkSettings(Settings): 18e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov def __init__(self, name): 19e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov super(BenchmarkSettings, self).__init__(name, "benchmark") 20a3e498a1d189010791f98183c1267d869f0d941bBrian Attwell self.AddField(TextField("test_name", 21e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The name of the test to run." 22e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "Defaults to the name of the benchmark.")) 23e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("test_args", 24e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="Arguments to be passed to the " 25e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng "test.")) 26e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng self.AddField(IntegerField("iterations", default=1, 2784a21cc711742f34f19978b2e02cba5f1743e9a5Wenyi Wang description="Number of iterations to run the " 28e0b2f1e2d01d1ac52ba207dc7ce76971d853298eChiao Cheng "test.")) 29e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("suite", default="", 30e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The type of the benchmark")) 31e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(IntegerField("retries", default=0, 32a3e498a1d189010791f98183c1267d869f0d941bBrian Attwell description="Number of times to retry a " 33e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "benchmark run.")) 34e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(BooleanField("run_local", 35e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="Run benchmark harness on the DUT. " 36267073407439d7df012a2e0df577e39a1f89c4a8Isaac Katzenelson "Currently only compatible with the suite: " 37bea2b8508930630a4665d83bc2e95a4ddf9557ccMarcus Hagerott "telemetry_Crosperf.", 382b995e2c10e23834b224cad8205c30acc88219d9Katherine Kuan required=False, default=True)) 39e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 40e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov 41e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikovclass LabelSettings(Settings): 42e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov def __init__(self, name): 43e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov super(LabelSettings, self).__init__(name, "label") 44e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("chromeos_image", required=False, 45e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The path to the image to run tests " 46e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "on, for local/custom-built images. See 'build' " 47e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "option for official or trybot images.")) 48e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("chromeos_root", 49e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The path to a chromeos checkout which " 50e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "contains a src/scripts directory. Defaults to " 51e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "the chromeos checkout which contains the " 524292dfa46123a6c0e1de9862b4d8694bfb87875aDmitri Plotnikov "chromeos_image.")) 53e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(ListField("remote", description= 54e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "A comma-separated list of ip's of chromeos" 55e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "devices to run experiments on.")) 56e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("image_args", required=False, 57e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov default="", 58e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="Extra arguments to pass to " 59e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "image_chromeos.py.")) 60e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("cache_dir", default="", 61e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The cache dir for this image.")) 62e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("compiler", default="gcc", 63e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The compiler used to build the " 64e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "ChromeOS image (gcc or llvm).")) 65e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov self.AddField(TextField("chrome_src", 66e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov description="The path to the source of chrome. " 67bea2b8508930630a4665d83bc2e95a4ddf9557ccMarcus Hagerott "This is used to run telemetry benchmarks. " 6884a21cc711742f34f19978b2e02cba5f1743e9a5Wenyi Wang "The default one is the src inside chroot.", 697967545e62b473503473b2c9e127cef405f67201Wenyi Wang required=False, default="")) 70bea2b8508930630a4665d83bc2e95a4ddf9557ccMarcus Hagerott self.AddField(TextField("build", 717967545e62b473503473b2c9e127cef405f67201Wenyi Wang description="The xbuddy specification for an " 722b995e2c10e23834b224cad8205c30acc88219d9Katherine Kuan "official or trybot image to use for tests. " 73e898a9fa52728b2ff6fcd3add693471e9e15553dDmitri Plotnikov "'/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