Skip to content

Commit a86daf4

Browse files
committed
Merge remote-tracking branch 'origin/master' into tim/GR-9957/dynamic-cast
2 parents d60014d + 4f57b69 commit a86daf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1806
-506
lines changed

graalpython/com.oracle.graal.python.cext/src/capi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ PyAPI_DATA(PyTypeObject) _PyExc_BaseException;
7373

7474
extern void* to_java(PyObject* obj);
7575
extern void* to_java_type(PyTypeObject* cls);
76+
void* native_to_java(PyObject* obj);
7677
extern PyObject* to_sulong(void *o);
7778
#define as_char_pointer(obj) polyglot_invoke(PY_TRUFFLE_CEXT, "to_char_pointer", to_java(obj))
7879
#define as_long(obj) ((long)polyglot_as_i64(polyglot_invoke(PY_TRUFFLE_CEXT, "to_long", to_java(obj))))

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ PyObject* PyObject_CallObject(PyObject* callable, PyObject* args) {
539539
PyObject* PyObject_CallFunction(PyObject* callable, const char* fmt, ...) {
540540
PyObject* args;
541541
CALL_WITH_VARARGS(args, Py_BuildValue, 2, fmt);
542-
args = to_sulong(args);
543542
if (strlen(fmt) < 2) {
544543
PyObject* singleArg = args;
545544
args = PyTuple_New(strlen(fmt));

graalpython/com.oracle.graal.python.test/src/python_unittests.py

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,38 @@
3636
# SOFTWARE.
3737

3838
import csv
39+
import gzip
3940
import os
4041
import re
4142
import subprocess
43+
import sys
4244
from collections import defaultdict
4345
from json import dumps
4446
from multiprocessing import Pool
4547
from pprint import pformat
48+
from time import gmtime, strftime
4649

4750
import argparse
48-
import sys
49-
from time import gmtime, strftime
5051

5152
# global CLI flags
5253
flags = None
5354

5455
# constants
5556
PATH_UNITTESTS = "graalpython/lib-python/3/test/"
5657

57-
CSV_RESULTS_NAME = "unittests.csv"
58-
HTML_RESULTS_NAME = "unittests.html"
58+
_BASE_NAME = "unittests"
59+
TXT_RESULTS_NAME = "{}.txt.gz".format(_BASE_NAME)
60+
CSV_RESULTS_NAME = "{}.csv".format(_BASE_NAME)
61+
HTML_RESULTS_NAME = "{}.html".format(_BASE_NAME)
62+
5963

6064
PTRN_ERROR = re.compile(r'^(?P<error>[A-Z][a-z][a-zA-Z]+):(?P<message>.*)$')
6165
PTRN_UNITTEST = re.compile(r'^#### running: graalpython/lib-python/3/test/(?P<unittest>.*)$')
6266
PTRN_NUM_TESTS = re.compile(r'^Ran (?P<num_tests>\d+) test.*$')
6367
PTRN_NUM_ERRORS = re.compile(
6468
r'^FAILED \((failures=(?P<failures>\d+))?(, )?(errors=(?P<errors>\d+))?(, )?(skipped=(?P<skipped>\d+))?\)$')
69+
PTRN_JAVA_EXCEPTION = re.compile(r'^(?P<exception>com\.oracle\.[^:]*):(?P<message>.*)')
70+
PTRN_MODULE_NOT_FOUND = re.compile(r'.*ModuleNotFound: \'(?P<module>.*)\'\..*', re.DOTALL)
6571

6672

6773
# ----------------------------------------------------------------------------------------------------------------------
@@ -79,7 +85,7 @@ def debug(msg, *args, **kwargs):
7985

8086

8187
def file_name(name, current_date_time):
82-
idx = name.rindex('.')
88+
idx = name.index('.')
8389
if idx > 0:
8490
return '{}-{}{}'.format(name[:idx], current_date_time, name[idx:])
8591
return '{}-{}'.format(name, current_date_time)
@@ -117,7 +123,7 @@ def scp(results_file_path, destination_path, destination_name=None):
117123

118124

119125
def _run_unittest(test_path):
120-
cmd = ["mx", "python3", "--python.CatchAllExceptions=true", test_path]
126+
cmd = ["mx", "python3", "--python.CatchAllExceptions=true", test_path, "-v"]
121127
success, output = _run_cmd(cmd)
122128
output = '''
123129
##############################################################
@@ -128,14 +134,17 @@ def _run_unittest(test_path):
128134

129135
def run_unittests(unittests):
130136
assert isinstance(unittests, (list, tuple))
131-
log("[EXEC] running {} unittests ... ".format(len(unittests)))
137+
num_unittests = len(unittests)
138+
log("[EXEC] running {} unittests ... ", num_unittests)
132139
results = []
140+
133141
pool = Pool()
134142
for ut in unittests:
135-
results.append(pool.apply_async(_run_unittest, args=(ut,)))
143+
results.append(pool.apply_async(_run_unittest, args=(ut, )))
136144
pool.close()
137145
pool.join()
138-
return [r.get()[1] for r in results]
146+
147+
return [res.get()[1] for res in results]
139148

140149

141150
def get_unittests(base_tests_path, limit=None, sort=True):
@@ -177,6 +186,7 @@ def process_output(output_lines):
177186

178187
unittests = []
179188
error_messages = defaultdict(set)
189+
java_exceptions = defaultdict(set)
180190
stats = defaultdict(StatEntry)
181191

182192
for line in output_lines:
@@ -191,6 +201,12 @@ def process_output(output_lines):
191201
error_messages[unittests[-1]].add((match.group('error'), match.group('message')))
192202
continue
193203

204+
# extract java exceptions
205+
match = re.match(PTRN_JAVA_EXCEPTION, line)
206+
if match:
207+
java_exceptions[unittests[-1]].add((match.group('exception'), match.group('message')))
208+
continue
209+
194210
# stats
195211
if line.strip() == 'OK':
196212
stats[unittests[-1]].all_ok()
@@ -213,27 +229,34 @@ def process_output(output_lines):
213229
stats[unittests[-1]].num_errors = int(errs) if errs else 0
214230
stats[unittests[-1]].num_skipped = int(skipped) if skipped else 0
215231

216-
return unittests, error_messages, stats
232+
return unittests, error_messages, java_exceptions, stats
217233

218234

219235
# ----------------------------------------------------------------------------------------------------------------------
220236
#
221237
# python error processing
222238
#
223239
# ----------------------------------------------------------------------------------------------------------------------
224-
def process_errors(unittests, error_messages, error, msg_processor):
240+
def process_errors(unittests, error_messages, error=None, msg_processor=None):
241+
def _err_filter(item):
242+
if not error:
243+
return True
244+
return item[0] == error
245+
246+
def _processor(msg):
247+
if not msg_processor:
248+
return msg
249+
return msg_processor(msg)
250+
225251
missing_modules = defaultdict(lambda: 0)
226252
for ut in unittests:
227253
errors = error_messages[ut]
228-
for name in map(msg_processor, (msg for err, msg in errors if err == error)):
254+
for name in map(_processor, (msg for err, msg in filter(_err_filter, errors))):
229255
missing_modules[name] = missing_modules[name] + 1
230256

231257
return missing_modules
232258

233259

234-
PTRN_MODULE_NOT_FOUND = re.compile(r'.*ModuleNotFound: \'(?P<module>.*)\'\..*', re.DOTALL)
235-
236-
237260
def get_missing_module(msg):
238261
match = re.match(PTRN_MODULE_NOT_FOUND, msg)
239262
return match.group('module') if match else None
@@ -278,7 +301,14 @@ class Stat(object):
278301
TEST_PERCENT_PASS = "test_percent_pass" # percentage of tests which pass from all running tests (all unittests)
279302

280303

281-
def save_as_csv(report_path, unittests, error_messages, stats, current_date):
304+
def save_as_txt(report_path, results):
305+
with gzip.open(report_path, 'wb') as TXT:
306+
output = '\n'.join(results)
307+
TXT.write(bytes(output, 'utf-8'))
308+
return output
309+
310+
311+
def save_as_csv(report_path, unittests, error_messages, java_exceptions, stats):
282312
rows = []
283313
with open(report_path, 'w') as CSV:
284314
totals = {
@@ -294,6 +324,9 @@ def save_as_csv(report_path, unittests, error_messages, stats, current_date):
294324
for unittest in unittests:
295325
unittest_stats = stats[unittest]
296326
unittest_errmsg = error_messages[unittest]
327+
if not unittest_errmsg:
328+
unittest_errmsg = java_exceptions[unittest]
329+
297330
rows.append({
298331
Col.UNITTEST: unittest,
299332
Col.NUM_TESTS: unittest_stats.num_tests,
@@ -424,7 +457,7 @@ def save_as_csv(report_path, unittests, error_messages, stats, current_date):
424457
'''
425458

426459

427-
def save_as_html(report_name, rows, totals, missing_modules, current_date):
460+
def save_as_html(report_name, rows, totals, missing_modules, java_issues, current_date):
428461
def grid(*components):
429462
def _fmt(cmp):
430463
if isinstance(cmp, tuple):
@@ -522,10 +555,15 @@ def format_val(row, k):
522555
'''
523556

524557
missing_modules_info = ul('missing modules', [
525-
'<b>{}</b>&nbsp;<span class="text-muted">count: {}</span>'.format(name, cnt)
558+
'<b>{}</b>&nbsp;<span class="text-muted">imported by {} unittests</span>'.format(name, cnt)
526559
for cnt, name in sorted(((cnt, name) for name, cnt in missing_modules.items()), reverse=True)
527560
])
528561

562+
java_issues_info = ul('Java issues', [
563+
'<b>{}</b>&nbsp;<span class="text-muted">caused by {} unittests</span>'.format(name, cnt)
564+
for cnt, name in sorted(((cnt, name) for name, cnt in java_issues.items()), reverse=True)
565+
])
566+
529567
total_stats_info = ul("<b>Summary</b>", [
530568
grid('<b># total</b> unittests: {}'.format(totals[Stat.UT_TOTAL])),
531569
grid((progress_bar(totals[Stat.UT_PERCENT_RUNS], color="info"), 3),
@@ -539,7 +577,7 @@ def format_val(row, k):
539577

540578
table_stats = table('stats', CSV_HEADER, rows)
541579

542-
content = ' <br> '.join([total_stats_info, table_stats, missing_modules_info])
580+
content = ' <br> '.join([total_stats_info, table_stats, missing_modules_info, java_issues_info])
543581

544582
report = HTML_TEMPLATE.format(
545583
title='GraalPython Unittests Stats',
@@ -595,19 +633,27 @@ def _fmt(t):
595633
unittests = get_unittests(flags.tests_path, limit=flags.limit)
596634

597635
results = run_unittests(unittests)
598-
unittests, error_messages, stats = process_output('\n'.join(results))
636+
txt_report_path = file_name(TXT_RESULTS_NAME, current_date)
637+
output = save_as_txt(txt_report_path, results)
638+
639+
unittests, error_messages, java_exceptions, stats = process_output(output)
599640

600641
csv_report_path = file_name(CSV_RESULTS_NAME, current_date)
601-
rows, totals = save_as_csv(csv_report_path, unittests, error_messages, stats, current_date)
642+
rows, totals = save_as_csv(csv_report_path, unittests, error_messages, java_exceptions, stats)
602643

603-
missing_modules = process_errors(unittests, error_messages, 'ModuleNotFoundError', get_missing_module)
644+
missing_modules = process_errors(unittests, error_messages, error='ModuleNotFoundError',
645+
msg_processor=get_missing_module)
604646
log("[MISSING MODULES] \n{}", pformat(dict(missing_modules)))
605647

648+
java_issues = process_errors(unittests, java_exceptions)
649+
log("[JAVA ISSUES] \n{}", pformat(dict(java_issues)))
650+
606651
html_report_path = file_name(HTML_RESULTS_NAME, current_date)
607-
save_as_html(html_report_path, rows, totals, missing_modules, current_date)
652+
save_as_html(html_report_path, rows, totals, missing_modules, java_issues, current_date)
608653

609654
if flags.path:
610655
log("[SAVE] saving results to {} ... ", flags.path)
656+
scp(txt_report_path, flags.path)
611657
scp(csv_report_path, flags.path)
612658
scp(html_report_path, flags.path)
613659

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def setUp(self):
6969

7070
def ccompile(self, name):
7171
from distutils.core import setup, Extension
72-
module = Extension(name, sources=['%s/%s.c' % (__dir__, name)])
72+
source_file = '%s/%s.c' % (__dir__, name)
73+
module = Extension(name, sources=[source_file])
7374
args = ['--quiet', 'build', 'install_lib', '-f', '--install-dir=%s' % __dir__]
7475
setup(
7576
script_name='setup',
@@ -79,6 +80,13 @@ def ccompile(self, name):
7980
description='',
8081
ext_modules=[module]
8182
)
83+
# ensure file was really written
84+
try:
85+
stat_result = os.stat(source_file)
86+
if stat_result[6] == 0:
87+
raise SystemError("empty source file %s" % (source_file,))
88+
except FileNotFoundError:
89+
raise SystemError("source file %s not available" % (source_file,))
8290

8391

8492
c_template = """
@@ -377,6 +385,7 @@ def create_module(self, name=None):
377385

378386

379387
class UnseenFormatter(Formatter):
388+
380389
def get_value(self, key, args, kwds):
381390
if isinstance(key, str):
382391
try:

graalpython/com.oracle.graal.python.test/src/tests/test_iterator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,16 @@ def test_iter():
100100

101101
def test_zip_no_args():
102102
assert list(zip(*[])) == []
103+
104+
105+
def test_iter_try_except():
106+
it = iter(range(3))
107+
exit_via_break = False
108+
while 1:
109+
try:
110+
next(it)
111+
except StopIteration:
112+
exit_via_break = True
113+
break
114+
115+
assert exit_via_break

0 commit comments

Comments
 (0)