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