def _native_junit(native_image, unittest_args, build_args=None, run_args=None, blacklist=None, whitelist=None, preserve_image=False): unittest_args = unittest_args build_args = build_args or [] run_args = run_args or ['--verbose'] junit_native_dir = join(svmbuild_dir(), platform_name(), 'junit') mkpath(junit_native_dir) junit_tmp_dir = tempfile.mkdtemp(dir=junit_native_dir) try: unittest_deps = [] def dummy_harness(test_deps, vm_launcher, vm_args): unittest_deps.extend(test_deps) unittest_file = join(junit_tmp_dir, 'svmjunit.tests') _run_tests(unittest_args, dummy_harness, _VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittest_file, blacklist, whitelist, None, None) if not exists(unittest_file): mx.abort('No matching unit tests found. Skip image build and execution.') with open(unittest_file, 'r') as f: mx.log('Building junit image for matching: ' + ' '.join(l.rstrip() for l in f)) extra_image_args = mx.get_runtime_jvm_args(unittest_deps, jdk=mx_compiler.jdk) unittest_image = native_image(build_args + extra_image_args + ['--macro:junit=' + unittest_file, '-H:Path=' + junit_tmp_dir]) if preserve_image: build_dir = join(svmbuild_dir(), 'junit') mkpath(build_dir) unittest_image_dst = join(build_dir, basename(unittest_image)) move(unittest_image, unittest_image_dst) unittest_image = unittest_image_dst mx.log('Running: ' + ' '.join(map(pipes.quote, [unittest_image] + run_args))) mx.run([unittest_image] + run_args) finally: remove_tree(junit_tmp_dir)
def native_junit(native_image, unittest_args, build_args=None, run_args=None): build_args = build_args if not None else [] run_args = run_args if not None else [] junit_native_dir = join(svmbuild_dir(), platform_subdir(), 'junit') mkpath(junit_native_dir) junit_tmp_dir = tempfile.mkdtemp(dir=junit_native_dir) try: unittest_deps = [] def dummy_harness(test_deps, vm_launcher, vm_args): unittest_deps.extend(test_deps) unittest_file = join(junit_tmp_dir, 'svmjunit.tests') _run_tests(unittest_args, dummy_harness, _VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittest_file, None, None, None, None) extra_image_args = mx.get_runtime_jvm_args(unittest_deps, jdk=mx_compiler.jdk) native_image( build_args + extra_image_args + ['--tool.junit=' + unittest_file, '-H:Path=' + junit_tmp_dir]) unittest_image = join(junit_tmp_dir, 'svmjunit') mx.run([unittest_image] + run_args) finally: remove_tree(junit_tmp_dir)
def build_tests_image(image_dir, options, unit_tests=None, additional_deps=None, shared_lib=False): native_image_context, svm = graalvm_svm() with native_image_context(svm.IMAGE_ASSERTION_FLAGS) as native_image: import mx_compiler build_options = [] + options if shared_lib: build_options = build_options + ['--shared'] build_deps = [] unittests_file = None if unit_tests: build_options = build_options + ['-ea', '-esa'] unittest_deps = [] unittests_file = join(image_dir, 'unittest.tests') mx_unittest._run_tests( unit_tests, lambda deps, vm_launcher, vm_args: unittest_deps.extend(deps), mx_unittest._VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittests_file, None, None, None, None) if not exists(unittests_file): mx.abort('No unit tests found matching the criteria {}'.format( ",".join(unit_tests))) build_deps = build_deps + unittest_deps if additional_deps: build_deps = build_deps + additional_deps extra_image_args = mx.get_runtime_jvm_args(build_deps, jdk=mx_compiler.jdk) tests_image = native_image(build_options + extra_image_args) import configparser artifacts = configparser.RawConfigParser(allow_no_value=True) artifacts_file_path = tests_image + '.build_artifacts.txt' if not exists(artifacts_file_path): mx.abort('Tests image build artifacts not found.') artifacts.read(artifacts_file_path) if shared_lib: if not any(s == 'SHARED_LIB' for s in artifacts.sections()): mx.abort('Shared lib not found in image build artifacts.') tests_image_path = join(image_dir, str(artifacts.items('SHARED_LIB')[0][0])) else: if not any(s == 'EXECUTABLE' for s in artifacts.sections()): mx.abort('Executable not found in image build artifacts.') tests_image_path = join(image_dir, str(artifacts.items('EXECUTABLE')[0][0])) mx.logv('Test image path: {}'.format(tests_image_path)) return tests_image_path, unittests_file
def gate_svm_sl_tck(tasks): with Task('SVM Truffle TCK', tasks, tags=[VmGateTasks.svm_sl_tck]) as t: if t: tools_suite = mx.suite('tools') if not tools_suite: mx.abort("Cannot resolve tools suite.") native_image_context, svm = graalvm_svm() with native_image_context( svm.IMAGE_ASSERTION_FLAGS) as native_image: svmbuild = mkdtemp() try: import mx_compiler unittest_deps = [] unittest_file = join(svmbuild, 'truffletck.tests') mx_unittest._run_tests( [], lambda deps, vm_launcher, vm_args: unittest_deps. extend(deps), mx_unittest._VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittest_file, [], [re.compile('com.oracle.truffle.tck.tests')], None, mx.suite('truffle')) if not exists(unittest_file): mx.abort('TCK tests not found.') unittest_deps.append( mx.dependency('truffle:TRUFFLE_SL_TCK')) unittest_deps.append( mx.dependency('truffle:TRUFFLE_TCK_INSTRUMENTATION')) vm_image_args = mx.get_runtime_jvm_args( unittest_deps, jdk=mx_compiler.jdk) options = [ '--macro:truffle', '--tool:all', '-H:Path={}'.format(svmbuild), '-H:+TruffleCheckBlackListedMethods', '-H:Class=org.junit.runner.JUnitCore', ] tests_image = native_image(vm_image_args + options) with open(unittest_file) as f: test_classes = [l.rstrip() for l in f.readlines()] mx.run([tests_image] + test_classes) finally: mx.rmtree(svmbuild)
def native_junit(native_image, unittest_args=None, build_args=None, run_args=None): unittest_args = unittest_args or ['com.oracle.svm.test'] build_args = build_args or [] run_args = run_args or ['--verbose'] junit_native_dir = join(svmbuild_dir(), platform_name(), 'junit') mkpath(junit_native_dir) junit_tmp_dir = tempfile.mkdtemp(dir=junit_native_dir) try: unittest_deps = [] def dummy_harness(test_deps, vm_launcher, vm_args): unittest_deps.extend(test_deps) unittest_file = join(junit_tmp_dir, 'svmjunit.tests') _run_tests(unittest_args, dummy_harness, _VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittest_file, None, None, None, None) if not exists(unittest_file): mx.abort('No matching unit tests found. Skip image build and execution.') with open(unittest_file, 'r') as f: mx.log('Building junit image for matching: ' + ' '.join(l.rstrip() for l in f)) extra_image_args = mx.get_runtime_jvm_args(unittest_deps, jdk=mx_compiler.jdk) unittest_image = native_image(build_args + extra_image_args + ['--tool:junit=' + unittest_file, '-H:Path=' + junit_tmp_dir]) mx.run([unittest_image] + run_args) finally: remove_tree(junit_tmp_dir)
def processImageArguments(args): """ Computes the projects, classpath, and extra arguments from command line arguments. :param args: Command line arguments. :return: (project list, classpath, extra arguments, extra VM arguments) """ projects = _extract_projects_from_arguments(args) classpathArgument = '' extraNormalArgs = [] extraVMArgs = [] buildjs = False js_version = None buildruby = False ruby_version = None buildsulong = False sulong_version = None buildpython = False python_version = None features = set() cleanup = [] required_memory_gb = 0 number_of_languages = 0 i = 0 while i < len(args): if args[i].startswith('-D'): extraVMArgs += [args.pop(i)] if args[i] == '-js': args.pop(i) projects += ['graal-js:GRAALJS', 'graal-js:GRAALJS_LAUNCHER'] extraNormalArgs += [ '-R:YoungGenerationSize=1g', '-R:OldGenerationSize=3g', '-H:MaxRuntimeCompileMethods=8000', '-H:Class=com.oracle.truffle.js.shell.JSLauncher', '-H:Name=js' ] buildjs = True number_of_languages += 1 required_memory_gb = 3 elif args[i].startswith('-js.version='): js_version = args.pop(i)[12:] elif args[i] == '-sl': args.pop(i) projects += ['truffle:TRUFFLE_SL', 'truffle:TRUFFLE_SL_LAUNCHER'] extraNormalArgs += [ '-H:Class=com.oracle.truffle.sl.launcher.SLMain', '-H:Name=sl' ] number_of_languages += 1 elif args[i] == '-ruby': args.pop(i) if not ruby_version and os.environ.has_key('TRUFFLE_RUBY_VERSION'): ruby_version = os.environ['TRUFFLE_RUBY_VERSION'] # Keep in sync with OptionHandlerRuby projects += [ 'truffleruby:TRUFFLERUBY', 'truffleruby:TRUFFLERUBY-LAUNCHER' ] features.add('com.oracle.svm.truffle.nfi.TruffleNFIFeature') extraNormalArgs += [ '-R:YoungGenerationSize=1g', '-R:OldGenerationSize=2g', '-H:MaxRuntimeCompileMethods=11000', '-H:+AddAllCharsets', '-H:SubstitutionResources=org/truffleruby/aot/substitutions.json', '-H:Class=org.truffleruby.Main', '-H:Name=ruby' ] buildruby = True number_of_languages += 1 required_memory_gb = 6 elif args[i] == '-sulong': args.pop(i) if not sulong_version and os.environ.has_key( 'TRUFFLE_SULONG_VERSION'): sulong_version = os.environ['TRUFFLE_SULONG_VERSION'] sulong_suite = ensure_trufflelanguage('sulong', sulong_version) projects += ['sulong:SULONG', 'SVM'] features.add('com.oracle.svm.truffle.nfi.TruffleNFIFeature') extraNormalArgs += [ '-H:Class=com.oracle.truffle.llvm.Sulong', '-H:Name=sulong' ] buildsulong = True number_of_languages += 1 required_memory_gb = 3 elif args[i] == '-python': args.pop(i) if not python_version and os.environ.has_key( 'TRUFFLE_PYTHON_VERSION'): python_version = os.environ['TRUFFLE_PYTHON_VERSION'] if not sulong_version and os.environ.has_key( 'TRUFFLE_SULONG_VERSION'): sulong_version = os.environ['TRUFFLE_SULONG_VERSION'] sulong_suite = ensure_trufflelanguage('sulong', sulong_version) python_suite = ensure_trufflelanguage('graalpython', python_version) projects += ['graalpython:GRAALPYTHON'] features.add('com.oracle.svm.truffle.nfi.TruffleNFIFeature') extraNormalArgs += [ '-H:MaxRuntimeCompileMethods=12000', '-H:Class=com.oracle.graal.python.shell.GraalPythonMain', '-H:SubstitutionResources=com/oracle/graal/python/aot/substitutions.json', '-H:Name=python' ] buildpython = True number_of_languages += 1 required_memory_gb = 4 elif args[i] == '-nfi': args.pop(i) features.add('com.oracle.svm.truffle.nfi.TruffleNFIFeature') elif args[i] == '-junit': args.pop(i) features.add('com.oracle.svm.junit.JUnitFeature') testArgs = [] while i < len(args) and not args[i].startswith('-'): testArgs += [args.pop(i)] (_, testfile) = tempfile.mkstemp(".testclasses", "mxsvm") os.close(_) cleanup += [lambda: os.remove(testfile)] def dummyHarness(unittestDeps, vmLauncher, vmArgs): projects.extend(unittestDeps) extraNormalArgs.extend(vmArgs) _run_tests(testArgs, dummyHarness, _VMLauncher('dummy launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], testfile, None, None, None, None) extraNormalArgs += [ '-H:Class=com.oracle.svm.junit.SVMJUnitRunner', '-H:Name=svmjunit', '-H:TestFile=' + testfile ] elif args[i] == '-cp': args.pop(i) classpathArgument = ':' + args.pop(i) else: i += 1 if number_of_languages > 1: extraVMArgs += ["-Xmx" + str(GB_MEM_BASE + number_of_languages) + "g"] elif required_memory_gb != 0 and number_of_languages == 1: extraVMArgs += ["-Xmx" + str(required_memory_gb) + "g"] extraNormalArgs += ['-H:Features=' + ','.join(features)] if buildjs: if not js_version and os.environ.has_key('TRUFFLE_JS_VERSION'): js_version = os.environ['TRUFFLE_JS_VERSION'] js_suite = ensure_trufflelanguage('graal-js', js_version) mx.log('Building image with js.version=' + str(js_suite.version())) if buildruby: truffleruby_suite = ensure_trufflelanguage('truffleruby', ruby_version) mx.log('Building image with truffleruby.version=' + str(truffleruby_suite.version())) if buildsulong: mx.log('Building image with sulong.version=' + str(sulong_suite.version())) if buildpython: mx.log('Building image with python.version=' + str(python_suite.version())) if buildjs or buildruby or buildsulong or buildpython: extraVMArgs += [ '-Dgraalvm.version=dev', "-Dorg.graalvm.launcher.home=" ] return (projects, classpathArgument, extraNormalArgs, extraVMArgs, cleanup)
def svm_gate_body(args, tasks): build_native_image_image() with native_image_context(IMAGE_ASSERTION_FLAGS) as native_image: with Task('image demos', tasks, tags=[GraalTags.helloworld]) as t: if t: javac_image(['--output-path', svmbuild_dir()]) javac_command = ' '.join(javac_image_command(svmbuild_dir())) helloworld(['--output-path', svmbuild_dir(), '--javac-command', javac_command]) helloworld(['--output-path', svmbuild_dir(), '--shared']) # Build and run helloworld as shared library cinterfacetutorial([]) clinittest([]) with Task('native unittests', tasks, tags=[GraalTags.test]) as t: if t: native_unittest(['--build-args', '--initialize-at-build-time']) with Task('Run Truffle NFI unittests with SVM image', tasks, tags=["svmjunit"]) as t: if t: testlib = mx_subst.path_substitutions.substitute('-Dnative.test.lib=<path:truffle:TRUFFLE_TEST_NATIVE>/<lib:nativetest>') native_unittest_args = ['com.oracle.truffle.nfi.test', '--build-args', '--initialize-at-build-time', '--language:nfi', '-H:MaxRuntimeCompileMethods=1500', '--run-args', testlib, '--very-verbose', '--enable-timing'] native_unittest(native_unittest_args) with Task('Truffle TCK', tasks, tags=[GraalTags.truffletck]) as t: if t: junit_native_dir = join(svmbuild_dir(), platform_name(), 'junit') mkpath(junit_native_dir) junit_tmp_dir = tempfile.mkdtemp(dir=junit_native_dir) try: unittest_deps = [] unittest_file = join(junit_tmp_dir, 'truffletck.tests') _run_tests([], lambda deps, vm_launcher, vm_args: unittest_deps.extend(deps), _VMLauncher('dummy_launcher', None, mx_compiler.jdk), ['@Test', '@Parameters'], unittest_file, [], [re.compile('com.oracle.truffle.tck.tests')], None, mx.suite('truffle')) if not exists(unittest_file): mx.abort('TCK tests not found.') unittest_deps.append(mx.dependency('truffle:TRUFFLE_SL_TCK')) vm_image_args = mx.get_runtime_jvm_args(unittest_deps, jdk=mx_compiler.jdk) tests_image = native_image(vm_image_args + ['--macro:truffle', '--initialize-at-build-time', '--features=com.oracle.truffle.tck.tests.TruffleTCKFeature', '-H:Class=org.junit.runner.JUnitCore', '-H:IncludeResources=com/oracle/truffle/sl/tck/resources/.*', '-H:MaxRuntimeCompileMethods=3000']) with open(unittest_file) as f: test_classes = [l.rstrip() for l in f.readlines()] mx.run([tests_image, '-Dtck.inlineVerifierInstrument=false'] + test_classes) finally: remove_tree(junit_tmp_dir) build_native_image_image(config=_graalvm_js_config) with native_image_context(IMAGE_ASSERTION_FLAGS, config=_graalvm_js_config) as native_image: with Task('JavaScript', tasks, tags=[GraalTags.js]) as t: if t: js = build_js(native_image) test_run([js, '-e', 'print("hello:" + Array.from(new Array(10), (x,i) => i*i ).join("|"))'], 'hello:0|1|4|9|16|25|36|49|64|81\n') test_js(js, [('octane-richards', 1000, 100, 300)]) with Task('maven plugin checks', tasks, tags=[GraalTags.maven]) as t: if t: maven_plugin_install(["--deploy-dependencies"]) maven_plugin_test([])