blob: a539d3ed9fd4c3f0e4454822414c85ec9062aa4f [file] [log] [blame]
bjanakiraman229d6262013-02-15 04:56:46 +00001#!/usr/bin/python2.6
2#
3# Copyright 2010 Google Inc. All Rights Reserved.
4
5"""Script to run ChromeOS benchmarks
6
7Inputs:
8 chromeos_root
9 toolchain_root
10 board
11 [chromeos/cpu/<benchname>|chromeos/browser/[pagecycler|sunspider]|chromeos/startup]
12 hostname/IP of Chromeos machine
13
14 chromeos/cpu/<benchname>
15 - Read run script rules from bench.mk perflab-bin, copy benchmark to host, run
16 and return results.
17
18 chromeos/startup
19 - Re-image host with image in perflab-bin
20 - Call run_tests to run startup test, gather results.
21 - Restore host back to what it was.
22
23 chromeos/browser/*
24 - Call build_chromebrowser to build image with new browser
25 - Copy image to perflab-bin
26
27"""
28
29__author__ = "bjanakiraman@google.com (Bhaskar Janakiraman)"
30
31import optparse
32import re
33import sys
34from utils import command_executer
35from utils import utils
36
37
38KNOWN_BENCHMARKS = [
39 "chromeos/startup",
40 "chromeos/browser/pagecycler",
41 "chromeos/browser/sunspider",
42 "chromeos/cpu/bikjmp"]
43
44# Run command template
45
46
47# Common initializations
48cmd_executer = command_executer.GetCommandExecuter()
49
50
51def Usage(parser, message):
52 print "ERROR: " + message
53 parser.print_help()
54 sys.exit(0)
55
56
57def RunBrowserBenchmark(bench, workdir, machine):
58 """Run browser benchmarks.
59
60 Args:
61 bench: Name of benchmark (chromeos/browser/*)
62 workdir: Directory containing benchmark directory
63 machine: name of chromeos machine
64 """
65 # TODO(bjanakiraman): Implement function
66 return 0
67
68
69def RunStartupBenchmark(bench, workdir, machine):
70 """Run browser benchmarks.
71
72 Args:
73 bench: Name of benchmark (chromeos/browser/*)
74 workdir: Directory containing benchmark directory
75 machine: name of chromeos machine
76 """
77 # TODO(bjanakiraman): Implement function
78 return 0
79
80
81def RunCpuBenchmark(bench, workdir, machine):
82 """Run CPU benchmark.
83
84 Args:
85 bench: Name of benchmark
86 workdir: directory containing benchmark directory
87 machine: name of chromeos machine
88
89 Returns:
90 status: 0 on success
91 """
92
93 benchname = re.split('/', bench)[2]
94 benchdir = '%s/%s' % (workdir, benchname)
95
96 # Delete any existing run directories on machine.
97 # Since this has exclusive access to the machine,
98 # we do not worry about duplicates.
99 args = 'chronos@%s ' % machine
100 args += 'rm -rf /tmp/%s' % benchname
101 retval = utils.ssh_cmd(args)
102 if retval:
103 return retval
104
105 # Copy benchmark directory.
106 args = ' -r %s ' % benchdir
107 args += 'chronos@%s:/tmp' % machine
108 retval = utils.scp_cmd(args)
109 if retval:
110 return retval
111
112 # Parse bench.mk to extract run flags.
113
114 benchmk_file = open('%s/bench.mk' % benchdir, 'r')
115 for line in benchmk_file:
116 line.rstrip()
117 if re.match('^run_cmd', line):
118 line = re.sub('^run_cmd.*\${PERFLAB_PATH}', '.', line)
119 line = re.sub('\${PERFLAB_INPUT}', './data', line)
120 run_cmd = line
121 break
122
123 # Execute on remote machine
124 # Capture output and process it.
125 sshargs = 'chronos@%s ' % machine
126 sshargs += 'cd /tmp/%s\;' % benchname
127 sshargs += 'time -p %s' % run_cmd
128 print sshargs
129 utils.ssh_cmd(sshargs)
130
131 return retval
132
133
134def Main(argv):
135 """Build ChromeOS."""
136 # Common initializations
137
138 parser = optparse.OptionParser()
139 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
140 help="Target directory for ChromeOS installation.")
141 parser.add_option("-t", "--toolchain_root", dest="toolchain_root",
142 help="The gcctools directory of your P4 checkout.")
143 parser.add_option("-m", "--machine", dest="machine",
144 help="The chromeos host machine.")
145 parser.add_option("--workdir", dest="workdir", default="./perflab-bin",
146 help="Work directory for perflab outputs.")
147 parser.add_option("--board", dest="board",
148 help="ChromeOS target board, e.g. x86-generic")
149
150 (options, args) = parser.parse_args(argv[1:])
151
152 # validate args
153 for arg in args:
154 if arg not in KNOWN_BENCHMARKS:
155 utils.AssertExit(False, "Bad benchmark %s specified" % arg)
156
157
158 if options.chromeos_root is None:
159 Usage(parser, "--chromeos_root must be set")
160
161 if options.toolchain_root is None:
162 Usage(parser, "--toolchain_root must be set")
163
164 if options.board is None:
165 Usage(parser, "--board must be set")
166
167 if options.machine is None:
168 Usage(parser, "--machine must be set")
169
170 found_err = 0
171 retval = 0
172 for arg in args:
173 # CPU benchmarks
174 if re.match('chromeos/cpu', arg):
175 comps = re.split('/', arg)
176 benchname = comps[2]
177 print "RUNNING %s" % benchname
178 retval = RunCpuBenchmark(arg, options.workdir, options.machine)
179 if not found_err:
180 found_err = retval
181 elif re.match('chromeos/startup', arg):
182 print "RUNNING %s" % arg
183 retval = RunStartupBenchmark(arg, options.workdir, options.machine)
184 if not found_err:
185 found_err = retval
186 elif re.match('chromeos/browser', arg):
187 print "RUNNING %s" % arg
188 retval = RunBrowserBenchmark(arg, options.workdir, options.machine)
189 if not found_err:
190 found_err = retval
191
192 return found_err
193
194if __name__ == "__main__":
195 Main(sys.argv)