Skip to content

Commit c65fe30

Browse files
committed
Use standalones to run the tests
1 parent c73da4e commit c65fe30

File tree

1 file changed

+98
-60
lines changed

1 file changed

+98
-60
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 98 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -820,17 +820,86 @@ def _join_bin(home, name):
820820
return os.path.join(home, "bin", name)
821821

822822

823-
def graalpy_standalone():
823+
def _graalpy_launcher(managed=False):
824+
name = 'graalpy-managed' if managed else 'graalpy'
825+
return f"{name}.exe" if WIN32 else name
826+
827+
828+
def graalpy_standalone_home(standalone_type, enterprise=False):
829+
assert standalone_type in ['native', 'jvm']
824830
jdk_version = mx.get_jdk().javaCompliance # Not our "get_jdk", because we do not want the jvmci tag.
825-
mx_args = ['-p', os.path.join(mx.suite('truffle').dir, '..', 'vm'), '--env', 'ce-python']
826-
if not DISABLE_REBUILD:
827-
mx.run_mx(mx_args + ["build", "--dep", f"PYTHON_JAVA_STANDALONE_SVM_JAVA{jdk_version}"])
828-
out = mx.OutputCapture()
829-
mx.run_mx(mx_args + ["standalone-home", "--type", "jvm", "python"], out=out)
830-
python_home = out.data.splitlines()[-1].strip()
831+
python_home = os.environ.get("GRAALPY_HOME", None)
832+
if python_home and "*" in python_home:
833+
python_home = os.path.abspath(glob.glob(python_home)[0])
834+
mx.log("Using GraalPy standalone from GRAALPY_HOME: " + python_home)
835+
# Try to verify that we're getting what we expect:
836+
has_java = os.path.exists(os.path.join(python_home, 'jvm', 'bin', 'java'))
837+
if has_java != (standalone_type == 'jvm'):
838+
mx.abort(f"GRAALPY_HOME is not compatible with the requested distribution type.\n"
839+
f"jvm/bin/java exists?: {has_java}, requested type={standalone_type}.")
840+
841+
line = ''
842+
with open(os.path.join(python_home, 'release'), 'r') as f:
843+
while 'JAVA_VERSION=' not in line:
844+
line = f.readline()
845+
if 'JAVA_VERSION=' not in line:
846+
mx.abort(f"GRAALPY_HOME does not contain 'release' file. Cannot check Java version.")
847+
actual_jdk_version = line.strip('JAVA_VERSION=').strip(' "\n\r')
848+
if actual_jdk_version != jdk_version:
849+
mx.abort(f"GRAALPY_HOME is not compatible with the requested JDK version.\n"
850+
f"actual version: '{actual_jdk_version}', version string: {line}, requested version: {jdk_version}.")
851+
852+
launcher = os.path.join(python_home, 'bin', _graalpy_launcher(enterprise))
853+
out = mx.OutputCapture()
854+
import_managed_status = mx.run([launcher, "-c", "import __graalpython_enterprise__"], nonZeroIsFatal=False, out=out, err=out)
855+
if enterprise != (import_managed_status == 0):
856+
mx.abort(f"GRAALPY_HOME is not compatible with requested distribution kind ({import_managed_status=}, {enterprise=}, {out=}).")
857+
else:
858+
env_file = 'ce-python'
859+
vm_suite_path = os.path.join(mx.suite('truffle').dir, '..', 'vm')
860+
svm_distr = ''
861+
if enterprise:
862+
env_file = 'ee-python'
863+
vm_suite_path = os.path.join(mx.suite('graal-enterprise').dir, '..', 'vm-enterprise')
864+
svm_distr = '_SVMEE'
865+
mx_args = ['-p', vm_suite_path, '--env', env_file]
866+
if not DISABLE_REBUILD:
867+
dep_type = 'JAVA' if standalone_type == 'jvm' else 'NATIVE'
868+
mx.run_mx(mx_args + ["build", "--dep", f"PYTHON_{dep_type}_STANDALONE_SVM{svm_distr}_JAVA{jdk_version}"])
869+
out = mx.OutputCapture()
870+
mx.run_mx(mx_args + ["standalone-home", "--type", standalone_type, "python"], out=out)
871+
python_home = out.data.splitlines()[-1].strip()
831872
return python_home
832873

833874

875+
def graalpy_standalone(standalone_type, managed=False):
876+
assert standalone_type in ['native', 'jvm']
877+
if standalone_type == 'native' and mx_gate.get_jacoco_agent_args():
878+
return graalpy_standalone('jvm')
879+
880+
launcher = os.path.join(graalpy_standalone_home(standalone_type, managed), 'bin', _graalpy_launcher(managed))
881+
return make_coverage_launcher_if_needed(launcher)
882+
883+
def graalpy_standalone_jvm():
884+
return graalpy_standalone('jvm')
885+
886+
887+
def graalpy_standalone_native():
888+
return graalpy_standalone('native')
889+
890+
891+
def graalpy_standalone_jvm_managed():
892+
return graalpy_standalone('jvm', managed=True)
893+
894+
895+
def graalpy_standalone_jvm_enterprise():
896+
return os.path.join(graalpy_standalone_home('jvm', enterprise=True), 'bin', _graalpy_launcher(managed=False))
897+
898+
899+
def graalpy_standalone_native_managed():
900+
return graalpy_standalone('native', managed=True)
901+
902+
834903
def graalvm_jdk():
835904
jdk_version = mx.get_jdk().javaCompliance # Not our "get_jdk", because we do not want the jvmci tag.
836905
mx_args = ['-p', os.path.join(mx.suite('truffle').dir, '..', 'vm'), '--env', 'ce']
@@ -870,8 +939,12 @@ def deploy_local_maven_repo():
870939

871940
def python_gvm(_=None):
872941
home = _graalvm_home(envfile="graalpython-bash-launcher")
873-
launcher = _join_bin(home, "graalpy")
942+
launcher = make_coverage_launcher_if_needed(_join_bin(home, "graalpy"))
943+
mx.log(launcher)
944+
return launcher
945+
874946

947+
def make_coverage_launcher_if_needed(launcher):
875948
if mx_gate.get_jacoco_agent_args():
876949
# patch our launchers created under jacoco to also run with jacoco.
877950
# do not use is_collecting_coverage() here, we only want to patch when
@@ -882,6 +955,7 @@ def graalvm_vm_arg(java_arg):
882955
java_arg = f.read()
883956
assert java_arg[0] == "-", java_arg
884957
return shlex.quote(f'--vm.{java_arg[1:]}')
958+
885959
agent_args = ' '.join(graalvm_vm_arg(arg) for arg in mx_gate.get_jacoco_agent_args() or [])
886960

887961
# We need to make sure the arguments get passed to subprocesses, so we create a temporary launcher
@@ -894,23 +968,7 @@ def graalvm_vm_arg(java_arg):
894968
f.write(f'{original_launcher} --jvm {exe_arg} {agent_args} "$@"\n')
895969
os.chmod(bash_launcher, 0o775)
896970
mx.log(f"Replaced {launcher} with {bash_launcher} to collect coverage")
897-
return bash_launcher
898-
899-
mx.log(launcher)
900-
return launcher
901-
902-
903-
def python_managed_gvm(_=None):
904-
home = _graalvm_home(envfile="graalpython-managed-bash-launcher")
905-
launcher = _join_bin(home, "graalpy-managed")
906-
mx.log(launcher)
907-
return launcher
908-
909-
910-
def python_enterprise_gvm(_=None):
911-
home = _graalvm_home(envfile="graalpython-managed-bash-launcher")
912-
launcher = _join_bin(home, "graalpy")
913-
mx.log(launcher)
971+
launcher = bash_launcher
914972
return launcher
915973

916974

@@ -923,13 +981,6 @@ def python_svm(_=None):
923981
return launcher
924982

925983

926-
def python_managed_svm():
927-
home = _graalvm_home(envfile="graalpython-managed-launcher")
928-
launcher = _join_bin(home, "graalpy-managed")
929-
mx.log(launcher)
930-
return launcher
931-
932-
933984
def native_image(args):
934985
mx.run_mx([
935986
"-p", os.path.join(mx.suite("truffle").dir, "..", "substratevm"),
@@ -946,14 +997,6 @@ def native_image(args):
946997
])
947998

948999

949-
def python_so():
950-
return _graalvm_home(envfile="graalpython-libpolyglot")
951-
952-
953-
def python_managed_so():
954-
return _graalvm_home(envfile="graalpython-managed-libpolyglot")
955-
956-
9571000
def _graalpytest_driver():
9581001
return os.path.join(SUITE.dir, "graalpython", "com.oracle.graal.python.test", "src", "graalpytest.py")
9591002

@@ -1399,7 +1442,7 @@ def graalpython_gate_runner(args, tasks):
13991442
if not WIN32:
14001443
mx.run(["env"])
14011444
run_python_unittests(
1402-
python_gvm(),
1445+
graalpy_standalone_jvm(),
14031446
javaAsserts=True,
14041447
exclude=excluded_tests,
14051448
nonZeroIsFatal=nonZeroIsFatal,
@@ -1419,39 +1462,35 @@ def graalpython_gate_runner(args, tasks):
14191462

14201463
with Task('GraalPython sandboxed tests', tasks, tags=[GraalPythonTags.unittest_sandboxed]) as task:
14211464
if task:
1422-
run_python_unittests(python_managed_gvm(), javaAsserts=True, exclude=excluded_tests, report=report())
1465+
run_python_unittests(graalpy_standalone_native_managed(), javaAsserts=True, exclude=excluded_tests, report=report())
14231466

14241467
with Task('GraalPython multi-context unittests', tasks, tags=[GraalPythonTags.unittest_multi]) as task:
14251468
if task:
1426-
run_python_unittests(python_gvm(), args=["-multi-context"], javaAsserts=True, exclude=excluded_tests, nonZeroIsFatal=nonZeroIsFatal, report=report())
1469+
run_python_unittests(graalpy_standalone_jvm(), args=["-multi-context"], javaAsserts=True, exclude=excluded_tests, nonZeroIsFatal=nonZeroIsFatal, report=report())
14271470

14281471
with Task('GraalPython Jython emulation tests', tasks, tags=[GraalPythonTags.unittest_jython]) as task:
14291472
if task:
1430-
run_python_unittests(python_gvm(), args=["--python.EmulateJython"], paths=["test_interop.py"], javaAsserts=True, report=report(), nonZeroIsFatal=nonZeroIsFatal)
1431-
1432-
with Task('GraalPython ginstall', tasks, tags=[GraalPythonTags.ginstall], report=True) as task:
1433-
if task:
1434-
run_ginstall(python_gvm(), args=["--quiet"])
1473+
run_python_unittests(graalpy_standalone_jvm(), args=["--python.EmulateJython"], paths=["test_interop.py"], javaAsserts=True, report=report(), nonZeroIsFatal=nonZeroIsFatal)
14351474

14361475
with Task('GraalPython HPy tests', tasks, tags=[GraalPythonTags.unittest_hpy]) as task:
14371476
if task:
1438-
run_hpy_unittests(python_svm(), nonZeroIsFatal=nonZeroIsFatal, report=report())
1477+
run_hpy_unittests(graalpy_standalone_native(), nonZeroIsFatal=nonZeroIsFatal, report=report())
14391478

14401479
with Task('GraalPython HPy sandboxed tests', tasks, tags=[GraalPythonTags.unittest_hpy_sandboxed]) as task:
14411480
if task:
1442-
run_hpy_unittests(python_managed_svm(), include_native=False, report=report())
1481+
run_hpy_unittests(graalpy_standalone_native_managed(), include_native=False, report=report())
14431482

14441483
with Task('GraalPython posix module tests', tasks, tags=[GraalPythonTags.unittest_posix]) as task:
14451484
if task:
1446-
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True, report=report())
1447-
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True, report=report())
1485+
run_python_unittests(graalpy_standalone_jvm(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True, report=report())
1486+
run_python_unittests(graalpy_standalone_jvm(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"], javaAsserts=True, report=report())
14481487

14491488
with Task('GraalPython standalone module tests', tasks, tags=[GraalPythonTags.unittest_standalone]) as task:
14501489
if task:
14511490
env = {
14521491
'ENABLE_STANDALONE_UNITTESTS': 'true',
14531492
'JAVA_HOME': graalvm_jdk(),
1454-
'PYTHON_STANDALONE_HOME': graalpy_standalone()
1493+
'PYTHON_STANDALONE_HOME': graalpy_standalone_home('jvm')
14551494
}
14561495
mvn_repo_path = deploy_local_maven_repo()
14571496
# setup maven downloader overrides
@@ -1470,20 +1509,20 @@ def graalpython_gate_runner(args, tasks):
14701509
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
14711510
if task:
14721511
# don't fail this task if we're running with the jacoco agent, we know that some tests don't pass with it enabled
1473-
run_tagged_unittests(python_svm(), nonZeroIsFatal=(not is_collecting_coverage()), report=report())
1512+
run_tagged_unittests(graalpy_standalone_native(), nonZeroIsFatal=(not is_collecting_coverage()), report=report())
14741513

14751514
with Task('GraalPython sandboxed Python tests', tasks, tags=[GraalPythonTags.tagged_sandboxed]) as task:
14761515
if task:
1477-
run_tagged_unittests(python_managed_gvm(), checkIfWithGraalPythonEE=True, cwd=SUITE.dir, report=report())
1516+
run_tagged_unittests(graalpy_standalone_native_managed(), checkIfWithGraalPythonEE=True, cwd=SUITE.dir, report=report())
14781517

14791518
# Unittests on SVM
14801519
with Task('GraalPython tests on SVM', tasks, tags=[GraalPythonTags.svmunit, GraalPythonTags.windows]) as task:
14811520
if task:
1482-
run_python_unittests(python_svm(), exclude=excluded_tests, aot_compatible=True, report=report())
1521+
run_python_unittests(graalpy_standalone_native(), exclude=excluded_tests, aot_compatible=True, report=report())
14831522

14841523
with Task('GraalPython sandboxed tests on SVM', tasks, tags=[GraalPythonTags.svmunit_sandboxed]) as task:
14851524
if task:
1486-
run_python_unittests(python_managed_svm(), aot_compatible=True, report=report())
1525+
run_python_unittests(graalpy_standalone_native_managed(), aot_compatible=True, report=report())
14871526

14881527
with Task('GraalPython license header update', tasks, tags=[GraalPythonTags.license]) as task:
14891528
if task:
@@ -2348,7 +2387,7 @@ def python_coverage(args):
23482387
'--exclude-src-gen',
23492388
], env=env)
23502389
if args.truffle:
2351-
executable = python_gvm()
2390+
executable = graalpy_standalone_jvm()
23522391
file_filter = f"*lib-graalpython*,*graalpython/include*,*com.oracle.graal.python.cext*,*lib/graalpy{graal_version_short()}*,*include/python{py_version_short()}*"
23532392
if os.environ.get("TAGGED_UNITTEST_PARTIAL"):
23542393
variants = [
@@ -2430,7 +2469,7 @@ def python_coverage(args):
24302469
f.name
24312470
], env=None)
24322471

2433-
home_launcher = os.path.join(os.path.dirname(os.path.dirname(executable)), 'languages/python')
2472+
home_launcher = os.path.dirname(os.path.dirname(executable))
24342473
suite_dir = SUITE.dir
24352474
if suite_dir.endswith("/"):
24362475
suite_dir = suite_dir[:-1]
@@ -3010,7 +3049,6 @@ def processDeps(self, deps):
30103049
'python-style': [python_style_checks, '[--fix] [--no-spotbugs]'],
30113050
'python-svm': [no_return(python_svm), ''],
30123051
'python-gvm': [no_return(python_gvm), ''],
3013-
'python-managed-gvm': [no_return(python_managed_gvm), ''],
30143052
'python-unittests': [python3_unittests, ''],
30153053
'python-compare-unittests': [compare_unittests, ''],
30163054
'python-retag-unittests': [retag_unittests, ''],

0 commit comments

Comments
 (0)