|
25 | 25 | from __future__ import print_function
|
26 | 26 |
|
27 | 27 | import contextlib
|
| 28 | +import datetime |
28 | 29 | import glob
|
29 | 30 | import json
|
30 | 31 | import os
|
@@ -378,6 +379,7 @@ def is_included(path):
|
378 | 379 |
|
379 | 380 | args += [_graalpytest_driver(), "-v"]
|
380 | 381 | args += testfiles
|
| 382 | + mx.logv(" ".join([python_binary] + args)) |
381 | 383 | return mx.run([python_binary] + args, nonZeroIsFatal=True)
|
382 | 384 |
|
383 | 385 |
|
@@ -1212,9 +1214,87 @@ def mx_post_parse_cmd_line(namespace):
|
1212 | 1214 |
|
1213 | 1215 |
|
1214 | 1216 | 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]) |
1218 | 1298 |
|
1219 | 1299 |
|
1220 | 1300 | def python_build_watch(args):
|
@@ -1487,6 +1567,6 @@ def checkout_find_version_for_graalvm(args):
|
1487 | 1567 | 'nativebuild': [nativebuild, ''],
|
1488 | 1568 | 'nativeclean': [nativeclean, ''],
|
1489 | 1569 | 'python-src-import': [import_python_sources, ''],
|
1490 |
| - 'python-coverage': [python_coverage, '[gate-tag]'], |
| 1570 | + 'python-coverage': [python_coverage, ''], |
1491 | 1571 | 'punittest': [punittest, ''],
|
1492 | 1572 | })
|
0 commit comments