Skip to content

Commit 689bdb8

Browse files
committed
[GR-17455] [GR-15519] Upload coverage results
PullRequest: graalpython/843
2 parents 4e5bf6e + 396d1c8 commit 689bdb8

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "24133c3957a7e99cef8bf3ecc52833e4eb0ba3fe" }
1+
{ "overlay": "05cd3bf109fc28e21f72b06e1265e07aa2d40c28" }

mx.graalpython/mx_graalpython.py

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from __future__ import print_function
2626

2727
import contextlib
28+
import datetime
2829
import glob
2930
import json
3031
import os
@@ -147,16 +148,16 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None
147148
dists += extra_dists
148149

149150
if not os.environ.get("CI"):
151+
graalpython_args.insert(0, "--llvm.enableLVI=true")
150152
# Try eagerly to include tools for convenience when running Python
151153
if not mx.suite("tools", fatalIfMissing=False):
152154
SUITE.import_suite("tools", version=None, urlinfos=None, in_subdir=True)
153155
if mx.suite("tools", fatalIfMissing=False):
154-
if os.path.exists(mx.suite("tools").dependency("CHROMEINSPECTOR").path):
155-
# CHROMEINSPECTOR was built, put it on the classpath
156-
dists.append('CHROMEINSPECTOR')
157-
graalpython_args.insert(0, "--llvm.enableLVI=true")
156+
for tool in ["CHROMEINSPECTOR", "TRUFFLE_COVERAGE"]:
157+
if os.path.exists(mx.suite("tools").dependency(tool).path):
158+
dists.append(tool)
158159
else:
159-
mx.logv("CHROMEINSPECTOR was not built, not including it automatically")
160+
mx.logv("%s was not built, not including it automatically" % tool)
160161

161162
graalpython_args.insert(0, '--experimental-options=true')
162163

@@ -378,6 +379,7 @@ def is_included(path):
378379

379380
args += [_graalpytest_driver(), "-v"]
380381
args += testfiles
382+
mx.logv(" ".join([python_binary] + args))
381383
return mx.run([python_binary] + args, nonZeroIsFatal=True)
382384

383385

@@ -1212,9 +1214,91 @@ def mx_post_parse_cmd_line(namespace):
12121214

12131215

12141216
def python_coverage(args):
1215-
"Generate coverage report running args"
1216-
mx.run_mx(['--jacoco=on', '--jacoco-whitelist-package=com.oracle.graal.python'] + args)
1217-
mx.command_function("jacocoreport")(["--omit-excluded", "--format=html"])
1217+
"Generate coverage report for our unittests"
1218+
os.system("which lcov")
1219+
os.system("which genhtml")
1220+
parser = ArgumentParser(prog='mx python-coverage')
1221+
parser.add_argument('--jacoco', action='store_true', help='do generate Jacoco coverage')
1222+
parser.add_argument('--truffle', action='store_true', help='do generate Truffle coverage')
1223+
parser.add_argument('--truffle-upload-url', help='Format is like rsync: user@host:/directory', default=None)
1224+
args = parser.parse_args(args)
1225+
1226+
if args.jacoco:
1227+
jacoco_args = [
1228+
'--jacoco-whitelist-package', 'com.oracle.graal.python',
1229+
# '--jacoco-exclude-annotation', '@GeneratedBy',
1230+
]
1231+
mx.run_mx(jacoco_args + [
1232+
'--strict-compliance',
1233+
'--dynamicimports', '/compiler',
1234+
'--primary', 'gate',
1235+
'-B=--force-deprecation-as-warning-for-dependencies',
1236+
'--strict-mode',
1237+
'--tags', 'python-unittest,python-tagged-unittest,python-junit',
1238+
'--jacocout', 'html',
1239+
])
1240+
if mx.get_env("SONAR_HOST_URL", None):
1241+
mx.run_mx(jacoco_args + [
1242+
'sonarqube-upload',
1243+
'-Dsonar.host.url=%s' % mx.get_env("SONAR_HOST_URL"),
1244+
'-Dsonar.projectKey=com.oracle.graalvm.python',
1245+
'-Dsonar.projectName=GraalVM - Python',
1246+
'--exclude-generated',
1247+
])
1248+
mx.run_mx(jacoco_args + [
1249+
'coverage-upload',
1250+
])
1251+
if args.truffle:
1252+
executable = python_gvm()
1253+
variants = [
1254+
{},
1255+
{"args": ["--python.EmulateJython"], "paths": ["test_interop.py"]},
1256+
# {"args": ["--llvm.managed"]},
1257+
{
1258+
"args": ["-v", "--python.WithThread=true", "--python.CAPI=" + _get_capi_home()],
1259+
"paths": ["test_tagged_unittests.py"],
1260+
"tagged": True
1261+
},
1262+
]
1263+
outputlcov = "coverage.lcov"
1264+
if os.path.exists(outputlcov):
1265+
os.unlink(outputlcov)
1266+
cmdargs = ["/usr/bin/env", "lcov", "-o", outputlcov]
1267+
for kwds in variants:
1268+
variant_str = re.sub(r"[^a-zA-Z]", "_", repr(kwds))
1269+
for pattern in ["py"]:
1270+
outfile = os.path.join(SUITE.dir, "coverage_%s_%s.lcov" % (variant_str, pattern))
1271+
if os.path.exists(outfile):
1272+
os.unlink(outfile)
1273+
extra_args = [
1274+
"--coverage",
1275+
"--coverage.TrackInternal",
1276+
"--coverage.FilterFile=*.%s" % pattern,
1277+
"--coverage.Output=lcov",
1278+
"--coverage.OutputFile=%s" % outfile,
1279+
]
1280+
kwds["args"] = extra_args + kwds.get("args", [])
1281+
if kwds.pop("tagged", False):
1282+
with set_env(ENABLE_CPYTHON_TAGGED_UNITTESTS="true", ENABLE_THREADED_GRAALPYTEST="true"):
1283+
with _dev_pythonhome_context():
1284+
run_python_unittests(executable, **kwds)
1285+
else:
1286+
run_python_unittests(executable, **kwds)
1287+
cmdargs += ["-a", outfile]
1288+
mx.run(cmdargs)
1289+
primary = mx.primary_suite()
1290+
info = primary.vc.parent_info(primary.dir)
1291+
rev = primary.vc.parent(primary.dir)
1292+
coverage_dir = '{}-truffle-coverage_{}_{}'.format(
1293+
primary.name,
1294+
datetime.datetime.fromtimestamp(info['author-ts']).strftime('%Y-%m-%d_%H_%M'),
1295+
rev[:7],
1296+
)
1297+
mx.run(["/usr/bin/env", "genhtml", "-o", coverage_dir, outputlcov])
1298+
if args.truffle_upload_url:
1299+
if not args.truffle_upload_url.endswith("/"):
1300+
args.truffle_upload_url = args.truffle_upload_url + "/"
1301+
mx.run(["scp", "-r", coverage_dir, args.truffle_upload_url])
12181302

12191303

12201304
def python_build_watch(args):
@@ -1487,6 +1571,6 @@ def checkout_find_version_for_graalvm(args):
14871571
'nativebuild': [nativebuild, ''],
14881572
'nativeclean': [nativeclean, ''],
14891573
'python-src-import': [import_python_sources, ''],
1490-
'python-coverage': [python_coverage, '[gate-tag]'],
1574+
'python-coverage': [python_coverage, ''],
14911575
'punittest': [punittest, ''],
14921576
})

0 commit comments

Comments
 (0)