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