diff options
author | Xia Wang <xiaw@google.com> | 2011-02-17 15:32:37 -0800 |
---|---|---|
committer | Xia Wang <xiaw@google.com> | 2011-02-17 15:32:37 -0800 |
commit | 6bffe14c78efa0b56327262543ce2e0dfc024219 (patch) | |
tree | e4a416f7c1652a9319bdb9b4ee72e9fd33167a29 /core/tests/ConnectivityManagerTest | |
parent | 3ca6d6bbfe614312ad936bce9ab5805615103267 (diff) | |
download | frameworks_base-6bffe14c78efa0b56327262543ce2e0dfc024219.zip frameworks_base-6bffe14c78efa0b56327262543ce2e0dfc024219.tar.gz frameworks_base-6bffe14c78efa0b56327262543ce2e0dfc024219.tar.bz2 |
Add ping test to verify data connection.
Change-Id: I88e06934747e9e98bd440ae84268e69486c74734
Diffstat (limited to 'core/tests/ConnectivityManagerTest')
3 files changed, 58 insertions, 0 deletions
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java index fb8b5ce..7756135 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java @@ -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 diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java index 4457de9..1374e7f 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java @@ -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 { diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java index ae009ca..2f2a283 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java @@ -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", |