Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2010-06-09 19:32:17 -0400
committereutarass2010-06-09 19:32:17 -0400
commit8a89625caa58b1cc08fdc944b5ab5a98bdbc099d (patch)
treea68215b1b2487a34a88f6ffd053dc1343a4983bc
parent6a570cb72955d1f9a6fa869d5856aa9cddae9500 (diff)
downloadorg.eclipse.tcf-8a89625caa58b1cc08fdc944b5ab5a98bdbc099d.tar.gz
org.eclipse.tcf-8a89625caa58b1cc08fdc944b5ab5a98bdbc099d.tar.xz
org.eclipse.tcf-8a89625caa58b1cc08fdc944b5ab5a98bdbc099d.zip
TCF Agent: added handling of error report parameters in errno_to_str()
TCF Debugger: diagnostics: added tests for transmitting and receiving TCF error reports
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java24
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java28
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java6
-rw-r--r--plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java23
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TCFTestSuite.java8
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestAttachTerminate.java2
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java103
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoFP.java2
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestExpressions.java2
-rw-r--r--plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestRCBP1.java3
10 files changed, 194 insertions, 7 deletions
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java
index 9f6dc3d46..8fd6869c9 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/local/DiagnosticsService.java
@@ -11,9 +11,12 @@
package org.eclipse.tm.internal.tcf.services.local;
import java.math.BigDecimal;
+import java.util.Map;
import org.eclipse.tm.internal.tcf.core.Token;
+import org.eclipse.tm.tcf.core.Command;
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.JSON;
import org.eclipse.tm.tcf.protocol.Protocol;
@@ -46,6 +49,12 @@ public class DiagnosticsService implements IDiagnostics {
Number n = (Number)args[0];
channel.sendResult(token, JSON.toJSONSequence(new Object[]{ n }));
}
+ else if (name.equals("echoERR")) {
+ if (args.length != 1) throw new Exception("Invalid number of arguments");
+ @SuppressWarnings("unchecked")
+ Map<String,Object> err = (Map<String,Object>)args[0];
+ channel.sendResult(token, JSON.toJSONSequence(new Object[]{ err, Command.toErrorString(err) }));
+ }
else if (name.equals("getTestList")) {
if (args.length != 0) throw new Exception("Invalid number of arguments");
channel.sendResult(token, JSON.toJSONSequence(new Object[]{ null, new String[0] }));
@@ -85,6 +94,21 @@ public class DiagnosticsService implements IDiagnostics {
return token;
}
+ public IToken echoERR(final Throwable err, final DoneEchoERR done) {
+ final IToken token = new Token();
+ Protocol.invokeLater(new Runnable() {
+ public void run() {
+ if (err instanceof IErrorReport) {
+ done.doneEchoERR(token, null, err, Command.toErrorString(((IErrorReport)err).getAttributes()));
+ }
+ else {
+ done.doneEchoERR(token, null, err, err.getMessage());
+ }
+ }
+ });
+ return token;
+ }
+
public IToken getTestList(final DoneGetTestList done) {
final IToken token = new Token();
Protocol.invokeLater(new Runnable() {
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java
index b2a0104fc..a5dbdaca2 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/internal/tcf/services/remote/DiagnosticsProxy.java
@@ -12,10 +12,12 @@ package org.eclipse.tm.internal.tcf.services.remote;
import java.math.BigDecimal;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Map;
import org.eclipse.tm.tcf.core.Command;
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;
@@ -108,6 +110,32 @@ public class DiagnosticsProxy implements IDiagnostics {
}.token;
}
+ public IToken echoERR(Throwable err, final DoneEchoERR done) {
+ Map<String,Object> map = null;
+ if (err instanceof IErrorReport) {
+ map = ((IErrorReport)err).getAttributes();
+ }
+ else {
+ map = new HashMap<String,Object>();
+ map.put(IErrorReport.ERROR_TIME, new Long(System.currentTimeMillis()));
+ map.put(IErrorReport.ERROR_CODE, new Integer(IErrorReport.TCF_ERROR_OTHER));
+ map.put(IErrorReport.ERROR_FORMAT, err.getMessage());
+ }
+ return new Command(channel, this, "echoERR", new Object[]{ map }) {
+ @Override
+ public void done(Exception error, Object[] args) {
+ Throwable err = null;
+ String str = null;
+ if (error == null) {
+ assert args.length == 2;
+ err = toError(args[0]);
+ str = (String)args[1];
+ }
+ done.doneEchoERR(token, error, err, str);
+ }
+ }.token;
+ }
+
public IToken getTestList(final DoneGetTestList done) {
return new Command(channel, this, "getTestList", null) {
@Override
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java
index 5fcf099fe..d2054ad0e 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/core/ErrorReport.java
@@ -15,13 +15,13 @@ import java.util.Map;
import org.eclipse.tm.tcf.protocol.IErrorReport;
-class ErrorReport extends Exception implements IErrorReport {
+public class ErrorReport extends Exception implements IErrorReport {
private static final long serialVersionUID = 3687543884858739977L;
private final Map<String,Object> attrs;
@SuppressWarnings("unchecked")
- ErrorReport(String msg, Map<String,Object> attrs) {
+ public ErrorReport(String msg, Map<String,Object> attrs) {
super(msg);
this.attrs = attrs;
Object caused_by = attrs.get(IErrorReport.ERROR_CAUSED_BY);
@@ -35,7 +35,7 @@ class ErrorReport extends Exception implements IErrorReport {
}
}
- ErrorReport(String msg, int code) {
+ public ErrorReport(String msg, int code) {
super(msg);
attrs = new HashMap<String,Object>();
attrs.put(ERROR_CODE, code);
diff --git a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java
index 98c5addb7..6ffa51237 100644
--- a/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java
+++ b/plugins/org.eclipse.tm.tcf.core/src/org/eclipse/tm/tcf/services/IDiagnostics.java
@@ -72,6 +72,29 @@ public interface IDiagnostics extends IService {
}
/**
+ * 'echoERR' command result returns same error report that was given as command argument.
+ * The command is used to test remote agent ability to receive and transmit TCF error reports.
+ * @param error - an error object.
+ * @param done - command result call back object.
+ * @return - pending command handle.
+ */
+ IToken echoERR(Throwable error, DoneEchoERR done);
+
+ /**
+ * Call back interface for 'echoERR' command.
+ */
+ interface DoneEchoERR {
+ /**
+ * Called when 'echoERR' command is done.
+ * @param token - command handle.
+ * @param error - communication error report or null.
+ * @param error_obj - error object, should be equal to the command argument.
+ * @param error_msg - error object converted to a human readable string.
+ */
+ void doneEchoERR(IToken token, Throwable error, Throwable error_obj, String error_msg);
+ }
+
+ /**
* Get list of test names that are implemented by the service.
* Clients can request remote peer to run a test from the list.
* When started, a test performs a predefined set actions.
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 e94efec53..e15b1dd3f 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
@@ -71,6 +71,14 @@ public class TCFTestSuite {
});
pending_tests.add(new Runnable() {
public void run() {
+ listener.progress("Running Echo ERR Test...", ++count_done, count_total);
+ for (IChannel channel : channels) {
+ active_tests.put(new TestEchoERR(TCFTestSuite.this, channel), channel);
+ }
+ }
+ });
+ pending_tests.add(new Runnable() {
+ 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);
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 3782cc692..2d0550b49 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
@@ -48,7 +48,7 @@ class TestAttachTerminate implements ITCFTest, IRunControl.RunControlListener {
rc.addListener(this);
diag.getTestList(new IDiagnostics.DoneGetTestList() {
public void doneGetTestList(IToken token, Throwable error, String[] list) {
- assert test_suite.isActive(TestAttachTerminate.this);
+ if (!test_suite.isActive(TestAttachTerminate.this)) return;
if (error != null) {
exit(error);
}
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
new file mode 100644
index 000000000..6f9ef7edc
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.debug/src/org/eclipse/tm/internal/tcf/debug/tests/TestEchoERR.java
@@ -0,0 +1,103 @@
+package org.eclipse.tm.internal.tcf.debug.tests;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.eclipse.tm.tcf.core.Command;
+import org.eclipse.tm.tcf.core.ErrorReport;
+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;
+
+class TestEchoERR implements ITCFTest, IDiagnostics.DoneEchoERR {
+
+ private final TCFTestSuite test_suite;
+ private final IDiagnostics diag;
+
+ private final Number[] numbers = {
+ 1,
+ 4,
+ new BigDecimal("0.5")
+ };
+
+ private final String[] strings = {
+ "",
+ "abc",
+ "a\u1134c",
+ "a\u0003c",
+ };
+
+ private final String[] formats = {
+ "",
+ "{0}",
+ "{0,number}",
+ "{0,number,integer}",
+ "{0,number,percent}",
+ "{1}",
+ "{0} abcde {1}",
+ "{1} '' {0}",
+ "{1} 'abcde{}' {1}",
+ };
+
+ private final LinkedList<ErrorReport> list = new LinkedList<ErrorReport>();
+
+ TestEchoERR(TCFTestSuite test_suite, IChannel channel) {
+ this.test_suite = test_suite;
+ diag = channel.getRemoteService(IDiagnostics.class);
+ }
+
+ public void start() {
+ for (Number n : numbers) {
+ for (String s : strings) {
+ for (String f : formats) {
+ ArrayList<Object> params = new ArrayList<Object>();
+ params.add(n);
+ params.add(s);
+ Map<String,Object> map = new HashMap<String,Object>();
+ map.put(IErrorReport.ERROR_TIME, new Long(System.currentTimeMillis()));
+ map.put(IErrorReport.ERROR_CODE, new Integer(IErrorReport.TCF_ERROR_OTHER));
+ map.put(IErrorReport.ERROR_FORMAT, f);
+ map.put(IErrorReport.ERROR_PARAMS, params);
+ map.put(s, s); // non-standard attribute
+ ErrorReport e = new ErrorReport("TCF error", map);
+ list.add(e);
+ diag.echoERR(e, this);
+ }
+ }
+ }
+ }
+
+ public void doneEchoERR(IToken token, Throwable error, Throwable error_obj, String error_msg) {
+ ErrorReport e = list.removeFirst();
+ if (!test_suite.isActive(this)) return;
+ Map<String,Object> map0 = e.getAttributes();
+ Map<String,Object> map1 = null;
+
+ if (error_obj instanceof IErrorReport) {
+ map1 = ((IErrorReport)error_obj).getAttributes();
+ }
+
+ String msg = Command.toErrorString(map0);
+
+ if (error instanceof IErrorReport && ((IErrorReport)error).getErrorCode() == IErrorReport.TCF_ERROR_INV_COMMAND) {
+ // Older agent: the command is not available. Just exit the test.
+ test_suite.done(this, null);
+ }
+ else if (error != null) {
+ test_suite.done(this, error);
+ }
+ else if (!map0.equals(map1)) {
+ test_suite.done(this, new Exception("Invalid error report attributes"));
+ }
+ else if (!msg.equals(error_msg)) {
+ test_suite.done(this, new Exception("Invalid error report text"));
+ }
+ else if (list.size() == 0) {
+ test_suite.done(this, null);
+ }
+ }
+}
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 da5b337fa..c77f8787f 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
@@ -18,7 +18,7 @@ import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IToken;
import org.eclipse.tm.tcf.services.IDiagnostics;
-public class TestEchoFP implements ITCFTest, IDiagnostics.DoneEchoFP {
+class TestEchoFP implements ITCFTest, IDiagnostics.DoneEchoFP {
private final TCFTestSuite test_suite;
private final IDiagnostics diag;
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 43aa1999a..e638b7106 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
@@ -115,7 +115,7 @@ class TestExpressions implements ITCFTest,
bp.addListener(this);
diag.getTestList(new IDiagnostics.DoneGetTestList() {
public void doneGetTestList(IToken token, Throwable error, String[] list) {
- assert test_suite.isActive(TestExpressions.this);
+ if (!test_suite.isActive(TestExpressions.this)) return;
if (error != null) {
exit(error);
}
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 ea6d0f89b..44a693a6b 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
@@ -75,6 +75,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
final String id;
final String pc;
final String reason;
+ @SuppressWarnings("unused")
final Map<String,Object> params;
SuspendedContext(String id, String pc, String reason, Map<String,Object> params) {
@@ -220,7 +221,7 @@ class TestRCBP1 implements ITCFTest, IRunControl.RunControlListener {
private void getTestList() {
diag.getTestList(new IDiagnostics.DoneGetTestList() {
public void doneGetTestList(IToken token, Throwable error, String[] list) {
- assert test_suite.isActive(TestRCBP1.this);
+ if (!test_suite.isActive(TestRCBP1.this)) return;
if (error != null) {
exit(error);
}

Back to the top