blob: 810e8a2f8a352e882cdb16b99ebf1d549f097612 [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",
45 "chromeos/cpu/bikjmp"]
46
bjanakiraman81a30d02013-02-15 04:57:20 +000047name_map = {
48 "pagecycler" : "Page",
49 "sunspider" : "SunSpider",
50 "startup" : "BootPerfServer"}
51
52
bjanakiraman229d6262013-02-15 04:56:46 +000053# Run command template
54
55
56# Common initializations
57cmd_executer = command_executer.GetCommandExecuter()
58
59
60def Usage(parser, message):
61 print "ERROR: " + message
62 parser.print_help()
63 sys.exit(0)
64
65
bjanakiraman81a30d02013-02-15 04:57:20 +000066def RunBrowserBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000067 """Run browser benchmarks.
68
69 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000070 chromeos_root: ChromeOS src dir
71 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000072 bench: Name of benchmark (chromeos/browser/*)
73 workdir: Directory containing benchmark directory
74 machine: name of chromeos machine
75 """
bjanakiraman81a30d02013-02-15 04:57:20 +000076 benchname = re.split('/', bench)[2]
77 benchdir = '%s/%s' % (workdir, benchname)
78 benchname = name_map[benchname]
79 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
80 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000081
82
bjanakiraman81a30d02013-02-15 04:57:20 +000083def RunStartupBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000084 """Run browser benchmarks.
85
86 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000087 chromeos_root: ChromeOS src dir
88 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000089 bench: Name of benchmark (chromeos/browser/*)
90 workdir: Directory containing benchmark directory
91 machine: name of chromeos machine
92 """
bjanakiraman81a30d02013-02-15 04:57:20 +000093 benchname = 'startup'
94 benchdir = '%s/%s' % (workdir, benchname)
95 benchname = name_map[benchname]
96 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
97 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000098
99
asharif4d2b7162013-02-15 05:14:57 +0000100def RunCpuBenchmark(chromeos_root, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +0000101 """Run CPU benchmark.
102
103 Args:
104 bench: Name of benchmark
105 workdir: directory containing benchmark directory
106 machine: name of chromeos machine
107
108 Returns:
109 status: 0 on success
110 """
111
112 benchname = re.split('/', bench)[2]
113 benchdir = '%s/%s' % (workdir, benchname)
114
115 # Delete any existing run directories on machine.
116 # Since this has exclusive access to the machine,
117 # we do not worry about duplicates.
asharif4d2b7162013-02-15 05:14:57 +0000118 args = 'rm -rf /tmp/%s' % benchname
119 retval = cmd_executer.CrosRunCommand(args, chromeos_root=chromeos_root,
120 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000121 if retval:
122 return retval
123
124 # Copy benchmark directory.
asharif29775b22013-02-15 05:15:38 +0000125 retval = cmd_executer.CopyFiles(benchdir, "/tmp/" + benchname,
asharif4d2b7162013-02-15 05:14:57 +0000126 chromeos_root=chromeos_root,
127 dest_machine=machine,
128 dest_cros=True)
bjanakiraman229d6262013-02-15 04:56:46 +0000129 if retval:
130 return retval
131
132 # Parse bench.mk to extract run flags.
133
134 benchmk_file = open('%s/bench.mk' % benchdir, 'r')
135 for line in benchmk_file:
136 line.rstrip()
137 if re.match('^run_cmd', line):
bjanakiraman4e8bdf22013-02-15 04:57:09 +0000138 line = re.sub('^run_cmd.*\${PERFLAB_PATH}', './out', line)
bjanakiraman229d6262013-02-15 04:56:46 +0000139 line = re.sub('\${PERFLAB_INPUT}', './data', line)
140 run_cmd = line
141 break
142
143 # Execute on remote machine
144 # Capture output and process it.
asharif4d2b7162013-02-15 05:14:57 +0000145 sshargs = "'cd /tmp/%s;" % benchname
146 sshargs += "time -p %s'" % run_cmd
147 cmd_executer.CrosRunCommand(sshargs, chromeos_root=chromeos_root,
148 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000149
150 return retval
151
152
153def Main(argv):
154 """Build ChromeOS."""
155 # Common initializations
156
157 parser = optparse.OptionParser()
158 parser.add_option("-c", "--chromeos_root", dest="chromeos_root",
159 help="Target directory for ChromeOS installation.")
bjanakiraman229d6262013-02-15 04:56:46 +0000160 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
bjanakiraman229d6262013-02-15 04:56:46 +0000178 if options.board is None:
179 Usage(parser, "--board must be set")
180
181 if options.machine is None:
182 Usage(parser, "--machine must be set")
183
184 found_err = 0
185 retval = 0
186 for arg in args:
187 # CPU benchmarks
asharif253e88b2013-02-15 05:15:34 +0000188 comps = re.split('/', arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000189 if re.match('chromeos/cpu', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000190 benchname = comps[2]
bjanakiraman229d6262013-02-15 04:56:46 +0000191 print "RUNNING %s" % benchname
asharif4d2b7162013-02-15 05:14:57 +0000192 retval = RunCpuBenchmark(options.chromeos_root,
193 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000194 if not found_err:
195 found_err = retval
196 elif re.match('chromeos/startup', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000197 benchname = comps[1]
asharif8de2c732013-02-15 05:15:25 +0000198 image_args = [os.path.dirname(os.path.abspath(__file__)) +
199 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000200 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000201 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000202 "--image=" + options.workdir + "/" +
203 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000204 ]
205 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif0e0e2682013-02-15 05:15:29 +0000206 image_chromeos.ImageChromeOS(image_args)
asharif8de2c732013-02-15 05:15:25 +0000207
208 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000209 retval = RunStartupBenchmark(options.chromeos_root,
210 options.board,
211 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000212 if not found_err:
213 found_err = retval
214 elif re.match('chromeos/browser', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000215 benchname = comps[2]
asharif8de2c732013-02-15 05:15:25 +0000216 image_args = [os.path.dirname(os.path.abspath(__file__)) +
217 "/image_chromeos.py",
asharif253e88b2013-02-15 05:15:34 +0000218 "--chromeos_root=" + options.chromeos_root,
asharif8de2c732013-02-15 05:15:25 +0000219 "--remote=" + options.machine,
asharif253e88b2013-02-15 05:15:34 +0000220 "--image=" + options.workdir + "/" +
221 benchname + "/chromiumos_image.bin"
asharif8de2c732013-02-15 05:15:25 +0000222 ]
223 logger.GetLogger().LogOutput("Reimaging machine %s" % options.machine)
asharif0e0e2682013-02-15 05:15:29 +0000224 image_chromeos.ImageChromeOS(image_args)
asharif8de2c732013-02-15 05:15:25 +0000225
226 logger.GetLogger().LogOutput("Running %s" % arg)
bjanakiraman81a30d02013-02-15 04:57:20 +0000227 retval = RunBrowserBenchmark(options.chromeos_root,
228 options.board,
229 arg, options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000230 if not found_err:
231 found_err = retval
232
233 return found_err
234
235if __name__ == "__main__":
236 Main(sys.argv)