blob: cee9abc8e657663e05bd28d4ad8dd281bfe90ae5 [file] [log] [blame]
Mike Frysingerc7f15932013-03-20 13:43:35 -04001#!/usr/bin/python
bjanakiraman229d6262013-02-15 04:56:46 +00002#
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
kbaclawski20082a02013-02-16 02:12:57 +000034
asharif8de2c732013-02-15 05:15:25 +000035import image_chromeos
kbaclawski20082a02013-02-16 02:12:57 +000036import run_tests
bjanakiraman229d6262013-02-15 04:56:46 +000037from utils import command_executer
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:
kbaclawski6999ada2013-02-15 19:57:09 +0000174 logger.GetLogger().LogFatal("Bad benchmark %s specified" % arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000175
176 if options.chromeos_root is None:
177 Usage(parser, "--chromeos_root must be set")
178
bjanakiraman229d6262013-02-15 04:56:46 +0000179 if options.board is None:
180 Usage(parser, "--board must be set")
181
182 if options.machine is None:
183 Usage(parser, "--machine must be set")
184
185 found_err = 0
186 retval = 0
187 for arg in args:
188 # CPU benchmarks
asharif253e88b2013-02-15 05:15:34 +0000189 comps = re.split('/', arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000190 if re.match('chromeos/cpu', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000191 benchname = comps[2]
bjanakiraman229d6262013-02-15 04:56:46 +0000192 print "RUNNING %s" % benchname
asharif4d2b7162013-02-15 05:14:57 +0000193 retval = RunCpuBenchmark(options.chromeos_root,
194 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000195 if not found_err:
196 found_err = retval
197 elif re.match('chromeos/startup', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000198 benchname = comps[1]
asharif8de2c732013-02-15 05:15:25 +0000199 image_args = [os.path.dirname(os.path.abspath(__file__)) +
200 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000201 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000202 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000203 "--image=" + options.workdir + "/" +
204 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000205 ]
206 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000207 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000208
209 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000210 retval = RunStartupBenchmark(options.chromeos_root,
211 options.board,
212 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000213 if not found_err:
214 found_err = retval
215 elif re.match('chromeos/browser', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000216 benchname = comps[2]
asharif8de2c732013-02-15 05:15:25 +0000217 image_args = [os.path.dirname(os.path.abspath(__file__)) +
218 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000219 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000220 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000221 "--image=" + options.workdir + "/" +
222 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000223 ]
224 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000225 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000226
227 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000228 retval = RunBrowserBenchmark(options.chromeos_root,
229 options.board,
230 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000231 if not found_err:
232 found_err = retval
233
234 return found_err
235
236if __name__ == "__main__":
asharif2198c512013-02-15 09:21:35 +0000237 retval = Main(sys.argv)
238 sys.exit(retval)