blob: ed862b82bd9e8b8df5ee138b220ae192dc12f4ef [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
asharif253e88b2013-02-15 05:15:34 +000031import os
bjanakiraman229d6262013-02-15 04:56:46 +000032import re
33import sys
bjanakiraman81a30d02013-02-15 04:57:20 +000034import run_tests
asharif8de2c732013-02-15 05:15:25 +000035import image_chromeos
bjanakiraman229d6262013-02-15 04:56:46 +000036from utils import command_executer
37from utils import utils
asharif8de2c732013-02-15 05:15:25 +000038from utils import logger
bjanakiraman229d6262013-02-15 04:56:46 +000039
40
41KNOWN_BENCHMARKS = [
42 "chromeos/startup",
43 "chromeos/browser/pagecycler",
44 "chromeos/browser/sunspider",
bjanakiramane7a379a2013-02-15 10:24:30 +000045 "chromeos/browser/v8bench",
bjanakiraman229d6262013-02-15 04:56:46 +000046 "chromeos/cpu/bikjmp"]
47
bjanakiraman81a30d02013-02-15 04:57:20 +000048name_map = {
49 "pagecycler" : "Page",
50 "sunspider" : "SunSpider",
bjanakiramane7a379a2013-02-15 10:24:30 +000051 "v8bench" : "V8Bench",
bjanakiraman81a30d02013-02-15 04:57:20 +000052 "startup" : "BootPerfServer"}
53
54
bjanakiraman229d6262013-02-15 04:56:46 +000055# Run command template
56
57
58# Common initializations
59cmd_executer = command_executer.GetCommandExecuter()
60
61
62def Usage(parser, message):
63 print "ERROR: " + message
64 parser.print_help()
65 sys.exit(0)
66
67
bjanakiraman81a30d02013-02-15 04:57:20 +000068def RunBrowserBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000069 """Run browser benchmarks.
70
71 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000072 chromeos_root: ChromeOS src dir
73 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000074 bench: Name of benchmark (chromeos/browser/*)
75 workdir: Directory containing benchmark directory
76 machine: name of chromeos machine
77 """
bjanakiraman81a30d02013-02-15 04:57:20 +000078 benchname = re.split('/', bench)[2]
79 benchdir = '%s/%s' % (workdir, benchname)
80 benchname = name_map[benchname]
81 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
82 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000083
84
bjanakiraman81a30d02013-02-15 04:57:20 +000085def RunStartupBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000086 """Run browser benchmarks.
87
88 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000089 chromeos_root: ChromeOS src dir
90 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000091 bench: Name of benchmark (chromeos/browser/*)
92 workdir: Directory containing benchmark directory
93 machine: name of chromeos machine
94 """
bjanakiraman81a30d02013-02-15 04:57:20 +000095 benchname = 'startup'
96 benchdir = '%s/%s' % (workdir, benchname)
97 benchname = name_map[benchname]
98 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
99 return retval
bjanakiraman229d6262013-02-15 04:56:46 +0000100
101
asharif4d2b7162013-02-15 05:14:57 +0000102def RunCpuBenchmark(chromeos_root, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +0000103 """Run CPU benchmark.
104
105 Args:
106 bench: Name of benchmark
107 workdir: directory containing benchmark directory
108 machine: name of chromeos machine
109
110 Returns:
111 status: 0 on success
112 """
113
114 benchname = re.split('/', bench)[2]
115 benchdir = '%s/%s' % (workdir, benchname)
116
117 # Delete any existing run directories on machine.
118 # Since this has exclusive access to the machine,
119 # we do not worry about duplicates.
asharif4d2b7162013-02-15 05:14:57 +0000120 args = 'rm -rf /tmp/%s' % benchname
121 retval = cmd_executer.CrosRunCommand(args, chromeos_root=chromeos_root,
122 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000123 if retval:
124 return retval
125
126 # Copy benchmark directory.
asharif29775b22013-02-15 05:15:38 +0000127 retval = cmd_executer.CopyFiles(benchdir, "/tmp/" + benchname,
asharif4d2b7162013-02-15 05:14:57 +0000128 chromeos_root=chromeos_root,
129 dest_machine=machine,
130 dest_cros=True)
bjanakiraman229d6262013-02-15 04:56:46 +0000131 if retval:
132 return retval
133
134 # Parse bench.mk to extract run flags.
135
136 benchmk_file = open('%s/bench.mk' % benchdir, 'r')
137 for line in benchmk_file:
138 line.rstrip()
139 if re.match('^run_cmd', line):
bjanakiraman4e8bdf22013-02-15 04:57:09 +0000140 line = re.sub('^run_cmd.*\${PERFLAB_PATH}', './out', line)
bjanakiraman229d6262013-02-15 04:56:46 +0000141 line = re.sub('\${PERFLAB_INPUT}', './data', line)
142 run_cmd = line
143 break
144
145 # Execute on remote machine
146 # Capture output and process it.
asharif4d2b7162013-02-15 05:14:57 +0000147 sshargs = "'cd /tmp/%s;" % benchname
148 sshargs += "time -p %s'" % run_cmd
149 cmd_executer.CrosRunCommand(sshargs, chromeos_root=chromeos_root,
150 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000151
152 return retval
153
154
155def Main(argv):
156 """Build ChromeOS."""
157 # Common initializations
158
159 parser = optparse.OptionParser()
160 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
161 help="Target directory for ChromeOS installation.")
bjanakiraman229d6262013-02-15 04:56:46 +0000162 parser.add_option("-m", "--machine", dest="machine",
163 help="The chromeos host machine.")
164 parser.add_option("--workdir", dest="workdir", default="./perflab-bin",
165 help="Work directory for perflab outputs.")
166 parser.add_option("--board", dest="board",
167 help="ChromeOS target board, e.g. x86-generic")
168
169 (options, args) = parser.parse_args(argv[1:])
170
171 # validate args
172 for arg in args:
173 if arg not in KNOWN_BENCHMARKS:
174 utils.AssertExit(False, "Bad benchmark %s specified" % arg)
175
176
177 if options.chromeos_root is None:
178 Usage(parser, "--chromeos_root must be set")
179
bjanakiraman229d6262013-02-15 04:56:46 +0000180 if options.board is None:
181 Usage(parser, "--board must be set")
182
183 if options.machine is None:
184 Usage(parser, "--machine must be set")
185
186 found_err = 0
187 retval = 0
188 for arg in args:
189 # CPU benchmarks
asharif253e88b2013-02-15 05:15:34 +0000190 comps = re.split('/', arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000191 if re.match('chromeos/cpu', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000192 benchname = comps[2]
bjanakiraman229d6262013-02-15 04:56:46 +0000193 print "RUNNING %s" % benchname
asharif4d2b7162013-02-15 05:14:57 +0000194 retval = RunCpuBenchmark(options.chromeos_root,
195 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000196 if not found_err:
197 found_err = retval
198 elif re.match('chromeos/startup', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000199 benchname = comps[1]
asharif8de2c732013-02-15 05:15:25 +0000200 image_args = [os.path.dirname(os.path.abspath(__file__)) +
201 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000202 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000203 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000204 "--image=" + options.workdir + "/" +
205 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000206 ]
207 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000208 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000209
210 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000211 retval = RunStartupBenchmark(options.chromeos_root,
212 options.board,
213 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000214 if not found_err:
215 found_err = retval
216 elif re.match('chromeos/browser', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000217 benchname = comps[2]
asharif8de2c732013-02-15 05:15:25 +0000218 image_args = [os.path.dirname(os.path.abspath(__file__)) +
219 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000220 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000221 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000222 "--image=" + options.workdir + "/" +
223 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000224 ]
225 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000226 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000227
228 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000229 retval = RunBrowserBenchmark(options.chromeos_root,
230 options.board,
231 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000232 if not found_err:
233 found_err = retval
234
235 return found_err
236
237if __name__ == "__main__":
asharif2198c512013-02-15 09:21:35 +0000238 retval = Main(sys.argv)
239 sys.exit(retval)