OSDN Git Service

Add support for specifying adb timeout in ddms testrunner.
authorBrett Chabot <brettchabot@android.com>
Thu, 15 Jul 2010 00:06:05 +0000 (17:06 -0700)
committerBrett Chabot <brettchabot@android.com>
Thu, 15 Jul 2010 00:10:11 +0000 (17:10 -0700)
Also handle TimeoutException in ADT test runner.

Change-Id: I585c2818f1c77ec80222bad282ae10b3ee8f5e1c

ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/IRemoteAndroidTestRunner.java
ddms/libs/ddmlib/src/com/android/ddmlib/testrunner/RemoteAndroidTestRunner.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/LaunchMessages.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/junit/runtime/RemoteAdtTestRunner.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/launch/messages.properties

index 22cafa6..a478216 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.ddmlib.testrunner;
 
+import com.android.ddmlib.IDevice;
 import com.android.ddmlib.TimeoutException;
 
 import java.io.IOException;
@@ -170,6 +171,15 @@ public interface IRemoteAndroidTestRunner {
     public void setCoverage(boolean coverage);
 
     /**
+     * Sets the timeout to use for the adb shell command issued.
+     * <p/>
+     * By default no timeout will be specified.
+     *
+     * @see {@link IDevice#executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, int)}
+     */
+    public void setTimeout(int timeout);
+
+    /**
      * Execute this test run.
      * <p/>
      * Convenience method for {@link #run(Collection)}.
index 7edbe74..9fd3fbf 100644 (file)
@@ -36,6 +36,9 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner  {
     private final String mPackageName;
     private final  String mRunnerName;
     private IDevice mRemoteDevice;
+    // default to no timeout
+    private int mAdbTimeout = 0;
+
     /** map of name-value instrumentation argument pairs */
     private Map<String, String> mArgMap;
     private InstrumentationResultParser mParser;
@@ -202,6 +205,13 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner  {
     /**
      * {@inheritDoc}
      */
+    public void setTimeout(int timeout) {
+        mAdbTimeout = timeout;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void run(ITestRunListener... listeners)  throws IOException, TimeoutException {
         run(Arrays.asList(listeners));
     }
@@ -216,7 +226,7 @@ public class RemoteAndroidTestRunner implements IRemoteAndroidTestRunner  {
                 mRemoteDevice.getSerialNumber()));
         mParser = new InstrumentationResultParser(listeners);
 
-        mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser);
+        mRemoteDevice.executeShellCommand(runCaseCommandStr, mParser, mAdbTimeout);
     }
 
     /**
index d09ddff..b2772f7 100644 (file)
@@ -44,6 +44,7 @@ public class LaunchMessages extends NLS {
     public static String RemoteAdtTestRunner_RunFailedMsg_s;
 
     public static String RemoteAdtTestRunner_RunIOException_s;
+    public static String RemoteAdtTestRunner_RunTimeoutException;
     public static String RemoteAdtTestRunner_RunStoppedMsg;
 
     static {
index 461fd9d..3f40230 100755 (executable)
@@ -16,6 +16,7 @@
 
 package com.android.ide.eclipse.adt.internal.launch.junit.runtime;
 
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.testrunner.ITestRunListener;
 import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
 import com.android.ddmlib.testrunner.TestIdentifier;
@@ -125,6 +126,8 @@ public class RemoteAdtTestRunner extends RemoteTestRunner {
             }
             AdtPlugin.printToConsole(mLaunchInfo.getProject(), "Running tests...");
             runner.run(new TestRunListener());
+        } catch (TimeoutException e) {
+            reportError(LaunchMessages.RemoteAdtTestRunner_RunTimeoutException);
         } catch (IOException e) {
             reportError(String.format(LaunchMessages.RemoteAdtTestRunner_RunIOException_s,
                     e.getMessage()));
index 67c9116..1ac7fb2 100644 (file)
@@ -35,5 +35,6 @@ 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_RunTimeoutException=Connection with device timed out.
+RemoteAdtTestRunner_RunIOException_s=Lost connection with device: %s
 RemoteAdtTestRunner_RunStoppedMsg=Test run stopped