Skip to content

Commit 7f66f25

Browse files
committed
Enable Java assertions for all JVM unittests
1 parent f1bb263 commit 7f66f25

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def run_cpython_test(args):
280280
testfiles = []
281281
for g in globs:
282282
testfiles += glob.glob(os.path.join(SUITE.dir, "graalpython/lib-python/3/test", "%s*" % g))
283-
mx.run([python_gvm()] + interp_args + [
283+
mx.run([python_gvm_with_assertions()] + interp_args + [
284284
os.path.join(SUITE.dir, "graalpython/com.oracle.graal.python.test/src/tests/run_cpython_test.py"),
285285
] + test_args + testfiles)
286286

@@ -309,7 +309,7 @@ def retag_unittests(args):
309309
'graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py',
310310
'--retag'
311311
]
312-
mx.run([python_gvm()] + args + remaining_args, env=env)
312+
mx.run([python_gvm_with_assertions()] + args + remaining_args, env=env)
313313
if parsed_args.upload_results_to:
314314
with tempfile.TemporaryDirectory(prefix='graalpython-retagger-') as d:
315315
filename = os.path.join(d, 'unittest-tags-{}.tar.bz2'.format(sys.platform))
@@ -484,6 +484,12 @@ def python_gvm(args=None, **kwargs):
484484
return _python_graalvm_launcher(args or [], **kwargs)
485485

486486

487+
def python_gvm_with_assertions(args=None, **kwargs):
488+
launcher = python_gvm(args, **kwargs)
489+
patch_batch_launcher(launcher, '-ea')
490+
return launcher
491+
492+
487493
def python_svm(args=None, **kwargs):
488494
"Build and run the native graalpython image"
489495
with set_env(FORCE_BASH_LAUNCHERS="true", NATIVE_IMAGES="graalpython", DISABLE_LIBPOLYGLOT="true", DISABLE_POLYGLOT="true"):
@@ -621,12 +627,7 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Fa
621627
launcher_path_bak = launcher_path + ".bak"
622628
shutil.copy(launcher_path, launcher_path_bak)
623629
try:
624-
with open(launcher_path, 'r', encoding='ascii', errors='ignore') as launcher:
625-
lines = launcher.readlines()
626-
assert re.match(r'^#!.*bash', lines[0]), "jacoco needs a bash launcher"
627-
lines.insert(-1, 'jvm_args+=(%s)\n' % agent_args)
628-
with open(launcher_path, 'w') as launcher:
629-
launcher.writelines(lines)
630+
patch_batch_launcher(launcher_path, agent_args)
630631
# jacoco only dumps the data on exit, and when we run all our unittests
631632
# at once it generates so much data we run out of heap space
632633
for testfile in testfiles:
@@ -639,6 +640,15 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Fa
639640
return mx.run([python_binary] + args, nonZeroIsFatal=True, env=env)
640641

641642

643+
def patch_batch_launcher(launcher_path, jvm_args):
644+
with open(launcher_path, 'r', encoding='ascii', errors='ignore') as launcher:
645+
lines = launcher.readlines()
646+
assert re.match(r'^#!.*bash', lines[0]), "expected a bash launcher"
647+
lines.insert(-1, 'jvm_args+=(%s)\n' % jvm_args)
648+
with open(launcher_path, 'w') as launcher:
649+
launcher.writelines(lines)
650+
651+
642652
def run_hpy_unittests(python_binary, args=None):
643653
args = [] if args is None else args
644654
with tempfile.TemporaryDirectory(prefix='hpy-test-site-') as d:
@@ -690,36 +700,36 @@ def graalpython_gate_runner(args, tasks):
690700
test_args = [exe, _graalpytest_driver(), "-v", _graalpytest_root()]
691701
mx.run(test_args, nonZeroIsFatal=True, env=env)
692702
mx.run(["env"])
693-
run_python_unittests(python_gvm())
703+
run_python_unittests(python_gvm_with_assertions())
694704

695705
with Task('GraalPython sandboxed tests', tasks, tags=[GraalPythonTags.unittest_sandboxed]) as task:
696706
if task:
697-
run_python_unittests(python_gvm(["sandboxed"]))
707+
run_python_unittests(python_gvm_with_assertions(["sandboxed"]))
698708

699709
with Task('GraalPython multi-context unittests', tasks, tags=[GraalPythonTags.unittest_multi]) as task:
700710
if task:
701-
run_python_unittests(python_gvm(), args=["-multi-context"])
711+
run_python_unittests(python_gvm_with_assertions(), args=["-multi-context"])
702712

703713
with Task('GraalPython Jython emulation tests', tasks, tags=[GraalPythonTags.unittest_jython]) as task:
704714
if task:
705-
run_python_unittests(python_gvm(), args=["--python.EmulateJython"], paths=["test_interop.py"])
715+
run_python_unittests(python_gvm_with_assertions(), args=["--python.EmulateJython"], paths=["test_interop.py"])
706716

707717
with Task('GraalPython HPy tests', tasks, tags=[GraalPythonTags.unittest_hpy]) as task:
708718
if task:
709-
run_hpy_unittests(python_gvm())
719+
run_hpy_unittests(python_gvm_with_assertions())
710720

711721
with Task('GraalPython HPy sandboxed tests', tasks, tags=[GraalPythonTags.unittest_hpy_sandboxed]) as task:
712722
if task:
713-
run_hpy_unittests(python_gvm(["sandboxed"]))
723+
run_hpy_unittests(python_gvm_with_assertions(["sandboxed"]))
714724

715725
with Task('GraalPython posix module tests', tasks, tags=[GraalPythonTags.unittest_posix]) as task:
716726
if task:
717-
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"])
718-
run_python_unittests(python_gvm(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"])
727+
run_python_unittests(python_gvm_with_assertions(), args=["--PosixModuleBackend=native"], paths=["test_posix.py", "test_mmap.py"])
728+
run_python_unittests(python_gvm_with_assertions(), args=["--PosixModuleBackend=java"], paths=["test_posix.py", "test_mmap.py"])
719729

720730
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
721731
if task:
722-
run_tagged_unittests(python_gvm())
732+
run_tagged_unittests(python_gvm_with_assertions())
723733

724734
# Unittests on SVM
725735
with Task('GraalPython tests on SVM', tasks, tags=[GraalPythonTags.svmunit]) as task:
@@ -1621,7 +1631,7 @@ def python_coverage(args):
16211631
'coverage-upload',
16221632
])
16231633
if args.truffle:
1624-
executable = python_gvm()
1634+
executable = python_gvm_with_assertions()
16251635
variants = [
16261636
{"args": []},
16271637
{"args": ["--python.EmulateJython"], "paths": ["test_interop.py"]},

0 commit comments

Comments
 (0)