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