Skip to content

Commit b4eae98

Browse files
committed
[GR-15084] Add gates for sandboxed svm, shared-object, and jvm unittests
PullRequest: graalpython/485
2 parents 21f029c + 17f0eff commit b4eae98

File tree

14 files changed

+222
-172
lines changed

14 files changed

+222
-172
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ UPCALL_ID(PyBytes_FromStringAndSize);
5252
UPCALL_ID(PyTruffle_Bytes_EmptyWithCapacity);
5353
PyObject* PyBytes_FromStringAndSize(const char* str, Py_ssize_t sz) {
5454
if (str != NULL) {
55-
return UPCALL_CEXT_O(_jls_PyBytes_FromStringAndSize, polyglot_from_i8_array(str, sz));
55+
return UPCALL_CEXT_O(_jls_PyBytes_FromStringAndSize, polyglot_from_i8_array(str, sz), sz);
5656
}
5757
return UPCALL_CEXT_O(_jls_PyTruffle_Bytes_EmptyWithCapacity, sz);
5858
}
5959

6060
PyObject * PyBytes_FromString(const char *str) {
6161
if (str != NULL) {
62-
return UPCALL_CEXT_O(_jls_PyBytes_FromStringAndSize, polyglot_from_i8_array(str, strlen(str)));
62+
return UPCALL_CEXT_O(_jls_PyBytes_FromStringAndSize, polyglot_from_i8_array(str, strlen(str)), strlen(str));
6363
}
6464
return UPCALL_CEXT_O(_jls_PyTruffle_Bytes_EmptyWithCapacity, 0);
6565
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static void enterContext(String... newArgs) {
9999
PythonTests.outArray.reset();
100100
PythonTests.errArray.reset();
101101
Context prevContext = context;
102-
context = Context.newBuilder().engine(engine).allowAllAccess(true).arguments("python", newArgs).option("python.Executable", executable).build();
102+
context = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).arguments("python", newArgs).option("python.Executable", executable).build();
103103
context.initialize("python");
104104
if (prevContext != null) {
105105
closeContext(prevContext);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/MultiContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public void testSharingWithStruct() {
6969
}
7070

7171
private static Context newContext(Engine engine) {
72-
return Context.newBuilder().allowAllAccess(true).engine(engine).build();
72+
return Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).engine(engine).build();
7373
}
7474
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/debug/PythonDebugTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class PythonDebugTest {
7878
@Before
7979
public void before() {
8080
Builder newBuilder = Context.newBuilder();
81+
newBuilder.allowExperimentalOptions(true);
8182
newBuilder.allowAllAccess(true);
8283
PythonTests.closeContext();
8384
tester = new DebuggerTester(newBuilder);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/InteropLibraryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class InteropLibraryTest extends PythonTests {
5959
@Before
6060
public void setUpTest() {
6161
Builder builder = Context.newBuilder();
62+
builder.allowExperimentalOptions(true);
6263
builder.allowAllAccess(true);
6364
context = builder.build();
6465
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@
5252
import java.util.Arrays;
5353
import java.util.List;
5454

55-
import com.oracle.graal.python.runtime.interop.InteropArray;
56-
import com.oracle.graal.python.test.PythonTests;
57-
import com.oracle.truffle.api.interop.ArityException;
58-
import com.oracle.truffle.api.interop.InteropLibrary;
59-
import com.oracle.truffle.api.interop.TruffleObject;
60-
import com.oracle.truffle.api.interop.UnknownIdentifierException;
61-
import com.oracle.truffle.api.library.ExportLibrary;
62-
import com.oracle.truffle.api.library.ExportMessage;
63-
6455
import org.graalvm.polyglot.Context;
6556
import org.graalvm.polyglot.Context.Builder;
6657
import org.graalvm.polyglot.Engine;
@@ -76,6 +67,15 @@
7667
import org.junit.runners.Parameterized.Parameter;
7768
import org.junit.runners.Parameterized.Parameters;
7869

70+
import com.oracle.graal.python.runtime.interop.InteropArray;
71+
import com.oracle.graal.python.test.PythonTests;
72+
import com.oracle.truffle.api.interop.ArityException;
73+
import com.oracle.truffle.api.interop.InteropLibrary;
74+
import com.oracle.truffle.api.interop.TruffleObject;
75+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
76+
import com.oracle.truffle.api.library.ExportLibrary;
77+
import com.oracle.truffle.api.library.ExportMessage;
78+
7979
@RunWith(Enclosed.class)
8080
public class JavaInteropTest {
8181
public static class GeneralInterop extends PythonTests {
@@ -89,6 +89,7 @@ public void setUpTest() {
8989
out = new ByteArrayOutputStream();
9090
err = new ByteArrayOutputStream();
9191
Builder builder = Context.newBuilder();
92+
builder.allowExperimentalOptions(true);
9293
builder.allowAllAccess(true);
9394
builder.out(out);
9495
builder.err(err);
@@ -113,7 +114,7 @@ public void evalFailsOnError() {
113114

114115
@Test
115116
public void evalNonInteractiveThrowsSyntaxError() throws IOException {
116-
try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
117+
try (Context c = Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
117118
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build());
118119
} catch (PolyglotException t) {
119120
assertTrue(t.isSyntaxError());
@@ -125,7 +126,7 @@ public void evalNonInteractiveThrowsSyntaxError() throws IOException {
125126

126127
@Test
127128
public void evalNonInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException {
128-
try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
129+
try (Context c = Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
129130
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build());
130131
} catch (PolyglotException t) {
131132
assertTrue(t.isSyntaxError());
@@ -137,7 +138,7 @@ public void evalNonInteractiveInInteractiveTerminalThrowsSyntaxError() throws IO
137138

138139
@Test
139140
public void evalInteractiveInNonInteractiveTerminalThrowsSyntaxError() throws IOException {
140-
try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
141+
try (Context c = Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
141142
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build());
142143
} catch (PolyglotException t) {
143144
assertTrue(t.isSyntaxError());
@@ -149,7 +150,7 @@ public void evalInteractiveInNonInteractiveTerminalThrowsSyntaxError() throws IO
149150

150151
@Test
151152
public void evalInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException {
152-
try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
153+
try (Context c = Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
153154
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build());
154155
} catch (PolyglotException t) {
155156
assertTrue(t.isSyntaxError());
@@ -513,7 +514,7 @@ static class OptionsChecker {
513514
private Builder builder;
514515

515516
OptionsChecker(String option, String code, String... values) {
516-
this.builder = Context.newBuilder("python").engine(engine).allowAllAccess(true);
517+
this.builder = Context.newBuilder("python").engine(engine).allowExperimentalOptions(true).allowAllAccess(true);
517518
this.option = "python." + option;
518519
this.source = Source.create("python", code);
519520
this.values = values;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/module/MemoryviewTest.java

Lines changed: 2 additions & 2 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, 2019, 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
@@ -56,6 +56,6 @@ public void testContextReuse() {
5656
}
5757

5858
private static Context newContext(Engine engine) {
59-
return Context.newBuilder().allowAllAccess(true).engine(engine).build();
59+
return Context.newBuilder().allowExperimentalOptions(true).allowAllAccess(true).engine(engine).build();
6060
}
6161
}

graalpython/com.oracle.graal.python.test/src/tests/cpyext/demo.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, 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
@@ -49,7 +49,11 @@ static PyObject* demo_system(PyObject *self, PyObject *args)
4949

5050
if (!PyArg_ParseTuple(args, "s", &command))
5151
return NULL;
52-
sts = system(command);
52+
if (!strcmp("echo 1", command)) {
53+
sts = 0;
54+
} else {
55+
sts = 1;
56+
}
5357
return Py_BuildValue("i", sts);
5458
}
5559

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import java.nio.charset.CharsetEncoder;
5656
import java.nio.charset.CodingErrorAction;
5757
import java.nio.charset.StandardCharsets;
58+
import java.util.Arrays;
5859
import java.util.List;
5960

6061
import com.oracle.graal.python.PythonLanguage;
@@ -71,6 +72,7 @@
7172
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
7273
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
7374
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
75+
import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike;
7476
import com.oracle.graal.python.builtins.objects.cext.CArrayWrappers.CByteArrayWrapper;
7577
import com.oracle.graal.python.builtins.objects.cext.CArrayWrappers.CStringWrapper;
7678
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
@@ -1158,15 +1160,23 @@ public static GetByteArrayNode create() {
11581160
return GetByteArrayNodeGen.create();
11591161
}
11601162

1163+
private static byte[] subRangeIfNeeded(byte[] ary, long n) {
1164+
if (ary.length > n && n >= 0 && n < Integer.MAX_VALUE) {
1165+
return Arrays.copyOf(ary, (int) n);
1166+
} else {
1167+
return ary;
1168+
}
1169+
}
1170+
11611171
@Specialization
1162-
byte[] doCArrayWrapper(CByteArrayWrapper o, @SuppressWarnings("unused") long n) {
1163-
return o.getByteArray();
1172+
byte[] doCArrayWrapper(CByteArrayWrapper o, long n) {
1173+
return subRangeIfNeeded(o.getByteArray(), n);
11641174
}
11651175

11661176
@Specialization
1167-
byte[] doSequenceArrayWrapper(PySequenceArrayWrapper obj, @SuppressWarnings("unused") long n,
1177+
byte[] doSequenceArrayWrapper(PySequenceArrayWrapper obj, long n,
11681178
@Cached("create()") BytesNodes.ToBytesNode toBytesNode) {
1169-
return toBytesNode.execute(obj.getDelegate());
1179+
return subRangeIfNeeded(toBytesNode.execute(obj.getDelegate()), n);
11701180
}
11711181

11721182
@Specialization(guards = "n < 0")
@@ -2135,16 +2145,32 @@ protected static boolean isPSequence(Object object) {
21352145
}
21362146
}
21372147

2138-
@Builtin(name = "PyBytes_FromStringAndSize", minNumOfPositionalArgs = 2, declaresExplicitSelf = true)
2148+
@Builtin(name = "PyBytes_FromStringAndSize", minNumOfPositionalArgs = 3, declaresExplicitSelf = true)
21392149
@GenerateNodeFactory
21402150
abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
2151+
// n.b.: the specializations for PIBytesLike are quite common on
2152+
// managed, when the PySequenceArrayWrapper that we used never went
2153+
// native, and during the upcall to here it was simply unwrapped again
2154+
// with the ToJava (rather than mapped from a native pointer back into a
2155+
// PythonNativeObject)
2156+
2157+
@Specialization
2158+
Object doGeneric(@SuppressWarnings("unused") Object module, PIBytesLike object, long size,
2159+
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode) {
2160+
byte[] ary = getByteArrayNode.execute(object);
2161+
if (size < Integer.MAX_VALUE && size >= 0 && size < ary.length) {
2162+
return factory().createBytes(Arrays.copyOf(ary, (int) size));
2163+
} else {
2164+
return factory().createBytes(ary);
2165+
}
2166+
}
21412167

21422168
@Specialization
2143-
Object doGeneric(Object module, PythonNativeObject object,
2169+
Object doGeneric(Object module, PythonNativeObject object, long size,
21442170
@Exclusive @Cached CExtNodes.GetNativeNullNode getNativeNullNode,
21452171
@Exclusive @Cached GetByteArrayNode getByteArrayNode) {
21462172
try {
2147-
return factory().createBytes(getByteArrayNode.execute(object.getPtr(), -1));
2173+
return factory().createBytes(getByteArrayNode.execute(object.getPtr(), size));
21482174
} catch (InteropException e) {
21492175
return raiseNative(getNativeNullNode.execute(module), PythonErrorType.TypeError, "%m", e);
21502176
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/DynamicObjectNativeWrapper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ public boolean isMemberModifiable(String member) {
11771177
}
11781178
}
11791179

1180-
public static class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
1180+
public static final class PrimitiveNativeWrapper extends DynamicObjectNativeWrapper {
11811181

11821182
public static final byte PRIMITIVE_STATE_BOOL = 1 << 0;
11831183
public static final byte PRIMITIVE_STATE_BYTE = 1 << 1;
@@ -1260,6 +1260,17 @@ public void setMaterializedObject(Object materializedPrimitive) {
12601260
setDelegate(materializedPrimitive);
12611261
}
12621262

1263+
@Override
1264+
public boolean equals(Object obj) {
1265+
return obj instanceof PrimitiveNativeWrapper && ((PrimitiveNativeWrapper) obj).state == state && ((PrimitiveNativeWrapper) obj).value == value &&
1266+
((PrimitiveNativeWrapper) obj).dvalue == dvalue;
1267+
}
1268+
1269+
@Override
1270+
public int hashCode() {
1271+
return (int) (value ^ Double.doubleToRawLongBits(dvalue) ^ state);
1272+
}
1273+
12631274
public static PrimitiveNativeWrapper createBool(boolean val) {
12641275
return new PrimitiveNativeWrapper(PRIMITIVE_STATE_BOOL, PInt.intValue(val));
12651276
}

0 commit comments

Comments
 (0)