Mercurial > hg > truffle
changeset 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 | f3a50640333b |
children | 338d46581e03 |
files | graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java mx/commands.py |
diffstat | 6 files changed, 128 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java Thu Dec 22 22:51:37 2011 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java Thu Dec 22 22:52:25 2011 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import junit.framework.AssertionFailedError; + import org.junit.*; import com.oracle.max.graal.compiler.phases.*; @@ -42,7 +44,7 @@ return 1; } - @Test + @Test(expected = AssertionFailedError.class) public void test1() { test("test1Snippet"); }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java Thu Dec 22 22:51:37 2011 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/EscapeAnalysisTest.java Thu Dec 22 22:52:25 2011 +0100 @@ -22,7 +22,7 @@ */ package com.oracle.max.graal.compiler.tests; -import junit.framework.Assert; +import junit.framework.*; import org.junit.Test; @@ -92,7 +92,7 @@ return x.intValue(); } - @Test + @Test(expected = AssertionFailedError.class) public void testMonitor2() { test("testMonitor2Snippet", CiConstant.forInt(0)); }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Thu Dec 22 22:51:37 2011 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java Thu Dec 22 22:52:25 2011 +0100 @@ -24,6 +24,8 @@ import java.util.*; +import junit.framework.AssertionFailedError; + import org.junit.*; import com.oracle.max.graal.compiler.phases.*; @@ -49,7 +51,7 @@ return 1; } - @Test + @Test(expected = AssertionFailedError.class) public void test1() { test("test1Snippet"); }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java Thu Dec 22 22:51:37 2011 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/ScalarTypeSystemTest.java Thu Dec 22 22:52:25 2011 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import junit.framework.AssertionFailedError; + import org.junit.*; import com.oracle.max.graal.compiler.phases.*; @@ -40,7 +42,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test1() { test("test1Snippet", "referenceSnippet1"); } @@ -57,7 +59,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test2() { test("test2Snippet", "referenceSnippet1"); } @@ -74,7 +76,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test3() { test("test3Snippet", "referenceSnippet2"); } @@ -99,7 +101,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test4() { test("test4Snippet", "referenceSnippet2"); } @@ -116,7 +118,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test5() { test("test5Snippet", "referenceSnippet3"); } @@ -141,7 +143,7 @@ } } - @Test + @Test(expected = AssertionFailedError.class) public void test6() { test("test6Snippet", "referenceSnippet3"); }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java Thu Dec 22 22:51:37 2011 +0100 +++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/StraighteningTest.java Thu Dec 22 22:52:25 2011 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.max.graal.compiler.tests; +import junit.framework.AssertionFailedError; + import org.junit.*; import com.oracle.max.graal.compiler.phases.*; @@ -68,17 +70,17 @@ return c == 1; } - @Test + @Test(expected = AssertionFailedError.class) public void test1() { test("test1Snippet"); } - @Test + @Test(expected = AssertionFailedError.class) public void test2() { test("test2Snippet"); } - @Test + @Test(expected = AssertionFailedError.class) public void test3() { test("test3Snippet"); }
--- a/mx/commands.py Thu Dec 22 22:51:37 2011 +0100 +++ b/mx/commands.py Thu Dec 22 22:52:25 2011 +0100 @@ -26,7 +26,7 @@ # # ---------------------------------------------------------------------------------------------------- -import os, sys, shutil, StringIO, zipfile, tempfile, re +import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime from os.path import join, exists, dirname, isdir, isfile, isabs, basename from argparse import ArgumentParser, REMAINDER import mx @@ -265,14 +265,14 @@ os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y') mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) -def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None): +def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None): """run the GraalVM""" build = _vmbuild if _vmSourcesAvailable else 'product' if mx.java().debug: args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) - return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) + return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) def ideinit(args): """(re)generate Eclipse project configurations""" @@ -405,13 +405,116 @@ content = f.read() mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content) +# Table of unit tests. +# Keys are project names, values are package name lists. +# All source files in the given (project,package) pairs are scanned for lines +# containing '@Test'. These are then detemrined to be the classes defining +# unit tests. +_unittests = { + 'com.oracle.max.graal.tests': ['com.oracle.max.graal.compiler.tests'], +} + +def _add_test_classes(testClassList, searchDir, pkgRoot): + pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") + for root, _, files in os.walk(searchDir): + for name in files: + if name.endswith('.java') and name != 'package-info.java': + hasTest = False + with open(join(root, name)) as f: + pkg = None + for line in f: + if line.startswith("package "): + match = pkgDecl.match(line) + if match: + pkg = match.group(1) + else: + if line.strip().startswith('@Test'): + hasTest = True + break + if hasTest: + assert pkg is not None + testClassList.append(pkg + '.' + name[:-len('.java')]) + +def unittest(args): + """run the Graal Compiler Unit Tests in the GraalVM + + If filters are supplied, only tests whose fully qualified name + include a filter as a substring are run. Negative filters are + those with a '-' prefix.""" + + pos = [a for a in args if a[0] != '-'] + neg = [a[1:] for a in args if a[0] == '-'] + + def containsAny(c, substrings): + for s in substrings: + if s in c: + return True + return False + + for proj in _unittests.iterkeys(): + p = mx.project(proj) + classes = [] + for pkg in _unittests[proj]: + _add_test_classes(classes, join(p.dir, 'src'), pkg) + + if len(pos) != 0: + classes = [c for c in classes if containsAny(c, pos)] + if len(neg) != 0: + classes = [c for c in classes if not containsAny(c, neg)] + + # (ds) The boot class path must be used for some reason I don't quite understand + vm(['-XX:-BootstrapGraal', '-esa', '-Xbootclasspath/a:' + mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) + +def gate(args): + """run the tests used to validate a push + + If this commands exits with a 0 exit code, then the source code is in + a state that would be accepted for integration into the main repository.""" + + start = time.time() + + # 1. Checkstyle + mx.log(time.strftime('%d %b %Y %H:%M:%S - Running Checkstyle...')) + if mx.checkstyle([]) != 0: + mx.abort('Checkstyle warnings were found') + + # 2. Canonical mx/projects + mx.log(time.strftime('%d %b %Y %H:%M:%S - Ensuring mx/projects files are canonicalized...')) + if mx.canonicalizeprojects([]) != 0: + mx.abort('Rerun "mx canonicalizeprojects" and check-in the modified mx/projects files.') + + # 3. Build + mx.log(time.strftime('%d %b %Y %H:%M:%S - Build...')) + build([]) + + # 4. Bootstrap with system assertions enabled + mx.log(time.strftime('%d %b %Y %H:%M:%S - Bootstrap with -esa...')) + vm(['-esa', '-version']) + + # 5. Run unittests + mx.log(time.strftime('%d %b %Y %H:%M:%S - Running unit tests...')) + unittest([]) + + # 6. Run selected DaCapo benchmarks + mx.log(time.strftime('%d %b %Y %H:%M:%S - Running DaCapo benchmarks...')) + dacapo(['eclipse']) + #dacapo(['tradesoap']) + dacapo(['batik']) + dacapo(['avrora']) + dacapo(['fop']) + + duration = datetime.timedelta(seconds=time.time() - start) + mx.log(time.strftime('%d %b %Y %H:%M:%S - Gate done (duration - ' + str(duration) + ')')) + def mx_init(): _vmbuild = 'product' commands = { + 'build': [build, ''], 'clean': [clean, ''], - 'build': [build, ''], 'dacapo': [dacapo, '[benchmark] [VM options|DaCapo options]'], 'example': [example, '[-v] example names...'], + 'gate' : [gate, ''], + 'unittest' : [unittest, '[filters...]'], 'vm': [vm, '[-options] class [args...]'], 'ideinit': [ideinit, ''] }