Skip to content

Commit dea1a7c

Browse files
committed
Add mx python-update-unittest-tags command
1 parent 0208d3c commit dea1a7c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import contextlib
2828
import datetime
2929
import glob
30+
import itertools
3031
import json
3132
import os
3233
import platform
@@ -232,6 +233,66 @@ def retag_unittests(args):
232233
mx.run(['scp', filename, parsed_args.upload_results_to.rstrip('/') + '/'])
233234

234235

236+
def _read_tags(path='.'):
237+
tags = set()
238+
tagfiles = glob.glob(os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/*.txt'))
239+
for tagfile in tagfiles:
240+
with open(tagfile) as f:
241+
tags |= {(os.path.basename(tagfile), line.strip()) for line in f if line.strip()}
242+
return tags
243+
244+
245+
def _write_tags(tags, path='.'):
246+
tagdir = os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/')
247+
tagfiles = glob.glob(os.path.join(path, 'graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/*.txt'))
248+
for file in tagfiles:
249+
os.unlink(file)
250+
for file, tags in itertools.groupby(sorted(tags), key=lambda x: x[0]):
251+
with open(os.path.join(tagdir, file), 'w') as f:
252+
for tag in tags:
253+
f.write(tag[1] + '\n')
254+
255+
256+
def _fetch_tags_for_platform(parsed_args, platform):
257+
oldpwd = os.getcwd()
258+
with tempfile.TemporaryDirectory(prefix='graalpython-update-tags-') as d:
259+
os.chdir(d)
260+
try:
261+
tarfile = 'unittest-tags-{}.tar.bz2'.format(platform)
262+
mx.run(['curl', '-O', '{}/{}'.format(parsed_args.tags_directory_url.rstrip('/'), tarfile)])
263+
os.mkdir(platform)
264+
mx.run(['tar', 'xf', tarfile, '-C', platform])
265+
return _read_tags(platform)
266+
finally:
267+
os.chdir(oldpwd)
268+
269+
270+
def update_unittest_tags(args):
271+
parser = ArgumentParser('mx python-update-unittest-tags')
272+
parser.add_argument('tags_directory_url')
273+
parsed_args = parser.parse_args(args)
274+
275+
current_tags = _read_tags()
276+
linux_tags = _fetch_tags_for_platform(parsed_args, 'linux')
277+
darwin_tags = _fetch_tags_for_platform(parsed_args, 'darwin')
278+
279+
# msimacek TODO: this is overly conservative as it wouldn't include tests that are skipped on the other platform
280+
result_tags = linux_tags & darwin_tags
281+
_write_tags(result_tags)
282+
283+
diff = linux_tags - darwin_tags
284+
if diff:
285+
mx.warn("The following tests work only on Linux:\n" + '\n'.join(x[1] for x in diff))
286+
287+
diff = darwin_tags - linux_tags
288+
if diff:
289+
mx.warn("The following tests work only on Darwin:\n" + '\n'.join(x[1] for x in diff))
290+
291+
diff = current_tags - result_tags
292+
if diff:
293+
mx.warn("Potential regressions:\n" + '\n'.join(x[1] for x in diff))
294+
295+
235296
AOT_INCOMPATIBLE_TESTS = ["test_interop.py"]
236297

237298
class GraalPythonTags(object):
@@ -1623,6 +1684,7 @@ def checkout_find_version_for_graalvm(args):
16231684
'python-gvm': [python_gvm, ''],
16241685
'python-unittests': [python3_unittests, ''],
16251686
'python-retag-unittests': [retag_unittests, ''],
1687+
'python-update-unittest-tags': [update_unittest_tags, ''],
16261688
'python-import-for-graal': [checkout_find_version_for_graalvm, ''],
16271689
'nativebuild': [nativebuild, ''],
16281690
'nativeclean': [nativeclean, ''],

0 commit comments

Comments
 (0)