Mercurial > hg > truffle
comparison mx/commands.py @ 5366:67e63e8dcbd2
build JaCoCo exclude list by scanning for snippets
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 08 May 2012 22:51:36 +0200 |
parents | 31fc6b6c0425 |
children | 206df7b3e022 |
comparison
equal
deleted
inserted
replaced
5365:33b8603f180d | 5366:67e63e8dcbd2 |
---|---|
48 _vmbuild = 'product' | 48 _vmbuild = 'product' |
49 | 49 |
50 _jacoco = 'off' | 50 _jacoco = 'off' |
51 | 51 |
52 _make_eclipse_launch = False | 52 _make_eclipse_launch = False |
53 | |
54 _jacocoExcludes = ['com.oracle.graal.hotspot.snippets.ArrayCopySnippets', | |
55 'com.oracle.graal.snippets.DoubleSnippets', | |
56 'com.oracle.graal.snippets.FloatSnippets', | |
57 'com.oracle.graal.snippets.MathSnippetsX86', | |
58 'com.oracle.graal.snippets.NodeClassSnippets', | |
59 'com.oracle.graal.hotspot.snippets.SystemSnippets', | |
60 'com.oracle.graal.hotspot.snippets.UnsafeSnippets', | |
61 'com.oracle.graal.compiler.tests.*'] | |
62 | 53 |
63 _copyrightTemplate = """/* | 54 _copyrightTemplate = """/* |
64 * Copyright (c) {0}, Oracle and/or its affiliates. All rights reserved. | 55 * Copyright (c) {0}, Oracle and/or its affiliates. All rights reserved. |
65 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 56 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
66 * | 57 * |
569 hsdis([]) | 560 hsdis([]) |
570 if mx.java().debug_port is not None: | 561 if mx.java().debug_port is not None: |
571 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(mx.java().debug_port)] + args | 562 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(mx.java().debug_port)] + args |
572 if _jacoco == 'on' or _jacoco == 'append': | 563 if _jacoco == 'on' or _jacoco == 'append': |
573 jacocoagent = mx.library("JACOCOAGENT", True) | 564 jacocoagent = mx.library("JACOCOAGENT", True) |
565 # Exclude all compiler tests and snippets | |
566 excludes = ['com.oracle.graal.compiler.tests.*'] | |
567 for p in mx.projects(): | |
568 for s in p.source_dirs(): | |
569 _add_classes_with_annotation(excludes, s, None, '@Snippet') | |
570 _add_classes_with_annotation(excludes, s, None, '@ClassSubstitution') | |
574 agentOptions = { | 571 agentOptions = { |
575 'append' : 'true' if _jacoco == 'append' else 'false', | 572 'append' : 'true' if _jacoco == 'append' else 'false', |
576 'bootclasspath' : 'true', | 573 'bootclasspath' : 'true', |
577 'includes' : 'com.oracle.*', | 574 'includes' : 'com.oracle.*', |
578 'excludes' : ':'.join(_jacocoExcludes) | 575 'excludes' : ':'.join(excludes) |
579 } | 576 } |
580 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args | 577 args = ['-javaagent:' + jacocoagent.get_path(True) + '=' + ','.join([k + '=' + v for k, v in agentOptions.items()])] + args |
581 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) | 578 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) |
582 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) | 579 return mx.run([exe, '-' + vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) |
580 | |
581 def _add_classes_with_annotation(classes, srcDir, pkgRoot, annotation): | |
582 """ | |
583 Scan 'srcDir' for Java source files containing a line starting with 'annotation' | |
584 (ignoring preceding whitespace) and add the fully qualified class name | |
585 to 'classes' for each Java source file matched. | |
586 """ | |
587 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") | |
588 for root, _, files in os.walk(srcDir): | |
589 for name in files: | |
590 if name.endswith('.java') and name != 'package-info.java': | |
591 hasTest = False | |
592 with open(join(root, name)) as f: | |
593 pkg = None | |
594 for line in f: | |
595 if line.startswith("package "): | |
596 match = pkgDecl.match(line) | |
597 if match: | |
598 pkg = match.group(1) | |
599 else: | |
600 if line.strip().startswith(annotation): | |
601 hasTest = True | |
602 break | |
603 if hasTest: | |
604 assert pkg is not None | |
605 if pkgRoot is None or pkg.startswith(pkgRoot): | |
606 classes.append(pkg + '.' + name[:-len('.java')]) | |
583 | 607 |
584 | 608 |
585 # Table of unit tests. | 609 # Table of unit tests. |
586 # Keys are project names, values are package name lists. | 610 # Keys are project names, values are package name lists. |
587 # All source files in the given (project,package) pairs are scanned for lines | 611 # All source files in the given (project,package) pairs are scanned for lines |
592 } | 616 } |
593 _jtttests = { | 617 _jtttests = { |
594 'com.oracle.graal.jtt': ['com.oracle.graal.jtt'], | 618 'com.oracle.graal.jtt': ['com.oracle.graal.jtt'], |
595 } | 619 } |
596 | 620 |
597 def _add_test_classes(testClassList, searchDir, pkgRoot): | |
598 pkgDecl = re.compile(r"^package\s+([a-zA-Z_][\w\.]*)\s*;$") | |
599 for root, _, files in os.walk(searchDir): | |
600 for name in files: | |
601 if name.endswith('.java') and name != 'package-info.java': | |
602 hasTest = False | |
603 with open(join(root, name)) as f: | |
604 pkg = None | |
605 for line in f: | |
606 if line.startswith("package "): | |
607 match = pkgDecl.match(line) | |
608 if match: | |
609 pkg = match.group(1) | |
610 else: | |
611 if line.strip().startswith('@Test'): | |
612 hasTest = True | |
613 break | |
614 if hasTest: | |
615 assert pkg is not None | |
616 if pkg.startswith(pkgRoot): | |
617 testClassList.append(pkg + '.' + name[:-len('.java')]) | |
618 | |
619 def unittest(args): | 621 def unittest(args): |
620 """run the Graal Compiler Unit Tests in the GraalVM | 622 """run the Graal Compiler Unit Tests in the GraalVM |
621 | 623 |
622 If filters are supplied, only tests whose fully qualified name | 624 If filters are supplied, only tests whose fully qualified name |
623 include a filter as a substring are run. Negative filters are | 625 include a filter as a substring are run. Negative filters are |
635 | 637 |
636 for proj in _unittests.iterkeys(): | 638 for proj in _unittests.iterkeys(): |
637 p = mx.project(proj) | 639 p = mx.project(proj) |
638 classes = [] | 640 classes = [] |
639 for pkg in _unittests[proj]: | 641 for pkg in _unittests[proj]: |
640 _add_test_classes(classes, join(p.dir, 'src'), pkg) | 642 _add_classes_with_annotation(classes, join(p.dir, 'src'), pkg, '@Test') |
641 | 643 |
642 if len(pos) != 0: | 644 if len(pos) != 0: |
643 classes = [c for c in classes if containsAny(c, pos)] | 645 classes = [c for c in classes if containsAny(c, pos)] |
644 if len(neg) != 0: | 646 if len(neg) != 0: |
645 classes = [c for c in classes if not containsAny(c, neg)] | 647 classes = [c for c in classes if not containsAny(c, neg)] |
646 | 648 |
647 vm(['-XX:-BootstrapGraal', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) | 649 vm(['-XX:-BootstrapGraal', '-esa'] + vmArgs + ['-cp', mx.classpath(proj), 'org.junit.runner.JUnitCore'] + classes) |
648 | 650 |
649 def jtt(args): | 651 def jtt(args): |
650 """run the Java Tester Tests in the GraalVM | 652 """run the Java Tester Tests in the GraalVM |
651 | 653 |
665 | 667 |
666 for proj in _jtttests.iterkeys(): | 668 for proj in _jtttests.iterkeys(): |
667 p = mx.project(proj) | 669 p = mx.project(proj) |
668 classes = [] | 670 classes = [] |
669 for pkg in _jtttests[proj]: | 671 for pkg in _jtttests[proj]: |
670 _add_test_classes(classes, join(p.dir, 'src'), pkg) | 672 _add_classes_with_annotation(classes, join(p.dir, 'src'), pkg, '@Test') |
671 | 673 |
672 if len(pos) != 0: | 674 if len(pos) != 0: |
673 classes = [c for c in classes if containsAny(c, pos)] | 675 classes = [c for c in classes if containsAny(c, pos)] |
674 if len(neg) != 0: | 676 if len(neg) != 0: |
675 classes = [c for c in classes if not containsAny(c, neg)] | 677 classes = [c for c in classes if not containsAny(c, neg)] |