|
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
|
@@ -147,16 +148,16 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, extra_dists=None
|
147 | 148 | dists += extra_dists
|
148 | 149 |
|
149 | 150 | if not os.environ.get("CI"):
|
| 151 | + graalpython_args.insert(0, "--llvm.enableLVI=true") |
150 | 152 | # Try eagerly to include tools for convenience when running Python
|
151 | 153 | if not mx.suite("tools", fatalIfMissing=False):
|
152 | 154 | SUITE.import_suite("tools", version=None, urlinfos=None, in_subdir=True)
|
153 | 155 | 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) |
158 | 159 | else:
|
159 |
| - mx.logv("CHROMEINSPECTOR was not built, not including it automatically") |
| 160 | + mx.logv("%s was not built, not including it automatically" % tool) |
160 | 161 |
|
161 | 162 | graalpython_args.insert(0, '--experimental-options=true')
|
162 | 163 |
|
@@ -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,91 @@ 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 | + 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]) |
1218 | 1302 |
|
1219 | 1303 |
|
1220 | 1304 | def python_build_watch(args):
|
@@ -1487,6 +1571,6 @@ def checkout_find_version_for_graalvm(args):
|
1487 | 1571 | 'nativebuild': [nativebuild, ''],
|
1488 | 1572 | 'nativeclean': [nativeclean, ''],
|
1489 | 1573 | 'python-src-import': [import_python_sources, ''],
|
1490 |
| - 'python-coverage': [python_coverage, '[gate-tag]'], |
| 1574 | + 'python-coverage': [python_coverage, ''], |
1491 | 1575 | 'punittest': [punittest, ''],
|
1492 | 1576 | })
|
0 commit comments