|
40 | 40 | */
|
41 | 41 | package com.oracle.truffle.api.test.polyglot;
|
42 | 42 |
|
| 43 | +import static com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest.assertFails; |
| 44 | +import static org.junit.Assert.assertEquals; |
| 45 | +import static org.junit.Assert.assertFalse; |
| 46 | +import static org.junit.Assert.assertNotNull; |
| 47 | +import static org.junit.Assert.assertTrue; |
| 48 | +import static org.junit.Assume.assumeFalse; |
| 49 | + |
43 | 50 | import java.io.BufferedReader;
|
44 | 51 | import java.io.ByteArrayOutputStream;
|
45 | 52 | import java.io.IOException;
|
|
66 | 73 | import java.util.Set;
|
67 | 74 | import java.util.regex.Pattern;
|
68 | 75 |
|
69 |
| -import com.oracle.truffle.api.CompilerDirectives; |
70 |
| -import com.oracle.truffle.api.InstrumentInfo; |
71 |
| -import com.oracle.truffle.api.TruffleFile; |
72 |
| -import com.oracle.truffle.api.TruffleLanguage; |
73 |
| -import com.oracle.truffle.api.instrumentation.TruffleInstrument; |
74 |
| -import com.oracle.truffle.api.test.OSUtils; |
75 |
| -import com.oracle.truffle.api.test.ReflectionUtils; |
76 |
| -import com.oracle.truffle.api.test.SubprocessTestUtils; |
77 |
| -import com.oracle.truffle.api.test.common.TestUtils; |
78 |
| -import com.oracle.truffle.tck.tests.TruffleTestAssumptions; |
79 | 76 | import org.graalvm.nativeimage.ImageInfo;
|
80 | 77 | import org.graalvm.polyglot.Context;
|
81 | 78 | import org.graalvm.polyglot.Engine;
|
|
84 | 81 | import org.junit.BeforeClass;
|
85 | 82 | import org.junit.Test;
|
86 | 83 |
|
| 84 | +import com.oracle.truffle.api.CompilerDirectives; |
87 | 85 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 86 | +import com.oracle.truffle.api.InstrumentInfo; |
88 | 87 | import com.oracle.truffle.api.InternalResource;
|
| 88 | +import com.oracle.truffle.api.TruffleFile; |
| 89 | +import com.oracle.truffle.api.TruffleLanguage; |
89 | 90 | import com.oracle.truffle.api.TruffleLanguage.Registration;
|
| 91 | +import com.oracle.truffle.api.instrumentation.TruffleInstrument; |
90 | 92 | import com.oracle.truffle.api.nodes.RootNode;
|
| 93 | +import com.oracle.truffle.api.test.OSUtils; |
| 94 | +import com.oracle.truffle.api.test.ReflectionUtils; |
| 95 | +import com.oracle.truffle.api.test.SubprocessTestUtils; |
91 | 96 | import com.oracle.truffle.api.test.common.AbstractExecutableTestLanguage;
|
92 |
| - |
93 |
| -import static org.junit.Assert.assertEquals; |
94 |
| -import static org.junit.Assert.assertFalse; |
95 |
| -import static org.junit.Assert.assertNotNull; |
96 |
| -import static org.junit.Assert.assertTrue; |
97 |
| -import static com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest.assertFails; |
98 |
| -import static org.junit.Assume.assumeFalse; |
| 97 | +import com.oracle.truffle.api.test.common.TestUtils; |
| 98 | +import com.oracle.truffle.tck.tests.TruffleTestAssumptions; |
99 | 99 |
|
100 | 100 | public class InternalResourceTest {
|
101 | 101 |
|
@@ -1113,111 +1113,131 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje
|
1113 | 1113 | }
|
1114 | 1114 |
|
1115 | 1115 | @Test
|
1116 |
| - public void testLogging() { |
| 1116 | + public void testLogging() throws IOException, InterruptedException { |
1117 | 1117 | TruffleTestAssumptions.assumeNotAOT();
|
1118 |
| - PrintStream originalErr = System.err; |
1119 |
| - ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
1120 |
| - System.setErr(new PrintStream(testErr)); |
1121 |
| - System.setProperty("polyglotimpl.TraceInternalResources", "true"); |
1122 |
| - try (Context context = Context.create()) { |
1123 |
| - String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
1124 |
| - AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
1125 |
| - String[] lines = testErr.toString().split("\n"); |
1126 |
| - String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
1127 |
| - assertNotNull(line); |
1128 |
| - line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
1129 |
| - assertNotNull(line); |
1130 |
| - } finally { |
1131 |
| - System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
1132 |
| - System.setErr(originalErr); |
1133 |
| - } |
| 1118 | + executeWithLogging(() -> { |
| 1119 | + PrintStream originalErr = System.err; |
| 1120 | + ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
| 1121 | + System.setErr(new PrintStream(testErr)); |
| 1122 | + try (Context context = Context.create()) { |
| 1123 | + String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
| 1124 | + AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
| 1125 | + String[] lines = testErr.toString().split("\n"); |
| 1126 | + String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
| 1127 | + assertNotNull(line); |
| 1128 | + line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
| 1129 | + assertNotNull(line); |
| 1130 | + } finally { |
| 1131 | + System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
| 1132 | + System.setErr(originalErr); |
| 1133 | + } |
| 1134 | + }); |
| 1135 | + } |
| 1136 | + |
| 1137 | + private static void executeWithLogging(Runnable action) throws IOException, InterruptedException { |
| 1138 | + SubprocessTestUtils.newBuilder(InternalResourceTest.class, action).prefixVmOption("-Dpolyglotimpl.TraceInternalResources=true").run(); |
1134 | 1139 | }
|
1135 | 1140 |
|
1136 | 1141 | @Test
|
1137 |
| - public void testLoggingOverriddenCacheRoot() throws IOException { |
| 1142 | + public void testLoggingOverriddenCacheRoot() throws IOException, InterruptedException { |
1138 | 1143 | TruffleTestAssumptions.assumeNotAOT();
|
1139 |
| - PrintStream originalErr = System.err; |
1140 |
| - ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
1141 |
| - Path tmpDir = Files.createTempDirectory("resources"); |
1142 |
| - String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
1143 |
| - Engine.copyResources(tmpDir, languageId); |
1144 |
| - System.setErr(new PrintStream(testErr)); |
1145 |
| - System.setProperty("polyglotimpl.TraceInternalResources", "true"); |
1146 |
| - System.setProperty("polyglot.engine.resourcePath", tmpDir.toString()); |
1147 |
| - try (Context context = Context.create()) { |
1148 |
| - AbstractExecutableTestLanguage.execute(context, TestLogging.class, tmpDir.toString()); |
1149 |
| - String[] lines = testErr.toString().split("\n"); |
1150 |
| - String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
1151 |
| - assertNotNull(line); |
1152 |
| - assertTrue(line.contains(tmpDir.toString())); |
1153 |
| - line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
1154 |
| - assertNotNull(line); |
1155 |
| - assertTrue(line.contains(tmpDir.toString())); |
1156 |
| - } finally { |
1157 |
| - System.getProperties().remove("polyglot.engine.resourcePath"); |
1158 |
| - System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
1159 |
| - System.setErr(originalErr); |
1160 |
| - } |
| 1144 | + executeWithLogging(() -> { |
| 1145 | + try { |
| 1146 | + PrintStream originalErr = System.err; |
| 1147 | + ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
| 1148 | + Path tmpDir = Files.createTempDirectory("resources"); |
| 1149 | + String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
| 1150 | + Engine.copyResources(tmpDir, languageId); |
| 1151 | + System.setErr(new PrintStream(testErr)); |
| 1152 | + System.setProperty("polyglot.engine.resourcePath", tmpDir.toString()); |
| 1153 | + try (Context context = Context.create()) { |
| 1154 | + AbstractExecutableTestLanguage.execute(context, TestLogging.class, tmpDir.toString()); |
| 1155 | + String[] lines = testErr.toString().split("\n"); |
| 1156 | + String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
| 1157 | + assertNotNull(line); |
| 1158 | + assertTrue(line.contains(tmpDir.toString())); |
| 1159 | + line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
| 1160 | + assertNotNull(line); |
| 1161 | + assertTrue(line.contains(tmpDir.toString())); |
| 1162 | + } finally { |
| 1163 | + System.getProperties().remove("polyglot.engine.resourcePath"); |
| 1164 | + System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
| 1165 | + System.setErr(originalErr); |
| 1166 | + } |
| 1167 | + } catch (IOException e) { |
| 1168 | + throw new AssertionError(e); |
| 1169 | + } |
| 1170 | + }); |
1161 | 1171 | }
|
1162 | 1172 |
|
1163 | 1173 | @Test
|
1164 |
| - public void testLoggingOverriddenComponentRoot() throws IOException { |
| 1174 | + public void testLoggingOverriddenComponentRoot() throws IOException, InterruptedException { |
1165 | 1175 | TruffleTestAssumptions.assumeNotAOT();
|
1166 |
| - PrintStream originalErr = System.err; |
1167 |
| - ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
1168 |
| - Path tmpDir = Files.createTempDirectory("resources"); |
1169 |
| - String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
1170 |
| - String overridePropName = "polyglot.engine.resourcePath." + languageId; |
1171 |
| - Path languageResources = tmpDir.resolve(languageId); |
1172 |
| - Engine.copyResources(tmpDir, languageId); |
1173 |
| - System.setErr(new PrintStream(testErr)); |
1174 |
| - System.setProperty("polyglotimpl.TraceInternalResources", "true"); |
1175 |
| - System.setProperty(overridePropName, languageResources.toString()); |
1176 |
| - try (Context context = Context.create()) { |
1177 |
| - AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
1178 |
| - String[] lines = testErr.toString().split("\n"); |
1179 |
| - String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
1180 |
| - assertNotNull(line); |
1181 |
| - assertTrue(line.contains(languageResources.toString())); |
1182 |
| - line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
1183 |
| - assertNotNull(line); |
1184 |
| - assertTrue(line.contains(languageResources.toString())); |
1185 |
| - } finally { |
1186 |
| - System.getProperties().remove(overridePropName); |
1187 |
| - System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
1188 |
| - System.setErr(originalErr); |
1189 |
| - delete(tmpDir); |
1190 |
| - } |
| 1176 | + executeWithLogging(() -> { |
| 1177 | + try { |
| 1178 | + PrintStream originalErr = System.err; |
| 1179 | + ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
| 1180 | + Path tmpDir = Files.createTempDirectory("resources"); |
| 1181 | + String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
| 1182 | + String overridePropName = "polyglot.engine.resourcePath." + languageId; |
| 1183 | + Path languageResources = tmpDir.resolve(languageId); |
| 1184 | + Engine.copyResources(tmpDir, languageId); |
| 1185 | + System.setErr(new PrintStream(testErr)); |
| 1186 | + System.setProperty(overridePropName, languageResources.toString()); |
| 1187 | + try (Context context = Context.create()) { |
| 1188 | + AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
| 1189 | + String[] lines = testErr.toString().split("\n"); |
| 1190 | + String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
| 1191 | + assertNotNull(line); |
| 1192 | + assertTrue(line.contains(languageResources.toString())); |
| 1193 | + line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
| 1194 | + assertNotNull(line); |
| 1195 | + assertTrue(line.contains(languageResources.toString())); |
| 1196 | + } finally { |
| 1197 | + System.getProperties().remove(overridePropName); |
| 1198 | + System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
| 1199 | + System.setErr(originalErr); |
| 1200 | + delete(tmpDir); |
| 1201 | + } |
| 1202 | + } catch (IOException e) { |
| 1203 | + throw new AssertionError(e); |
| 1204 | + } |
| 1205 | + }); |
1191 | 1206 | }
|
1192 | 1207 |
|
1193 | 1208 | @Test
|
1194 |
| - public void testLoggingOverriddenResourceRoot() throws IOException { |
| 1209 | + public void testLoggingOverriddenResourceRoot() throws IOException, InterruptedException { |
1195 | 1210 | TruffleTestAssumptions.assumeNotAOT();
|
1196 |
| - PrintStream originalErr = System.err; |
1197 |
| - ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
1198 |
| - Path tmpDir = Files.createTempDirectory("resources"); |
1199 |
| - String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
1200 |
| - String overridePropName = "polyglot.engine.resourcePath." + languageId + '.' + SourcesResource.ID; |
1201 |
| - Engine.copyResources(tmpDir, languageId); |
1202 |
| - Path sourceResource = tmpDir.resolve(languageId).resolve(SourcesResource.ID); |
1203 |
| - System.setErr(new PrintStream(testErr)); |
1204 |
| - System.setProperty("polyglotimpl.TraceInternalResources", "true"); |
1205 |
| - System.setProperty(overridePropName, sourceResource.toString()); |
1206 |
| - try (Context context = Context.create()) { |
1207 |
| - AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
1208 |
| - String[] lines = testErr.toString().split("\n"); |
1209 |
| - String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
1210 |
| - assertNotNull(line); |
1211 |
| - assertTrue(line.contains(sourceResource.toString())); |
1212 |
| - line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
1213 |
| - assertNotNull(line); |
1214 |
| - assertFalse(line.contains(sourceResource.toString())); |
1215 |
| - } finally { |
1216 |
| - System.getProperties().remove(overridePropName); |
1217 |
| - System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
1218 |
| - System.setErr(originalErr); |
1219 |
| - delete(tmpDir); |
1220 |
| - } |
| 1211 | + executeWithLogging(() -> { |
| 1212 | + try { |
| 1213 | + PrintStream originalErr = System.err; |
| 1214 | + ByteArrayOutputStream testErr = new ByteArrayOutputStream(); |
| 1215 | + Path tmpDir = Files.createTempDirectory("resources"); |
| 1216 | + String languageId = TestUtils.getDefaultLanguageId(TestLogging.class); |
| 1217 | + String overridePropName = "polyglot.engine.resourcePath." + languageId + '.' + SourcesResource.ID; |
| 1218 | + Engine.copyResources(tmpDir, languageId); |
| 1219 | + Path sourceResource = tmpDir.resolve(languageId).resolve(SourcesResource.ID); |
| 1220 | + System.setErr(new PrintStream(testErr)); |
| 1221 | + System.setProperty(overridePropName, sourceResource.toString()); |
| 1222 | + try (Context context = Context.create()) { |
| 1223 | + AbstractExecutableTestLanguage.execute(context, TestLogging.class); |
| 1224 | + String[] lines = testErr.toString().split("\n"); |
| 1225 | + String line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + SourcesResource.ID, lines); |
| 1226 | + assertNotNull(line); |
| 1227 | + assertTrue(line.contains(sourceResource.toString())); |
| 1228 | + line = findLine("^\\[engine\\]\\[resource\\].*" + languageId + "::" + LibraryResource.ID, lines); |
| 1229 | + assertNotNull(line); |
| 1230 | + assertFalse(line.contains(sourceResource.toString())); |
| 1231 | + } finally { |
| 1232 | + System.getProperties().remove(overridePropName); |
| 1233 | + System.getProperties().remove("polyglotimpl.TraceInternalResources"); |
| 1234 | + System.setErr(originalErr); |
| 1235 | + delete(tmpDir); |
| 1236 | + } |
| 1237 | + } catch (IOException e) { |
| 1238 | + throw new AssertionError(e); |
| 1239 | + } |
| 1240 | + }); |
1221 | 1241 | }
|
1222 | 1242 |
|
1223 | 1243 | @Test
|
|
0 commit comments