comparison mx/commands.py @ 4215:a2caa019ba3a

Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments. Fix mx : call the mx_post_parse_cmd_line hook from commands' scripts OutputParser : cosmetic changes to logged output, return the retcode along yith the parsed output Add a new Test class representing a sanity check and/or a benchmark Port dacapo command to use this class, begning work on benchmarks
author Gilles Duboscq <gilles.m.duboscq@gmail.com>
date Wed, 04 Jan 2012 13:52:46 +0100
parents ac5c2bdfcca2
children a13d61d3910e
comparison
equal deleted inserted replaced
4213:e4cfa571d8c4 4215:a2caa019ba3a
25 # questions. 25 # questions.
26 # 26 #
27 # ---------------------------------------------------------------------------------------------------- 27 # ----------------------------------------------------------------------------------------------------
28 28
29 import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime, platform, subprocess 29 import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime, platform, subprocess
30 from os.path import join, exists, dirname, isdir, isfile, isabs, basename 30 from os.path import join, exists, dirname, isdir, isabs, basename
31 from argparse import ArgumentParser, REMAINDER 31 from argparse import ArgumentParser, REMAINDER
32 import mx 32 import mx
33 import sanitycheck
33 34
34 _graal_home = dirname(dirname(__file__)) 35 _graal_home = dirname(dirname(__file__))
35 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) 36 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src'))
36 _vmbuild = 'product' 37 _vmbuild = 'product'
37 _winSDK = 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\' 38 _winSDK = 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\'
138 """run one or all DaCapo benchmarks 139 """run one or all DaCapo benchmarks
139 140
140 DaCapo options are distinguised from VM options by a '@' prefix. 141 DaCapo options are distinguised from VM options by a '@' prefix.
141 For example, '@--iterations @5' will pass '--iterations 5' to the 142 For example, '@--iterations @5' will pass '--iterations 5' to the
142 DaCapo harness.""" 143 DaCapo harness."""
143 144
144 benchmarks = [ 145 numTests = {}
145 'avrora', 146
146 'batik', 147 if len(args) > 0:
147 'eclipse', 148 level = getattr(sanitycheck.SanityCheckLevel, args[0], None)
148 'fop', 149 if level is not None:
149 'h2', 150 del args[0]
150 'jython', 151 for (bench, ns) in sanitycheck.dacapoSanityWarmup.items():
151 'luindex', 152 if ns[level] > 0:
152 'lusearch', 153 numTests[bench] = ns[level]
153 'pmd', 154 else:
154 'sunflow', 155 while len(args) != 0 and args[0][0] not in ['-', '@']:
155 'tomcat', 156 n = 1
156 'tradebeans', 157 if args[0].isdigit():
157 'tradesoap', 158 n = int(args[0])
158 'xalan' 159 assert len(args) > 1 and args[1][0] not in ['-', '@'] and not args[1].isdigit()
159 ] 160 bm = args[1]
160 161 del args[0]
161 dacapo = mx.get_env('DACAPO_CP') 162 else:
162 if dacapo is None: 163 bm = args[0]
163 dacapo = _graal_home + r'/lib/dacapo-9.12-bach.jar' 164
164 165 del args[0]
165 if not isfile(dacapo) or not dacapo.endswith('.jar'): 166 if bm not in sanitycheck.dacapoSanityWarmup.keys():
166 mx.abort('Specified DaCapo jar file does not exist or is not a jar file: ' + dacapo) 167 mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(sanitycheck.dacapoSanityWarmup.keys()))
167 168 numTests[bm] = n
168 vmOpts = ['-Xms1g', '-Xmx2g', '-cp', dacapo] 169
169 170 if len(numTests) is 0:
170 selected = [] 171 for bench in sanitycheck.dacapoSanityWarmup.keys():
171 while len(args) != 0 and args[0][0] not in ['-', '@']: 172 numTests[bench] = 1
172 bm = args[0]
173 del args[0]
174 if bm not in benchmarks:
175 mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(benchmarks))
176 selected.append(bm)
177
178 if len(selected) != 0:
179 benchmarks = selected
180 173
181 # Extract DaCapo options 174 # Extract DaCapo options
182 dacapoArgs = [(arg[1:]) for arg in args if arg.startswith('@')] 175 dacapoArgs = [(arg[1:]) for arg in args if arg.startswith('@')]
183 176
184 # The remainder are VM options 177 # The remainder are VM options
185 vmOpts += [arg for arg in args if not arg.startswith('@')] 178 vmOpts = [arg for arg in args if not arg.startswith('@')]
186 179
187 dacapoSuccess = re.compile(r"^===== DaCapo 9\.12 ([a-zA-Z0-9_]+) PASSED in ([0-9]+) msec =====$") 180 failed = []
188 passed = [] 181 print str(numTests)
189 182 for (test, n) in numTests.items():
190 for bm in benchmarks: 183 if not sanitycheck.getDacapo(test, n, dacapoArgs).test('-graal', opts=vmOpts):
191 def errFilter(line): 184 failed.append(test)
192 if dacapoSuccess.match(line):
193 passed.append(bm)
194 sys.stderr.write(line)
195 vm(vmOpts + ['Harness'] + dacapoArgs + [bm], err=errFilter)
196
197 failed = list(set(benchmarks).difference(set(passed)))
198 185
199 if len(failed) != 0: 186 if len(failed) != 0:
200 mx.abort('Benchmark failures: ' + str(failed)) 187 mx.abort('DaCapo failures: ' + str(failed))
201 188
202 def _jdk(build='product', create=False): 189 def _jdk(build='product', create=False):
203 """ 190 """
204 Get the JDK into which Graal is installed, creating it first if necessary. 191 Get the JDK into which Graal is installed, creating it first if necessary.
205 """ 192 """
244 return res 231 return res
245 else: 232 else:
246 mx.abort('Unknown build type: ' + build) 233 mx.abort('Unknown build type: ' + build)
247 234
248 # run a command in the windows SDK Debug Shell 235 # run a command in the windows SDK Debug Shell
249 def runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}): 236 def _runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}):
250 newLine = os.linesep 237 newLine = os.linesep
251 STARTTOKEN = 'RUNINDEBUGSHELL_STARTSEQUENCE' 238 STARTTOKEN = 'RUNINDEBUGSHELL_STARTSEQUENCE'
252 ENDTOKEN = 'RUNINDEBUGSHELL_ENDSEQUENCE' 239 ENDTOKEN = 'RUNINDEBUGSHELL_ENDSEQUENCE'
253 p = subprocess.Popen('cmd.exe /E:ON /V:ON /K ""' + _winSDK + '/Bin/SetEnv.cmd" & echo ' + STARTTOKEN + '"', \ 240 p = subprocess.Popen('cmd.exe /E:ON /V:ON /K ""' + _winSDK + '/Bin/SetEnv.cmd" & echo ' + STARTTOKEN + '"', \
254 shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 241 shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
308 if not 'Xusage.txt' in line: 295 if not 'Xusage.txt' in line:
309 sys.stderr.write(line + os.linesep) 296 sys.stderr.write(line + os.linesep)
310 297
311 if platform.system() == 'Windows': 298 if platform.system() == 'Windows':
312 compilelogfile = _graal_home + '/graalCompile.log' 299 compilelogfile = _graal_home + '/graalCompile.log'
313 runInDebugShell('msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcproj /p:Configuration=compiler1_product /target:clean', _graal_home) 300 _runInDebugShell('msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcproj /p:Configuration=compiler1_product /target:clean', _graal_home)
314 winCompileCmd = r'set HotSpotMksHome=' + _mksHome + r'& set OUT_DIR=' + jdk + r'& set JAVA_HOME=' + jdk + r'& set path=%JAVA_HOME%\bin;%path%;%HotSpotMksHome%& cd /D "' +_graal_home + r'\make\windows"& call create.bat ' + _graal_home + '' 301 winCompileCmd = r'set HotSpotMksHome=' + _mksHome + r'& set OUT_DIR=' + jdk + r'& set JAVA_HOME=' + jdk + r'& set path=%JAVA_HOME%\bin;%path%;%HotSpotMksHome%& cd /D "' +_graal_home + r'\make\windows"& call create.bat ' + _graal_home + ''
315 print(winCompileCmd) 302 print(winCompileCmd)
316 winCompileSuccess = re.compile(r"^Writing \.vcxproj file:") 303 winCompileSuccess = re.compile(r"^Writing \.vcxproj file:")
317 if not runInDebugShell(winCompileCmd, _graal_home, compilelogfile, winCompileSuccess): 304 if not _runInDebugShell(winCompileCmd, _graal_home, compilelogfile, winCompileSuccess):
318 mx.log('Error executing create command') 305 mx.log('Error executing create command')
319 return 306 return
320 winBuildCmd = 'msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcxproj /p:Configuration=compiler1_product /p:Platform=x64' 307 winBuildCmd = 'msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcxproj /p:Configuration=compiler1_product /p:Platform=x64'
321 winBuildSuccess = re.compile('Build succeeded.') 308 winBuildSuccess = re.compile('Build succeeded.')
322 if not runInDebugShell(winBuildCmd, _graal_home, compilelogfile, winBuildSuccess): 309 if not _runInDebugShell(winBuildCmd, _graal_home, compilelogfile, winBuildSuccess):
323 mx.log('Error building project') 310 mx.log('Error building project')
324 return 311 return
325 else: 312 else:
326 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y') 313 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y')
327 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) 314 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage)
579 dacapo(['avrora']) 566 dacapo(['avrora'])
580 dacapo(['fop']) 567 dacapo(['fop'])
581 568
582 duration = datetime.timedelta(seconds=time.time() - start) 569 duration = datetime.timedelta(seconds=time.time() - start)
583 mx.log(time.strftime('%d %b %Y %H:%M:%S - Gate done (duration - ' + str(duration) + ')')) 570 mx.log(time.strftime('%d %b %Y %H:%M:%S - Gate done (duration - ' + str(duration) + ')'))
571
572 def bench(args):
573
574 for test in sanitycheck.getDacapos(level=sanitycheck.SanityCheckLevel.Fast):
575 print test.bench('-graal')
584 576
585 def mx_init(): 577 def mx_init():
586 _vmbuild = 'product' 578 _vmbuild = 'product'
587 commands = { 579 commands = {
588 'build': [build, ''], 580 'build': [build, ''],
589 'clean': [clean, ''], 581 'clean': [clean, ''],
590 'copyrightcheck': [copyrightcheck, ''], 582 'copyrightcheck': [copyrightcheck, ''],
591 'dacapo': [dacapo, '[benchmark] [VM options|DaCapo options]'], 583 'dacapo': [dacapo, '[benchmark] [VM options|DaCapo options]'],
592 'example': [example, '[-v] example names...'], 584 'example': [example, '[-v] example names...'],
593 'gate' : [gate, ''], 585 'gate' : [gate, ''],
586 'bench' : [bench, ''],
594 'unittest' : [unittest, '[filters...]'], 587 'unittest' : [unittest, '[filters...]'],
595 'vm': [vm, '[-options] class [args...]'], 588 'vm': [vm, '[-options] class [args...]'],
596 'ideinit': [ideinit, ''] 589 'ideinit': [ideinit, '']
597 } 590 }
598 591
615 assert len(parts) >= 2 608 assert len(parts) >= 2
616 assert parts[0] == '1' 609 assert parts[0] == '1'
617 major = int(parts[1]) 610 major = int(parts[1])
618 if not major >= 7: 611 if not major >= 7:
619 mx.abort('Requires Java version 1.7 or greater, got version ' + version) 612 mx.abort('Requires Java version 1.7 or greater, got version ' + version)
620 613
621 if (_vmSourcesAvailable): 614 if (_vmSourcesAvailable):
622 if hasattr(opts, 'vmbuild'): 615 if hasattr(opts, 'vmbuild'):
623 global _vmbuild 616 global _vmbuild
624 _vmbuild = opts.vmbuild 617 _vmbuild = opts.vmbuild