diff options
author | Eugene Tarassov | 2016-03-11 20:34:17 +0000 |
---|---|---|
committer | Eugene Tarassov | 2016-03-11 20:35:46 +0000 |
commit | 82e5a0e04629bb413608ef6757b53b94f3cb2bbf (patch) | |
tree | 6b60602d9e601ff60e9f429f3063863fdc2cb88d /plugins | |
parent | d1a7ae6b18ef7f1b56c5f00175da27d1d5787e56 (diff) | |
download | org.eclipse.tcf-82e5a0e04629bb413608ef6757b53b94f3cb2bbf.tar.gz org.eclipse.tcf-82e5a0e04629bb413608ef6757b53b94f3cb2bbf.tar.xz org.eclipse.tcf-82e5a0e04629bb413608ef6757b53b94f3cb2bbf.zip |
TCF Tests: added tests for sending integer numbers over TCF channel
Diffstat (limited to 'plugins')
7 files changed, 215 insertions, 23 deletions
diff --git a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/local/DiagnosticsService.java b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/local/DiagnosticsService.java index 6842bd4e3..4be5077e1 100644 --- a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/local/DiagnosticsService.java +++ b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/local/DiagnosticsService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2016 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 @@ -11,6 +11,7 @@ package org.eclipse.tcf.internal.services.local; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Map; import org.eclipse.tcf.internal.core.Token; @@ -49,6 +50,11 @@ public class DiagnosticsService implements IDiagnostics { Number n = (Number)args[0]; channel.sendResult(token, JSON.toJSONSequence(new Object[]{ n })); } + else if (name.equals("echoINT")) { + if (args.length != 2) throw new Exception("Invalid number of arguments"); + Number n = (Number)args[1]; + 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") @@ -94,6 +100,16 @@ public class DiagnosticsService implements IDiagnostics { return token; } + public IToken echoINT(int t, final BigInteger n, final DoneEchoINT done) { + final IToken token = new Token(); + Protocol.invokeLater(new Runnable() { + public void run() { + done.doneEchoINT(token, null, n); + } + }); + return token; + } + public IToken echoERR(final Throwable err, final DoneEchoERR done) { final IToken token = new Token(); Protocol.invokeLater(new Runnable() { diff --git a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/remote/DiagnosticsProxy.java b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/remote/DiagnosticsProxy.java index c2b503cc8..b231cb02b 100644 --- a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/remote/DiagnosticsProxy.java +++ b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/internal/services/remote/DiagnosticsProxy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2016 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 @@ -11,6 +11,7 @@ package org.eclipse.tcf.internal.services.remote; import java.math.BigDecimal; +import java.math.BigInteger; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -110,6 +111,26 @@ public class DiagnosticsProxy implements IDiagnostics { }.token; } + public IToken echoINT(int t, BigInteger n, final DoneEchoINT done) { + return new Command(channel, this, "echoINT", new Object[]{ t, n }) { + @Override + public void done(Exception error, Object[] args) { + BigInteger n = null; + if (error == null) { + assert args.length == 1; + Number x = (Number)args[0]; + if (x instanceof BigInteger) { + n = (BigInteger)x; + } + else { + n = new BigInteger(x.toString()); + } + } + done.doneEchoINT(token, error, n); + } + }.token; + } + public IToken echoERR(Throwable err, final DoneEchoERR done) { Map<String,Object> map = null; if (err instanceof IErrorReport) { diff --git a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/services/IDiagnostics.java b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/services/IDiagnostics.java index 6c95531b9..f0352694f 100644 --- a/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/services/IDiagnostics.java +++ b/plugins/org.eclipse.tcf.core/src/org/eclipse/tcf/services/IDiagnostics.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2016 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 @@ -11,6 +11,7 @@ package org.eclipse.tcf.services; import java.math.BigDecimal; +import java.math.BigInteger; import org.eclipse.tcf.protocol.IService; import org.eclipse.tcf.protocol.IToken; @@ -74,6 +75,36 @@ public interface IDiagnostics extends IService { } /** + * 'echoINT' command result returns same integer number that was given as command argument. + * The command is used to test communication channel ability to transmit arbitrary integer numbers in + * both directions. + * @param t - number type: + * 0 - signed, up to 32 bits + * 1 - unsigned, up to 32 bits + * 2 - signed, up to 64 bits + * 3 - unsigned, up to 64 bits + * @param n - the number. + * @param done - command result call back object. + * @return - pending command handle. + * @since 1.4 + */ + IToken echoINT(int t, BigInteger n, DoneEchoINT done); + + /** + * Call back interface for 'echoINT' command. + * @since 1.4 + */ + interface DoneEchoINT { + /** + * Called when 'echoINT' command is done. + * @param token - command handle. + * @param error - error object or null. + * @param n - same number as the command argument. + */ + void doneEchoINT(IToken token, Throwable error, BigInteger n); + } + + /** * '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. diff --git a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TCFTestSuite.java b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TCFTestSuite.java index b5db69bc4..eebcf9ccf 100644 --- a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TCFTestSuite.java +++ b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TCFTestSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2016 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 @@ -76,6 +76,14 @@ public class TCFTestSuite { }); pending_tests.add(new Runnable() { public void run() { + listener.progress("Running Echo INT Test...", count_done++, count_total); + for (IChannel channel : channels) { + active_tests.put(new TestEchoINT(TCFTestSuite.this, channel), channel); + } + } + }); + 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); diff --git a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoERR.java b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoERR.java index 8662ab4dc..43f06e019 100644 --- a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoERR.java +++ b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoERR.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2016 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 @@ -28,28 +28,28 @@ class TestEchoERR implements ITCFTest, IDiagnostics.DoneEchoERR { private final IDiagnostics diag; private final Number[] numbers = { - 1, - 4, - // new BigDecimal("0.5") - fails, representation depends on locale + 1, + 4, + // new BigDecimal("0.5") - fails, representation depends on locale }; private final String[] strings = { - "", - "abc", - "a\u1134c", - "a\u0003c", + "", + "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}", + "", + "{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>(); diff --git a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoFP.java b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoFP.java index 40847a718..d4d31dfa5 100644 --- a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoFP.java +++ b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoFP.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Wind River Systems, Inc. and others. + * Copyright (c) 2010, 2016 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 @@ -25,7 +25,7 @@ class TestEchoFP implements ITCFTest, IDiagnostics.DoneEchoFP { private final LinkedList<BigDecimal> msgs = new LinkedList<BigDecimal>(); private final Random rnd = new Random(); - private static final int MAX_COUNT = 0x800; + private static final int MAX_COUNT = 0x1000; private static final int MAX_TIME_MS = 4000; private int count = 0; diff --git a/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoINT.java b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoINT.java new file mode 100644 index 000000000..03777b6e3 --- /dev/null +++ b/plugins/org.eclipse.tcf.debug/src/org/eclipse/tcf/internal/debug/tests/TestEchoINT.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2010, 2016 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: + * Xilinx - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.internal.debug.tests; + +import java.math.BigInteger; +import java.util.LinkedList; +import java.util.Random; + +import org.eclipse.tcf.protocol.IChannel; +import org.eclipse.tcf.protocol.IErrorReport; +import org.eclipse.tcf.protocol.IToken; +import org.eclipse.tcf.services.IDiagnostics; + +class TestEchoINT implements ITCFTest, IDiagnostics.DoneEchoINT { + + private final TCFTestSuite test_suite; + private final IDiagnostics diag; + private final LinkedList<BigInteger> msgs = new LinkedList<BigInteger>(); + private final Random rnd = new Random(); + + private static final int MAX_COUNT = 0x1000; + private static final int MAX_TIME_MS = 4000; + + private int count = 0; + private long start_time; + + TestEchoINT(TCFTestSuite test_suite, IChannel channel) { + this.test_suite = test_suite; + diag = channel.getRemoteService(IDiagnostics.class); + } + + public void start() { + if (diag == null) { + test_suite.done(this, null); + } + else { + start_time = System.currentTimeMillis(); + for (int i = 0; i < 100; i++) sendMessage(); + } + } + + private void sendMessage() { + int t = 0; + BigInteger n = null; + switch (count) { + case 0: n = new BigInteger("-2147483648"); break; + case 1: n = new BigInteger("2147483647"); break; + case 2: t = 2; n = new BigInteger("-9223372036854775808"); break; + case 3: t = 2; n = new BigInteger("9223372036854775807"); break; + } + if (n == null) { + byte[] buf = null; + t = rnd.nextInt() & 3; + switch (t) { + case 0: + n = BigInteger.valueOf(rnd.nextInt()); + break; + case 1: + buf = new byte[4]; + rnd.nextBytes(buf); + n = new BigInteger(1, buf); + break; + case 2: + buf = new byte[8]; + rnd.nextBytes(buf); + buf[0] = (byte)(buf[0] & 0x7f); + n = new BigInteger(rnd.nextBoolean() ? 1 : -1, buf); + break; + case 3: + buf = new byte[8]; + rnd.nextBytes(buf); + n = new BigInteger(1, buf); + break; + } + } + msgs.add(n); + diag.echoINT(t, n, this); + count++; + } + + public void doneEchoINT(IToken token, Throwable error, BigInteger b) { + BigInteger s = msgs.removeFirst(); + if (!test_suite.isActive(this)) return; + if (error instanceof IErrorReport && ((IErrorReport)error).getErrorCode() == IErrorReport.TCF_ERROR_INV_COMMAND) { + test_suite.done(this, null); + } + else if (error != null) { + test_suite.done(this, error); + } + else if (!s.equals(b)) { + test_suite.done(this, new Exception("EchoINT test failed: " + s + " != " + b)); + } + else if (count < MAX_COUNT) { + sendMessage(); + // Don't run the test longer then MAX_TIME_MS ms + if (count % 0x40 == 0 && System.currentTimeMillis() - start_time >= MAX_TIME_MS) { + count = MAX_COUNT; + } + } + else if (msgs.isEmpty()) { + test_suite.done(this, null); + } + } + + public boolean canResume(String id) { + return true; + } +} |