Search in sources :

Example 16 with OptionKey

use of org.graalvm.compiler.options.OptionKey in project graal by oracle.

the class GraphResetDebugTest method test1.

@SuppressWarnings("try")
@Test
public void test1() {
    EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
    // Configure with an option that enables scopes
    map.put(DebugOptions.DumpOnError, true);
    DebugContext debug = getDebugContext(new OptionValues(map));
    StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES, debug);
    boolean resetSucceeded = false;
    try (Scope scope = debug.scope("some scope")) {
        graph.resetDebug(DebugContext.DISABLED);
        resetSucceeded = true;
    } catch (AssertionError expected) {
    }
    Assert.assertFalse(resetSucceeded);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Scope(org.graalvm.compiler.debug.DebugContext.Scope) OptionKey(org.graalvm.compiler.options.OptionKey) DebugContext(org.graalvm.compiler.debug.DebugContext) Test(org.junit.Test)

Example 17 with OptionKey

use of org.graalvm.compiler.options.OptionKey in project graal by oracle.

the class DebugContextTest method testEnabledSandbox.

@Test
public void testEnabledSandbox() {
    EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
    // Configure with an option that enables scopes
    map.put(DebugOptions.DumpOnError, true);
    OptionValues options = new OptionValues(map);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DebugContext debug = DebugContext.create(options, NO_DESCRIPTION, NO_GLOBAL_METRIC_VALUES, new PrintStream(baos), DebugHandlersFactory.LOADER);
    Exception e = new Exception("testEnabledSandbox");
    String scopeName = "";
    try {
        try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
            scopeName = d.getQualifiedName();
            throw e;
        } catch (Throwable t) {
            assert e == t;
            debug.handle(t);
        }
    } catch (Throwable t) {
        // The exception object should propagate all the way out through
        // a enabled sandbox scope
        Assert.assertEquals(e, t);
    }
    String logged = baos.toString();
    String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
    String line = "-------------------------------------------------------";
    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));
}
Also used : PrintStream(java.io.PrintStream) OptionValues(org.graalvm.compiler.options.OptionValues) Scope(org.graalvm.compiler.debug.DebugContext.Scope) OptionKey(org.graalvm.compiler.options.OptionKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DebugContext(org.graalvm.compiler.debug.DebugContext) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

OptionKey (org.graalvm.compiler.options.OptionKey)17 OptionValues (org.graalvm.compiler.options.OptionValues)15 Test (org.junit.Test)13 DebugContext (org.graalvm.compiler.debug.DebugContext)8 IOException (java.io.IOException)4 Scope (org.graalvm.compiler.debug.DebugContext.Scope)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 OptionDescriptors (org.graalvm.compiler.options.OptionDescriptors)2 HostedOptionKey (com.oracle.svm.core.option.HostedOptionKey)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Properties (java.util.Properties)1