Skip to content

Commit ee60ed5

Browse files
committed
[GR-22245] [GR-23280] Fix a few builtin tests
PullRequest: graalpython/979
2 parents 0ddcc33 + c575eac commit ee60ed5

File tree

14 files changed

+222
-116
lines changed

14 files changed

+222
-116
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/ConsoleHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -88,12 +88,15 @@ public void setHistory(BooleanSupplier shouldRecord, IntSupplier getSize, Consum
8888
public InputStream createInputStream() {
8989
return new InputStream() {
9090
byte[] buffer = null;
91-
int pos = -1;
91+
int pos = 0;
9292

9393
@Override
9494
public int read() throws IOException {
95-
if (buffer == null) {
95+
if (pos < 0) {
9696
pos = 0;
97+
return -1;
98+
} else if (buffer == null) {
99+
assert pos == 0;
97100
String line = readLine(false);
98101
if (line == null) {
99102
return -1;
@@ -102,6 +105,7 @@ public int read() throws IOException {
102105
}
103106
if (pos == buffer.length) {
104107
buffer = null;
108+
pos = -1;
105109
return '\n';
106110
} else {
107111
return buffer[pos++];

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,21 @@ def __init__(self):
117117
self.passed = 0
118118
self.failed = 0
119119

120+
def get_useful_frame(self, tb):
121+
from traceback import extract_tb
122+
frame_summaries = extract_tb(tb)
123+
frame_summaries.reverse()
124+
for summary in frame_summaries:
125+
# Skip frame summary entries that refer to this file. These summaries will mostly be there because of the
126+
# assert functions and their location is not interesting.
127+
if summary[0] != __file__:
128+
return summary
129+
130+
120131
def run_safely(self, func, print_immediately=False):
121132
if verbose:
122133
with print_lock:
123-
print(u"\n\t\u21B3 ", func.__name__, " ", end="")
134+
print(u"\n\t\u21B3 ", func.__name__, " ", end="", flush=True)
124135
try:
125136
func()
126137
except BaseException as e:
@@ -132,8 +143,7 @@ def run_safely(self, func, print_immediately=False):
132143
code = func.__code__
133144
_, _, tb = sys.exc_info()
134145
try:
135-
from traceback import extract_tb
136-
filename, line, func, text = extract_tb(tb)[-1]
146+
filename, line, func, text = self.get_useful_frame(tb)
137147
self.exceptions.append(
138148
("In test '%s': %s:%d (%s)" % (code.co_filename, filename, line, func), e)
139149
)
@@ -152,18 +162,24 @@ def run_test(self, func):
152162
pass
153163
else:
154164
def do_run():
165+
start = time.monotonic()
155166
r = self.run_safely(func)
167+
end = time.monotonic() - start
156168
with print_lock:
157-
self.success() if r else self.failure()
169+
self.success(end) if r else self.failure(end)
158170
ThreadPool.start(do_run)
159171

160-
def success(self):
172+
def success(self, time):
161173
self.passed += 1
174+
if verbose:
175+
print("[%.3fs]" % time, end=" ")
162176
print(".", end="", flush=True)
163177

164-
def failure(self):
178+
def failure(self, time):
165179
self.failed += 1
166180
fail_msg = FAIL + BOLD + "F" + ENDC if verbose else "F"
181+
if verbose:
182+
print("[%.3fs]" % time, end=" ")
167183
print(fail_msg, end="", flush=True)
168184

169185
def assertIsInstance(self, value, cls):

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def fun(self):
9292
cmd.append(os.path.join(os.path.dirname(test.__file__), "%s.py" % testmod))
9393
subprocess.check_call(cmd)
9494
print(working_test[0], "was finished.")
95-
95+
9696
fun.__name__ = "%s[%d/%d]" % (working_test[0], idx + 1, len(WORKING_TESTS))
9797
return fun
9898

@@ -142,6 +142,8 @@ def parse_unittest_output(output):
142142
elif arg == "--help":
143143
print(sys.argv[0] + " [--retag] [--maxrepeats=n] [glob]")
144144
else:
145+
if not (arg.endswith(".py") or arg.endswith("*")):
146+
arg += ".py"
145147
glob_pattern = os.path.join(os.path.dirname(test.__file__), arg)
146148

147149
p = subprocess.run(["/usr/bin/which", "timeout" if sys.platform != 'darwin' else 'gtimeout'], **kwargs)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
11
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_all
22
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_any
33
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_bin
4+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_bug_27936
5+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_bytearray_extend_error
6+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_bytearray_translate
7+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_callable
8+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_cmp
9+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_delattr
10+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_exec
11+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_exec_redirected
12+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_hex
13+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_id
14+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_isinstance
15+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_issubclass
16+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_map
17+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_neg
18+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_next
19+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_oct
20+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_open_default_encoding
21+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_repr
22+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_round_large
23+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_type
24+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_zip
25+
*graalpython.lib-python.3.test.test_builtin.BuiltinTest.test_zip_bad_iterable
26+
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_no_stdout_fileno
27+
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty
28+
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty_non_ascii
29+
*graalpython.lib-python.3.test.test_builtin.PtyTests.test_input_tty_non_ascii_unicode_errors
30+
*graalpython.lib-python.3.test.test_builtin.TestBreakpoint.test_breakpoint_with_passthru_error
31+
*graalpython.lib-python.3.test.test_builtin.TestSorted.test_basic
32+
*graalpython.lib-python.3.test.test_builtin.TestSorted.test_inputtypes

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Builtin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
*/
2626
package com.oracle.graal.python.builtins;
2727

28+
import java.lang.annotation.Repeatable;
2829
import java.lang.annotation.Retention;
2930
import java.lang.annotation.RetentionPolicy;
3031

3132
@Retention(RetentionPolicy.RUNTIME)
33+
@Repeatable(value = Builtins.class)
3234
public @interface Builtin {
3335

3436
String name() default "";
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.builtins;
42+
43+
import java.lang.annotation.Retention;
44+
import java.lang.annotation.RetentionPolicy;
45+
46+
@Retention(RetentionPolicy.RUNTIME)
47+
public @interface Builtins {
48+
Builtin[] value();
49+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
import java.util.List;
3434
import java.util.Map;
3535
import java.util.Map.Entry;
36-
import com.oracle.graal.python.util.BiConsumer;
3736

3837
import com.oracle.graal.python.builtins.objects.PNone;
3938
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4039
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
4140
import com.oracle.graal.python.nodes.function.BuiltinFunctionRootNode;
4241
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4342
import com.oracle.graal.python.runtime.PythonCore;
43+
import com.oracle.graal.python.util.BiConsumer;
4444
import com.oracle.truffle.api.RootCallTarget;
4545
import com.oracle.truffle.api.Truffle;
4646
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -117,8 +117,15 @@ private void initializeEachFactoryWith(BiConsumer<NodeFactory<? extends PythonBu
117117
List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> factories = getNodeFactories();
118118
assert factories != null : "No factories found. Override getFactories() to resolve this.";
119119
for (NodeFactory<? extends PythonBuiltinBaseNode> factory : factories) {
120-
Builtin builtin = factory.getNodeClass().getAnnotation(Builtin.class);
121-
func.accept(factory, builtin);
120+
Boolean needsFrame = null;
121+
for (Builtin builtin : factory.getNodeClass().getAnnotationsByType(Builtin.class)) {
122+
if (needsFrame == null) {
123+
needsFrame = builtin.needsFrame();
124+
} else if (needsFrame != builtin.needsFrame()) {
125+
throw new IllegalStateException(String.format("Implementation error in %s: all @Builtin annotations must agree if the node needs a frame.", factory.getNodeClass().getName()));
126+
}
127+
func.accept(factory, builtin);
128+
}
122129
}
123130
}
124131

0 commit comments

Comments
 (0)