blob: 75ef48c537147b2bcd8bedfc1b7822261e2326d6 [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.
bjanakiraman229d6262013-02-15 04:56:46 +00004"""Script to run ChromeOS benchmarks
5
6Inputs:
7 chromeos_root
bjanakiraman229d6262013-02-15 04:56:46 +00008 board
9 [chromeos/cpu/<benchname>|chromeos/browser/[pagecycler|sunspider]|chromeos/startup]
10 hostname/IP of Chromeos machine
11
12 chromeos/cpu/<benchname>
Luis Lozanof2a3ef42015-12-15 13:49:30 -080013 - Read run script rules from bench.mk perflab-bin, copy benchmark to
14 host, run
bjanakiraman229d6262013-02-15 04:56:46 +000015 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
Luis Lozanof2a3ef42015-12-15 13:49:30 -080028__author__ = 'bjanakiraman@google.com (Bhaskar Janakiraman)'
bjanakiraman229d6262013-02-15 04:56:46 +000029
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
bjanakiraman229d6262013-02-15 04:56:46 +000040KNOWN_BENCHMARKS = [
Luis Lozanof2a3ef42015-12-15 13:49:30 -080041 'chromeos/startup', 'chromeos/browser/pagecycler',
42 'chromeos/browser/sunspider', 'chromeos/browser/v8bench',
43 'chromeos/cpu/bikjmp'
44]
bjanakiraman229d6262013-02-15 04:56:46 +000045
bjanakiraman81a30d02013-02-15 04:57:20 +000046name_map = {
Luis Lozanof2a3ef42015-12-15 13:49:30 -080047 'pagecycler': 'Page',
48 'sunspider': 'SunSpider',
49 'v8bench': 'V8Bench',
50 'startup': 'BootPerfServer'
51}
bjanakiraman81a30d02013-02-15 04:57:20 +000052
bjanakiraman229d6262013-02-15 04:56:46 +000053# Run command template
54
bjanakiraman229d6262013-02-15 04:56:46 +000055# Common initializations
56cmd_executer = command_executer.GetCommandExecuter()
57
58
59def Usage(parser, message):
Luis Lozanof2a3ef42015-12-15 13:49:30 -080060 print 'ERROR: ' + message
bjanakiraman229d6262013-02-15 04:56:46 +000061 parser.print_help()
62 sys.exit(0)
63
64
bjanakiraman81a30d02013-02-15 04:57:20 +000065def RunBrowserBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000066 """Run browser benchmarks.
67
68 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000069 chromeos_root: ChromeOS src dir
70 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000071 bench: Name of benchmark (chromeos/browser/*)
72 workdir: Directory containing benchmark directory
73 machine: name of chromeos machine
74 """
bjanakiraman81a30d02013-02-15 04:57:20 +000075 benchname = re.split('/', bench)[2]
76 benchdir = '%s/%s' % (workdir, benchname)
77 benchname = name_map[benchname]
78 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
79 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000080
81
bjanakiraman81a30d02013-02-15 04:57:20 +000082def RunStartupBenchmark(chromeos_root, board, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +000083 """Run browser benchmarks.
84
85 Args:
bjanakiraman81a30d02013-02-15 04:57:20 +000086 chromeos_root: ChromeOS src dir
87 board: Board being tested
bjanakiraman229d6262013-02-15 04:56:46 +000088 bench: Name of benchmark (chromeos/browser/*)
89 workdir: Directory containing benchmark directory
90 machine: name of chromeos machine
91 """
bjanakiraman81a30d02013-02-15 04:57:20 +000092 benchname = 'startup'
93 benchdir = '%s/%s' % (workdir, benchname)
94 benchname = name_map[benchname]
95 retval = run_tests.RunRemoteTests(chromeos_root, machine, board, benchname)
96 return retval
bjanakiraman229d6262013-02-15 04:56:46 +000097
98
asharif4d2b7162013-02-15 05:14:57 +000099def RunCpuBenchmark(chromeos_root, bench, workdir, machine):
bjanakiraman229d6262013-02-15 04:56:46 +0000100 """Run CPU benchmark.
101
102 Args:
103 bench: Name of benchmark
104 workdir: directory containing benchmark directory
105 machine: name of chromeos machine
106
107 Returns:
108 status: 0 on success
109 """
110
111 benchname = re.split('/', bench)[2]
112 benchdir = '%s/%s' % (workdir, benchname)
113
114 # Delete any existing run directories on machine.
115 # Since this has exclusive access to the machine,
116 # we do not worry about duplicates.
asharif4d2b7162013-02-15 05:14:57 +0000117 args = 'rm -rf /tmp/%s' % benchname
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800118 retval = cmd_executer.CrosRunCommand(args,
119 chromeos_root=chromeos_root,
asharif4d2b7162013-02-15 05:14:57 +0000120 machine=machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000121 if retval:
122 return retval
123
124 # Copy benchmark directory.
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800125 retval = cmd_executer.CopyFiles(benchdir,
126 '/tmp/' + benchname,
127 chromeos_root=chromeos_root,
128 dest_machine=machine,
129 dest_cros=True)
bjanakiraman229d6262013-02-15 04:56:46 +0000130 if retval:
131 return retval
132
133 # Parse bench.mk to extract run flags.
134
135 benchmk_file = open('%s/bench.mk' % benchdir, 'r')
136 for line in benchmk_file:
137 line.rstrip()
138 if re.match('^run_cmd', line):
bjanakiraman4e8bdf22013-02-15 04:57:09 +0000139 line = re.sub('^run_cmd.*\${PERFLAB_PATH}', './out', line)
bjanakiraman229d6262013-02-15 04:56:46 +0000140 line = re.sub('\${PERFLAB_INPUT}', './data', line)
141 run_cmd = line
142 break
143
144 # Execute on remote machine
145 # Capture output and process it.
asharif4d2b7162013-02-15 05:14:57 +0000146 sshargs = "'cd /tmp/%s;" % benchname
147 sshargs += "time -p %s'" % run_cmd
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800148 cmd_executer.CrosRunCommand(sshargs,
149 chromeos_root=chromeos_root,
asharif4d2b7162013-02-15 05:14:57 +0000150 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()
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800160 parser.add_option('-c',
161 '--chromeos_root',
162 dest='chromeos_root',
163 help='Target directory for ChromeOS installation.')
164 parser.add_option('-m',
165 '--machine',
166 dest='machine',
167 help='The chromeos host machine.')
168 parser.add_option('--workdir',
169 dest='workdir',
170 default='./perflab-bin',
171 help='Work directory for perflab outputs.')
172 parser.add_option('--board',
173 dest='board',
174 help='ChromeOS target board, e.g. x86-generic')
bjanakiraman229d6262013-02-15 04:56:46 +0000175
176 (options, args) = parser.parse_args(argv[1:])
177
178 # validate args
179 for arg in args:
180 if arg not in KNOWN_BENCHMARKS:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800181 logger.GetLogger().LogFatal('Bad benchmark %s specified' % arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000182
183 if options.chromeos_root is None:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800184 Usage(parser, '--chromeos_root must be set')
bjanakiraman229d6262013-02-15 04:56:46 +0000185
bjanakiraman229d6262013-02-15 04:56:46 +0000186 if options.board is None:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800187 Usage(parser, '--board must be set')
bjanakiraman229d6262013-02-15 04:56:46 +0000188
189 if options.machine is None:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800190 Usage(parser, '--machine must be set')
bjanakiraman229d6262013-02-15 04:56:46 +0000191
192 found_err = 0
193 retval = 0
194 for arg in args:
195 # CPU benchmarks
asharif253e88b2013-02-15 05:15:34 +0000196 comps = re.split('/', arg)
bjanakiraman229d6262013-02-15 04:56:46 +0000197 if re.match('chromeos/cpu', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000198 benchname = comps[2]
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800199 print 'RUNNING %s' % benchname
200 retval = RunCpuBenchmark(options.chromeos_root, arg, options.workdir,
201 options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000202 if not found_err:
203 found_err = retval
204 elif re.match('chromeos/startup', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000205 benchname = comps[1]
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800206 image_args = [
207 os.path.dirname(os.path.abspath(__file__)) + '/image_chromeos.py',
208 '--chromeos_root=' + options.chromeos_root,
209 '--remote=' + options.machine, '--image=' + options.workdir + '/' +
210 benchname + '/chromiumos_image.bin'
211 ]
212 logger.GetLogger().LogOutput('Reimaging machine %s' % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000213 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000214
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800215 logger.GetLogger().LogOutput('Running %s' % arg)
216 retval = RunStartupBenchmark(options.chromeos_root, options.board, arg,
217 options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000218 if not found_err:
219 found_err = retval
220 elif re.match('chromeos/browser', arg):
bjanakiraman1c19a7f2013-02-15 06:31:19 +0000221 benchname = comps[2]
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800222 image_args = [
223 os.path.dirname(os.path.abspath(__file__)) + '/image_chromeos.py',
224 '--chromeos_root=' + options.chromeos_root,
225 '--remote=' + options.machine, '--image=' + options.workdir + '/' +
226 benchname + '/chromiumos_image.bin'
227 ]
228 logger.GetLogger().LogOutput('Reimaging machine %s' % options.machine)
asharif8697d4e2013-02-15 09:18:09 +0000229 image_chromeos.Main(image_args)
asharif8de2c732013-02-15 05:15:25 +0000230
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800231 logger.GetLogger().LogOutput('Running %s' % arg)
232 retval = RunBrowserBenchmark(options.chromeos_root, options.board, arg,
233 options.workdir, options.machine)
bjanakiraman229d6262013-02-15 04:56:46 +0000234 if not found_err:
235 found_err = retval
236
237 return found_err
238
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800239
240if __name__ == '__main__':
asharif2198c512013-02-15 09:21:35 +0000241 retval = Main(sys.argv)
242 sys.exit(retval)