Skip to content

Commit b60d6f8

Browse files
committed
generate and potentially upload both jacoco and truffle coverage
1 parent a54f264 commit b60d6f8

File tree

2 files changed

+85
-5
lines changed

2 files changed

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

12191299

12201300
def python_build_watch(args):
@@ -1487,6 +1567,6 @@ def checkout_find_version_for_graalvm(args):
14871567
'nativebuild': [nativebuild, ''],
14881568
'nativeclean': [nativeclean, ''],
14891569
'python-src-import': [import_python_sources, ''],
1490-
'python-coverage': [python_coverage, '[gate-tag]'],
1570+
'python-coverage': [python_coverage, ''],
14911571
'punittest': [punittest, ''],
14921572
})

0 commit comments

Comments
 (0)