diff options
author | Brett Chabot <brettchabot@android.com> | 2010-03-26 17:54:31 -0700 |
---|---|---|
committer | Brett Chabot <brettchabot@android.com> | 2010-03-26 17:58:20 -0700 |
commit | af9eb5e271992ae22cd769a4d2eb316b37e18b62 (patch) | |
tree | 40bb0df2dc80835b945cc8cd5b9d42148ef383e6 | |
parent | 532bfee321d688084e0f25e5274429f73e397a66 (diff) | |
download | sdk-af9eb5e271992ae22cd769a4d2eb316b37e18b62.zip sdk-af9eb5e271992ae22cd769a4d2eb316b37e18b62.tar.gz sdk-af9eb5e271992ae22cd769a4d2eb316b37e18b62.tar.bz2 |
Change ddms testrunner to raise IOException to callers.
This is to fit with design decision to make ddms a relatively dumb pipe, and
have callers handle any reliability/retry scenarios.
Change-Id: I454e0f37a7d50ba194f59aeba6a4ab9d9ed3ded8
6 files changed, 40 insertions, 34 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/IRemoteAndroidTestRunner.java b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/IRemoteAndroidTestRunner.java index 75c8eeb..67b999d 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/IRemoteAndroidTestRunner.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/IRemoteAndroidTestRunner.java @@ -16,6 +16,7 @@ package com.android.ddmlib.testrunner; +import java.io.IOException; import java.util.Collection; /** @@ -112,15 +113,17 @@ public interface IRemoteAndroidTestRunner { * Convenience method for {@link #run(Collection)}. * * @param listeners listens for test results + * @throws IOException if connection to device was lost. */ - public void run(ITestRunListener... listeners); + public void run(ITestRunListener... listeners) throws IOException; /** * Execute this test run. * * @param listeners collection of listeners for test results + * @throws IOException if connection to device was lost. */ - public void run(Collection<ITestRunListener> listeners); + public void run(Collection<ITestRunListener> listeners) throws IOException; /** * Requests cancellation of this test run. diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java index f45d267..fec2af0 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java @@ -183,27 +183,20 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner { /** * {@inheritDoc} */ - public void run(ITestRunListener... listeners) { + public void run(ITestRunListener... listeners) throws IOException { run(Arrays.asList(listeners)); } /** * {@inheritDoc} */ - public void run(Collection<ITestRunListener> listeners) { + public void run(Collection<ITestRunListener> listeners) throws IOException { final String runCaseCommandStr = String.format("am instrument -w -r %s %s", getArgsCommand(), getRunnerPath()); Log.d(LOG_TAG, runCaseCommandStr); mParser = new InstrumentationResultParser(listeners); - try { - mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser); - } catch (IOException e) { - Log.e(LOG_TAG, e); - for (ITestRunListener listener : listeners) { - listener.testRunFailed(e.toString()); - } - } + mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser); } /** diff --git a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java index 02a6b7d..f9af29a 100644 --- a/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java +++ b/ddms/libs/ddmlib/tests/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunnerTest.java @@ -52,7 +52,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { /** * Test the basic case building of the instrumentation runner command with no arguments. */ - public void testRun() { + public void testRun() throws IOException { mRunner.run(new EmptyListener()); assertStringsEquals(String.format("am instrument -w -r %s/%s", TEST_PACKAGE, TEST_RUNNER), mMockDevice.getLastShellCommand()); @@ -61,7 +61,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { /** * Test the building of the instrumentation runner command with log set. */ - public void testRunWithLog() { + public void testRunWithLog() throws IOException { mRunner.setLogOnly(true); mRunner.run(new EmptyListener()); assertStringsEquals(String.format("am instrument -w -r -e log true %s/%s", TEST_PACKAGE, @@ -71,7 +71,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { /** * Test the building of the instrumentation runner command with method set. */ - public void testRunWithMethod() { + public void testRunWithMethod() throws IOException { final String className = "FooTest"; final String testName = "fooTest"; mRunner.setMethodName(className, testName); @@ -83,7 +83,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { /** * Test the building of the instrumentation runner command with test package set. */ - public void testRunWithPackage() { + public void testRunWithPackage() throws IOException { final String packageName = "foo.test"; mRunner.setTestPackageName(packageName); mRunner.run(new EmptyListener()); @@ -94,7 +94,7 @@ public class RemoteAndroidTestRunnerTest extends TestCase { /** * Test the building of the instrumentation runner command with extra argument added. */ - public void testRunWithAddInstrumentationArg() { + public void testRunWithAddInstrumentationArg() throws IOException { final String extraArgName = "blah"; final String extraArgValue = "blahValue"; mRunner.addInstrumentationArg(extraArgName, extraArgValue); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchMessages.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchMessages.java index c105215..d09ddff 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchMessages.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchMessages.java @@ -42,6 +42,8 @@ public class LaunchMessages extends NLS { public static String InstrValidator_WrongRunnerTypeMsg_s; public static String RemoteAdtTestRunner_RunCompleteMsg; public static String RemoteAdtTestRunner_RunFailedMsg_s; + + public static String RemoteAdtTestRunner_RunIOException_s; public static String RemoteAdtTestRunner_RunStoppedMsg; static { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/runtime/RemoteAdtTestRunner.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/runtime/RemoteAdtTestRunner.java index af87254..0a045bc 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/runtime/RemoteAdtTestRunner.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/runtime/RemoteAdtTestRunner.java @@ -27,6 +27,8 @@ import org.eclipse.jdt.internal.junit.runner.RemoteTestRunner; import org.eclipse.jdt.internal.junit.runner.TestExecution; import org.eclipse.jdt.internal.junit.runner.TestReferenceFailure; +import java.io.IOException; + /** * Supports Eclipse JUnit execution of Android tests. * <p/> @@ -98,24 +100,29 @@ public class RemoteAdtTestRunner extends RemoteTestRunner { // set log only to first collect test case info, so Eclipse has correct test case count/ // tree info runner.setLogOnly(true); - TestCollector collector = new TestCollector(); - runner.run(collector); - if (collector.getErrorMessage() != null) { - // error occurred during test collection. - reportError(collector.getErrorMessage()); - // abort here - notifyTestRunEnded(0); - return; - } - notifyTestRunStarted(collector.getTestCaseCount()); - collector.sendTrees(this); - - // now do real execution - runner.setLogOnly(false); - if (mLaunchInfo.isDebugMode()) { - runner.setDebug(true); + TestCollector collector = new TestCollector(); + try { + runner.run(collector); + if (collector.getErrorMessage() != null) { + // error occurred during test collection. + reportError(collector.getErrorMessage()); + // abort here + notifyTestRunEnded(0); + return; + } + notifyTestRunStarted(collector.getTestCaseCount()); + collector.sendTrees(this); + + // now do real execution + runner.setLogOnly(false); + if (mLaunchInfo.isDebugMode()) { + runner.setDebug(true); + } + runner.run(new TestRunListener()); + } catch (IOException e) { + reportError(String.format(LaunchMessages.RemoteAdtTestRunner_RunIOException_s, + e.getMessage())); } - runner.run(new TestRunListener()); } /** diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/messages.properties b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/messages.properties index 756aa61..67c9116 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/messages.properties +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/messages.properties @@ -35,4 +35,5 @@ InstrValidator_NoTestLibMsg_s=The application does not declare uses-library %1$s InstrValidator_WrongRunnerTypeMsg_s=The instrumentation runner must be of type %1$s RemoteAdtTestRunner_RunCompleteMsg=Test run complete RemoteAdtTestRunner_RunFailedMsg_s=Test run failed: %1$s +RemoteAdtTestRunner_RunIOException_s=Test run failed. Lost connection with device: %s RemoteAdtTestRunner_RunStoppedMsg=Test run stopped |