Skip to content

Commit 88e97e5

Browse files
committed
Try to keep heapdump from transient leak test failures
1 parent 16fdf43 commit 88e97e5

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None
270270

271271

272272
def _pythonhome_context():
273-
return set_env(GRAAL_PYTHONHOME=mx.dependency("GRAALPYTHON_GRAALVM_SUPPORT").get_output())
273+
return set_env(GRAAL_PYTHONHOME=_pythonhome())
274+
275+
276+
def _pythonhome():
277+
return mx.dependency("GRAALPYTHON_GRAALVM_SUPPORT").get_output()
274278

275279

276280
def _dev_pythonhome_context():
@@ -316,11 +320,11 @@ def punittest(ars, report=False):
316320
# test leaks with Python code only
317321
run_leak_launcher(common_args + ["--code", "pass", ]),
318322
# test leaks when some C module code is involved
319-
run_leak_launcher(common_args + ["--code", "import _testcapi, mmap, bz2; print(memoryview(b'').nbytes)"]),
323+
run_leak_launcher(common_args + ["--code", 'import _testcapi, mmap, bz2; print(memoryview(b"").nbytes)']),
320324
# test leaks with shared engine Python code only
321325
run_leak_launcher(common_args + ["--shared-engine", "--code", "pass"]),
322326
# test leaks with shared engine when some C module code is involved
323-
run_leak_launcher(common_args + ["--shared-engine", "--code", "import _testcapi, mmap, bz2; print(memoryview(b'').nbytes)"])
327+
run_leak_launcher(common_args + ["--shared-engine", "--code", 'import _testcapi, mmap, bz2; print(memoryview(b"").nbytes)'])
324328
]):
325329
mx.abort(1)
326330

@@ -2677,43 +2681,47 @@ def exclude_files(*files):
26772681
"Provides-Extra: dev\n".format(imported_version).strip())
26782682

26792683

2680-
def run_leak_launcher(input_args, out=None):
2681-
print("mx python-leak-test " + " ".join(input_args))
2684+
def run_leak_launcher(input_args):
2685+
print(shlex.join(["mx", "python-leak-test", *input_args]))
26822686

26832687
args = input_args
26842688
capi_home = _get_capi_home()
2685-
args.insert(0, "--experimental-options")
2686-
args.insert(0, "--python.CAPI=%s" % capi_home)
2689+
args = [
2690+
"--keep-dump",
2691+
"--experimental-options",
2692+
f"--python.CAPI={capi_home}",
2693+
*args,
2694+
]
26872695

26882696
env = os.environ.copy()
2689-
env.setdefault("GRAAL_PYTHONHOME", _dev_pythonhome())
2697+
env.setdefault("GRAAL_PYTHONHOME", _pythonhome())
26902698

26912699
dists = ['GRAALPYTHON', 'TRUFFLE_NFI', 'SULONG_NATIVE', 'GRAALPYTHON_UNIT_TESTS']
26922700

26932701
vm_args, graalpython_args = mx.extract_VM_args(args, useDoubleDash=True, defaultAllVMArgs=False)
26942702
vm_args += mx.get_runtime_jvm_args(dists)
2703+
vm_args.append('-Dpolyglot.engine.WarnInterpreterOnly=false')
26952704
jdk = get_jdk()
26962705
vm_args.append("com.oracle.graal.python.test.advance.LeakTest")
2697-
retval = mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, nonZeroIsFatal=False, out=out)
2706+
out = mx.OutputCapture()
2707+
retval = mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, nonZeroIsFatal=False, out=mx.TeeOutputCapture(out))
2708+
dump_path = out.data.strip().partition("Dump file:")[2].strip()
26982709
if retval == 0:
26992710
print("PASSED")
2711+
if dump_path:
2712+
print("Removing heapdump for passed test")
2713+
os.unlink(dump_path)
27002714
return True
2701-
elif os.environ.get("CI") and "--keep-dump" not in input_args:
2702-
# rerun once with heap dumping enabled
2703-
out = mx.OutputCapture()
2704-
run_leak_launcher(["--keep-dump"] + input_args, out=out)
2705-
path = out.data.strip().partition("Dump file:")[2].strip()
2706-
if path:
2715+
else:
2716+
print("FAILED")
2717+
if 'CI' in os.environ and dump_path:
27072718
save_path = os.path.join(SUITE.dir, "dumps", "leak_test")
27082719
try:
27092720
os.makedirs(save_path)
27102721
except OSError:
27112722
pass
2712-
dest = shutil.copy(path, save_path)
2713-
print("Heapdump file kept in " + dest)
2714-
return False
2715-
else:
2716-
print("FAILED")
2723+
dest = shutil.copy(dump_path, save_path)
2724+
print(f"Heapdump file kept in {dest}")
27172725
return False
27182726

27192727

0 commit comments

Comments
 (0)