blob: 11fe78f1a7b8c06c7f9076f28c920fc1eae9a2af [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
bjanakiraman229d6262013-02-15 04:56:46 +00009 board
10 [chromeos/cpu/<benchname>|chromeos/browser/[pagecycler|sunspider]|chromeos/startup]
11 hostname/IP of Chromeos machine
12
13 chromeos/cpu/<benchname>
14 - Read run script rules from bench.mk perflab-bin, copy benchmark to host, run
15 and return results.
16
17 chromeos/startup
18 - Re-image host with image in perflab-bin
19 - Call run_tests to run startup test, gather results.
20 - Restore host back to what it was.
21
22 chromeos/browser/*
23 - Call build_chromebrowser to build image with new browser
24 - Copy image to perflab-bin
25
26"""
27
28__author__ = "bjanakiraman@google.com (Bhaskar Janakiraman)"
29
30import optparse
31import re
32import sys
bjanakiraman81a30d02013-02-15 04:57:20 +000033import run_tests
bjanakiraman229d6262013-02-15 04:56:46 +000034from 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
bjanakiraman81a30d02013-02-15 04:57:20 +000044name_map = {
45 "pagecycler" : "Page",
46 "sunspider" : "SunSpider",
47 "startup" : "BootPerfServer"}
48
49
bjanakiraman229d6262013-02-15 04:56:46 +000050# Run command template
51
52
53# Common initializations
54cmd_executer = command_executer.GetCommandExecuter()
55
56
57def Usage(parser, message):
58 print "ERROR: " + message
59 parser.print_help()
60 sys.exit(0)
61
62
bjanakiraman81a30d02013-02-15 04:57:20 +000063def RunBrowserBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000064 """Run browser benchmarks.
65
66 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000067 chromeos_root: ChromeOS src dir
68 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000069 bench: Name of benchmark (chromeos/browser/*)
70 workdir: Directory containing benchmark directory
71 machine: name of chromeos machine
72 """
bjanakiraman81a30d02013-02-15 04:57:20 +000073 benchname = re.split('/', bench)[2]
74 benchdir = '%s/%s' % (workdir, benchname)
75 benchname = name_map[benchname]
76 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
77 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000078
79
bjanakiraman81a30d02013-02-15 04:57:20 +000080def RunStartupBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000081 """Run browser benchmarks.
82
83 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000084 chromeos_root: ChromeOS src dir
85 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000086 bench: Name of benchmark (chromeos/browser/*)
87 workdir: Directory containing benchmark directory
88 machine: name of chromeos machine
89 """
bjanakiraman81a30d02013-02-15 04:57:20 +000090 benchname = 'startup'
91 benchdir = '%s/%s' % (workdir, benchname)
92 benchname = name_map[benchname]
93 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
94 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000095
96
asharif4d2b7162013-02-15 05:14:57 +000097def RunCpuBenchmark(chromeos_root, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000098 """Run CPU benchmark.
99
100 Args:
101 bench: Name of benchmark
102 workdir: directory containing benchmark directory
103 machine: name of chromeos machine
104
105 Returns:
106 status: 0 on success
107 """
108
109 benchname = re.split('/', bench)[2]
110 benchdir = '%s/%s' % (workdir, benchname)
111
112 # Delete any existing run directories on machine.
113 # Since this has exclusive access to the machine,
114 # we do not worry about duplicates.
asharif4d2b7162013-02-15 05:14:57 +0000115 args = 'rm -rf /tmp/%s' % benchname
116 retval = cmd_executer.CrosRunCommand(args, chromeos_root=chromeos_root,
117 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000118 if retval:
119 return retval
120
121 # Copy benchmark directory.
asharif4d2b7162013-02-15 05:14:57 +0000122 retval = cmd_executer.CopyFiles(benchdir, "/tmp",
123 chromeos_root=chromeos_root,
124 dest_machine=machine,
125 dest_cros=True)
bjanakiraman229d6262013-02-15 04:56:46 +0000126 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.
asharif4d2b7162013-02-15 05:14:57 +0000142 sshargs = "'cd /tmp/%s;" % benchname
143 sshargs += "time -p %s'" % run_cmd
144 cmd_executer.CrosRunCommand(sshargs, chromeos_root=chromeos_root,
145 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000146
147 return retval
148
149
150def Main(argv):
151 """Build ChromeOS."""
152 # Common initializations
153
154 parser = optparse.OptionParser()
155 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
156 help="Target directory for ChromeOS installation.")
bjanakiraman229d6262013-02-15 04:56:46 +0000157 parser.add_option("-m", "--machine", dest="machine",
158 help="The chromeos host machine.")
159 parser.add_option("--workdir", dest="workdir", default="./perflab-bin",
160 help="Work directory for perflab outputs.")
161 parser.add_option("--board", dest="board",
162 help="ChromeOS target board, e.g. x86-generic")
163
164 (options, args) = parser.parse_args(argv[1:])
165
166 # validate args
167 for arg in args:
168 if arg not in KNOWN_BENCHMARKS:
169 utils.AssertExit(False, "Bad benchmark %s specified" % arg)
170
171
172 if options.chromeos_root is None:
173 Usage(parser, "--chromeos_root must be set")
174
bjanakiraman229d6262013-02-15 04:56:46 +0000175 if options.board is None:
176 Usage(parser, "--board must be set")
177
178 if options.machine is None:
179 Usage(parser, "--machine must be set")
180
181 found_err = 0
182 retval = 0
183 for arg in args:
184 # CPU benchmarks
185 if re.match('chromeos/cpu', arg):
186 comps = re.split('/', arg)
187 benchname = comps[2]
188 print "RUNNING %s" % benchname
asharif4d2b7162013-02-15 05:14:57 +0000189 retval = RunCpuBenchmark(options.chromeos_root,
190 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000191 if not found_err:
192 found_err = retval
193 elif re.match('chromeos/startup', arg):
194 print "RUNNING %s" % arg
bjanakiraman81a30d02013-02-15 04:57:20 +0000195 retval = RunStartupBenchmark(options.chromeos_root,
196 options.board,
197 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000198 if not found_err:
199 found_err = retval
200 elif re.match('chromeos/browser', arg):
201 print "RUNNING %s" % arg
bjanakiraman81a30d02013-02-15 04:57:20 +0000202 retval = RunBrowserBenchmark(options.chromeos_root,
203 options.board,
204 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000205 if not found_err:
206 found_err = retval
207
208 return found_err
209
210if __name__ == "__main__":
211 Main(sys.argv)