Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2011-07-19 16:45:39 +0000
committereutarass2011-07-19 16:45:39 +0000
commitcef7fb444253195bbef7e76f8b798e7a27eecddb (patch)
treeed13f6db3efa0ef5a3813b2109ee9357454d7781 /plugins/org.eclipse.tm.tcf.debug
parentce3a6133f16a441ef52707efed7288a53c1ce5d3 (diff)
downloadorg.eclipse.tcf-cef7fb444253195bbef7e76f8b798e7a27eecddb.tar.gz
org.eclipse.tcf-cef7fb444253195bbef7e76f8b798e7a27eecddb.tar.xz
org.eclipse.tcf-cef7fb444253195bbef7e76f8b798e7a27eecddb.zip
TCF Tests: common run control logic is moved into a separate class - RunControl.
Diffstat (limited to 'plugins/org.eclipse.tm.tcf.debug')
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/ITCFTest.java8
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/RunControl.java240
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java57
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java86
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEcho.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java129
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestFileSystem.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestPathMap.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java126
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestStreams.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestSysMonitor.java5
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestTerminals.java15
14 files changed, 402 insertions, 294 deletions
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/ITCFTest.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/ITCFTest.java
index 961abadf9..1fc67adbd 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/ITCFTest.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/ITCFTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.tm.internal.tcf.debug.tests;
-import org.eclipse.tm.tcf.services.IRunControl;
-
/**
* Each (sub)test in TCF Test Suite should implement this interface.
*/
@@ -24,8 +22,8 @@ interface ITCFTest {
/**
* Check if the test don't need the context to stay suspended.
- * @param ctx - run control context.
+ * @param id - run control context ID.
* @return true if it is OK to resume the context.
*/
- boolean canResume(IRunControl.RunControlContext ctx);
+ boolean canResume(String id);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/RunControl.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/RunControl.java
new file mode 100644
index 000000000..edc0c46b7
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/RunControl.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tm.internal.tcf.debug.tests;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import org.eclipse.tm.tcf.protocol.IChannel;
+import org.eclipse.tm.tcf.protocol.IToken;
+import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.tcf.services.IDiagnostics;
+import org.eclipse.tm.tcf.services.IRunControl;
+import org.eclipse.tm.tcf.services.IRunControl.RunControlContext;
+
+class RunControl {
+
+ private final TCFTestSuite test_suite;
+ private final IChannel channel;
+ private final IRunControl rc_service;
+ private final HashSet<String> suspended_ctx_ids = new HashSet<String>();
+ private final HashSet<IToken> get_state_cmds = new HashSet<IToken>();
+ private final HashMap<String,IToken> resume_cmds = new HashMap<String,IToken>();
+ private final HashSet<String> pending_resume_ids = new HashSet<String>();
+ private final HashMap<String,IRunControl.RunControlContext> ctx_map = new HashMap<String,IRunControl.RunControlContext>();
+ private final Random rnd = new Random();
+
+ private boolean sync_pending;
+
+ private final IRunControl.RunControlListener listener = new IRunControl.RunControlListener() {
+
+ public void contextAdded(RunControlContext[] contexts) {
+ for (IRunControl.RunControlContext ctx : contexts) {
+ ctx_map.put(ctx.getID(), ctx);
+ }
+ }
+
+ public void contextChanged(RunControlContext[] contexts) {
+ for (IRunControl.RunControlContext ctx : contexts) {
+ ctx_map.put(ctx.getID(), ctx);
+ }
+ }
+
+ public void contextRemoved(String[] context_ids) {
+ for (String id : context_ids) {
+ ctx_map.remove(id);
+ test_suite.getCanceledTests().remove(id);
+ suspended_ctx_ids.remove(id);
+ }
+ }
+
+ public void contextSuspended(final String id, String pc, String reason, Map<String,Object> params) {
+ suspended_ctx_ids.add(id);
+ Protocol.invokeLater(new Runnable() {
+ public void run() {
+ resume(id, IRunControl.RM_RESUME);
+ }
+ });
+ }
+
+ public void contextResumed(String context) {
+ suspended_ctx_ids.remove(context);
+ pending_resume_ids.remove(context);
+ }
+
+ public void containerSuspended(String context, String pc, String reason, Map<String, Object> params, String[] suspended_ids) {
+ for (String id : suspended_ids) {
+ suspended_ctx_ids.add(id);
+ resume(id, IRunControl.RM_RESUME);
+ }
+ }
+
+ public void containerResumed(String[] context_ids) {
+ for (String id : context_ids) {
+ suspended_ctx_ids.remove(id);
+ pending_resume_ids.remove(id);
+ }
+ }
+
+ public void contextException(String context, String msg) {
+ }
+ };
+
+ RunControl(TCFTestSuite test_suite, IChannel channel) {
+ this.test_suite = test_suite;
+ this.channel = channel;
+ rc_service = channel.getRemoteService(IRunControl.class);
+ if (rc_service != null) {
+ rc_service.addListener(listener);
+ getState();
+ startTimer();
+ }
+ }
+
+ private void getState() {
+ get_state_cmds.add(rc_service.getChildren(null, new IRunControl.DoneGetChildren() {
+ public void doneGetChildren(IToken token, Exception error, String[] context_ids) {
+ get_state_cmds.remove(token);
+ if (error != null) {
+ exit(error);
+ }
+ else {
+ for (final String id : context_ids) {
+ get_state_cmds.add(rc_service.getChildren(id, this));
+ get_state_cmds.add(rc_service.getContext(id, new IRunControl.DoneGetContext() {
+ public void doneGetContext(IToken token, Exception error, RunControlContext context) {
+ get_state_cmds.remove(token);
+ if (error != null) {
+ exit(error);
+ }
+ else {
+ ctx_map.put(id, context);
+ if (context.hasState()) {
+ get_state_cmds.add(context.getState(new IRunControl.DoneGetState() {
+ public void doneGetState(IToken token, Exception error, boolean suspended,
+ String pc, String reason, Map<String, Object> params) {
+ get_state_cmds.remove(token);
+ if (error != null) {
+ if (ctx_map.get(id) != null) exit(new Exception(
+ "Cannot get context state", error));
+ }
+ else {
+ if (suspended) suspended_ctx_ids.add(id);
+ }
+ }
+ }));
+ }
+ }
+ }
+ }));
+ }
+ }
+ }
+ }));
+ }
+
+ private void startTimer() {
+ Protocol.invokeLater(50, new Runnable() {
+ public void run() {
+ if (channel.getState() != IChannel.STATE_OPEN) return;
+ if (test_suite.cancel) return;
+ Protocol.invokeLater(50, this);
+ Set<String> s = test_suite.getCanceledTests().keySet();
+ if (s.size() > 0 || suspended_ctx_ids.size() > 0) {
+ Set<String> ids = new HashSet<String>(s);
+ ids.addAll(suspended_ctx_ids);
+ String[] arr = ids.toArray(new String[ids.size()]);
+ resume(arr[rnd.nextInt(arr.length)], IRunControl.RM_RESUME);
+ }
+ }
+ });
+ }
+
+ private void exit(Throwable error) {
+ Collection<ITCFTest> c = test_suite.getActiveTests();
+ ITCFTest[] arr = c.toArray(new ITCFTest[c.size()]);
+ for (ITCFTest t : arr) test_suite.done(t, error);
+ }
+
+ IRunControl.RunControlContext getContext(String id) {
+ return ctx_map.get(id);
+ }
+
+ boolean canResume(String id) {
+ if (sync_pending) return false;
+ if (resume_cmds.get(id) != null) return false;
+ if (test_suite.getCanceledTests().get(id) == null && !suspended_ctx_ids.contains(id)) return false;
+ IRunControl.RunControlContext ctx = ctx_map.get(id);
+ if (ctx == null) return false;
+ String grp = ctx.getRCGroup();
+ if (grp != null) {
+ for (String s : resume_cmds.keySet()) {
+ IRunControl.RunControlContext c = ctx_map.get(s);
+ if (c == null) return false;
+ if (grp.equals(c.getRCGroup())) return false;
+ }
+ }
+ return true;
+ }
+
+ void resume(final String id, final int mode) {
+ if (!canResume(id)) return;
+ assert !sync_pending;
+ sync_pending = true;
+ Protocol.sync(new Runnable() {
+ public void run() {
+ sync_pending = false;
+ if (test_suite.canResume(id)) {
+ assert resume_cmds.get(id) == null;
+ final String test_id = test_suite.getCanceledTests().get(id);
+ if (test_id != null) {
+ IDiagnostics diag = channel.getRemoteService(IDiagnostics.class);
+ resume_cmds.put(id, diag.cancelTest(test_id, new IDiagnostics.DoneCancelTest() {
+ public void doneCancelTest(IToken token, Throwable error) {
+ assert resume_cmds.get(id) == token;
+ resume_cmds.remove(id);
+ if (error != null && ctx_map.get(test_id) != null) exit(error);
+ }
+ }));
+ }
+ else {
+ IRunControl.RunControlContext ctx = ctx_map.get(id);
+ if (ctx != null) {
+ pending_resume_ids.add(id);
+ resume_cmds.put(id, ctx.resume(mode, 1, new IRunControl.DoneCommand() {
+ public void doneCommand(IToken token, Exception error) {
+ assert resume_cmds.get(id) == token;
+ resume_cmds.remove(id);
+ if (error != null) {
+ pending_resume_ids.remove(id);
+ if (suspended_ctx_ids.contains(id)) exit(error);
+ }
+ else if (pending_resume_ids.contains(id)) {
+ exit(new Exception("Missing contextResumed event"));
+ }
+ }
+ }));
+ }
+ }
+ }
+ }
+ });
+ }
+
+ void cancel(String thread_id, String test_id) {
+ test_suite.getCanceledTests().put(thread_id, test_id);
+ resume(thread_id, 0);
+ }
+}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java
index 3a55c09b3..91979100d 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -24,8 +24,7 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IPeer;
import org.eclipse.tm.tcf.protocol.Protocol;
import org.eclipse.tm.tcf.services.IMemoryMap;
-import org.eclipse.tm.tcf.services.IRunControl;
-import org.eclipse.tm.tcf.services.IPathMap.PathMapRule;
+import org.eclipse.tm.tcf.services.IPathMap;
/**
* TCF Test Suite implements stress testing of communication channels and capabilities of remote peer.
@@ -38,9 +37,11 @@ public class TCFTestSuite {
private final TestListener listener;
private final IChannel[] channels;
+ private final Map<IChannel,RunControl> run_controls = new HashMap<IChannel, RunControl>();
private final LinkedList<Runnable> pending_tests = new LinkedList<Runnable>();
private final Collection<Throwable> errors = new ArrayList<Throwable>();
private final Map<ITCFTest,IChannel> active_tests = new HashMap<ITCFTest,IChannel>();
+ private final static HashMap<String,String> cancel_test_ids = new HashMap<String,String>();
private int count_total;
private int count_done;
@@ -54,8 +55,8 @@ public class TCFTestSuite {
public void done(Collection<Throwable> errors);
}
- public TCFTestSuite(final IPeer peer, final TestListener listener,
- final List<PathMapRule> path_map, final Map<String,ArrayList<IMemoryMap.MemoryRegion>> mem_map) throws IOException {
+ public TCFTestSuite(final IPeer peer, final TestListener listener, final List<IPathMap.PathMapRule> path_map,
+ final Map<String,ArrayList<IMemoryMap.MemoryRegion>> mem_map) throws IOException {
this.listener = listener;
pending_tests.add(new Runnable() {
public void run() {
@@ -85,7 +86,7 @@ public class TCFTestSuite {
public void run() {
listener.progress("Running Debugger Attach/Terminate Test...", ++count_done, count_total);
for (IChannel channel : channels) {
- active_tests.put(new TestAttachTerminate(TCFTestSuite.this, channel), channel);
+ active_tests.put(new TestAttachTerminate(TCFTestSuite.this, run_controls.get(channel), channel), channel);
}
}
});
@@ -101,7 +102,7 @@ public class TCFTestSuite {
public void run() {
listener.progress("Running Expressions Test...", ++count_done, count_total);
for (IChannel channel : channels) {
- active_tests.put(new TestExpressions(TCFTestSuite.this, channel), channel);
+ active_tests.put(new TestExpressions(TCFTestSuite.this, run_controls.get(channel), channel), channel);
}
}
});
@@ -134,7 +135,8 @@ public class TCFTestSuite {
int i = 0;
listener.progress("Running Run Control Test...", ++count_done, count_total);
for (IChannel channel : channels) {
- active_tests.put(new TestRCBP1(TCFTestSuite.this, channel, i++, path_map, mem_map), channel);
+ active_tests.put(new TestRCBP1(TCFTestSuite.this, run_controls.get(channel),
+ channel, i++, path_map, mem_map), channel);
}
}
});
@@ -152,21 +154,22 @@ public class TCFTestSuite {
listener.progress("Running Interability Test...", ++count_done, count_total);
Random rnd = new Random();
for (int i = 0; i < channels.length; i++) {
+ IChannel channel = channels[i];
ITCFTest test = null;
switch (rnd.nextInt(11)) {
- case 0: test = new TestEcho(TCFTestSuite.this, channels[i]); break;
- case 1: test = new TestEchoERR(TCFTestSuite.this, channels[i]); break;
- case 2: test = new TestEchoFP(TCFTestSuite.this, channels[i]); break;
- case 3: test = new TestAttachTerminate(TCFTestSuite.this, channels[i]); break;
- case 4: test = new TestExpressions(TCFTestSuite.this, channels[i]); break;
- case 5: test = new TestRCBP1(TCFTestSuite.this, channels[i], i, path_map, mem_map); break;
- case 6: test = new TestFileSystem(TCFTestSuite.this, channels[i], i); break;
- case 7: test = new TestPathMap(TCFTestSuite.this, channels[i], path_map); break;
- case 8: test = new TestStreams(TCFTestSuite.this, channels[i]); break;
- case 9: test = new TestSysMonitor(TCFTestSuite.this, channels[i]); break;
- case 10: test = new TestTerminals(TCFTestSuite.this, channels[i]); break;
+ case 0: test = new TestEcho(TCFTestSuite.this, channel); break;
+ case 1: test = new TestEchoERR(TCFTestSuite.this, channel); break;
+ case 2: test = new TestEchoFP(TCFTestSuite.this, channel); break;
+ case 3: test = new TestAttachTerminate(TCFTestSuite.this, run_controls.get(channel), channel); break;
+ case 4: test = new TestExpressions(TCFTestSuite.this, run_controls.get(channel), channel); break;
+ case 5: test = new TestRCBP1(TCFTestSuite.this, run_controls.get(channel), channel, i, path_map, mem_map); break;
+ case 6: test = new TestFileSystem(TCFTestSuite.this, channel, i); break;
+ case 7: test = new TestPathMap(TCFTestSuite.this, channel, path_map); break;
+ case 8: test = new TestStreams(TCFTestSuite.this, channel); break;
+ case 9: test = new TestSysMonitor(TCFTestSuite.this, channel); break;
+ case 10: test = new TestTerminals(TCFTestSuite.this, channel); break;
}
- active_tests.put(test, channels[i]);
+ active_tests.put(test, channel);
}
}
});
@@ -202,6 +205,9 @@ public class TCFTestSuite {
if (channels[i] == null) return;
if (channels[i].getState() != IChannel.STATE_OPEN) return;
}
+ for (int i = 0; i < channels.length; i++) {
+ run_controls.put(channels[i], new RunControl(TCFTestSuite.this, channels[i]));
+ }
runNextTest();
}
@@ -265,9 +271,16 @@ public class TCFTestSuite {
return active_tests.keySet();
}
- boolean canResume(IRunControl.RunControlContext ctx) {
+ Map<String,String> getCanceledTests() {
+ return cancel_test_ids;
+ }
+
+ boolean canResume(String id) {
+ for (RunControl r : run_controls.values()) {
+ if (!r.canResume(id)) return false;
+ }
for (ITCFTest t : active_tests.keySet()) {
- if (!t.canResume(ctx)) return false;
+ if (!t.canResume(id)) return false;
}
return true;
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java
index 544e60528..b258f0035 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,13 +10,11 @@
*******************************************************************************/
package org.eclipse.tm.internal.tcf.debug.tests;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import org.eclipse.tm.tcf.protocol.IChannel;
-import org.eclipse.tm.tcf.protocol.IErrorReport;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.protocol.Protocol;
import org.eclipse.tm.tcf.services.IDiagnostics;
@@ -26,20 +24,18 @@ import org.eclipse.tm.tcf.services.IRunControl.RunControlContext;
class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
private final TCFTestSuite test_suite;
+ private final RunControl test_rc;
private final IDiagnostics diag;
private final IRunControl rc;
private final Random rnd = new Random();
private int cnt = 0;
- private final HashMap<String,IRunControl.RunControlContext> ctx_map =
- new HashMap<String,IRunControl.RunControlContext>();
private final HashSet<String> test_ctx_ids = new HashSet<String>();
- private final HashSet<String> suspended_ctx_ids = new HashSet<String>();
- private final HashMap<String,IToken> resume_cmds = new HashMap<String,IToken>();
- TestAttachTerminate(TCFTestSuite test_suite, IChannel channel) {
+ TestAttachTerminate(TCFTestSuite test_suite, RunControl test_rc, IChannel channel) {
this.test_suite = test_suite;
+ this.test_rc = test_rc;
diag = channel.getRemoteService(IDiagnostics.class);
rc = channel.getRemoteService(IRunControl.class);
}
@@ -68,13 +64,12 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
}
else if (cnt < 300) {
Protocol.invokeLater(100, this);
- for (String id : suspended_ctx_ids) resume(id);
}
else if (test_ctx_ids.isEmpty()) {
- exit(new Error("Missing 'contextAdded' event"));
+ exit(new Error("Timeout waiting for 'contextAdded' event"));
}
else {
- exit(new Error("Missing 'contextRemoved' event for " + test_ctx_ids));
+ exit(new Error("Timeout waiting for 'contextRemoved' event. Context: " + test_ctx_ids));
}
}
});
@@ -86,38 +81,10 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
}
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
- if (resume_cmds.get(ctx.getID()) != null) return false;
- String grp = ctx.getRCGroup();
- if (grp != null) {
- for (String id : resume_cmds.keySet()) {
- IRunControl.RunControlContext c = ctx_map.get(id);
- if (c == null) return false;
- if (grp.equals(c.getRCGroup())) return false;
- }
- }
+ public boolean canResume(String id) {
return true;
}
- private void resume(final String id) {
- IRunControl.RunControlContext ctx = ctx_map.get(id);
- if (ctx != null && test_suite.canResume(ctx)) {
- assert resume_cmds.get(id) == null;
- resume_cmds.put(id, ctx.resume(IRunControl.RM_RESUME, 1, new IRunControl.DoneCommand() {
- public void doneCommand(IToken token, Exception error) {
- assert resume_cmds.get(id) == token;
- resume_cmds.remove(id);
- if (error instanceof IErrorReport) {
- int code = ((IErrorReport)error).getErrorCode();
- if (code == IErrorReport.TCF_ERROR_ALREADY_RUNNING) return;
- if (code == IErrorReport.TCF_ERROR_INV_CONTEXT && ctx_map.get(id) == null) return;
- }
- if (error != null) exit(error);
- }
- }));
- }
- }
-
private void startTestContext(String test_name) {
for (int i = 0; i < 4; i++) {
diag.runTest(test_name, new IDiagnostics.DoneRunTest() {
@@ -128,33 +95,12 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
}
else {
assert id != null;
- if (ctx_map.get(id) == null) {
+ if (test_rc.getContext(id) == null) {
exit(new Error("Missing 'contextAdded' event for context " + id));
}
else {
test_ctx_ids.add(id);
- Runnable r = new Runnable() {
- public void run() {
- if (!test_suite.isActive(TestAttachTerminate.this)) return;
- IRunControl.RunControlContext ctx = ctx_map.get(id);
- if (ctx == null) return;
- if (!test_suite.canResume(ctx)) {
- Protocol.invokeLater(100, this);
- }
- else {
- diag.cancelTest(id, new IDiagnostics.DoneCancelTest() {
- public void doneCancelTest(IToken token, Throwable error) {
- if (error instanceof IErrorReport) {
- int code = ((IErrorReport)error).getErrorCode();
- if (code == IErrorReport.TCF_ERROR_INV_CONTEXT && ctx_map.get(id) == null) return;
- }
- if (error != null) exit(error);
- }
- });
- }
- }
- };
- Protocol.invokeLater(r);
+ test_rc.cancel(id, id);
}
}
}
@@ -183,17 +129,9 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
}
public void contextAdded(RunControlContext[] contexts) {
- for (RunControlContext ctx : contexts) {
- if (ctx_map.get(ctx.getID()) != null) exit(new Error("Invalid 'contextAdded' event"));
- ctx_map.put(ctx.getID(), ctx);
- }
}
public void contextChanged(RunControlContext[] contexts) {
- for (RunControlContext ctx : contexts) {
- if (ctx_map.get(ctx.getID()) == null) return;
- ctx_map.put(ctx.getID(), ctx);
- }
}
public void contextException(String context, String msg) {
@@ -201,20 +139,14 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
public void contextRemoved(String[] context_ids) {
for (String id : context_ids) {
- ctx_map.remove(id);
test_ctx_ids.remove(id);
- suspended_ctx_ids.remove(id);
}
if (cnt == 0 && test_ctx_ids.isEmpty()) exit(null);
}
public void contextResumed(String context) {
- suspended_ctx_ids.remove(context);
}
public void contextSuspended(String context, String pc, String reason, Map<String,Object> params) {
- assert context != null;
- suspended_ctx_ids.add(context);
- resume(context);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEcho.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEcho.java
index b5f33175d..eb4a3ff33 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEcho.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEcho.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,7 +16,6 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IErrorReport;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IDiagnostics;
-import org.eclipse.tm.tcf.services.IRunControl;
class TestEcho implements ITCFTest, IDiagnostics.DoneEcho {
@@ -89,7 +88,7 @@ class TestEcho implements ITCFTest, IDiagnostics.DoneEcho {
}
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java
index 1b49c6c49..c855fb90a 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,7 +22,6 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IErrorReport;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IDiagnostics;
-import org.eclipse.tm.tcf.services.IRunControl;
class TestEchoERR implements ITCFTest, IDiagnostics.DoneEchoERR {
@@ -112,7 +111,7 @@ class TestEchoERR implements ITCFTest, IDiagnostics.DoneEchoERR {
}
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java
index 998defdd2..69e1d3212 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,7 +17,6 @@ import java.util.Random;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IDiagnostics;
-import org.eclipse.tm.tcf.services.IRunControl;
class TestEchoFP implements ITCFTest, IDiagnostics.DoneEchoFP {
@@ -76,7 +75,7 @@ class TestEchoFP implements ITCFTest, IDiagnostics.DoneEchoFP {
}
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java
index a54fd3d4c..a155d4cad 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,6 +32,7 @@ class TestExpressions implements ITCFTest,
IRunControl.RunControlListener, IExpressions.ExpressionsListener, IBreakpoints.BreakpointsListener {
private final TCFTestSuite test_suite;
+ private final RunControl test_rc;
private final IDiagnostics diag;
private final IExpressions expr;
private final ISymbols syms;
@@ -49,6 +50,7 @@ class TestExpressions implements ITCFTest,
private String thread_id;
private boolean run_to_bp_done;
private boolean test_done;
+ private boolean cancel_test_sent;
private IRunControl.RunControlContext test_ctx;
private IRunControl.RunControlContext thread_ctx;
private String suspended_pc;
@@ -56,9 +58,6 @@ class TestExpressions implements ITCFTest,
private String[] stack_trace;
private IStackTrace.StackTraceContext[] stack_frames;
private String[] local_vars;
- private final HashSet<String> suspended_ctx_ids = new HashSet<String>();
- private final HashMap<String,IToken> resume_cmds = new HashMap<String,IToken>();
- private final HashMap<String,IRunControl.RunControlContext> ctx_map = new HashMap<String,IRunControl.RunControlContext>();
private final Map<String,IExpressions.Expression> expr_ctx = new HashMap<String,IExpressions.Expression>();
private final Map<String,IExpressions.Value> expr_val = new HashMap<String,IExpressions.Value>();
private final Map<String,ISymbols.Symbol> expr_sym = new HashMap<String,ISymbols.Symbol>();
@@ -109,8 +108,9 @@ class TestExpressions implements ITCFTest,
"&tcf_test_func3",
};
- TestExpressions(TCFTestSuite test_suite, IChannel channel) {
+ TestExpressions(TCFTestSuite test_suite, RunControl test_rc, IChannel channel) {
this.test_suite = test_suite;
+ this.test_rc = test_rc;
diag = channel.getRemoteService(IDiagnostics.class);
expr = channel.getRemoteService(IExpressions.class);
syms = channel.getRemoteService(ISymbols.class);
@@ -146,8 +146,11 @@ class TestExpressions implements ITCFTest,
exit(null);
}
else if (cnt < 600) {
+ if (test_done && !cancel_test_sent) {
+ test_rc.cancel(thread_id, test_ctx_id);
+ cancel_test_sent = true;
+ }
Protocol.invokeLater(100, this);
- for (String id : suspended_ctx_ids) resume(id);
}
else if (test_ctx_id == null) {
exit(new Error("Timeout waiting for reply of Diagnostics.runTest command"));
@@ -166,12 +169,15 @@ class TestExpressions implements ITCFTest,
}
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
if (test_ctx_id != null && thread_ctx == null) return false;
- if (resume_cmds.get(ctx.getID()) != null) return false;
- String grp = ctx.getRCGroup();
if (thread_ctx != null && !test_done) {
- if (ctx.getID().equals(thread_id) || grp != null && grp.equals(thread_ctx.getRCGroup())) {
+ assert thread_ctx.getID().equals(thread_id);
+ IRunControl.RunControlContext ctx = test_rc.getContext(id);
+ if (ctx == null) return false;
+ String grp = ctx.getRCGroup();
+ if (id.equals(thread_id) || grp != null && grp.equals(thread_ctx.getRCGroup())) {
+ if (run_to_bp_done) return false;
if (sym_func3 == null) return false;
if (suspended_pc == null) return false;
BigInteger pc0 = new BigInteger(sym_func3.getValue().toString());
@@ -179,30 +185,9 @@ class TestExpressions implements ITCFTest,
if (pc0.equals(pc1)) return false;
}
}
- if (grp != null) {
- for (String id : resume_cmds.keySet()) {
- IRunControl.RunControlContext c = ctx_map.get(id);
- if (c == null) return false;
- if (grp.equals(c.getRCGroup())) return false;
- }
- }
return true;
}
- private void resume(final String id) {
- IRunControl.RunControlContext ctx = ctx_map.get(id);
- if (ctx != null && test_suite.canResume(ctx)) {
- assert resume_cmds.get(id) == null;
- resume_cmds.put(id, ctx.resume(IRunControl.RM_RESUME, 1, new IRunControl.DoneCommand() {
- public void doneCommand(IToken token, Exception error) {
- assert resume_cmds.get(id) == token;
- resume_cmds.remove(id);
- if (error != null && suspended_ctx_ids.contains(id)) exit(error);
- }
- }));
- }
- }
-
@SuppressWarnings("unchecked")
private void runTest() {
if (bp_id == null) {
@@ -246,7 +231,7 @@ class TestExpressions implements ITCFTest,
else if (id == null) {
exit(new Exception("Test context ID must not be null"));
}
- else if (ctx_map.get(id) == null) {
+ else if (test_rc.getContext(id) == null) {
exit(new Exception("Missing context added event"));
}
else {
@@ -319,7 +304,7 @@ class TestExpressions implements ITCFTest,
boolean suspended, String pc, String reason,
Map<String,Object> params) {
if (error != null) {
- exit(error);
+ exit(new Exception("Cannot get context state", error));
}
else if (suspended) {
suspended_pc = pc;
@@ -354,25 +339,24 @@ class TestExpressions implements ITCFTest,
BigInteger pc1 = new BigInteger(suspended_pc);
if (!pc0.equals(pc1)) {
waiting_suspend = true;
- resume(thread_ctx.getID());
+ test_rc.resume(thread_id, IRunControl.RM_RESUME);
return;
}
run_to_bp_done = true;
}
+ assert test_done || !canResume(thread_id);
if (stack_trace == null) {
stk.getChildren(thread_id, new IStackTrace.DoneGetChildren() {
public void doneGetChildren(IToken token, Exception error, String[] context_ids) {
if (error != null) {
exit(error);
}
+ else if (context_ids == null || context_ids.length < 2) {
+ exit(new Exception("Invalid stack trace"));
+ }
else {
stack_trace = context_ids;
- if (stack_trace == null || stack_trace.length < 2) {
- exit(new Exception("Invalid stack trace"));
- }
- else {
- runTest();
- }
+ runTest();
}
}
});
@@ -384,14 +368,12 @@ class TestExpressions implements ITCFTest,
if (error != null) {
exit(error);
}
+ else if (frames == null || frames.length != stack_trace.length) {
+ exit(new Exception("Invalid stack trace"));
+ }
else {
stack_frames = frames;
- if (stack_frames == null || stack_frames.length != stack_trace.length) {
- exit(new Exception("Invalid stack trace"));
- }
- else {
- runTest();
- }
+ runTest();
}
}
});
@@ -400,7 +382,7 @@ class TestExpressions implements ITCFTest,
if (local_vars == null) {
expr.getChildren(stack_trace[stack_trace.length - 2], new IExpressions.DoneGetChildren() {
public void doneGetChildren(IToken token, Exception error, String[] context_ids) {
- if (error != null) {
+ if (error != null || context_ids == null) {
// Need to continue tests even if local variables info is not available.
// TODO: need to distinguish absence of debug info from other errors.
local_vars = new String[0];
@@ -547,24 +529,7 @@ class TestExpressions implements ITCFTest,
return;
}
test_done = true;
- if (test_suite.canResume(thread_ctx)) {
- final String id = thread_ctx.getID();
- assert resume_cmds.get(id) == null;
- resume_cmds.put(id, diag.cancelTest(test_ctx_id, new IDiagnostics.DoneCancelTest() {
- public void doneCancelTest(IToken token, Throwable error) {
- assert resume_cmds.get(id) == token;
- resume_cmds.remove(id);
- if (error != null) exit(error);
- }
- }));
- }
- else {
- Protocol.invokeLater(20, new Runnable() {
- public void run() {
- runTest();
- }
- });
- }
+ test_rc.resume(thread_id, IRunControl.RM_RESUME);
}
private void exit(Throwable x) {
@@ -589,22 +554,14 @@ class TestExpressions implements ITCFTest,
}
public void contextAdded(IRunControl.RunControlContext[] contexts) {
- for (IRunControl.RunControlContext ctx : contexts) {
- if (ctx_map.get(ctx.getID()) != null) exit(new Error("Invalid 'contextAdded' event"));
- ctx_map.put(ctx.getID(), ctx);
- }
}
public void contextChanged(IRunControl.RunControlContext[] contexts) {
- for (IRunControl.RunControlContext ctx : contexts) {
- if (ctx_map.get(ctx.getID()) == null) return;
- ctx_map.put(ctx.getID(), ctx);
- }
}
public void contextException(String context, String msg) {
if (test_done) return;
- IRunControl.RunControlContext ctx = ctx_map.get(context);
+ IRunControl.RunControlContext ctx = test_rc.getContext(context);
if (ctx != null) {
String p = ctx.getParentID();
String c = ctx.getCreatorID();
@@ -615,8 +572,6 @@ class TestExpressions implements ITCFTest,
public void contextRemoved(String[] context_ids) {
for (String id : context_ids) {
- suspended_ctx_ids.remove(id);
- ctx_map.remove(id);
if (id.equals(test_ctx_id)) {
if (test_done) {
bp.set(null, new IBreakpoints.DoneCommand() {
@@ -633,16 +588,19 @@ class TestExpressions implements ITCFTest,
}
}
- public void contextResumed(String context) {
- suspended_ctx_ids.remove(context);
- if (context.equals(thread_id)) {
+ public void contextResumed(String id) {
+ if (id.equals(thread_id)) {
+ if (run_to_bp_done && !test_done) {
+ assert thread_ctx != null;
+ assert !canResume(thread_id);
+ exit(new Exception("Unexpected contextResumed event: " + id));
+ }
suspended_pc = null;
}
}
public void contextSuspended(String context, String pc, String reason, Map<String,Object> params) {
assert context != null;
- suspended_ctx_ids.add(context);
if (context.equals(thread_id)) {
if (pc == null && thread_ctx != null) {
thread_ctx.getState(new IRunControl.DoneGetState() {
@@ -650,9 +608,15 @@ class TestExpressions implements ITCFTest,
boolean suspended, String pc, String reason,
Map<String,Object> params) {
if (error != null) {
- exit(error);
+ exit(new Exception("Cannot get context state", error));
+ }
+ else if (!suspended) {
+ exit(new Exception("Invalid context state"));
}
- else if (suspended) {
+ else if (pc == null || pc.length() == 0 || pc.equals("0")) {
+ exit(new Exception("Invalid context PC"));
+ }
+ else {
suspended_pc = pc;
if (waiting_suspend) {
waiting_suspend = false;
@@ -670,7 +634,6 @@ class TestExpressions implements ITCFTest,
}
}
}
- resume(context);
}
//--------------------------- Expressions listener ---------------------------//
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestFileSystem.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestFileSystem.java
index 5457f5508..e86c8b8c3 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestFileSystem.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestFileSystem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,6 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.protocol.Protocol;
import org.eclipse.tm.tcf.services.IFileSystem;
-import org.eclipse.tm.tcf.services.IRunControl;
import org.eclipse.tm.tcf.services.IFileSystem.DirEntry;
import org.eclipse.tm.tcf.services.IFileSystem.FileAttrs;
import org.eclipse.tm.tcf.services.IFileSystem.FileSystemException;
@@ -426,7 +425,7 @@ class TestFileSystem implements ITCFTest, IFileSystem.DoneStat,
test_suite.done(this, x);
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestPathMap.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestPathMap.java
index 079a26df3..c120565de 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestPathMap.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestPathMap.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 1011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,7 +18,6 @@ import java.util.Random;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IPathMap;
-import org.eclipse.tm.tcf.services.IRunControl;
import org.eclipse.tm.tcf.services.IPathMap.PathMapRule;
class TestPathMap implements ITCFTest {
@@ -177,7 +176,7 @@ class TestPathMap implements ITCFTest {
test_suite.done(this, x);
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return false;
}
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java
index 373406e71..e44457f9a 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java
@@ -48,6 +48,7 @@ import org.eclipse.tm.tcf.services.ISymbols.Symbol;
class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
private final TCFTestSuite test_suite;
+ private final RunControl test_rc;
private final int channel_id;
private final List<PathMapRule> path_map;
private final Map<String,ArrayList<MemoryRegion>> mem_map;
@@ -68,7 +69,6 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
private final Map<String,Map<String,Object>[]> disassembly_capabilities = new HashMap<String,Map<String,Object>[]>();
private final Set<String> running = new HashSet<String>();
private final Set<IToken> get_state_cmds = new HashSet<IToken>();
- private final HashMap<String,IToken> resume_cmds = new HashMap<String,IToken>();
private final Map<String,Map<String,IRegisters.RegistersContext>> regs =
new HashMap<String,Map<String,IRegisters.RegistersContext>>();
private final Map<String,Map<String,Object>> bp_list = new HashMap<String,Map<String,Object>>();
@@ -232,9 +232,10 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
};
- TestRCBP1(TCFTestSuite test_suite, IChannel channel, int channel_id,
+ TestRCBP1(TCFTestSuite test_suite, RunControl test_rc, IChannel channel, int channel_id,
List<PathMapRule> path_map, Map<String,ArrayList<MemoryRegion>> mem_map) {
this.test_suite = test_suite;
+ this.test_rc = test_rc;
this.channel_id = channel_id;
this.path_map = path_map;
this.mem_map = mem_map;
@@ -281,15 +282,6 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
if (test_id != null) {
if (test_ctx_id == null) {
startTestContext();
- Protocol.invokeLater(200, new Runnable() {
- public void run() {
- if (!test_suite.isActive(TestRCBP1.this)) return;
- Protocol.invokeLater(200, this);
- for (SuspendedContext sc : suspended.values()) {
- if (sc.ok_to_resume) resume(sc);
- }
- }
- });
return;
}
if (test_context == null) {
@@ -337,11 +329,9 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
return;
}
assert resume_cnt == 0;
+ assert !all_setup_done;
all_setup_done = true;
- for (SuspendedContext s : suspended.values()) {
- if (s.get_state_pending) continue;
- resume(s.id);
- }
+ for (SuspendedContext s : suspended.values()) resume(s.id);
}
else if (suspended.size() > 0) {
final int test_cnt = suspended.size();
@@ -374,13 +364,8 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
else {
if (list == null) list = new String[0];
+ if (list.length > 0) test_id = list[rnd.nextInt(list.length)];
test_list = list;
- for (String s : list) {
- if (s.equals("RCBP1")) test_id = s;
- }
- if (test_id == null && list.length > 0) {
- test_id = list[rnd.nextInt(list.length)];
- }
runTest();
}
}
@@ -462,6 +447,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
srv_breakpoints.getCapabilities(test_ctx_id, new IBreakpoints.DoneGetCapabilities() {
public void doneGetCapabilities(IToken token, Exception error, Map<String,Object> capabilities) {
+ if (!test_suite.isActive(TestRCBP1.this)) return;
if (error != null) {
exit(error);
return;
@@ -671,10 +657,14 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
exit(error);
return;
}
- for (ITCFTest t : test_suite.getActiveTests()) {
- if (t instanceof TestRCBP1 && ((TestRCBP1)t).threads.get(id) != null) {
- exit(new Exception("Invalid or missing 'CreatorID' context attribute.\nContext: " + ctx));
- return;
+ if (test_id != null) {
+ assert test_ctx_id != null;
+ assert isMyContext(ctx);
+ for (ITCFTest t : test_suite.getActiveTests()) {
+ if (t != TestRCBP1.this && t instanceof TestRCBP1 && ((TestRCBP1)t).threads.get(id) != null) {
+ exit(new Exception("Invalid or missing 'CreatorID' context attribute.\nContext: " + ctx));
+ return;
+ }
}
}
if (ctx.hasState()) {
@@ -686,7 +676,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
get_state_cmds.remove(token);
if (test_suite.cancel) return;
if (error != null) {
- exit(error);
+ exit(new Exception("Cannot get context state", error));
return;
}
if (!susp) {
@@ -704,15 +694,16 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
SuspendedContext sc = suspended.get(id);
if (sc != null && sc.pc != null && !sc.pc.equals(pc)) {
- exit(new Exception("Invalid result of getState command: invalid PC"));
+ exit(new Exception("Invalid result of getState command: invalid PC. Context: " + id));
return;
}
if (sc != null && sc.reason != null && !sc.reason.equals(reason)) {
- exit(new Exception("Invalid result of getState command: invalid suspend reason"));
+ exit(new Exception("Invalid result of getState command: invalid suspend reason. Context: " + id));
return;
}
if (test_id != null && "Breakpoint".equals(reason)) {
- exit(new Exception("Invalid suspend reason of main thread after test start: " + reason + " " + pc));
+ exit(new Exception("Invalid suspend reason of main thread " +
+ id + " after test start: " + reason + " " + pc));
return;
}
assert !done_get_state;
@@ -903,7 +894,8 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
return;
}
}
- if (!bp_change_done) {
+ if (threads.size() > 0 && !all_setup_done) {
+ assert !canResume(id);
exit(new Exception("Unexpected contextAdded event\nContext: " + ctx));
return;
}
@@ -966,7 +958,6 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
public void contextResumed(String id) {
- resume_cmds.remove(id);
IRunControl.RunControlContext ctx = threads.get(id);
if (ctx == null) return;
assert isMyContext(ctx);
@@ -975,8 +966,8 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
return;
}
SuspendedContext sc = suspended.remove(id);
- if (!done_get_state) return;
- if (sc == null || !sc.ok_to_resume || sc.get_state_pending && ctx.getRCGroup() == null) {
+ if (!done_get_state || sc == null || !sc.ok_to_resume || sc.get_state_pending && ctx.getRCGroup() == null) {
+ assert !canResume(id);
exit(new Exception("Unexpected contextResumed event: " + id));
return;
}
@@ -1071,7 +1062,6 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
}
if (!all_setup_done) return;
if (!test_suite.isActive(this)) return;
- assert resume_cmds.get(sc.id) == null;
Runnable done = new Runnable() {
public void run() {
if (suspended.get(sc.id) == sc) resume(sc.id);
@@ -1103,6 +1093,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
private boolean isMyContext(IRunControl.RunControlContext ctx) {
// Check if the context was created by this test
+ if (test_ctx_id == null) return false;
return test_ctx_id.equals(ctx.getID()) ||
test_ctx_id.equals(ctx.getParentID()) ||
test_ctx_id.equals(ctx.getCreatorID());
@@ -1153,9 +1144,8 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
assert !done_get_state || done_disassembly || srv_disassembly == null;
suspended.put(id, sc);
}
- if (!bp_sync_done) return;
+ if (!all_setup_done) return;
assert get_state_cmds.size() == 0;
- assert resume_cmds.get(id) == null;
assert suspended.get(id) == sc;
assert !sc.get_state_pending;
sc.get_state_pending = true;
@@ -1164,7 +1154,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
public void doneGetState(IToken token, Exception error, boolean susp,
String pc, String reason, Map<String, Object> params) {
if (error != null) {
- exit(error);
+ exit(new Exception("Cannot get context state", error));
}
else if (suspended.get(id) != sc0) {
exit(new Exception("Context resumed before RunControl.getState result"));
@@ -1194,30 +1184,28 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
});
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
- if (test_ctx_id != null && !all_setup_done) return false;
- if (resume_cmds.get(ctx.getID()) != null) return false;
+ public boolean canResume(String id) {
+ if (test_ctx_id != null && threads.size() == 0)
+ // Don't know yet neither my thread IDs nor my RC group.
+ return false;
+ IRunControl.RunControlContext ctx = test_rc.getContext(id);
+ if (ctx == null) return false;
+ if (isMyContext(ctx) && (!all_setup_done || threads.get(id) == null))
+ // My threads should stay suspended until all_setup_done
+ return false;
String grp = ctx.getRCGroup();
for (IRunControl.RunControlContext x : threads.values()) {
- if (x.getID().equals(ctx.getID()) || grp != null && grp.equals(x.getRCGroup())) {
+ if (x.getID().equals(id) || grp != null && grp.equals(x.getRCGroup())) {
SuspendedContext sc = suspended.get(x.getID());
if (sc == null) return false;
if (!sc.ok_to_resume) return false;
}
}
- if (grp != null) {
- for (String id : resume_cmds.keySet()) {
- IRunControl.RunControlContext c = threads.get(id);
- if (c == null) return false;
- if (grp.equals(c.getRCGroup())) return false;
- }
- }
return true;
}
private void resume(String id) {
assert done_get_state || resume_cnt == 0;
- assert resume_cmds.get(id) == null;
assert bp_sync_done;
assert mem_map_test_done;
resume_cnt++;
@@ -1227,40 +1215,13 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
assert !sc.get_state_pending;
assert !sc.ok_to_resume;
sc.ok_to_resume = true;
- resume(sc);
- }
- }
-
- private void resume(final SuspendedContext sc) {
- assert sc.ok_to_resume;
- final String id = sc.id;
- final IRunControl.RunControlContext ctx = threads.get(id);
- if (!test_suite.canResume(ctx)) return;
- int rm = IRunControl.RM_RESUME;
- if (isMyBreakpoint(sc)) {
- rm = rnd.nextInt(6);
- if (!ctx.canResume(rm)) rm = IRunControl.RM_RESUME;
- }
- resume_cmds.put(id, ctx.resume(rm, 1, new HashMap<String,Object>(), new IRunControl.DoneCommand() {
- public void doneCommand(IToken token, Exception error) {
- if (test_suite.cancel) return;
- if (!test_suite.isActive(TestRCBP1.this)) return;
- if (threads.get(id) == null) return;
- if (error instanceof IErrorReport &&
- ((IErrorReport)error).getErrorCode() == IErrorReport.TCF_ERROR_ALREADY_RUNNING &&
- ctx.getRCGroup() != null) {
- error = null;
- }
- if (error != null) {
- exit(error);
- return;
- }
- if (suspended.get(id) == sc || resume_cmds.get(id) == token) {
- exit(new Exception("Missing contextResumed event after resume command"));
- return;
- }
+ int rm = IRunControl.RM_RESUME;
+ if (isMyBreakpoint(sc)) {
+ rm = rnd.nextInt(6);
+ if (!ctx.canResume(rm)) rm = IRunControl.RM_RESUME;
}
- }));
+ test_rc.resume(id, rm);
+ }
}
private void runMemoryTest(final SuspendedContext sc, final Runnable done) {
@@ -1462,7 +1423,6 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
exit(error);
return;
}
- assert resume_cmds.get(sc.id) == null;
if (ctx.getSize() != value.length) {
exit(new Exception("Invalid register value size"));
return;
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestStreams.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestStreams.java
index e818c583d..e066a4b47 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestStreams.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestStreams.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,7 +16,6 @@ import java.util.Random;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IDiagnostics;
-import org.eclipse.tm.tcf.services.IRunControl;
import org.eclipse.tm.tcf.services.IStreams;
class TestStreams implements ITCFTest, IStreams.StreamsListener {
@@ -300,7 +299,7 @@ class TestStreams implements ITCFTest, IStreams.StreamsListener {
if (!stream_ids.remove(stream_id)) exit(new Exception("Invalid stream ID in Streams.disposed event"));
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestSysMonitor.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestSysMonitor.java
index c15545d5a..74059492c 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestSysMonitor.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestSysMonitor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2010, 2011 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,7 +16,6 @@ import java.util.HashSet;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IErrorReport;
import org.eclipse.tm.tcf.protocol.IToken;
-import org.eclipse.tm.tcf.services.IRunControl;
import org.eclipse.tm.tcf.services.ISysMonitor;
import org.eclipse.tm.tcf.services.ISysMonitor.SysMonitorContext;
@@ -114,7 +113,7 @@ class TestSysMonitor implements ITCFTest {
test_suite.done(this, x);
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
}
diff --git a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestTerminals.java b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestTerminals.java
index 9ce85e5ef..3fedb173a 100644
--- a/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestTerminals.java
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestTerminals.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Wind River Systems, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
package org.eclipse.tm.internal.tcf.debug.tests;
import java.util.Collection;
@@ -10,7 +20,6 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.protocol.Protocol;
import org.eclipse.tm.tcf.services.IProcesses;
-import org.eclipse.tm.tcf.services.IRunControl;
import org.eclipse.tm.tcf.services.IStreams;
import org.eclipse.tm.tcf.services.ITerminals;
import org.eclipse.tm.tcf.services.ITerminals.TerminalContext;
@@ -324,7 +333,7 @@ class TestTerminals implements ITCFTest {
streams.read(id, 0x1000, stderr_read);
}
if (!delay_done) {
- Protocol.invokeLater(rnd.nextInt(500), new Runnable() {
+ Protocol.invokeLater(rnd.nextInt(250), new Runnable() {
public void run() {
delay_done = true;
TestTerminals.this.run();
@@ -424,7 +433,7 @@ class TestTerminals implements ITCFTest {
test_suite.done(this, x);
}
- public boolean canResume(IRunControl.RunControlContext ctx) {
+ public boolean canResume(String id) {
return true;
}
}

Back to the top