< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.debug.test/src/org/graalvm/compiler/debug/test/DebugContextTest.java

Print this page
rev 52509 : [mq]: graal2


 180                     for (Object o : debug.context()) {
 181                         Assert.assertEquals(o, "A");
 182                     }
 183                 } catch (Throwable t) {
 184                     throw debug.handle(t);
 185                 }
 186                 try (DebugContext.Scope s1 = debug.withContext("B")) {
 187                     for (Object o : debug.context()) {
 188                         Assert.assertEquals(o, "B");
 189                     }
 190                 } catch (Throwable t) {
 191                     throw debug.handle(t);
 192                 }
 193             }
 194         }
 195 
 196     }
 197 
 198     @Test
 199     public void testEnabledSandbox() {

 200         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 201         // Configure with an option that enables scopes
 202         map.put(DebugOptions.DumpOnError, true);
 203         OptionValues options = new OptionValues(map);
 204         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 205         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 206         Exception e = new Exception("testEnabledSandbox");
 207         String scopeName = "";
 208         try {
 209             try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
 210                 scopeName = d.getQualifiedName();
 211                 throw e;
 212             } catch (Throwable t) {
 213                 assert e == t;
 214                 debug.handle(t);
 215             }
 216         } catch (Throwable t) {
 217             // The exception object should propagate all the way out through
 218             // a enabled sandbox scope
 219             Assert.assertEquals(e, t);
 220         }
 221         String logged = baos.toString();
 222         String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
 223         String line = "-------------------------------------------------------";
 224         Assert.assertTrue(String.format("Could not find \"%s\" in content between lines below:%n%s%n%s%s", expected, line, logged, line), logged.contains(expected));
 225     }
 226 
 227     @Test
 228     public void testDisabledSandbox() {

 229         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 230         // Configure with an option that enables scopes
 231         map.put(DebugOptions.DumpOnError, true);
 232         OptionValues options = new OptionValues(map);
 233         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 234         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 235         Exception e = new Exception("testDisabledSandbox");
 236         try {
 237             // Test a disabled sandbox scope
 238             try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", null)) {
 239                 throw e;
 240             } catch (Throwable t) {
 241                 assert e == t;
 242                 debug.handle(t);
 243             }
 244         } catch (Throwable t) {
 245             // The exception object should propagate all the way out through
 246             // a disabled sandbox scope
 247             Assert.assertEquals(e, t);
 248         }


 266         AssertionError[] result = {null};
 267         Thread thread = new Thread() {
 268 
 269             @Override
 270             public void run() {
 271                 try {
 272                     counter.add(debug, 1);
 273                 } catch (AssertionError e) {
 274                     result[0] = e;
 275                 }
 276             }
 277         };
 278         thread.start();
 279         thread.join();
 280 
 281         Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
 282     }
 283 
 284     @Test
 285     public void testDisableIntercept() {

 286         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 287         // Configure with an option that enables scopes
 288         map.put(DebugOptions.DumpOnError, true);
 289         OptionValues options = new OptionValues(map);
 290         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 291         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 292         Exception e = new Exception();
 293         try {
 294             try (DebugCloseable disabled = debug.disableIntercept(); Scope s1 = debug.scope("ScopeWithDisabledIntercept")) {
 295                 try (Scope s2 = debug.scope("InnerScopeInheritsDisabledIntercept")) {
 296                     throw e;
 297                 }
 298             } catch (Throwable t) {
 299                 assert e == t;
 300                 debug.handle(t);
 301             }
 302         } catch (Throwable t) {
 303             // The exception object should propagate all the way out through
 304             // an intercept disabled scope
 305             Assert.assertEquals(e, t);


 180                     for (Object o : debug.context()) {
 181                         Assert.assertEquals(o, "A");
 182                     }
 183                 } catch (Throwable t) {
 184                     throw debug.handle(t);
 185                 }
 186                 try (DebugContext.Scope s1 = debug.withContext("B")) {
 187                     for (Object o : debug.context()) {
 188                         Assert.assertEquals(o, "B");
 189                     }
 190                 } catch (Throwable t) {
 191                     throw debug.handle(t);
 192                 }
 193             }
 194         }
 195 
 196     }
 197 
 198     @Test
 199     public void testEnabledSandbox() {
 200         TimerKeyTest.assumeManagementLibraryIsLoadable();
 201         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 202         // Configure with an option that enables scopes
 203         map.put(DebugOptions.DumpOnError, true);
 204         OptionValues options = new OptionValues(map);
 205         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 206         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 207         Exception e = new Exception("testEnabledSandbox");
 208         String scopeName = "";
 209         try {
 210             try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
 211                 scopeName = d.getQualifiedName();
 212                 throw e;
 213             } catch (Throwable t) {
 214                 assert e == t;
 215                 debug.handle(t);
 216             }
 217         } catch (Throwable t) {
 218             // The exception object should propagate all the way out through
 219             // a enabled sandbox scope
 220             Assert.assertEquals(e, t);
 221         }
 222         String logged = baos.toString();
 223         String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
 224         String line = "-------------------------------------------------------";
 225         Assert.assertTrue(String.format("Could not find \"%s\" in content between lines below:%n%s%n%s%s", expected, line, logged, line), logged.contains(expected));
 226     }
 227 
 228     @Test
 229     public void testDisabledSandbox() {
 230         TimerKeyTest.assumeManagementLibraryIsLoadable();
 231         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 232         // Configure with an option that enables scopes
 233         map.put(DebugOptions.DumpOnError, true);
 234         OptionValues options = new OptionValues(map);
 235         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 236         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 237         Exception e = new Exception("testDisabledSandbox");
 238         try {
 239             // Test a disabled sandbox scope
 240             try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", null)) {
 241                 throw e;
 242             } catch (Throwable t) {
 243                 assert e == t;
 244                 debug.handle(t);
 245             }
 246         } catch (Throwable t) {
 247             // The exception object should propagate all the way out through
 248             // a disabled sandbox scope
 249             Assert.assertEquals(e, t);
 250         }


 268         AssertionError[] result = {null};
 269         Thread thread = new Thread() {
 270 
 271             @Override
 272             public void run() {
 273                 try {
 274                     counter.add(debug, 1);
 275                 } catch (AssertionError e) {
 276                     result[0] = e;
 277                 }
 278             }
 279         };
 280         thread.start();
 281         thread.join();
 282 
 283         Assert.assertNotNull("Expected thread to throw AssertionError", result[0]);
 284     }
 285 
 286     @Test
 287     public void testDisableIntercept() {
 288         TimerKeyTest.assumeManagementLibraryIsLoadable();
 289         EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
 290         // Configure with an option that enables scopes
 291         map.put(DebugOptions.DumpOnError, true);
 292         OptionValues options = new OptionValues(map);
 293         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 294         DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
 295         Exception e = new Exception();
 296         try {
 297             try (DebugCloseable disabled = debug.disableIntercept(); Scope s1 = debug.scope("ScopeWithDisabledIntercept")) {
 298                 try (Scope s2 = debug.scope("InnerScopeInheritsDisabledIntercept")) {
 299                     throw e;
 300                 }
 301             } catch (Throwable t) {
 302                 assert e == t;
 303                 debug.handle(t);
 304             }
 305         } catch (Throwable t) {
 306             // The exception object should propagate all the way out through
 307             // an intercept disabled scope
 308             Assert.assertEquals(e, t);
< prev index next >