Mercurial > hg > graal-jvmci-8
comparison mx/commands.py @ 4159:e253ca26b2d5
Added 'unittest' command to run the Graal unit tests.
Added 'gate' command.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 22 Dec 2011 22:52:25 +0100 |
parents | b26279781d95 |
children | 338d46581e03 |
comparison
equal
deleted
inserted
replaced
4158:f3a50640333b | 4159:e253ca26b2d5 |
---|---|
24 # or visit www.oracle.com if you need additional information or have any | 24 # or visit www.oracle.com if you need additional information or have any |
25 # questions. | 25 # questions. |
26 # | 26 # |
27 # ---------------------------------------------------------------------------------------------------- | 27 # ---------------------------------------------------------------------------------------------------- |
28 | 28 |
29 import os, sys, shutil, StringIO, zipfile, tempfile, re | 29 import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime |
30 from os.path import join, exists, dirname, isdir, isfile, isabs, basename | 30 from os.path import join, exists, dirname, isdir, isfile, isabs, basename |
31 from argparse import ArgumentParser, REMAINDER | 31 from argparse import ArgumentParser, REMAINDER |
32 import mx | 32 import mx |
33 | 33 |
34 _graal_home = dirname(dirname(__file__)) | 34 _graal_home = dirname(dirname(__file__)) |
263 sys.stderr.write(line + os.linesep) | 263 sys.stderr.write(line + os.linesep) |
264 | 264 |
265 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y') | 265 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y') |
266 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) | 266 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) |
267 | 267 |
268 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None): | 268 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None): |
269 """run the GraalVM""" | 269 """run the GraalVM""" |
270 | 270 |
271 build = _vmbuild if _vmSourcesAvailable else 'product' | 271 build = _vmbuild if _vmSourcesAvailable else 'product' |
272 if mx.java().debug: | 272 if mx.java().debug: |
273 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args | 273 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args |
274 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) | 274 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) |
275 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) | 275 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) |
276 | 276 |
277 def ideinit(args): | 277 def ideinit(args): |
278 """(re)generate Eclipse project configurations""" | 278 """(re)generate Eclipse project configurations""" |
279 | 279 |
280 | 280 |
403 | 403 |
404 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f: | 404 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f: |
405 content = f.read() | 405 content = f.read() |
406 mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content) | 406 mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content) |
407 | 407 |
408 # Table of unit tests. | |
409 # Keys are project names, values are package name lists. | |
410 # All source files in the given (project,package) pairs are scanned for lines | |
411 # containing '@Test'. These are then detemrined to be the classes defining | |
412 # unit tests. | |
413 _unittests = { | |
414 'com.oracle.max.graal.tests': ['com.oracle.max.graal.compiler.tests'], | |
415 } | |
416 | |
417 def _add_test_classes(testClassList, searchDir, pkgRoot): | |
418 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") | |
419 for root, _, files in os.walk(searchDir): | |
420 for name in files: | |
421 if name.endswith('.java') and name != 'package-info.java': | |
422 hasTest = False | |
423 with open(join(root, name)) as f: | |
424 pkg = None | |
425 for line in f: | |
426 if line.startswith("package "): | |
427 match = pkgDecl.match(line) | |
428 if match: | |
429 pkg = match.group(1) | |
430 else: | |
431 if line.strip().startswith('@Test'): | |
432 hasTest = True | |
433 break | |
434 if hasTest: | |
435 assert pkg is not None | |
436 testClassList.append(pkg + '.' + name[:-len('.java')]) | |
437 | |
438 def unittest(args): | |
439 """run the Graal Compiler Unit Tests in the GraalVM | |
440 | |
441 If filters are supplied, only tests whose fully qualified name | |
442 include a filter as a substring are run. Negative filters are | |
443 those with a '-' prefix.""" | |
444 | |
445 pos = [a for a in args if a[0] != '-'] | |
446 neg = [a[1:] for a in args if a[0] == '-'] | |
447 | |
448 def containsAny(c, substrings): | |
449 for s in substrings: | |
450 if s in c: | |
451 return True | |
452 return False | |
453 | |
454 for proj in _unittests.iterkeys(): | |
455 p = mx.project(proj) | |
456 classes = [] | |
457 for pkg in _unittests[proj]: | |
458 _add_test_classes(classes, join(p.dir, 'src'), pkg) | |
459 | |
460 if len(pos) != 0: | |
461 classes = [c for c in classes if containsAny(c, pos)] | |
462 if len(neg) != 0: | |
463 classes = [c for c in classes if not containsAny(c, neg)] | |
464 | |
465 # (ds) The boot class path must be used for some reason I don't quite understand | |
466 vm(['-XX:-BootstrapGraal', '-esa', '-Xbootclasspath/a:' + mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) | |
467 | |
468 def gate(args): | |
469 """run the tests used to validate a push | |
470 | |
471 If this commands exits with a 0 exit code, then the source code is in | |
472 a state that would be accepted for integration into the main repository.""" | |
473 | |
474 start = time.time() | |
475 | |
476 # 1. Checkstyle | |
477 mx.log(time.strftime('%d %b %Y %H:%M:%S - Running Checkstyle...')) | |
478 if mx.checkstyle([]) != 0: | |
479 mx.abort('Checkstyle warnings were found') | |
480 | |
481 # 2. Canonical mx/projects | |
482 mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) | |
483 if mx.canonicalizeprojects([]) != 0: | |
484 mx.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') | |
485 | |
486 # 3. Build | |
487 mx.log(time.strftime('%d %b %Y %H:%M:%S - Build...')) | |
488 build([]) | |
489 | |
490 # 4. Bootstrap with system assertions enabled | |
491 mx.log(time.strftime('%d %b %Y %H:%M:%S - Bootstrap with -esa...')) | |
492 vm(['-esa', '-version']) | |
493 | |
494 # 5. Run unittests | |
495 mx.log(time.strftime('%d %b %Y %H:%M:%S - Running unit tests...')) | |
496 unittest([]) | |
497 | |
498 # 6. Run selected DaCapo benchmarks | |
499 mx.log(time.strftime('%d %b %Y %H:%M:%S - Running DaCapo benchmarks...')) | |
500 dacapo(['eclipse']) | |
501 #dacapo(['tradesoap']) | |
502 dacapo(['batik']) | |
503 dacapo(['avrora']) | |
504 dacapo(['fop']) | |
505 | |
506 duration = datetime.timedelta(seconds=time.time() - start) | |
507 mx.log(time.strftime('%d %b %Y %H:%M:%S - Gate done (duration - ' + str(duration) + ')')) | |
508 | |
408 def mx_init(): | 509 def mx_init(): |
409 _vmbuild = 'product' | 510 _vmbuild = 'product' |
410 commands = { | 511 commands = { |
512 'build': [build, ''], | |
411 'clean': [clean, ''], | 513 'clean': [clean, ''], |
412 'build': [build, ''], | |
413 'dacapo': [dacapo, '[benchmark] [VM options|DaCapo options]'], | 514 'dacapo': [dacapo, '[benchmark] [VM options|DaCapo options]'], |
414 'example': [example, '[-v] example names...'], | 515 'example': [example, '[-v] example names...'], |
516 'gate' : [gate, ''], | |
517 'unittest' : [unittest, '[filters...]'], | |
415 'vm': [vm, '[-options] class [args...]'], | 518 'vm': [vm, '[-options] class [args...]'], |
416 'ideinit': [ideinit, ''] | 519 'ideinit': [ideinit, ''] |
417 } | 520 } |
418 | 521 |
419 if (_vmSourcesAvailable): | 522 if (_vmSourcesAvailable): |