Mercurial > hg > truffle
comparison mx/commands.py @ 5649:14505f3e6b4c
modified harness for running JUnit and JTT tests such that only projects declaring a 'testHarness' attribute in mx/projects are scanned for tests
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 19 Jun 2012 11:36:27 +0200 |
parents | e4b1bc5e29e0 |
children | 87fc13b59258 |
comparison
equal
deleted
inserted
replaced
5648:1cfa35d467de | 5649:14505f3e6b4c |
---|---|
173 | 173 |
174 def dacapo(args): | 174 def dacapo(args): |
175 """run one or all DaCapo benchmarks | 175 """run one or all DaCapo benchmarks |
176 | 176 |
177 DaCapo options are distinguished from VM options by a '@' prefix. | 177 DaCapo options are distinguished from VM options by a '@' prefix. |
178 For example, '@--iterations @5' will pass '--iterations 5' to the | 178 For example, '@-n @5' will pass '-n 5' to the |
179 DaCapo harness.""" | 179 DaCapo harness.""" |
180 | 180 |
181 numTests = {} | 181 numTests = {} |
182 if len(args) > 0: | 182 if len(args) > 0: |
183 level = getattr(sanitycheck.SanityCheckLevel, args[0], None) | 183 level = getattr(sanitycheck.SanityCheckLevel, args[0], None) |
622 if e.endswith('.class') and (e.startswith(basename) or e.startswith(basename + '$')): | 622 if e.endswith('.class') and (e.startswith(basename) or e.startswith(basename + '$')): |
623 classes.append(pkg + '.' + e[:-len('.class')]) | 623 classes.append(pkg + '.' + e[:-len('.class')]) |
624 elif e == basename + '.class': | 624 elif e == basename + '.class': |
625 classes.append(pkg + '.' + basename) | 625 classes.append(pkg + '.' + basename) |
626 | 626 |
627 | 627 def _run_tests(args, harnessName, harness): |
628 # Table of unit tests. | |
629 # Keys are project names, values are package name lists. | |
630 # All source files in the given (project,package) pairs are scanned for lines | |
631 # containing '@Test'. These are then determined to be the classes defining | |
632 # unit tests. | |
633 _unittests = { | |
634 'com.oracle.graal.tests': ['com.oracle.graal.compiler.tests'], | |
635 } | |
636 _jtttests = { | |
637 'com.oracle.graal.jtt': ['com.oracle.graal.jtt'], | |
638 } | |
639 | |
640 def unittest(args): | |
641 """run the Graal Compiler Unit Tests in the GraalVM | |
642 | |
643 If filters are supplied, only tests whose fully qualified name | |
644 include a filter as a substring are run. Negative filters are | |
645 those with a '-' prefix. VM args should have a @ prefix.""" | |
646 | |
647 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] | 628 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] |
648 neg = [a[1:] for a in args if a[0] == '-'] | 629 neg = [a[1:] for a in args if a[0] == '-'] |
649 vmArgs = [a[1:] for a in args if a[0] == '@'] | 630 vmArgs = [a[1:] for a in args if a[0] == '@'] |
650 | 631 |
651 def containsAny(c, substrings): | 632 def containsAny(c, substrings): |
652 for s in substrings: | 633 for s in substrings: |
653 if s in c: | 634 if s in c: |
654 return True | 635 return True |
655 return False | 636 return False |
656 | 637 |
657 for proj in _unittests.iterkeys(): | 638 for p in mx.projects(): |
658 p = mx.project(proj) | 639 if getattr(p, 'testHarness', None) == harnessName: |
659 classes = [] | 640 classes = [] |
660 for pkg in _unittests[proj]: | 641 _find_classes_with_annotations(classes, p, None, ['@Test']) |
661 _find_classes_with_annotations(classes, p, pkg, ['@Test']) | 642 |
662 | 643 if len(pos) != 0: |
663 if len(pos) != 0: | 644 classes = [c for c in classes if containsAny(c, pos)] |
664 classes = [c for c in classes if containsAny(c, pos)] | 645 if len(neg) != 0: |
665 if len(neg) != 0: | 646 classes = [c for c in classes if not containsAny(c, neg)] |
666 classes = [c for c in classes if not containsAny(c, neg)] | 647 |
667 | 648 if len(classes) != 0: |
668 vm(['-XX:-BootstrapGraal', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) | 649 mx.log('running tests in ' + p.name) |
669 | 650 harness(p, vmArgs, classes) |
670 def jtt(args): | 651 |
671 """run the Java Tester Tests in the GraalVM | 652 def unittest(args): |
653 """run the Graal Compiler Unit Tests in the GraalVM | |
672 | 654 |
673 If filters are supplied, only tests whose fully qualified name | 655 If filters are supplied, only tests whose fully qualified name |
674 include a filter as a substring are run. Negative filters are | 656 include a filter as a substring are run. Negative filters are |
675 those with a '-' prefix. VM args should have a @ prefix.""" | 657 those with a '-' prefix. VM args should have a @ prefix.""" |
676 | 658 |
677 pos = [a for a in args if a[0] != '-' and a[0] != '@' ] | 659 def harness(p, vmArgs, classes): |
678 neg = [a[1:] for a in args if a[0] == '-'] | 660 vm(['-XX:-BootstrapGraal', '-esa'] + vmArgs + ['-cp', mx.classpath(p.name), 'org.junit.runner.JUnitCore'] + classes) |
679 vmArgs = [a[1:] for a in args if a[0] == '@'] | 661 _run_tests(args, 'unittest', harness) |
680 | 662 |
681 def containsAny(c, substrings): | 663 def jtt(args): |
682 for s in substrings: | 664 """run the Java Tester Tests in the GraalVM |
683 if s in c: | 665 |
684 return True | 666 If filters are supplied, only tests whose fully qualified name |
685 return False | 667 include a filter as a substring are run. Negative filters are |
686 | 668 those with a '-' prefix. VM args should have a @ prefix.""" |
687 for proj in _jtttests.iterkeys(): | 669 |
688 p = mx.project(proj) | 670 def harness(p, vmArgs, classes): |
689 classes = [] | 671 vm(['-XX:-BootstrapGraal', '-XX:CompileOnly=com/oracle/graal/jtt', '-XX:CompileCommand=compileonly,java/lang/Object::<init>', '-XX:CompileCommand=quiet', '-Xcomp', '-esa'] + vmArgs + ['-cp', mx.classpath(p.name), 'org.junit.runner.JUnitCore'] + classes) |
690 for pkg in _jtttests[proj]: | 672 _run_tests(args, 'jtt', harness) |
691 _find_classes_with_annotations(classes, p, pkg, ['@Test']) | |
692 | |
693 if len(pos) != 0: | |
694 classes = [c for c in classes if containsAny(c, pos)] | |
695 if len(neg) != 0: | |
696 classes = [c for c in classes if not containsAny(c, neg)] | |
697 | |
698 vm(['-XX:-BootstrapGraal', '-XX:CompileOnly=com/oracle/graal/jtt', '-XX:CompileCommand=compileonly,java/lang/Object::<init>', '-XX:CompileCommand=quiet', '-Xcomp', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) | |
699 | 673 |
700 def buildvms(args): | 674 def buildvms(args): |
701 """build one or more VMs in various configurations""" | 675 """build one or more VMs in various configurations""" |
702 | 676 |
703 parser = ArgumentParser(prog='mx buildvms'); | 677 parser = ArgumentParser(prog='mx buildvms'); |