Search in sources :

Example 11 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testUnwindReenterOnException.

@Test
public void testUnwindReenterOnException() throws Exception {
    List<CodeAction> actionsUnwind = new ArrayList<>();
    List<CodeAction> actionsReenter = new ArrayList<>();
    // Unwind at DEFINE() and Reenter after pop from CALL(a):
    actionsUnwind.add(new CodeAction("STATEMENT(DEFINE(a, ROOT()))", TestControlFlow.ACTION.UNWIND, "3uw"));
    actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
    testControlFlow.actions.put(TestControlFlow.WHERE.RETURN_EXCEPTIONAL, actionsUnwind);
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
    String message = null;
    try {
        run(CODE2_EXC);
        fail();
    } catch (PolyglotException pe) {
        message = pe.getMessage();
        assertTrue(message, message.contains("Identifier redefinition not supported"));
    }
    assertEquals(0, actionsUnwind.size());
    assertEquals(0, actionsReenter.size());
    assertEquals("[CALL(a), CALL(b), STATEMENT(DEFINE(a, ROOT())), CALL(a), CALL(b), STATEMENT(DEFINE(a, ROOT()))]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(DEFINE(a, ROOT())), CALL(b), CALL(a), STATEMENT(DEFINE(a, ROOT())), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
    String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
    assertEquals("[" + message + ", " + uw + ", " + uw + ", " + message + ", " + message + ", " + message + "]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[STATEMENT(DEFINE(a, ROOT())), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) PolyglotException(org.graalvm.polyglot.PolyglotException) Test(org.junit.Test)

Example 12 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testUnwindReturnOnEnter.

@Test
public void testUnwindReturnOnEnter() throws Exception {
    List<CodeAction> actionsUnwind = new ArrayList<>();
    List<CodeAction> actionsReenter = new ArrayList<>();
    // Unwind at STATEMENT() and Return after pop from CALL(a):
    actionsUnwind.add(new CodeAction("STATEMENT()", TestControlFlow.ACTION.UNWIND, "3uw"));
    actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.RETURN, 42));
    testControlFlow.actions.put(TestControlFlow.WHERE.ENTER, actionsUnwind);
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
    int ret = context.eval(lines(CODE2)).asInt();
    assertEquals(42, ret);
    assertEquals(0, actionsUnwind.size());
    assertEquals(0, actionsReenter.size());
    assertEquals("[CALL(a), CALL(b), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
    String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
    assertEquals("[" + uw + ", " + uw + ", " + uw + "]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with CodeAction

use of com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction in project graal by oracle.

the class UnwindReenterReturnTest method testUnwindReenterOnEnter.

@Test
public void testUnwindReenterOnEnter() throws Exception {
    List<CodeAction> actionsUnwind = new ArrayList<>();
    List<CodeAction> actionsReenter = new ArrayList<>();
    // Unwind at STATEMENT() and Reenter after pop from CALL(a):
    actionsUnwind.add(new CodeAction("STATEMENT()", TestControlFlow.ACTION.UNWIND, "3uw"));
    actionsReenter.add(new CodeAction("CALL(a)", TestControlFlow.ACTION.REENTER));
    testControlFlow.actions.put(TestControlFlow.WHERE.ENTER, actionsUnwind);
    testControlFlow.actions.put(TestControlFlow.WHERE.UNWIND, actionsReenter);
    run(CODE2);
    assertEquals(0, actionsUnwind.size());
    assertEquals(0, actionsReenter.size());
    assertEquals("[CALL(a), CALL(b), STATEMENT(), CALL(a), CALL(b), STATEMENT()]", testControlFlow.nodesEntered.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a), STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesReturned.toString());
    String uw = "com.oracle.truffle.api.instrumentation.UnwindException";
    assertEquals("[" + uw + ", " + uw + ", " + uw + ", Null, Null, Null]", testControlFlow.returnValuesExceptions.toString());
    assertEquals("[STATEMENT(), CALL(b), CALL(a)]", testControlFlow.nodesUnwound.toString());
    assertEquals("[3uw, 3uw, 3uw]", testControlFlow.unwoundInfos.toString());
}
Also used : CodeAction(com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CodeAction (com.oracle.truffle.api.instrumentation.test.UnwindReenterReturnTest.TestControlFlow.CodeAction)13 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)13 PolyglotException (org.graalvm.polyglot.PolyglotException)2