Skip to content

Commit 5bb6e14

Browse files
committed
[GR-24569] Fix coverage gate
PullRequest: graalpython/1091
2 parents d41d0cc + ae74d79 commit 5bb6e14

File tree

3 files changed

+55
-40
lines changed

3 files changed

+55
-40
lines changed

graalpython/lib-python/3/_md5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# coding=utf-8
1+
# -*- coding: iso-8859-1 -*-
22
# Copyright (c) 2017, 2018, Oracle and/or its affiliates.
33
# Copyright (c) 2017, The PyPy Project
44
#

graalpython/lib-python/3/_sha1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# coding=utf-8
1+
# -*- coding: iso-8859-1 -*-
22
# Copyright (c) 2017, 2018, Oracle and/or its affiliates.
33
# Copyright (c) 2017, The PyPy Project
44
#

mx.graalpython/mx_graalpython.py

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import platform
3434
import re
3535
import shutil
36+
import shlex
3637
import sys
3738

3839
HPY_IMPORT_ORPHAN_BRANCH_NAME = "hpy-import"
@@ -555,25 +556,49 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Tr
555556

556557
args += [_graalpytest_driver(), "-v"]
557558

558-
agent_args = " ".join(mx_gate.get_jacoco_agent_args() or [])
559+
agent_args = ' '.join(shlex.quote(arg) for arg in mx_gate.get_jacoco_agent_args() or [])
559560
if agent_args:
560-
# if we leave the excludes, the string is too long and it will be ignored by
561-
# the JVM, which ignores JAVA_TOOL_OPTIONS long than 1024 chars silently on JDK8
562-
agent_args = re.sub("excludes=[^,]+,", "", agent_args)
563-
# we know these can be excluded
564-
agent_args += ",excludes=*NodeGen*:*LibraryGen*:*BuiltinsFactory*"
565-
assert len(agent_args) < 1024
561+
# We need to make sure the arguments get passed to subprocesses, so we create a temporary launcher
562+
# with the arguments
563+
basedir = os.path.realpath(os.path.join(os.path.dirname(python_binary), '..'))
564+
jacoco_basedir = "%s-jacoco" % basedir
565+
shutil.rmtree(jacoco_basedir, ignore_errors=True)
566+
shutil.copytree(basedir, jacoco_basedir, symlinks=True)
567+
launcher_path = os.path.join(jacoco_basedir, 'bin', 'graalpython')
568+
with open(launcher_path, 'r', encoding='ascii', errors='ignore') as launcher:
569+
lines = launcher.readlines()
570+
assert re.match(r'^#!.*bash', lines[0]), "jacoco needs a bash launcher"
571+
lines.insert(-1, 'jvm_args+=(%s)\n' % agent_args)
572+
with open(launcher_path, 'w') as launcher:
573+
launcher.writelines(lines)
566574
# jacoco only dumps the data on exit, and when we run all our unittests
567575
# at once it generates so much data we run out of heap space
568-
env['JAVA_TOOL_OPTIONS'] = agent_args
569576
for testfile in testfiles:
570-
mx.run([python_binary] + args + [testfile], nonZeroIsFatal=True, env=env)
577+
mx.run([launcher_path] + args + [testfile], nonZeroIsFatal=True, env=env)
571578
else:
572579
args += testfiles
573580
mx.logv(" ".join([python_binary] + args))
574581
return mx.run([python_binary] + args, nonZeroIsFatal=True, env=env)
575582

576583

584+
def run_tagged_unittests(python_binary, env=None):
585+
if env is None:
586+
env = os.environ
587+
env = env.copy()
588+
env.update(
589+
ENABLE_CPYTHON_TAGGED_UNITTESTS="true",
590+
ENABLE_THREADED_GRAALPYTEST="true",
591+
PYTHONPATH=os.path.join(_dev_pythonhome(), 'lib-python/3'),
592+
)
593+
run_python_unittests(
594+
python_binary,
595+
args=["-v",
596+
"--python.WithThread=true"],
597+
paths=["test_tagged_unittests.py"],
598+
env=env,
599+
)
600+
601+
577602
def graalpython_gate_runner(args, tasks):
578603
# JUnit tests
579604
with Task('GraalPython JUnit', tasks, tags=[GraalPythonTags.junit]) as task:
@@ -613,19 +638,7 @@ def graalpython_gate_runner(args, tasks):
613638

614639
with Task('GraalPython Python tests', tasks, tags=[GraalPythonTags.tagged]) as task:
615640
if task:
616-
env = os.environ.copy()
617-
env.update(
618-
ENABLE_CPYTHON_TAGGED_UNITTESTS="true",
619-
ENABLE_THREADED_GRAALPYTEST="true",
620-
PYTHONPATH=os.path.join(_dev_pythonhome(), 'lib-python/3'),
621-
)
622-
run_python_unittests(
623-
python_gvm(),
624-
args=["-v",
625-
"--python.WithThread=true"],
626-
paths=["test_tagged_unittests.py"],
627-
env=env,
628-
)
641+
run_tagged_unittests(python_gvm())
629642

630643
# Unittests on SVM
631644
with Task('GraalPython tests on SVM', tasks, tags=[GraalPythonTags.svmunit]) as task:
@@ -1469,11 +1482,7 @@ def python_coverage(args):
14691482
{"args": []},
14701483
{"args": ["--python.EmulateJython"], "paths": ["test_interop.py"]},
14711484
# {"args": ["--llvm.managed"]},
1472-
{
1473-
"args": ["-v", "--python.WithThread=true"],
1474-
"paths": ["test_tagged_unittests.py"],
1475-
"tagged": True
1476-
},
1485+
{"tagged": True},
14771486
]
14781487
outputlcov = "coverage.lcov"
14791488
if os.path.exists(outputlcov):
@@ -1487,20 +1496,19 @@ def python_coverage(args):
14871496
if os.path.exists(outfile):
14881497
os.unlink(outfile)
14891498
extra_args = [
1499+
"--experimental-options",
14901500
"--coverage",
14911501
"--coverage.TrackInternal",
1492-
"--coverage.FilterFile=%s/*.%s" % (prefix, pattern),
1502+
"--coverage.FilterFile=*/lib-*/*.%s" % pattern,
14931503
"--coverage.Output=lcov",
14941504
"--coverage.OutputFile=%s" % outfile,
14951505
]
1496-
with set_env(GRAAL_PYTHON_ARGS=" ".join(extra_args)):
1497-
with _dev_pythonhome_context(): # run all our tests in the dev-home, so that lcov has consistent paths
1498-
kwds["args"].append("--python.CAPI=" + _get_capi_home())
1499-
if kwds.pop("tagged", False):
1500-
with set_env(ENABLE_CPYTHON_TAGGED_UNITTESTS="true", ENABLE_THREADED_GRAALPYTEST="true"):
1501-
run_python_unittests(executable, **kwds)
1502-
else:
1503-
run_python_unittests(executable, **kwds)
1506+
env = os.environ.copy()
1507+
env['GRAAL_PYTHON_ARGS'] = " ".join(extra_args)
1508+
if kwds.pop("tagged", False):
1509+
run_tagged_unittests(executable, env=env)
1510+
else:
1511+
run_python_unittests(executable, env=env, **kwds)
15041512

15051513
# generate a synthetic lcov file that includes all sources with 0
15061514
# coverage. this is to ensure all sources actuall show up - otherwise,
@@ -1517,7 +1525,7 @@ def python_coverage(args):
15171525
for filename in filenames:
15181526
if filename.endswith(".py"):
15191527
fullname = os.path.join(dirpath, filename)
1520-
with open(fullname, 'r') as f:
1528+
with open(fullname, 'rb') as f:
15211529
try:
15221530
compile(f.read(), fullname, 'exec')
15231531
except BaseException as e:
@@ -1537,9 +1545,16 @@ def python_coverage(args):
15371545
f.name
15381546
])
15391547

1548+
home_launcher = os.path.join(os.path.dirname(os.path.dirname(executable)), 'jre/languages/python')
15401549
# merge all generated lcov files
15411550
for f in os.listdir(SUITE.dir):
1542-
if f.endswith(".lcov"):
1551+
if f.endswith(".lcov") and os.path.getsize(f):
1552+
# Normalize lib-graalpython path
1553+
with open(f) as lcov_file:
1554+
lcov = lcov_file.read()
1555+
lcov = lcov.replace(home_launcher, prefix)
1556+
with open(f, 'w') as lcov_file:
1557+
lcov_file.write(lcov)
15431558
cmdargs += ["-a", f]
15441559

15451560
mx.run(cmdargs)

0 commit comments

Comments
 (0)