def _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex, suite): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) candidates = find_test_candidates(annotations, suite, vmLauncher.jdk()) classes, depsContainingTests = _filter_test_candidates(candidates, tests) full_ignorelist = blacklist or [] full_ignorelist += _global_ignore_globs if full_ignorelist: classes = [ c for c in classes if not any((glob.match(c) for glob in full_ignorelist)) ] if whitelist: classes = [ c for c in classes if any((glob.match(c) for glob in whitelist)) ] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in sorted(classes): f_testfile.write(c + '\n') f_testfile.close() harness(depsContainingTests, vmLauncher, vmArgs)
def image_server_start(args, dumpArgs=False, timeout=None): """Run an SVM image build server on a defined port. If the port is not defined, the server is started on the default port 26681. In case a server is already running command will not start a new server. This is a convenience for downstream projects so they can always run `image_server_start` in their builds to obviate the need for developers to keep track of their servers. Options: -port=<port_number> port of the build server """ if dumpArgs: print(' '.join(['image_server_start'] + args)) port = extractPortNumber(args) running = image_server_running(port) if running: print("Native image build server is already running.") else: classpath = _classpath([svmDistribution]) extraVmArgs, extraNormalArgs = _parse_standard_arguments(False, args) vmArgs, normalArgs = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) noTruffleRuntimeVmArgs = [ arg for arg in vmArgs + extraVmArgs if not arg.startswith('-Dtruffle.TruffleRuntime=') ] run_java(['-Xss10m', '-Xms2G'] + GRAAL_COMPILER_FLAGS + ['-cp', classpath] + noTruffleRuntimeVmArgs + [ 'com.oracle.svm.hosted.server.NativeImageBuildServer', PORT_PREFIX + str(port) ] + normalArgs + extraNormalArgs, timeout=timeout)
def doImage(args, projects, imageVmArgs, imageNormalArgs, extraClassPath="", timeout=None): projects += [svmDistribution] if imageVmArgs is None: imageVmArgs = [] if imageNormalArgs is None: imageNormalArgs = [] extraVmArgs, extraNormalArgs = _parse_standard_arguments(False, args) server, port = processServerArguments(args) compilerClasspath = _classpath([svmDistribution]) cpVmArgs = mx.get_runtime_jvm_args([librarySupportDistribution] + projects, cp_suffix=extraClassPath, jdk=mx_compiler.jdk) (idx, classpath) = mx.find_classpath_arg(cpVmArgs) imageVmArgs += cpVmArgs[:idx-1] + cpVmArgs[idx+1:] classpathlist = list(set(classpath.split(os.pathsep))) classpath = os.pathsep.join(classpathlist) vmArgs, normalArgs = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) imageGenArgs = extraNormalArgs + imageNormalArgs + normalArgs if mx._opts.strip_jars: imageGenArgs += ['-H:-VerifyNamingConventions'] run_executable(server, port, imageVmArgs + extraVmArgs + vmArgs, 'com.oracle.svm.hosted.NativeImageGeneratorRunner', compilerClasspath, classpath, imageGenArgs, timeout=timeout)
def microbench(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') known_args, args = parser.parse_known_args(args) vmArgs, jmhArgs = mx.extract_VM_args(args, useDoubleDash=True) if JVMCI_VERSION < 9: if isJVMCIEnabled( get_vm()) and '-XX:-UseJVMCIClassLoader' not in vmArgs: vmArgs = ['-XX:-UseJVMCIClassLoader'] + 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 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.name) cp = mx.classpath(jmhProjects) # execute JMH runner args = ['-cp', cp] if not forking: args += vmArgs args += ['org.openjdk.jmh.Main'] if forking: jdk = get_jvmci_jdk() jvm = get_vm() def quoteSpace(s): if " " in s: return '"' + s + '"' return s forkedVmArgs = map(quoteSpace, jdk.parseVmArgs(vmArgs)) args += ['--jvmArgsPrepend', ' '.join(['-' + jvm] + forkedVmArgs)] run_vm(args + jmhArgs)
def repl(args): """run a simple command line debugger for Truffle-implemented languages on the class path""" vmArgs, slArgs = mx.extract_VM_args(args, useDoubleDash=True) mx.run_java( vmArgs + _path_args() + ["com.oracle.truffle.tools.debug.shell.client.SimpleREPLClient"] + slArgs)
def run_mg_internal(args, verbose=False, extraVmArgs=None, env=None, jdk=None, **kwargs): vmArgs, mgArgs = mx.extract_VM_args(args) vmArgs = ['-cp', mx.classpath(["edu.uci.megaguards"])] vmArgs.append("edu.uci.megaguards.shell.MGMain") if not jdk: jdk = get_jdk() out = mx.OutputCapture() _out = out if not verbose else mx.TeeOutputCapture(out) out_err = mx.OutputCapture() _out_err = out if not verbose else mx.TeeOutputCapture(out_err) n = 3 for t in range(n): retcode = mx.run_java(vmArgs + [mgArgs], out=_out, err=_out_err, jdk=jdk, **kwargs) if retcode == 0: break return out.data
def _run_benchmark(args, availableBenchmarks, runBenchmark): vmOpts, benchmarksAndOptions = mx.extract_VM_args( args, useDoubleDash=availableBenchmarks is None) if availableBenchmarks is None: harnessArgs = benchmarksAndOptions return runBenchmark(None, harnessArgs, vmOpts) if len(benchmarksAndOptions) == 0: mx.abort('at least one benchmark name or "all" must be specified') benchmarks = list( itertools.takewhile(lambda x: not x.startswith('-'), benchmarksAndOptions)) harnessArgs = benchmarksAndOptions[len(benchmarks):] if 'all' in benchmarks: benchmarks = availableBenchmarks else: for bm in benchmarks: if bm not in availableBenchmarks: mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(availableBenchmarks)) failed = [] for bm in benchmarks: if not runBenchmark(bm, harnessArgs, vmOpts): failed.append(bm) if len(failed) != 0: mx.abort('Benchmark failures: ' + str(failed))
def _run_benchmark(args, availableBenchmarks, runBenchmark): vmOpts, benchmarksAndOptions = mx.extract_VM_args(args, useDoubleDash=availableBenchmarks is None) if availableBenchmarks is None: harnessArgs = benchmarksAndOptions return runBenchmark(None, harnessArgs, vmOpts) if len(benchmarksAndOptions) == 0: mx.abort('at least one benchmark name or "all" must be specified') benchmarks = list(itertools.takewhile(lambda x: not x.startswith('-'), benchmarksAndOptions)) harnessArgs = benchmarksAndOptions[len(benchmarks):] if 'all' in benchmarks: benchmarks = availableBenchmarks else: for bm in benchmarks: if bm not in availableBenchmarks: mx.abort('unknown benchmark: ' + bm + '\nselect one of: ' + str(availableBenchmarks)) failed = [] for bm in benchmarks: if not runBenchmark(bm, harnessArgs, vmOpts): failed.append(bm) if len(failed) != 0: mx.abort('Benchmark failures: ' + str(failed))
def do_run_python(args, extraVmArgs=None, jdk=None, **kwargs): check_vm_env = os.environ.get('ZIPPY_MUST_USE_GRAAL') if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() vmArgs, zippyArgs = mx.extract_VM_args(args) vmArgs = ['-cp', mx.classpath(["edu.uci.python"])] if not jdk: jdk = get_jdk() vmArgs += _graal_heuristics_options() # default: assertion checking is enabled if extraVmArgs is None or not '-da' in extraVmArgs: vmArgs += ['-ea', '-esa'] if extraVmArgs: vmArgs += extraVmArgs # vmArgs = _sanitize_vmArgs(jdk, vmArgs) # if len(zippyArgs) > 0: vmArgs.append("edu.uci.python.shell.Shell") # else: # print 'Interactive shell is not implemented yet..' # sys.exit(1) return mx.run_java(vmArgs + args, jdk=jdk, **kwargs)
def sl(args): """run an SL program""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + _path_args([ "TRUFFLE_API", "com.oracle.truffle.sl", "com.oracle.truffle.sl.launcher" ]) + ["com.oracle.truffle.sl.launcher.SLMain"] + slArgs)
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 microbench(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") known_args, args = parser.parse_known_args(args) vmArgs, jmhArgs = mx.extract_VM_args(args, useDoubleDash=True) if JVMCI_VERSION < 9: if isJVMCIEnabled(get_vm()) and "-XX:-UseJVMCIClassLoader" not in vmArgs: vmArgs = ["-XX:-UseJVMCIClassLoader"] + 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 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.name) cp = mx.classpath(jmhProjects) # execute JMH runner args = ["-cp", cp] if not forking: args += vmArgs args += ["org.openjdk.jmh.Main"] if forking: jdk = get_jvmci_jdk() jvm = get_vm() def quoteSpace(s): if " " in s: return '"' + s + '"' return s forkedVmArgs = map(quoteSpace, jdk.parseVmArgs(vmArgs)) args += ["--jvmArgsPrepend", " ".join(["-" + jvm] + forkedVmArgs)] run_vm(args + jmhArgs)
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs): if not env: env = os.environ check_vm_env = env.get('GRAALPYTHON_MUST_USE_GRAAL', False) if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() dists = ['GRAALPYTHON', 'TRUFFLE_NFI', 'SULONG'] env["PYTHONUSERBASE"] = mx_subst.path_substitutions.substitute( "<path:PYTHON_USERBASE>") vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) graalpython_args, additional_dists = _extract_graalpython_internal_options( graalpython_args) dists += additional_dists if mx.suite("sulong-managed", fatalIfMissing=False): dists.append('SULONG_MANAGED') # Try eagerly to include tools for convenience when running Python if not mx.suite("tools", fatalIfMissing=False): SUITE.import_suite("tools", version=None, urlinfos=None, in_subdir=True) if mx.suite("tools", fatalIfMissing=False): if os.path.exists( mx.suite("tools").dependency("CHROMEINSPECTOR").path): # CHROMEINSPECTOR was built, put it on the classpath dists.append('CHROMEINSPECTOR') graalpython_args.insert(0, "--llvm.enableLVI=true") else: mx.logv( "CHROMEINSPECTOR was not built, not including it automatically" ) graalpython_args.insert(0, '--experimental-options=true') graalpython_args.insert(1, '-ensure-capi') vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk) if not jdk: jdk = get_jdk() # default: assertion checking is enabled if extra_vm_args is None or '-da' not in extra_vm_args: vm_args += ['-ea', '-esa'] if extra_vm_args: vm_args += extra_vm_args vm_args.append("com.oracle.graal.python.shell.GraalPythonMain") return mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, **kwargs)
def sl(args): """run an SL program""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + [ '-cp', mx.classpath(["TRUFFLE_API", "com.oracle.truffle.sl"]), "com.oracle.truffle.sl.SLMain" ] + slArgs)
def _brainfck_standalone_command(args): """Brainf*ck standalone command from distribution jars + arguments""" vm_args, args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) return (vm_args + mx.get_runtime_jvm_args( ['BRAINFCK', 'BRAINFCK_LAUNCHER'], jdk=mx.get_jdk()) + [mx.distribution('BRAINFCK_LAUNCHER').mainClass] + args)
def slcoverage(args): """Demo: run an SL program with coverage counts printed when done""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + [ '-cp', mx.classpath("com.oracle.truffle.sl.tools"), "com.oracle.truffle.sl.tools.SLCoverage" ] + slArgs)
def sldebug(args): """run a simple command line debugger for the Simple Language""" vmArgs, slArgs = mx.extract_VM_args(args, useDoubleDash=True) mx.run_java(vmArgs + [ '-cp', mx.classpath("com.oracle.truffle.sl.tools"), "com.oracle.truffle.sl.tools.debug.SLREPLServer" ] + slArgs)
def sl(args): """run an SL program""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java( vmArgs + ["-cp", mx.classpath(["TRUFFLE_API", "com.oracle.truffle.sl"]), "com.oracle.truffle.sl.SLLanguage"] + slArgs )
def sldebug(args): """run a simple command line debugger for the Simple Language""" vmArgs, slArgs = mx.extract_VM_args(args, useDoubleDash=True) mx.run_java( vmArgs + ["-cp", mx.classpath("com.oracle.truffle.sl.tools"), "com.oracle.truffle.sl.tools.debug.SLREPL"] + slArgs )
def _espresso_standalone_command(args): """Espresso standalone command from distribution jars + arguments""" vm_args, args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) return (vm_args + mx.get_runtime_jvm_args( ['ESPRESSO', 'ESPRESSO_LAUNCHER'], jdk=mx.get_jdk()) + [mx.distribution('ESPRESSO_LAUNCHER').mainClass] + args)
def pascal(args): """run a Pascal program""" vmArgs, pascalArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + [ '-cp', mx.classpath(["TRUFFLE_API", "com.oracle.truffle.pascal"]), "cz.cuni.mff.d3s.trupple.compiler.CompilerMain" ] + pascalArgs)
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 do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs): if not env: env = os.environ check_vm_env = env.get('GRAALPYTHON_MUST_USE_GRAAL', False) if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() dists = ['GRAALPYTHON'] vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) internal_graalpython_args, graalpython_args, additional_dists = _extract_graalpython_internal_options(graalpython_args) dists += additional_dists if '--python.WithJavaStacktrace' not in graalpython_args: graalpython_args.insert(0, '--python.WithJavaStacktrace') if _sulong: dists.append('SULONG') if mx.suite("sulong-managed", fatalIfMissing=False): dists.append('SULONG_MANAGED') vm_args.append(mx_subst.path_substitutions.substitute('-Dpolyglot.llvm.libraryPath=<path:SULONG_LIBS>:<path:SULONG_MANAGED_LIBS>')) else: vm_args.append(mx_subst.path_substitutions.substitute('-Dpolyglot.llvm.libraryPath=<path:SULONG_LIBS>')) # Try eagerly to include tools on Tim's computer if not mx.suite("/tools", fatalIfMissing=False): def _is_user(user, home=None): if home: return os.environ.get("USER") == user and os.environ.get(home) return os.environ.get("USER") == user if _is_user("tim", "MAGLEV_HOME") or _is_user("cbasca") or _is_user("fa"): _suite.import_suite("tools", version=None, urlinfos=None, in_subdir=True) dists.append('CHROMEINSPECTOR') if _sulong: vm_args.append("-Dpolyglot.llvm.enableLVI=true") vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk) vm_args += internal_graalpython_args if not jdk: jdk = get_jdk() # default: assertion checking is enabled if extra_vm_args is None or '-da' not in extra_vm_args: vm_args += ['-ea', '-esa'] if extra_vm_args: vm_args += extra_vm_args vm_args.append("com.oracle.graal.python.shell.GraalPythonMain") return mx.run_java(vm_args + graalpython_args, jdk=jdk, **kwargs)
def wasm(args): """Run a WebAssembly program.""" mx.get_opts().jdk = "jvmci" vmArgs, wasmArgs = mx.extract_VM_args(args, True) path_args = mx.get_runtime_jvm_args([ "TRUFFLE_API", "org.graalvm.wasm", "org.graalvm.wasm.launcher", ] + (['tools:CHROMEINSPECTOR', 'tools:TRUFFLE_PROFILER', 'tools:AGENTSCRIPT'] if mx.suite('tools', fatalIfMissing=False) is not None else [])) mx.run_java(vmArgs + path_args + ["org.graalvm.wasm.launcher.WasmLauncher"] + wasmArgs)
def wasm(args): """Run a WebAssembly program.""" mx.get_opts().jdk = "jvmci" vmArgs, wasmArgs = mx.extract_VM_args(args) path_args = mx_truffle._path_args([ "TRUFFLE_API", "org.graalvm.wasm", "org.graalvm.wasm.launcher", ]) mx.run_java(vmArgs + path_args + ["org.graalvm.wasm.launcher.WasmLauncher"] + wasmArgs)
def microbench(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') known_args, args = parser.parse_known_args(args) vmArgs, jmhArgs = mx.extract_VM_args(args, useDoubleDash=True) # 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 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.name) cp = mx.classpath(jmhProjects) # execute JMH runner args = ['-cp', cp] if not forking: args += vmArgs args += ['org.openjdk.jmh.Main'] if forking: jvm = get_vm() def quoteSpace(s): if " " in s: return '"' + s + '"' return s forkedVmArgs = map(quoteSpace, _parseVmArgs(_jdk, vmArgs)) args += ['--jvmArgsPrepend', ' '.join(['-' + jvm] + forkedVmArgs)] run_vm(args + jmhArgs)
def squeak(args, extra_vm_args=None, env=None, jdk=None, **kwargs): if not env: env = os.environ check_vm_env = env.get('GRAALPYTHON_MUST_USE_GRAAL', False) if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() vm_args, squeak_args = mx.extract_VM_args(args, useDoubleDash=False, defaultAllVMArgs=False) classpath = ["de.hpi.swa.trufflesqueak"] if mx.suite("tools-enterprise", fatalIfMissing=False): classpath.append("tools-enterprise:CHROMEINSPECTOR") vm_args = ['-cp', mx.classpath(classpath)] if not jdk: jdk = mx.get_jdk() vm_args += [ # '-XX:+UseJVMCICompiler', # '-Djvmci.Compiler=graal', # '-Dgraal.TraceTruffleCompilation=true', # '-Dgraal.Dump=', # '-Dgraal.MethodFilter=Truffle.*', # '-XX:CompileCommand=print,*OptimizedCallTarget.callRoot', # '-XX:CompileCommand=exclude,*OptimizedCallTarget.callRoot', # '-Dgraal.TruffleBackgroundCompilation=false', # '-Dgraal.TruffleCompileImmediately=true', # '-Dgraal.TraceTrufflePerformanceWarnings=true', # '-Dgraal.TruffleCompilationExceptionsArePrinted=true', ] # default: assertion checking is enabled if extra_vm_args is None or '-da' not in extra_vm_args: vm_args += ['-ea', '-esa'] if extra_vm_args: vm_args += extra_vm_args vm_args.append("de.hpi.swa.trufflesqueak.TruffleSqueakMain") return mx.run_java(vm_args + squeak_args, jdk=jdk, **kwargs)
def do_run_python(args, extraVmArgs=None, env=None, jdk=None, **kwargs): if _zippy_help_options(args): sys.exit(1) if not env: env = os.environ if not 'ZIPPY_HOME' in env: env['ZIPPY_HOME'] = _suite.dir check_vm_env = env[ 'ZIPPY_MUST_USE_GRAAL'] if 'ZIPPY_MUST_USE_GRAAL' in env else None if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() vmArgs, zippyArgs = mx.extract_VM_args(args) internalZippyArgs, zippyArgs = _extract_zippy_internal_options(zippyArgs) vmArgs = internalZippyArgs + ['-cp', mx.classpath(["edu.uci.python"])] if not jdk: jdk = get_jdk() vmArgs += _graal_heuristics_options(_mx_graal) # default: assertion checking is enabled # if extraVmArgs is None or not '-da' in extraVmArgs: # vmArgs += ['-ea', '-esa'] if extraVmArgs: vmArgs += extraVmArgs # vmArgs = _sanitize_vmArgs(jdk, vmArgs) # if len(zippyArgs) > 0: vmArgs.append("edu.uci.python.shell.ZipPyMain") # else: # print 'Interactive shell is not implemented yet..' # sys.exit(1) return mx.run_java(vmArgs + zippyArgs, jdk=jdk, **kwargs)
def ruby_check_heap_dump(input_args, out=None): print("mx ruby_check_heap_dump " + " ".join(input_args)) args = input_args args.insert(0, "--experimental-options") dists = ['TRUFFLERUBY', 'TRUFFLE_NFI', 'SULONG_NATIVE', 'TRUFFLERUBY-TEST'] vm_args, truffleruby_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) vm_args += mx.get_runtime_jvm_args(dists) # vm_args.append("-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y") vm_args.append("org.truffleruby.LeakTest") out = mx.OutputCapture() if out is None else out retval = mx.run_java(vm_args + truffleruby_args, jdk=jdk, nonZeroIsFatal=False, out=out) if retval == 0: print("PASSED") print(out.data) elif os.environ.get("CI") and "--keep-dump" not in input_args: # rerun once with heap dumping enabled out = mx.OutputCapture() ruby_check_heap_dump(["--keep-dump"] + input_args, out=out) path = out.data.strip().partition("Dump file:")[2].strip() if path: save_path = os.path.join(root, "dumps", "leak_test") try: os.makedirs(save_path) except OSError: pass dest = shutil.copy(path, save_path) # pylint: disable=assignment-from-no-return print("Heapdump file kept in " + dest) raise Exception("heap dump check failed") else: print("FAILED") print(out.data) raise Exception("heap dump check failed")
def _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex, suite): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) # this is what should be used compat_suite = suite if suite else mx.primary_suite() if suite != mx._mx_suite and compat_suite.getMxCompatibility( ).useDistsForUnittest(): jar_distributions = [ d for d in mx.sorted_dists() if d.isJARDistribution() and exists(d.classpath_repr( resolve=False)) and (not suite or d.suite == suite) ] # find a corresponding distribution for each test candidates = _find_classes_by_annotated_methods( annotations, jar_distributions, vmLauncher.jdk()) else: binary_deps = [ d for d in mx.dependencies(opt_limit_to_suite=True) if d.isJARDistribution() and isinstance(d.suite, mx.BinarySuite) and (not suite or suite == d.suite) ] candidates = _find_classes_by_annotated_methods( annotations, binary_deps, vmLauncher.jdk()) for p in mx.projects(opt_limit_to_suite=True): if not p.isJavaProject(): continue if suite and not p.suite == suite: continue if vmLauncher.jdk().javaCompliance < p.javaCompliance: continue for c in _find_classes_with_annotations(p, None, annotations): candidates[c] = p classes = [] if len(tests) == 0: classes = candidates.keys() depsContainingTests = set(candidates.values()) else: depsContainingTests = set() found = False if len(tests) == 1 and '#' in tests[0]: words = tests[0].split('#') if len(words) != 2: mx.abort("Method specification is class#method: " + tests[0]) t, method = words for c, p in candidates.iteritems(): # prefer exact matches first if t == c: found = True classes.append(c) depsContainingTests.add(p) if not found: for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.warn('no tests matched by substring: ' + t + ' (did you forget to run "mx build"?)') elif len(classes) != 1: mx.abort('More than one test matches substring {0} {1}'.format( t, classes)) classes = [c + "#" + method for c in classes] else: for t in tests: if '#' in t: mx.abort( 'Method specifications can only be used in a single test: ' + t) for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.warn('no tests matched by substring: ' + t + ' (did you forget to run "mx build"?)') if blacklist: classes = [ c for c in classes if not any((glob.match(c) for glob in blacklist)) ] if whitelist: classes = [ c for c in classes if any((glob.match(c) for glob in whitelist)) ] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in classes: f_testfile.write(c + '\n') f_testfile.close() harness(depsContainingTests, vmLauncher, vmArgs)
def _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) candidates = {} for p in mx.projects_opt_limit_to_suites(): if mx.java().javaCompliance < p.javaCompliance: continue for c in _find_classes_with_annotations(p, None, annotations).keys(): candidates[c] = p classes = [] if len(tests) == 0: classes = candidates.keys() projectsCp = mx.classpath([pcp.name for pcp in mx.projects_opt_limit_to_suites() if pcp.javaCompliance <= mx.java().javaCompliance]) else: projs = set() found = False if len(tests) == 1 and '#' in tests[0]: words = tests[0].split('#') if len(words) != 2: mx.abort("Method specification is class#method: " + tests[0]) t, method = words for c, p in candidates.iteritems(): # prefer exact matches first if t == c: found = True classes.append(c) projs.add(p.name) if not found: for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) projs.add(p.name) if not found: mx.log('warning: no tests matched by substring "' + t) elif len(classes) != 1: mx.abort('More than one test matches substring {0} {1}'.format(t, classes)) classes = [c + "#" + method for c in classes] else: for t in tests: if '#' in t: mx.abort('Method specifications can only be used in a single test: ' + t) for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) projs.add(p.name) if not found: mx.log('warning: no tests matched by substring "' + t) projectsCp = mx.classpath(projs) if blacklist: classes = [c for c in classes if not any((glob.match(c) for glob in blacklist))] if whitelist: classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in classes: f_testfile.write(c + '\n') f_testfile.close() harness(projectsCp, vmLauncher, vmArgs)
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 _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex, suite): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) # this is what should be used compat_suite = suite if suite else mx.primary_suite() if suite != mx._mx_suite and compat_suite.getMxCompatibility().useDistsForUnittest(): jar_distributions = [d for d in mx.sorted_dists() if d.isJARDistribution() and (not suite or d.suite == suite)] # find a corresponding distribution for each test candidates = _find_classes_by_annotated_methods(annotations, jar_distributions, vmLauncher.jdk()) else: binary_deps = [d for d in mx.dependencies(opt_limit_to_suite=True) if d.isJARDistribution() and isinstance(d.suite, mx.BinarySuite) and (not suite or suite == d.suite)] candidates = _find_classes_by_annotated_methods(annotations, binary_deps, vmLauncher.jdk()) for p in mx.projects(opt_limit_to_suite=True): if not p.isJavaProject(): continue if suite and not p.suite == suite: continue if vmLauncher.jdk().javaCompliance < p.javaCompliance: continue for c in _find_classes_with_annotations(p, None, annotations): candidates[c] = p classes = [] if len(tests) == 0: classes = candidates.keys() depsContainingTests = set(candidates.values()) else: depsContainingTests = set() found = False if len(tests) == 1 and '#' in tests[0]: words = tests[0].split('#') if len(words) != 2: mx.abort("Method specification is class#method: " + tests[0]) t, method = words for c, p in candidates.iteritems(): # prefer exact matches first if t == c: found = True classes.append(c) depsContainingTests.add(p) if not found: for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring: ' + t) elif len(classes) != 1: mx.abort('More than one test matches substring {0} {1}'.format(t, classes)) classes = [c + "#" + method for c in classes] else: for t in tests: if '#' in t: mx.abort('Method specifications can only be used in a single test: ' + t) for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring: ' + t) if blacklist: classes = [c for c in classes if not any((glob.match(c) for glob in blacklist))] if whitelist: classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in classes: f_testfile.write(c + '\n') f_testfile.close() harness(depsContainingTests, vmLauncher, vmArgs)
def repl(args): """run a simple command line debugger for Truffle-implemented languages on the class path""" vmArgs, slArgs = mx.extract_VM_args(args, useDoubleDash=True) mx.run_java(vmArgs + _path_args() + ["com.oracle.truffle.tools.debug.shell.client.SimpleREPLClient"] + slArgs)
def slcoverage(args): """Demo: run an SL program with coverage counts printed when done""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl.tools"), "com.oracle.truffle.sl.tools.SLCoverage"] + slArgs)
def _squeak(args, extra_vm_args=None, env=None, jdk=None, **kwargs): """run TruffleSqueak""" env = env if env else os.environ vm_args, raw_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) parser = argparse.ArgumentParser(prog='mx squeak') parser.add_argument('-A', '--assertions', help='enable assertion', dest='assertions', action='store_true', default=False) parser.add_argument('-B', '--no-background', help='disable background compilation', dest='background_compilation', action='store_false', default=True) parser.add_argument('-c', '--code', help='Smalltalk code to be executed in headless mode', dest='code') parser.add_argument('--cpusampler', help='enable CPU sampling', dest='cpusampler', action='store_true', default=False) parser.add_argument('--cputracer', help='enable CPU tracing', dest='cputracer', action='store_true', default=False) parser.add_argument('-d', '--disable-interrupts', help='disable interrupt handler', dest='disable_interrupts', action='store_true', default=False) parser.add_argument('--disable-startup', help='disable startup routine in headless mode', dest='disable_startup', action='store_true', default=False) parser.add_argument('-etf', '--enable-transcript-forwarding', help='Forward stdio to Transcript', dest='enable_transcript_forwarding', action='store_true', default=False) parser.add_argument('-fc', '--force-compilation', help='compile immediately to test Truffle compiler', dest='force_compilation', action='store_true', default=False) parser.add_argument('--gc', action='store_true', help='print garbage collection details') parser.add_argument('--graal-options', help='print Graal options', dest='print_graal_options', action='store_true', default=False) parser.add_argument('--headless', help='Run without a display', dest='headless', action='store_true', default=False) parser.add_argument('--igv', action='store_true', help='dump to igv') parser.add_argument('--inspect', help='enable Chrome inspector', dest='inspect', action='store_true', default=False) parser.add_argument('--jdk-ci-time', help='collect timing information for compilation ' '(contains `JVMCI-native` when libgraal is used)', dest='jdk_ci_time', action='store_true', default=False) parser.add_argument('-l', '--low-level', help='enable low-level optimization output', dest='low_level', action='store_true', default=False) parser.add_argument('--log', help='enable TruffleLogger for class, e.g.: ' '"%s.model.ArrayObject=FINER"' % PACKAGE_NAME, dest='log') parser.add_argument('--machine-code', help='print machine code', dest='print_machine_code', action='store_true', default=False) parser.add_argument('--memtracer', help='enable Memory tracing', dest='memtracer', action='store_true', default=False) parser.add_argument('--print-defaults', help='print VM defaults', dest='print_defaults', action='store_true', default=False) parser.add_argument('-tc', '--trace-compilation', help='trace Truffle compilation', dest='trace_compilation', action='store_true', default=False) parser.add_argument('-td', '--trace-deopts', help='trace deoptimizations', dest='deopts', action='store_true', default=False) parser.add_argument( '-ti', '--trace-invalid', help='trace assumption invalidation and transfers to interpreter', dest='trace_invalidation', action='store_true', default=False) parser.add_argument( '-tin', '--trace-inlining', help='print information for inlining for each compilation', dest='trace_inlining', action='store_true', default=False) parser.add_argument('-tio', '--trace-interop', help='trace interop errors, ...', dest='trace_interop', action='store_true', default=False) parser.add_argument('-tif', '--trace-iterate-frames', help='trace iterate frames', dest='trace_iterate_frames', action='store_true', default=False) parser.add_argument('-tpf', '--trace-primitive-failures', help='trace primitive failures', dest='trace_primitive_failures', action='store_true', default=False) parser.add_argument('-tps', '--trace-process-switches', help='trace Squeak process switches, ...', dest='trace_process_switches', action='store_true', default=False) parser.add_argument('-ts', '--trace-splitting', help='print splitting summary on shutdown', dest='trace_splitting', action='store_true', default=False) parser.add_argument('-tcd', '--truffle-compilation-details', help='print Truffle compilation details', dest='truffle_compilation_details', action='store_true', default=False) parser.add_argument( '-tcp', '--truffle-compilation-polymorphism', help='print all polymorphic and generic nodes after each compilation', dest='truffle_compilation_polymorphism', action='store_true', default=False) parser.add_argument( '-tcs', '--truffle-compilation-statistics', help='print Truffle compilation statistics at the end of a run', dest='truffle_compilation_stats', action='store_true', default=False) parser.add_argument('-teh', '--truffle-expansion-histogram', help='print a histogram of all expanded Java methods', dest='truffle_expansion_histogram', action='store_true', default=False) parser.add_argument( '-tib', '--truffle-instrument-boundaries', help='instrument Truffle boundaries and output profiling information', dest='truffle_instrument_boundaries', action='store_true', default=False) parser.add_argument('-v', '--verbose', help='enable verbose output', dest='verbose', action='store_true', default=False) parser.add_argument('-w', '--perf-warnings', help='enable performance warnings', dest='perf_warnings', action='store_true', default=False) parser.add_argument('image', help='path to Squeak image file', nargs='?') parser.add_argument('image_arguments', help='image arguments', nargs=argparse.REMAINDER) parsed_args = parser.parse_args(raw_args) vm_args = BASE_VM_ARGS + _get_runtime_jvm_args(jdk) if _compiler: vm_args += _graal_vm_args(parsed_args) # default: assertion checking is enabled if parsed_args.assertions: vm_args += ['-ea', '-esa'] if parsed_args.gc: vm_args += ['-XX:+PrintGC', '-XX:+PrintGCDetails'] if parsed_args.jdk_ci_time: vm_args.append('-XX:+CITime') if parsed_args.print_defaults: vm_args.append('-XX:+PrintFlagsFinal') if extra_vm_args: vm_args += extra_vm_args if parsed_args.code: vm_args.append('-Djava.awt.headless=true') vm_args.append('%s.launcher.TruffleSqueakLauncher' % PACKAGE_NAME) squeak_arguments = [] if parsed_args.disable_interrupts: squeak_arguments.append('--%s.disable-interrupts' % LANGUAGE_ID) if parsed_args.disable_startup: squeak_arguments.extend( ['--experimental-options', '--%s.disable-startup' % LANGUAGE_ID]) if parsed_args.headless: squeak_arguments.append('--%s.headless' % LANGUAGE_ID) if parsed_args.code: squeak_arguments.extend(['--code', parsed_args.code]) if parsed_args.cpusampler: squeak_arguments.append('--cpusampler') if parsed_args.cputracer: squeak_arguments.append('--cputracer') if parsed_args.enable_transcript_forwarding: squeak_arguments.append('--enable-transcript-forwarding') if parsed_args.inspect: squeak_arguments.append('--inspect') if parsed_args.trace_interop: parsed_args.log = 'interop=FINE' if parsed_args.trace_iterate_frames: parsed_args.log = 'iterate-frames=FINE' if parsed_args.trace_primitive_failures: parsed_args.log = 'primitives=FINE' if parsed_args.trace_process_switches: parsed_args.log = 'scheduling=FINE' if parsed_args.log: split = parsed_args.log.split("=") if len(split) != 2: mx.abort('Must be in the format de.hpi.swa.graal...Class=LOGLEVEL') squeak_arguments.append('--log.%s.%s.level=%s' % (LANGUAGE_ID, split[0], split[1])) if parsed_args.memtracer: squeak_arguments.extend(['--experimental-options', '--memtracer']) squeak_arguments.append('--polyglot') # enable polyglot mode by default if parsed_args.image: squeak_arguments.append(parsed_args.image) else: if len(squeak_arguments) > 1: parser.error('an image needs to be explicitly provided') if parsed_args.image_arguments: squeak_arguments.extend(parsed_args.image_arguments) if not jdk: jdk = mx.get_jdk(tag='jvmci' if _compiler else None) return mx.run_java(vm_args + squeak_arguments, jdk=jdk, **kwargs)
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 _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex, suite): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) # Dictionary from fully qualified class names to the project or distribution containing the class candidates = _find_classes_by_annotated_methods(annotations, suite) jdk = mx.get_jdk() for p in mx.projects(opt_limit_to_suite=True): if not p.isJavaProject(): continue if suite and not p.suite == suite: continue if jdk.javaCompliance < p.javaCompliance: continue for c in _find_classes_with_annotations(p, None, annotations): candidates[c] = p classes = [] if len(tests) == 0: classes = candidates.keys() depsContainingTests = set(candidates.values()) else: depsContainingTests = set() found = False if len(tests) == 1 and '#' in tests[0]: words = tests[0].split('#') if len(words) != 2: mx.abort("Method specification is class#method: " + tests[0]) t, method = words for c, p in candidates.iteritems(): # prefer exact matches first if t == c: found = True classes.append(c) depsContainingTests.add(p) if not found: for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring "' + t) elif len(classes) != 1: mx.abort('More than one test matches substring {0} {1}'.format(t, classes)) classes = [c + "#" + method for c in classes] else: for t in tests: if '#' in t: mx.abort('Method specifications can only be used in a single test: ' + t) for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring "' + t) unittestCp = mx.classpath(depsContainingTests) if blacklist: classes = [c for c in classes if not any((glob.match(c) for glob in blacklist))] if whitelist: classes = [c for c in classes if any((glob.match(c) for glob in whitelist))] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in classes: f_testfile.write(c + '\n') f_testfile.close() harness(unittestCp, vmLauncher, vmArgs)
def _run_tests(args, harness, vmLauncher, annotations, testfile, blacklist, whitelist, regex, suite): vmArgs, tests = mx.extract_VM_args(args) for t in tests: if t.startswith('-'): mx.abort('VM option ' + t + ' must precede ' + tests[0]) # Dictionary from fully qualified class names to the project or distribution containing the class candidates = _find_classes_by_annotated_methods(annotations, suite) jdk = mx.get_jdk() for p in mx.projects(opt_limit_to_suite=True): if not p.isJavaProject(): continue if suite and not p.suite == suite: continue if jdk.javaCompliance < p.javaCompliance: continue for c in _find_classes_with_annotations(p, None, annotations): candidates[c] = p classes = [] if len(tests) == 0: classes = candidates.keys() depsContainingTests = set(candidates.values()) else: depsContainingTests = set() found = False if len(tests) == 1 and '#' in tests[0]: words = tests[0].split('#') if len(words) != 2: mx.abort("Method specification is class#method: " + tests[0]) t, method = words for c, p in candidates.iteritems(): # prefer exact matches first if t == c: found = True classes.append(c) depsContainingTests.add(p) if not found: for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring "' + t) elif len(classes) != 1: mx.abort('More than one test matches substring {0} {1}'.format( t, classes)) classes = [c + "#" + method for c in classes] else: for t in tests: if '#' in t: mx.abort( 'Method specifications can only be used in a single test: ' + t) for c, p in candidates.iteritems(): if t in c: found = True classes.append(c) depsContainingTests.add(p) if not found: mx.log('warning: no tests matched by substring "' + t) unittestCp = mx.classpath(depsContainingTests, jdk=vmLauncher.jdk()) if blacklist: classes = [ c for c in classes if not any((glob.match(c) for glob in blacklist)) ] if whitelist: classes = [ c for c in classes if any((glob.match(c) for glob in whitelist)) ] if regex: classes = [c for c in classes if re.search(regex, c)] if len(classes) != 0: f_testfile = open(testfile, 'w') for c in classes: f_testfile.write(c + '\n') f_testfile.close() harness(unittestCp, vmLauncher, vmArgs)
def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs): if not env: env = os.environ check_vm_env = env.get('GRAALPYTHON_MUST_USE_GRAAL', False) if check_vm_env: if check_vm_env == '1': check_vm(must_be_jvmci=True) elif check_vm_env == '0': check_vm() dists = ['GRAALPYTHON'] vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False) internal_graalpython_args, graalpython_args, additional_dists = _extract_graalpython_internal_options( graalpython_args) dists += additional_dists if '--python.WithJavaStacktrace' not in graalpython_args: graalpython_args = ['--python.WithJavaStacktrace'] + graalpython_args if _sulong: vm_args.append( mx_subst.path_substitutions.substitute( '-Dpolyglot.llvm.libraryPath=<path:SULONG_LIBS>')) dists.append('SULONG') # Try eagerly to include tools on Tim's computer if not mx.suite("/tools", fatalIfMissing=False): def _is_user(user, home=None): if home: return os.environ.get("USER") == user and os.environ.get(home) return os.environ.get("USER") == user if _is_user("tim", "MAGLEV_HOME") or _is_user("cbasca"): suite_import = mx.SuiteImport("tools", version=None, urlinfos=None, dynamicImport=True, in_subdir=True) imported_suite, _ = mx._find_suite_import(_suite, suite_import, fatalIfMissing=False, load=False) if imported_suite: imported_suite._preload_suite_dict() try: mx._register_suite(imported_suite) imported_suite._load() imported_suite._init_metadata() imported_suite._resolve_dependencies() imported_suite._post_init() except AssertionError: pass # already registered dists.append('CHROMEINSPECTOR') if _sulong: vm_args.append("-Dpolyglot.llvm.enableLVI=true") vm_args += mx.get_runtime_jvm_args(dists, jdk=jdk) vm_args += internal_graalpython_args if not jdk: jdk = get_jdk() # default: assertion checking is enabled if extra_vm_args is None or '-da' not in extra_vm_args: vm_args += ['-ea', '-esa'] if extra_vm_args: vm_args += extra_vm_args vm_args.append("com.oracle.graal.python.shell.GraalPythonMain") return mx.run_java(vm_args + graalpython_args, jdk=jdk, **kwargs)
def sl(args): """run an SL program""" vmArgs, slArgs = mx.extract_VM_args(args) mx.run_java(vmArgs + _path_args(["TRUFFLE_API", "com.oracle.truffle.sl"]) + ["com.oracle.truffle.sl.SLMain"] + slArgs)