OSDN Git Service

Add ping test to verify data connection.
authorXia Wang <xiaw@google.com>
Thu, 17 Feb 2011 23:32:37 +0000 (15:32 -0800)
committerXia Wang <xiaw@google.com>
Thu, 17 Feb 2011 23:32:37 +0000 (15:32 -0800)
Change-Id: I88e06934747e9e98bd440ae84268e69486c74734

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java
core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java

index fb8b5ce..7756135 100644 (file)
@@ -30,7 +30,9 @@ import android.provider.Settings;
 import android.util.Log;
 import android.view.KeyEvent;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
 import android.widget.LinearLayout;
@@ -485,6 +487,44 @@ public class ConnectivityManagerTestActivity extends Activity {
     }
 
     /**
+     * @param pingServerList a list of servers that can be used for ping test, can be null
+     * @return true if the ping test is successful, false otherwise.
+     */
+    public boolean pingTest(String[] pingServerList) {
+        boolean result = false;
+        String[] hostList = {"www.google.com", "www.yahoo.com",
+                "www.bing.com", "www.facebook.com", "www.ask.com"};
+        if (pingServerList != null) {
+            hostList = pingServerList;
+        }
+        try {
+            // assume the chance that all servers are down is very small
+            for (int i = 0; i < hostList.length; i++ ) {
+                String host = hostList[i];
+                log("Start ping test, ping " + host);
+                Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
+                int status = p.waitFor();
+                if (status == 0) {
+                    // if any of the ping test is successful, return true
+                    result = true;
+                    break;
+                } else {
+                    result = false;
+                    log("ping " + host + " failed.");
+                }
+            }
+        } catch (UnknownHostException e) {
+            log("Ping test Fail: Unknown Host");
+        } catch (IOException e) {
+            log("Ping test Fail:  IOException");
+        } catch (InterruptedException e) {
+            log("Ping test Fail: InterruptedException");
+        }
+        log("return");
+        return result;
+    }
+
+    /**
      * Associate the device to given SSID
      * If the device is already associated with a WiFi, disconnect and forget it,
      * We don't verify whether the connection is successful or not, leave this to the test
index 4457de9..1374e7f 100644 (file)
@@ -107,6 +107,17 @@ public class WifiApStress
             } catch (Exception e) {
                 fail("thread in sleep is interrupted");
             }
+            assertTrue("no uplink data connection after Wi-Fi tethering", mAct.pingTest(null));
+            // Wait for 5 minutes, and verify the data connection again.
+            // bug id: 3400027
+            try {
+                Thread.sleep(5 * 60 * 1000);
+            } catch (Exception e) {
+                fail("thread in sleep is interrupted");
+            }
+            // Verify the uplink data connection
+            assertTrue("no uplink data connection", mAct.pingTest(null));
+            // Disable soft AP
             assertTrue(mAct.mWifiManager.setWifiApEnabled(config, false));
             // Wait for 30 seconds until Wi-Fi tethering is stopped
             try {
index ae009ca..2f2a283 100644 (file)
@@ -243,6 +243,9 @@ public class WifiStressTest
                 ConnectivityManagerTestActivity.SHORT_TIMEOUT));
         assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
                 ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        // Run ping test to verify the data connection
+        assertTrue("Wi-Fi is connected, but no data connection.", mAct.pingTest(null));
+
         int i;
         for (i = 0; i < mReconnectIterations; i++) {
             // 1. Put device into sleep mode
@@ -271,6 +274,9 @@ public class WifiStressTest
                     mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState());
             assertEquals("Cellular connection is down", State.CONNECTED,
                     mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
+
+            assertTrue("Mobile is connected, but no data connection.", mAct.pingTest(null));
+
             // Turn screen on again
             mAct.turnScreenOn();
             assertTrue("Wait for Wi-Fi enable timeout after wake up",
@@ -279,6 +285,7 @@ public class WifiStressTest
             assertTrue("Wait for Wi-Fi connection timeout after wake up",
                     mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
                     ConnectivityManagerTestActivity.LONG_TIMEOUT));
+            assertTrue("Reconnect to Wi-Fi network, but no data connection.", mAct.pingTest(null));
         }
         if (i == mReconnectIterations) {
             writeOutput(String.format("iteration %d out of %d",