def microbench(self, args): """run JMH microbenchmark projects""" parser = ArgumentParser(prog='mx microbench', description=microbench.__doc__, usage="%(prog)s [command options|VM options] [-- [JMH options]]") parser.add_argument('--jar', help='Explicitly specify micro-benchmark location') self.add_arguments(parser) mx.warn("`mx microbench` is deprecated! Consider moving to `mx_benchmark.JMHRunnerBenchmarkSuite`") known_args, args = parser.parse_known_args(args) vmArgs, jmhArgs = mx.extract_VM_args(args, useDoubleDash=True) vmArgs = self.parseVmArgs(vmArgs) # look for -f in JMH arguments forking = True for i in range(len(jmhArgs)): arg = jmhArgs[i] if arg.startswith('-f'): if arg == '-f' and (i+1) < len(jmhArgs): arg += jmhArgs[i+1] try: if int(arg[2:]) == 0: forking = False except ValueError: pass if known_args.jar: # use the specified jar args = ['-jar', known_args.jar] if not forking: args += vmArgs # we do not know the compliance level of the jar - assuming 1.8 self.javaCompliance = mx.JavaCompliance('1.8') else: # find all projects with a direct JMH dependency projects_dict = mx_benchmark.JMHRunnerBenchmarkSuite.get_jmh_projects_dict() jmhProjects = projects_dict['JMH'] if 'JMH' in projects_dict else [] # get java compliance - 1.8 is minimum since we build jmh-runner with java 8 self.javaCompliance = max([p.javaCompliance for p in jmhProjects] + [mx.JavaCompliance('1.8')]) cpArgs = mx.get_runtime_jvm_args([p.name for p in jmhProjects], jdk=mx.get_jdk(self.javaCompliance)) # execute JMH runner if forking: args, cpVmArgs = self.filterVmArgs(cpArgs) vmArgs += cpVmArgs else: args = cpArgs + vmArgs args += ['org.openjdk.jmh.Main'] if forking: def quoteSpace(s): if " " in s: return '"' + s + '"' return s forkedVmArgs = map(quoteSpace, self.parseForkedVmArgs(vmArgs)) args += ['--jvmArgsPrepend', ' '.join(forkedVmArgs)] self.run_java(args + jmhArgs)
def jackpot(args, suite=None, nonZeroIsFatal=False): """run Jackpot 3.0 against non-test Java projects""" jackpotHome = mx.get_env('JACKPOT_HOME', None) if jackpotHome: jackpotJar = join(jackpotHome, 'jackpot.jar') else: jackpotJar = mx.library('JACKPOT').get_path(resolve=True) assert exists(jackpotJar) if suite is None: suite = mx.primary_suite() nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 0 groups = [] for p in nonTestProjects: javacClasspath = [] deps = [] p.walk_deps(visit=lambda dep, edge: deps.append(dep) if dep.isLibrary() or dep.isJavaProject() else None) annotationProcessorOnlyDeps = [] if len(p.annotation_processors()) > 0: for apDep in p.annotation_processors(): if not apDep in deps: deps.append(apDep) annotationProcessorOnlyDeps.append(apDep) for dep in deps: if dep == p: continue if dep in annotationProcessorOnlyDeps: continue javacClasspath.append(dep.classpath_repr(resolve=True)) sourceLevel = min(p.javaCompliance.value, 9) groups = groups + [ '--group', "--classpath " + mx._separatedCygpathU2W( _escape_string(os.pathsep.join(javacClasspath))) + " --source " + str(sourceLevel) + " " + " ".join([_escape_string(d) for d in p.source_dirs()]) ] cmd = [ '-classpath', mx._cygpathU2W(jackpotJar), 'org.netbeans.modules.jackpot30.cmdline.Main' ] cmd = cmd + ['--fail-on-warnings', '--progress'] + args + groups jdk = mx.get_jdk(mx.JavaCompliance("8"), cancel='cannot run Jackpot', purpose="run Jackpot") if jdk is None: mx.warn('Skipping Jackpot since JDK 8 is not available') return 0 else: return mx.run_java(cmd, nonZeroIsFatal=nonZeroIsFatal, jdk=jdk)
def _runmake(args): """run the JDK make process To build hotspot and import it into the JDK: "mx make hotspot import-hotspot" {0}""" jdkBuildDir = _get_jdk_build_dir() if not exists(jdkBuildDir): # JDK10 must be bootstrapped with a JDK9 compliance = mx.JavaCompliance('9') jdk9 = mx.get_jdk(compliance.exactMatch, versionDescription=compliance.value) cmd = [ 'sh', 'configure', '--with-debug-level=' + _vm.debugLevel, '--with-native-debug-symbols=external', '--disable-precompiled-headers', '--with-jvm-features=graal', '--with-jvm-variants=' + _vm.jvmVariant, '--disable-warnings-as-errors', '--with-boot-jdk=' + jdk9.home, '--with-jvm-features=graal' ] mx.run(cmd, cwd=_jdkSourceRoot) cmd = [mx.gmake_cmd(), 'CONF=' + _vm.debugLevel] if mx.get_opts().verbose: cmd.append('LOG=debug') cmd.extend(args) if mx.get_opts().use_jdk_image and 'images' not in args: cmd.append('images') if not mx.get_opts().verbose: mx.log('--------------- make execution ----------------------') mx.log('Working directory: ' + _jdkSourceRoot) mx.log('Command line: ' + ' '.join(cmd)) mx.log('-----------------------------------------------------') mx.run(cmd, cwd=_jdkSourceRoot)
def mx_post_parse_cmd_line(opts): mx.addJDKFactory(_JVMCI_JDK_TAG, mx.JavaCompliance('9'), JVMCIJDKFactory()) mx.set_java_command_default_jdk_tag(_JVMCI_JDK_TAG) jdkTag = mx.get_jdk_option().tag jvmVariant = None debugLevel = None jvmciMode = None if opts.jdk_jvm_variant is not None: jvmVariant = opts.jdk_jvm_variant if jdkTag and jdkTag != _JVMCI_JDK_TAG: mx.warn( 'Ignoring "--jdk-jvm-variant" option as "--jdk" tag is not "' + _JVMCI_JDK_TAG + '"') if opts.jdk_debug_level is not None: debugLevel = _translateLegacyDebugLevel(opts.jdk_debug_level) if jdkTag and jdkTag != _JVMCI_JDK_TAG: mx.warn( 'Ignoring "--jdk-debug-level" option as "--jdk" tag is not "' + _JVMCI_JDK_TAG + '"') if opts.jvmci_mode is not None: jvmciMode = opts.jvmci_mode if jdkTag and jdkTag != _JVMCI_JDK_TAG: mx.warn('Ignoring "--jvmci-mode" option as "--jdk" tag is not "' + _JVMCI_JDK_TAG + '"') _vm.update(jvmVariant, debugLevel, jvmciMode) for jdkDist in jdkDeployedDists: jdkDist.post_parse_cmd_line()
def build(self): if hasattr(self.args, "jdt") and self.args.jdt and not self.args.force_javac: return _output_dir = join(_suite.dir, self.subject.outputDir) cp = mx.classpath('com.oracle.truffle.js.snapshot') tool_main_class = 'com.oracle.truffle.js.snapshot.SnapshotTool' _output_dir_bin = join(_output_dir, "bin") mx.ensure_dir_exists(_output_dir_bin) mx.run_java(['-cp', cp, tool_main_class, '--binary', '--internal'] + ['--outdir=' + _output_dir_bin], cwd=_output_dir_bin) _output_dir_src_gen = join(_output_dir, "src_gen") mx.ensure_dir_exists(_output_dir_src_gen) mx.run_java(['-cp', cp, tool_main_class, '--java', '--internal'] + ['--outdir=' + _output_dir_src_gen], cwd=_output_dir_src_gen) compliance = mx.JavaCompliance("1.8") jdk = mx.get_jdk(compliance, tag=mx.DEFAULT_JDK_TAG) java_file_list = [] for root, _, files in os.walk(_output_dir_src_gen, followlinks=True): java_file_list += [ join(root, name) for name in files if name.endswith('.java') ] java_file_list = sorted(java_file_list) # for reproducibility mx.run([ jdk.javac, '-source', str(compliance), '-target', str(compliance), '-classpath', mx.classpath('com.oracle.truffle.js.parser'), '-d', _output_dir_bin ] + java_file_list)
def jackpot(args, suite=None, nonZeroIsFatal=False): """run Jackpot 11.1 against non-test Java projects""" jackpotHome = mx.get_env('JACKPOT_HOME', None) if jackpotHome: jackpotJar = join(jackpotHome, 'jackpot.jar') else: jackpotJar = mx.library('JACKPOT').get_path(resolve=True) assert exists(jackpotJar) if suite is None: suite = mx.primary_suite() nonTestProjects = [p for p in mx.projects() if _should_test_project(p)] if not nonTestProjects: return 0 groups = [] for p in nonTestProjects: javacClasspath = [] deps = [] p.walk_deps(visit=lambda dep, edge: deps.append(dep) if dep.isLibrary() or dep.isJavaProject() else None) annotationProcessorOnlyDeps = [] if len(p.annotation_processors()) > 0: for apDep in p.annotation_processors(): if not apDep in deps: deps.append(apDep) annotationProcessorOnlyDeps.append(apDep) for dep in deps: if dep == p: continue if dep in annotationProcessorOnlyDeps: continue javacClasspath.append(dep.classpath_repr(resolve=True)) sourceLevel = min(p.javaCompliance.value, 9) groups = groups + ['--group', "--classpath " + mx._separatedCygpathU2W(_escape_string(os.pathsep.join(javacClasspath))) + " --source " + str(sourceLevel) + " " + " ".join([_escape_string(d) for d in p.source_dirs()])] cmd = ['--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED', '--add-opens=java.base/java.net=ALL-UNNAMED', '--add-opens=java.desktop/sun.awt=ALL-UNNAMED'] cmd = cmd + ['-classpath', mx._cygpathU2W(jackpotJar), 'org.netbeans.modules.jackpot30.cmdline.Main'] jackCmd = ['--fail-on-warnings', '--progress'] + args + groups jdk = mx.get_jdk(mx.JavaCompliance("11+"), cancel='cannot run Jackpot', purpose="run Jackpot") if jdk is None: mx.warn('Skipping Jackpot since JDK 11+ is not available') return 0 else: with tempfile.NamedTemporaryFile(mode='w', suffix='.jackpot') as f: for c in jackCmd: print(c, file=f) f.flush() ret = mx.run_java(cmd + ['@' + f.name], nonZeroIsFatal=nonZeroIsFatal, jdk=jdk) if ret != 0: mx.warn('To simulate the failure execute `mx -p {0} jackpot`.'.format(suite.dir)) mx.warn('To fix the error automatically try `mx -p {0} jackpot --apply`'.format(suite.dir)) return ret
def _runmake(args): """run the JDK make process To build hotspot and import it into the JDK: "mx make hotspot import-hotspot" {0}""" jdkBuildDir = _get_jdk_build_dir() if not exists(jdkBuildDir): # JDK9 must be bootstrapped with a JDK8 compliance = mx.JavaCompliance('8') jdk8 = mx.get_jdk(compliance.exactMatch, versionDescription=compliance.value) cmd = [ 'sh', 'configure', '--with-debug-level=' + _vm.debugLevel, '--with-native-debug-symbols=external', '--disable-precompiled-headers', '--with-jvm-variants=' + _vm.jvmVariant, '--disable-warnings-as-errors', '--with-boot-jdk=' + jdk8.home ] mx.run(cmd, cwd=_jdkSourceRoot) cmd = [mx.gmake_cmd(), 'CONF=' + _vm.debugLevel] if mx.get_opts().verbose: cmd.append('LOG=debug') cmd.extend(args) if mx.get_opts().use_jdk_image and 'images' not in args: cmd.append('images') if not mx.get_opts().verbose: mx.log('--------------- make execution ----------------------') mx.log('Working directory: ' + _jdkSourceRoot) mx.log('Command line: ' + ' '.join(cmd)) mx.log('-----------------------------------------------------') mx.run(cmd, cwd=_jdkSourceRoot) if 'images' in cmd: jdkImageDir = join(jdkBuildDir, 'images', 'jdk') # The OpenJDK build creates an empty cacerts file so copy one from # the default JDK (which is assumed to be an OracleJDK) srcCerts = join( mx.get_jdk(tag='default').home, 'lib', 'security', 'cacerts') if not exists(srcCerts): # Might be building with JDK8 which has cacerts under jre/ srcCerts = join( mx.get_jdk(tag='default').home, 'jre', 'lib', 'security', 'cacerts') dstCerts = join(jdkImageDir, 'lib', 'security', 'cacerts') shutil.copyfile(srcCerts, dstCerts) _create_jdk_bundle(jdkBuildDir, _vm.debugLevel, jdkImageDir)
self._original = original mx.JDKConfig.__init__(self, original.home, tag=_JVMCI_JDK_TAG) def run_java(self, args, **kwArgs): run_java(self._original, args, **kwArgs) class GraalJDKFactory(mx.JDKFactory): def getJDKConfig(self): return GraalJVMCI9JDKConfig(_jdk) def description(self): return "JVMCI JDK with Graal" # This will override the 'generic' JVMCI JDK with a Graal JVMCI JDK that has # support for -G style Graal options. mx.addJDKFactory(_JVMCI_JDK_TAG, mx.JavaCompliance('9'), GraalJDKFactory()) def run_vm(args, vm=None, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None, debugLevel=None, vmbuild=None): """run a Java program by executing the java executable in a JVMCI JDK""" return run_java(_jdk, args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) class GraalArchiveParticipant: def __init__(self, dist): self.dist = dist def __opened__(self, arc, srcArc, services): self.services = services self.arc = arc def __add__(self, arcname, contents):
def svm_java80(): return svm_java_compliance() <= mx.JavaCompliance('1.8')
def sonarqube_upload(args): """run SonarQube scanner and upload JaCoCo results""" sonarqube_cli = mx.library("SONARSCANNER_CLI_4_2_0_1873", True) parser = ArgumentParser(prog='mx sonarqube-upload') parser.add_argument('--exclude-generated', action='store_true', help='Exclude generated source files') parser.add_argument('--skip-coverage', action='store_true', default=False, help='Do not upload coverage reports') args, sonar_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=True) args, other_args = parser.parse_known_args(args) java_props, other_args = _parse_java_properties(other_args) def _check_required_prop(prop): if prop not in java_props: mx.abort("Required property '{prop}' not present. (Format is '-D{prop}=<value>')".format(prop=prop)) _check_required_prop('sonar.projectKey') _check_required_prop('sonar.host.url') basedir = mx.primary_suite().dir # collect excluded projects excludes, includes = _jacoco_excludes_includes_projects(limit_to_primary=True) # collect excluded classes exclude_classes = _jacoco_exclude_classes(includes) java_bin = [] java_src = [] java_libs = [] def _visit_deps(dep, edge): if dep.isJARDistribution() or dep.isLibrary(): java_libs.append(dep.classpath_repr()) mx.walk_deps(includes, visit=_visit_deps) # collect all sources and binaries -- do exclusion later for p in includes: java_src.extend(p.source_dirs()) if not args.exclude_generated: gen_dir = p.source_gen_dir() if os.path.exists(gen_dir): java_src.append(gen_dir) java_bin.append(p.output_dir()) java_src = [os.path.relpath(s, basedir) for s in java_src] java_bin = [os.path.relpath(b, basedir) for b in java_bin] # Overlayed sources and classes must be excluded jdk_compliance = mx.get_jdk().javaCompliance overlayed_sources = [] overlayed_classfiles = {} for p in includes: if hasattr(p, "multiReleaseJarVersion") and jdk_compliance not in p.javaCompliance: # JDK9+ overlays for srcDir in p.source_dirs(): for root, _, files in os.walk(srcDir): for name in files: if name.endswith('.java') and name != 'package-info.java': overlayed_sources.append(join(os.path.relpath(root, basedir), name)) elif hasattr(p, "overlayTarget"): # JDK8 overlays target = mx.project(p.overlayTarget) overlay_sources = [] for srcDir in p.source_dirs(): for root, _, files in os.walk(srcDir): for name in files: if name.endswith('.java') and name != 'package-info.java': overlay_sources.append(join(os.path.relpath(root, srcDir), name)) print(p, target, overlay_sources) for srcDir in target.source_dirs(): for root, _, files in os.walk(srcDir): for name in files: if name.endswith('.java') and name != 'package-info.java': s = join(os.path.relpath(root, srcDir), name) if s in overlay_sources: overlayed = join(os.path.relpath(root, basedir), name) overlayed_sources.append(overlayed) for s in overlay_sources: classfile = join(os.path.relpath(target.output_dir(), basedir), s[:-len('java')] + 'class') with open(classfile, 'rb') as fp: overlayed_classfiles[classfile] = fp.read() exclude_dirs = [] for p in excludes: exclude_dirs.extend(p.source_dirs()) exclude_dirs.append(p.source_gen_dir()) javaCompliance = max([p.javaCompliance for p in includes]) if includes else mx.JavaCompliance('1.7') jacoco_exec = get_jacoco_dest_file() if not os.path.exists(jacoco_exec) and not args.skip_coverage: mx.abort('No JaCoCo report file found: ' + jacoco_exec) def _add_default_prop(key, value): if key not in java_props: java_props[key] = value # default properties _add_default_prop('sonar.java.source', str(javaCompliance)) _add_default_prop('sonar.projectBaseDir', basedir) if not args.skip_coverage: _add_default_prop('sonar.jacoco.reportPaths', jacoco_exec) _add_default_prop('sonar.sources', ','.join(java_src)) _add_default_prop('sonar.java.binaries', ','.join(java_bin)) _add_default_prop('sonar.java.libraries', ','.join(java_libs)) exclude_patterns = [os.path.relpath(e, basedir) + '**' for e in exclude_dirs] + \ overlayed_sources + \ list(set([os.path.relpath(match[0], basedir) for _, match in exclude_classes.items()])) if exclude_patterns: _add_default_prop('sonar.exclusions', ','.join(exclude_patterns)) _add_default_prop('sonar.coverage.exclusions', ','.join(exclude_patterns)) _add_default_prop('sonar.verbose', 'true' if mx._opts.verbose else 'false') with tempfile.NamedTemporaryFile(suffix="-sonarqube.properties", mode="w+") as fp: # prepare properties file fp.writelines(('{}={}\n'.format(k, v) for k, v in java_props.items())) fp.flush() # Since there's no options to exclude individual classes, # we temporarily delete the overlayed class files instead. for classfile in overlayed_classfiles: os.remove(classfile) try: # run sonarqube cli java_args = other_args + ['-Dproject.settings=' + fp.name, '-jar', sonarqube_cli.get_path(True)] + sonar_args exit_code = mx.run_java(java_args, nonZeroIsFatal=False) finally: # Restore temporarily deleted class files for classfile, data in overlayed_classfiles.items(): with open(classfile, 'wb') as cf: cf.write(data) if exit_code != 0: fp.seek(0) mx.abort('SonarQube scanner terminated with non-zero exit code: {}\n Properties file:\n{}'.format( exit_code, ''.join((' ' + l for l in fp.readlines()))))
def __init__(self, debugLevel): JVMCI9JDKConfig.__init__(self, debugLevel) def parseVmArgs(self, args, addDefaultArgs=True): return JVMCI9JDKConfig.parseVmArgs( self, _buildGOptionsArgs(args), addDefaultArgs=addDefaultArgs) jdk = GraalJDK9Config(jvmci_jdk.debugLevel) _graal_jdks['default'] = jdk return jdk class GraalJDKFactory(mx.JDKFactory): def getJDKConfig(self): return get_graal_jdk() def description(self): return "Graal JDK" # This will override the 'generic' JVMCI JDK with a Graal JVMCI JDK that has # support for -G style Graal options. mx.addJDKFactory(_JVMCI_JDK_TAG, mx.JavaCompliance(str(JVMCI_VERSION)), GraalJDKFactory()) def mx_post_parse_cmd_line(opts): add_bootclasspath_prepend(mx.distribution('truffle:TRUFFLE_API'))
from mx_substratevm_benchmark import run_js, host_vm_tuple, output_processors, rule_snippets # pylint: disable=unused-import from mx_unittest import _run_tests, _VMLauncher JVM_COMPILER_THREADS = 2 if mx.cpu_count() <= 4 else 4 GRAAL_COMPILER_FLAGS = [ '-XX:+UseJVMCICompiler', '-Dgraal.CompileGraalWithC1Only=false', '-XX:CICompilerCount=' + str(JVM_COMPILER_THREADS), '-Dtruffle.TrustAllTruffleRuntimeProviders=true', # GR-7046 '-Dgraal.VerifyGraalGraphs=false', '-Dgraal.VerifyGraalGraphEdges=false', '-Dgraal.VerifyGraalPhasesSize=false', '-Dgraal.VerifyPhases=false' ] if mx.get_jdk(tag='default').javaCompliance <= mx.JavaCompliance('1.8'): GRAAL_COMPILER_FLAGS += ['-XX:-UseJVMCIClassLoader'] else: # JVMCI access GRAAL_COMPILER_FLAGS += [ '--add-exports', 'jdk.internal.vm.ci/jdk.vm.ci.runtime=ALL-UNNAMED' ] GRAAL_COMPILER_FLAGS += [ '--add-exports', 'jdk.internal.vm.ci/jdk.vm.ci.code=ALL-UNNAMED' ] GRAAL_COMPILER_FLAGS += [ '--add-exports', 'jdk.internal.vm.ci/jdk.vm.ci.amd64=ALL-UNNAMED' ] # Reflective access GRAAL_COMPILER_FLAGS += [ '--add-exports', 'jdk.unsupported/sun.reflect=ALL-UNNAMED'
from __future__ import print_function import os import pipes from os.path import join, exists, basename import shutil import mx import mx_gate import mx_sdk_vm import mx_subst import mx_spotbugs # Fail early and clearly when trying to build with a too old JDK jdk = mx.get_jdk(mx.JavaCompliance('11+'), 'building TruffleRuby which requires JDK 11 or newer') if mx_sdk_vm.base_jdk_version() < 11: mx.abort('Building TruffleRuby requires JDK 11 or newer') if 'RUBY_BENCHMARKS' in os.environ: import mx_truffleruby_benchmark # pylint: disable=unused-import _suite = mx.suite('truffleruby') root = _suite.dir def add_ext_suffix(name): """ Adds the platform specific C extension suffix to a name """
def microbench(self, args): """run JMH microbenchmark projects""" parser = ArgumentParser( prog='mx microbench', description=microbench.__doc__, usage="%(prog)s [command options|VM options] [-- [JMH options]]") parser.add_argument('--jar', help='Explicitly specify micro-benchmark location') self.add_arguments(parser) known_args, args = parser.parse_known_args(args) vmArgs, jmhArgs = mx.extract_VM_args(args, useDoubleDash=True) vmArgs = self.parseVmArgs(vmArgs) # look for -f in JMH arguments forking = True for i in range(len(jmhArgs)): arg = jmhArgs[i] if arg.startswith('-f'): if arg == '-f' and (i + 1) < len(jmhArgs): arg += jmhArgs[i + 1] try: if int(arg[2:]) == 0: forking = False except ValueError: pass if known_args.jar: # use the specified jar args = ['-jar', known_args.jar] if not forking: args += vmArgs # we do not know the compliance level of the jar - assuming 1.8 self.javaCompliance = mx.JavaCompliance('1.8') else: # find all projects with a direct JMH dependency jmhProjects = [] for p in mx.projects_opt_limit_to_suites(): if 'JMH' in [x.name for x in p.deps]: jmhProjects.append(p) # get java compliance - 1.8 is minimum since we build jmh-runner with java 8 self.javaCompliance = max([p.javaCompliance for p in jmhProjects] + [mx.JavaCompliance('1.8')]) cp = mx.classpath([p.name for p in jmhProjects], jdk=mx.get_jdk(self.javaCompliance)) # execute JMH runner args = ['-cp', cp] if not forking: args += vmArgs args += ['org.openjdk.jmh.Main'] if forking: def quoteSpace(s): if " " in s: return '"' + s + '"' return s forkedVmArgs = map(quoteSpace, self.parseForkedVmArgs(vmArgs)) args += ['--jvmArgsPrepend', ' '.join(forkedVmArgs)] self.run_java(args + jmhArgs)
def _test(): """ Mx suite specific tests. """ from collections import namedtuple # JavaCompliance tests good_specs = [ (2, True), (1.2, True), (11, True), (200, True), ('2', True), ('1.2', True), ('1.8', True), ('1.5+', False), ('2..4', False), ('1.8..9', False), ('2..3,4+', False), ('2..3,4,7+', False), ('2..3,4..5,7+', False), ('2..3,4..5,7,8,9,10,15..18,120', False), ] bad_specs = [ 1, '1', '1.1', '1.10', '1.8..1.10', '1.10+', '2..1', '2..2', '1,,3', '1..3+', '1+,4..5', '13+ignored', '1..3,7..5', '4,7,1..3,', '4..5,1..3', ] range_case = namedtuple('range_case', ['spec', 'range_spec', 'should_match']) range_specs = [ range_case('1.8', '1.8', True), range_case('11', '11', True), range_case('17', '17', True), range_case('1.8', '1.7', False), range_case('1.8', '11', False), range_case('17', '1.8', False), range_case('1.8', '11..17', False), range_case('11', '11..17', True), range_case('15', '11..17', True), range_case('17', '11..17', True), range_case('19', '11..17', False), range_case('11..17', '11..17', True), range_case('13..14', '11..17', True), range_case('11..19', '11..17', False), range_case('16', '11..15,17', False), range_case('11..12,14..15', '11..15,17', True), range_case('11,12,13,14,15,16,17', '11..17', True), range_case('11+', '11..17', False), ] for spec, exact in good_specs: p = mx.JavaCompliance(spec) assert p._is_exact_bound() is exact, p # Just ensure these methods execute without exception p.as_version_check() p._values(stop=20) hash(p) if mx.get_opts().verbose: if isinstance(spec, str): spec = '"' + spec + '"' mx.log('{}: str="{}", repr="{}", hash={}'.format( spec, str(p), repr(p), hash(p))) for spec in bad_specs: class SpecError(Exception): pass def _parse_error(msg): if mx.get_opts().verbose: mx.log('saw expected SpecError: ' + msg) raise SpecError(msg) try: mx.JavaCompliance(spec, parse_error=_parse_error) mx.abort('expected SpecError while parsing "{}"'.format(spec)) except SpecError: pass for spec, range_spec, should_match in range_specs: match = spec in mx.JavaCompliance(range_spec) assert match == should_match, '"{}" in "{}" should returns {}'.format( spec, range_spec, should_match)
def _test(): """ Mx suite specific tests. """ # JavaCompliance tests good_specs = [ (2, True), (1.2, True), (11, True), (200, True), ('2', True), ('1.2', True), ('1.8', True), ('1.5+', False), ('2..4', False), ('1.8..9', False), ('2..3,4+', False), ('2..3,4,7+', False), ('2..3,4..5,7+', False), ('2..3,4..5,7,8,9,10,15..18,120', False), ] bad_specs = [ 1, '1', '1.1', '1.10', '1.8..1.10', '1.10+', '2..1', '2..2', '1,,3', '1..3+', '1+,4..5', '13+ignored', '1..3,7..5', '4,7,1..3,', '4..5,1..3', ] for spec, exact in good_specs: p = mx.JavaCompliance(spec) assert p._is_exact_bound() is exact, p # Just ensure these methods execute without exception p.as_version_check() p._values(stop=20) hash(p) if mx.get_opts().verbose: if isinstance(spec, str): spec = '"' + spec + '"' mx.log('{}: str="{}", repr="{}", hash={}'.format( spec, str(p), repr(p), hash(p))) for spec in bad_specs: class SpecError(Exception): pass def _parse_error(msg): if mx.get_opts().verbose: mx.log('saw expected SpecError: ' + msg) raise SpecError(msg) try: mx.JavaCompliance(spec, parse_error=_parse_error) mx.abort('expected SpecError while parsing "{}"'.format(spec)) except SpecError: pass