Skip to content

Commit 11986fc

Browse files
committed
Clean up MultiContextCExtTest
1 parent 34584e4 commit 11986fc

File tree

3 files changed

+70
-75
lines changed

3 files changed

+70
-75
lines changed

graalpython/com.oracle.graal.python.test.integration/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,11 @@ Additionally, one can change the polyglot artifacts version with
173173
<scope>runtime</scope>
174174
<type>pom</type>
175175
</dependency>
176-
<dependency>
177-
<!-- See MultiContextCExtTest -->
178-
<groupId>org.graalvm.python</groupId>
179-
<artifactId>python-launcher</artifactId>
180-
<version>${com.oracle.graal.python.test.polyglot.version}</version>
181-
</dependency>
182176
<dependency>
183177
<groupId>org.graalvm.python</groupId>
184178
<artifactId>python-embedding</artifactId>
185179
<version>${com.oracle.graal.python.test.polyglot.version}</version>
186180
</dependency>
187-
<dependency>
188-
<groupId>org.graalvm.python</groupId>
189-
<artifactId>python-embedding-tools</artifactId>
190-
<version>${com.oracle.graal.python.test.polyglot.version}</version>
191-
</dependency>
192181
<dependency>
193182
<groupId>junit</groupId>
194183
<artifactId>junit</artifactId>

graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -183,69 +183,76 @@ public void testCreatingVenvForMulticontext() throws IOException {
183183
var engine = Engine.newBuilder("python").logHandler(log).build();
184184
var builder = Context.newBuilder().engine(engine).allowAllAccess(true).option("python.Sha3ModuleBackend", "native").option("python.ForceImportSite", "true").option("python.Executable",
185185
exe).option("log.python.level", "CONFIG");
186-
var c0 = builder.build();
187-
c0.initialize("python");
188-
c0.eval("python", String.format("__graalpython__.replicate_extensions_in_venv('%s', 2)", venv.toString().replace('\\', '/')));
189-
190-
assertTrue("created a copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup0")));
191-
assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup1")));
192-
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
193-
194-
builder.option("python.IsolateNativeModules", "true");
195-
var c1 = builder.build();
196-
var c2 = builder.build();
197-
var c3 = builder.build();
198-
var c4 = builder.build();
199-
builder.option("python.Executable", "");
200-
var c5 = builder.build();
201-
c0.initialize("python");
202-
c1.initialize("python");
203-
c2.initialize("python");
204-
c3.initialize("python");
205-
c4.initialize("python");
206-
c5.initialize("python");
207-
var code = Source.create("python", "import _sha3; _sha3.implementation");
208-
// First one works
209-
var r1 = c1.eval(code);
210-
assertEquals("tiny_sha3", r1.asString());
211-
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
212-
// Second one works because of isolation
213-
var r2 = c2.eval(code);
214-
assertEquals("tiny_sha3", r2.asString());
215-
c2.eval("python", "import _sha3; _sha3.implementation = '12'");
216-
r2 = c2.eval(code);
217-
assertEquals("12", r2.asString());
218-
// first context is unaffected
219-
r1 = c1.eval(code);
220-
assertEquals("tiny_sha3", r1.asString());
221-
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
222-
// Third one works and triggers a dynamic relocation
223-
c3.eval(code);
224-
assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
225-
// Fourth one does not work because we changed the sys.prefix
226-
c4.eval("python", "import sys; sys.prefix = 12");
186+
var contexts = new ArrayList<Context>();
227187
try {
228-
c4.eval(code);
229-
fail("should not reach here");
230-
} catch (PolyglotException e) {
231-
assertTrue("We rely on sys.prefix", e.getMessage().contains("sys.prefix must be a str"));
232-
}
233-
// Fifth one does not work because we don't have the venv configured
234-
try {
235-
c5.eval(code);
236-
fail("should not reach here");
237-
} catch (PolyglotException e) {
238-
assertTrue("We need a venv", e.getMessage().contains("sys.prefix must point to a venv"));
239-
}
240-
// Using a context without isolation in the same process needs to use LLVM
241-
assertFalse("have not had a context use LLVM, yet", log.truffleLog.toString().contains("as bitcode"));
242-
try {
243-
c0.eval(code);
244-
fail("should not reach here");
245-
} catch (PolyglotException e) {
246-
assertTrue("needs LLVM", e.getMessage().contains("LLVM"));
247-
}
188+
Context c0, c1, c2, c3, c4, c5;
189+
contexts.add(c0 = builder.build());
190+
c0.initialize("python");
191+
c0.eval("python", String.format("__graalpython__.replicate_extensions_in_venv('%s', 2)", venv.toString().replace('\\', '/')));
192+
193+
assertTrue("created a copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup0")));
194+
assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup1")));
195+
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
248196

197+
builder.option("python.IsolateNativeModules", "true");
198+
contexts.add(c1 = builder.build());
199+
contexts.add(c2 = builder.build());
200+
contexts.add(c3 = builder.build());
201+
contexts.add(c4 = builder.build());
202+
builder.option("python.Executable", "");
203+
contexts.add(c5 = builder.build());
204+
c0.initialize("python");
205+
c1.initialize("python");
206+
c2.initialize("python");
207+
c3.initialize("python");
208+
c4.initialize("python");
209+
c5.initialize("python");
210+
var code = Source.create("python", "import _sha3; _sha3.implementation");
211+
// First one works
212+
var r1 = c1.eval(code);
213+
assertEquals("tiny_sha3", r1.asString());
214+
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
215+
// Second one works because of isolation
216+
var r2 = c2.eval(code);
217+
assertEquals("tiny_sha3", r2.asString());
218+
c2.eval("python", "import _sha3; _sha3.implementation = '12'");
219+
r2 = c2.eval(code);
220+
assertEquals("12", r2.asString());
221+
// first context is unaffected
222+
r1 = c1.eval(code);
223+
assertEquals("tiny_sha3", r1.asString());
224+
assertFalse("created no more copies of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
225+
// Third one works and triggers a dynamic relocation
226+
c3.eval(code);
227+
assertTrue("created another copy of the capi", Files.list(venv).anyMatch((p) -> p.getFileName().toString().startsWith(pythonNative) && p.getFileName().toString().endsWith(".dup2")));
228+
// Fourth one does not work because we changed the sys.prefix
229+
c4.eval("python", "import sys; sys.prefix = 12");
230+
try {
231+
c4.eval(code);
232+
fail("should not reach here");
233+
} catch (PolyglotException e) {
234+
assertTrue("We rely on sys.prefix", e.getMessage().contains("sys.prefix must be a str"));
235+
}
236+
// Fifth one does not work because we don't have the venv configured
237+
try {
238+
c5.eval(code);
239+
fail("should not reach here");
240+
} catch (PolyglotException e) {
241+
assertTrue("We need a venv", e.getMessage().contains("sys.prefix must point to a venv"));
242+
}
243+
// Using a context without isolation in the same process needs to use LLVM
244+
assertFalse("have not had a context use LLVM, yet", log.truffleLog.toString().contains("as bitcode"));
245+
try {
246+
c0.eval(code);
247+
fail("should not reach here");
248+
} catch (PolyglotException e) {
249+
assertTrue("needs LLVM", e.getMessage().contains("LLVM"));
250+
}
251+
} finally {
252+
for (var c : contexts) {
253+
c.close(true);
254+
}
255+
}
249256
}
250257

251258
private static boolean isVerbose() {

mx.graalpython/suite.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@
469469
"truffle:TRUFFLE_TCK",
470470
"mx:JUNIT",
471471
"NETBEANS-LIB-PROFILER",
472+
"GRAALPYTHON_EMBEDDING_TOOLS",
472473
],
473474
"requires": [
474475
"java.management",
@@ -498,7 +499,6 @@
498499
"sourceDirs": ["src"],
499500
"dependencies": [
500501
"GRAALPYTHON_EMBEDDING",
501-
"GRAALPYTHON_EMBEDDING_TOOLS",
502502
"mx:JUNIT",
503503
"sdk:GRAAL_SDK",
504504
],
@@ -1236,6 +1236,7 @@
12361236
"distDependencies": [
12371237
"GRAALPYTHON",
12381238
"GRAALPYTHON-LAUNCHER",
1239+
"GRAALPYTHON_EMBEDDING_TOOLS", # See MultiContextCExtTest
12391240
"sulong:SULONG_NATIVE", # See MultiContextTest#testSharingWithStruct
12401241
"truffle:TRUFFLE_TCK",
12411242
"GRAALPYTHON_INTEGRATION_UNIT_TESTS",
@@ -1254,9 +1255,7 @@
12541255
"distDependencies": [
12551256
"GRAALPYTHON",
12561257
"GRAALPYTHON_RESOURCES",
1257-
"GRAALPYTHON-LAUNCHER", # See MultiContextCExtTest
12581258
"GRAALPYTHON_EMBEDDING",
1259-
"GRAALPYTHON_EMBEDDING_TOOLS",
12601259
"sulong:SULONG_NATIVE", # See MultiContextTest#testSharingWithStruct
12611260
"sdk:GRAAL_SDK",
12621261
],

0 commit comments

Comments
 (0)