blob: 5918f02f8788df4fa8ed7c4651d57359634f26ae [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
bjanakiraman81a30d02013-02-15 04:57:20 +000034import run_tests
bjanakiraman229d6262013-02-15 04:56:46 +000035from utils import command_executer
36from utils import utils
37
38
39KNOWN_BENCHMARKS = [
40 "chromeos/startup",
41 "chromeos/browser/pagecycler",
42 "chromeos/browser/sunspider",
43 "chromeos/cpu/bikjmp"]
44
bjanakiraman81a30d02013-02-15 04:57:20 +000045name_map = {
46 "pagecycler" : "Page",
47 "sunspider" : "SunSpider",
48 "startup" : "BootPerfServer"}
49
50
bjanakiraman229d6262013-02-15 04:56:46 +000051# Run command template
52
53
54# Common initializations
55cmd_executer = command_executer.GetCommandExecuter()
56
57
58def Usage(parser, message):
59 print "ERROR: " + message
60 parser.print_help()
61 sys.exit(0)
62
63
bjanakiraman81a30d02013-02-15 04:57:20 +000064def RunBrowserBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000065 """Run browser benchmarks.
66
67 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000068 chromeos_root: ChromeOS src dir
69 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000070 bench: Name of benchmark (chromeos/browser/*)
71 workdir: Directory containing benchmark directory
72 machine: name of chromeos machine
73 """
bjanakiraman81a30d02013-02-15 04:57:20 +000074 benchname = re.split('/', bench)[2]
75 benchdir = '%s/%s' % (workdir, benchname)
76 benchname = name_map[benchname]
77 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
78 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000079
80
bjanakiraman81a30d02013-02-15 04:57:20 +000081def RunStartupBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000082 """Run browser benchmarks.
83
84 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000085 chromeos_root: ChromeOS src dir
86 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000087 bench: Name of benchmark (chromeos/browser/*)
88 workdir: Directory containing benchmark directory
89 machine: name of chromeos machine
90 """
bjanakiraman81a30d02013-02-15 04:57:20 +000091 benchname = 'startup'
92 benchdir = '%s/%s' % (workdir, benchname)
93 benchname = name_map[benchname]
94 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
95 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000096
97
98def RunCpuBenchmark(bench, workdir, machine):
99 """Run CPU benchmark.
100
101 Args:
102 bench: Name of benchmark
103 workdir: directory containing benchmark directory
104 machine: name of chromeos machine
105
106 Returns:
107 status: 0 on success
108 """
109
110 benchname = re.split('/', bench)[2]
111 benchdir = '%s/%s' % (workdir, benchname)
112
113 # Delete any existing run directories on machine.
114 # Since this has exclusive access to the machine,
115 # we do not worry about duplicates.
116 args = 'chronos@%s ' % machine
117 args += 'rm -rf /tmp/%s' % benchname
118 retval = utils.ssh_cmd(args)
119 if retval:
120 return retval
121
122 # Copy benchmark directory.
123 args = ' -r %s ' % benchdir
124 args += 'chronos@%s:/tmp' % machine
125 retval = utils.scp_cmd(args)
126 if retval:
127 return retval
128
129 # Parse bench.mk to extract run flags.
130
131 benchmk_file = open('%s/bench.mk' % benchdir, 'r')
132 for line in benchmk_file:
133 line.rstrip()
134 if re.match('^run_cmd', line):
bjanakiraman4e8bdf22013-02-15 04:57:09 +0000135 line = re.sub('^run_cmd.*\${PERFLAB_PATH}', './out', line)
bjanakiraman229d6262013-02-15 04:56:46 +0000136 line = re.sub('\${PERFLAB_INPUT}', './data', line)
137 run_cmd = line
138 break
139
140 # Execute on remote machine
141 # Capture output and process it.
142 sshargs = 'chronos@%s ' % machine
143 sshargs += 'cd /tmp/%s\;' % benchname
144 sshargs += 'time -p %s' % run_cmd
145 print sshargs
146 utils.ssh_cmd(sshargs)
147
148 return retval
149
150
151def Main(argv):
152 """Build ChromeOS."""
153 # Common initializations
154
155 parser = optparse.OptionParser()
156 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
157 help="Target directory for ChromeOS installation.")
158 parser.add_option("-t", "--toolchain_root", dest="toolchain_root",
159 help="The gcctools directory of your P4 checkout.")
160 parser.add_option("-m", "--machine", dest="machine",
161 help="The chromeos host machine.")
162 parser.add_option("--workdir", dest="workdir", default="./perflab-bin",
163 help="Work directory for perflab outputs.")
164 parser.add_option("--board", dest="board",
165 help="ChromeOS target board, e.g. x86-generic")
166
167 (options, args) = parser.parse_args(argv[1:])
168
169 # validate args
170 for arg in args:
171 if arg not in KNOWN_BENCHMARKS:
172 utils.AssertExit(False, "Bad benchmark %s specified" % arg)
173
174
175 if options.chromeos_root is None:
176 Usage(parser, "--chromeos_root must be set")
177
178 if options.toolchain_root is None:
179 Usage(parser, "--toolchain_root must be set")
180
181 if options.board is None:
182 Usage(parser, "--board must be set")
183
184 if options.machine is None:
185 Usage(parser, "--machine must be set")
186
187 found_err = 0
188 retval = 0
189 for arg in args:
190 # CPU benchmarks
191 if re.match('chromeos/cpu', arg):
192 comps = re.split('/', arg)
193 benchname = comps[2]
194 print "RUNNING %s" % benchname
195 retval = RunCpuBenchmark(arg, options.workdir, options.machine)
196 if not found_err:
197 found_err = retval
198 elif re.match('chromeos/startup', arg):
199 print "RUNNING %s" % arg
bjanakiraman81a30d02013-02-15 04:57:20 +0000200 retval = RunStartupBenchmark(options.chromeos_root,
201 options.board,
202 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000203 if not found_err:
204 found_err = retval
205 elif re.match('chromeos/browser', arg):
206 print "RUNNING %s" % arg
bjanakiraman81a30d02013-02-15 04:57:20 +0000207 retval = RunBrowserBenchmark(options.chromeos_root,
208 options.board,
209 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000210 if not found_err:
211 found_err = retval
212
213 return found_err
214
215if __name__ == "__main__":
216 Main(sys.argv)