use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerSessionTest method testResumeAll3.
@Test
public void testResumeAll3() {
Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
try (DebuggerSession session = startSession()) {
for (int i = 0; i < 10; i++) {
suspend(session, getEvalThread());
session.resumeAll();
startEval(testSource);
expectDone();
}
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerThreadsTest method testSpawnThreads.
@Test
public void testSpawnThreads() {
int numThreads = 10;
final Source source = testSource("ROOT(DEFINE(foo, STATEMENT), LOOP(" + numThreads + ", SPAWN(foo)), JOIN())");
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
try (DebuggerSession session = startSession()) {
session.setThreadsListener(threadsListener, false);
startEval(source);
expectDone();
}
assertEquals(1 + 2 * numThreads, events.size());
List<ThreadEvent> startEvents = new ArrayList<>(1 + numThreads);
for (ThreadEvent event : events) {
if (event.isNew) {
startEvents.add(event);
}
}
assertEquals(1 + numThreads, startEvents.size());
DebugContext dcontext = events.get(0).context;
for (ThreadEvent event : events) {
assertEquals(dcontext, event.context);
}
events.clear();
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerThreadsTest method testContextThreads.
@Test
public void testContextThreads() throws Exception {
Engine engine = Engine.create();
final Source source = testSource("STATEMENT()");
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
int numThreads = 10;
Thread[] threads = new Thread[numThreads];
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
try (DebuggerSession session = debugger.startSession(null)) {
session.setThreadsListener(threadsListener, false);
for (int i = 0; i < numThreads; i++) {
threads[i] = new Thread() {
@Override
public void run() {
try (Context context = Context.newBuilder().engine(engine).build()) {
context.eval(source);
}
}
};
}
for (int i = 0; i < numThreads; i++) {
threads[i].start();
}
for (int i = 0; i < numThreads; i++) {
threads[i].join();
}
}
assertEquals(2 * numThreads, events.size());
List<ThreadEvent> startEvents = new ArrayList<>(numThreads);
for (ThreadEvent event : events) {
if (event.isNew) {
startEvents.add(event);
}
}
assertEquals(numThreads, startEvents.size());
// Verify that we got all threads in the events:
Set<Thread> allThreads = new HashSet<>(Arrays.asList(threads));
for (int i = 0; i < numThreads; i++) {
assertTrue(allThreads.remove(startEvents.get(i).thread));
}
assertTrue(allThreads.toString(), allThreads.isEmpty());
// Verify that we got 'numThreads' number of contexts:
Set<DebugContext> distinctContexts = new HashSet<>();
for (ThreadEvent event : events) {
distinctContexts.add(event.context);
}
assertEquals(numThreads, distinctContexts.size());
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class DebuggerThreadsTest method testGetStartedThreads.
@Test
public void testGetStartedThreads() throws Exception {
Engine engine = Engine.create();
TestThreadsListener threadsListener = new TestThreadsListener();
List<ThreadEvent> events = threadsListener.events;
Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
CountDownLatch latch = new CountDownLatch(1);
DebuggerSession[] sessionPtr = new DebuggerSession[1];
try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {
@Override
public void onSuspend(SuspendedEvent event) {
latch.countDown();
sessionPtr[0].setThreadsListener(threadsListener, true);
assertEquals(events.toString(), 2, events.size());
assertTrue(events.get(0).isNew);
assertNotNull(events.get(0).context);
assertTrue(events.get(1).isNew);
assertEquals(events.get(0).context, events.get(1).context);
assertNotEquals(events.get(0).thread, events.get(1).thread);
}
})) {
session.suspendNextExecution();
sessionPtr[0] = session;
try (Context context = Context.newBuilder().engine(engine).allowCreateThread(true).build()) {
Source source = testSource("ROOT(DEFINE(f1, EXPRESSION), SPAWN(f1), JOIN())");
context.eval(source);
source = testSource("ROOT(DEFINE(foo, STATEMENT), SPAWN(foo))");
context.eval(source);
latch.await();
context.eval(testSource("JOIN()"));
assertEquals(events.toString(), 3, events.size());
assertFalse(events.get(2).isNew);
assertTrue(events.get(0).thread == events.get(2).thread || events.get(1).thread == events.get(2).thread);
}
assertEquals(4, events.size());
}
}
use of com.oracle.truffle.api.debug.DebuggerSession in project graal by oracle.
the class BreakpointTest method testDisableBreakpointsDuringSuspend.
@Test
public void testDisableBreakpointsDuringSuspend() throws Throwable {
Source source = testSource("ROOT(\n" + " DEFINE(foo,\n" + " LOOP(3,\n" + " STATEMENT)\n" + " ),\n" + " CALL(foo)\n" + ")\n");
try (DebuggerSession session = startSession()) {
Breakpoint breakpoint1 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
startEval(source);
for (int i = 0; i < 3; i++) {
expectSuspended((SuspendedEvent event) -> {
checkState(event, 4, true, "STATEMENT").prepareContinue();
});
if (i == 0) {
breakpoint3.dispose();
}
if (i == 1) {
breakpoint1.dispose();
}
}
Assert.assertEquals(2, breakpoint1.getHitCount());
Assert.assertEquals(3, breakpoint2.getHitCount());
Assert.assertEquals(1, breakpoint3.getHitCount());
expectDone();
}
}
Aggregations