Merge "Add delay in ping connectivity test retry" into lmp-dev

This commit is contained in:
Eric Rowe
2014-10-23 01:41:17 +00:00
committed by Android (Google) Code Review
4 changed files with 18 additions and 33 deletions

View File

@@ -49,7 +49,8 @@ import java.util.List;
*/
public class ConnectivityManagerTestBase extends InstrumentationTestCase {
private static final String PING_IP_ADDR = "8.8.8.8";
private static final String[] PING_HOST_LIST = {
"www.google.com", "www.yahoo.com", "www.bing.com", "www.facebook.com", "www.ask.com"};
protected static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; //10 seconds
protected static final int WIFI_SCAN_TIMEOUT = 50 * 1000; // 50 seconds
@@ -281,22 +282,14 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
}
/**
* @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.
*/
protected boolean pingTest(String[] pingServerList) {
String[] hostList = {"www.google.com", "www.yahoo.com",
"www.bing.com", "www.facebook.com", "www.ask.com"};
if (pingServerList != null) {
hostList = pingServerList;
}
protected boolean pingTest() {
long startTime = System.currentTimeMillis();
while ((System.currentTimeMillis() - startTime) < PING_TIMER) {
try {
// assume the chance that all servers are down is very small
for (int i = 0; i < hostList.length; i++ ) {
String host = hostList[i];
for (String host : PING_HOST_LIST) {
logv("Start ping test, ping " + host);
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
int status = p.waitFor();
@@ -312,6 +305,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
} catch (InterruptedException e) {
logv("Ping test Fail: InterruptedException");
}
SystemClock.sleep(SHORT_TIMEOUT);
}
// ping test timeout
return false;
@@ -458,14 +452,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
// use ping request against Google public DNS to verify connectivity
protected boolean checkNetworkConnectivity() {
assertTrue("no active network connection", waitForActiveNetworkConnection(LONG_TIMEOUT));
try {
Process proc = Runtime.getRuntime().exec(new String[]{
"/system/bin/ping", "-W", "30", "-c", "1", PING_IP_ADDR});
return proc.waitFor() == 0;
} catch (InterruptedException | IOException e) {
Log.e(mLogTag, "Ping failed", e);
}
return false;
return pingTest();
}
@Override

View File

@@ -72,16 +72,6 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase
super.tearDown();
}
// help function to verify 3G connection
public void verifyCellularConnection() {
NetworkInfo extraNetInfo = mCm.getActiveNetworkInfo();
assertEquals("network type is not MOBILE", ConnectivityManager.TYPE_MOBILE,
extraNetInfo.getType());
assertTrue("not connected to cellular network", extraNetInfo.isConnected());
}
// Test case 1: Test enabling Wifi without associating with any AP, no broadcast on network
// event should be expected.
@LargeTest
@@ -336,4 +326,12 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase
assertTrue("wifi state not disabled", waitForWifiState(
WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
}
// help function to verify 3G connection
private void verifyCellularConnection() {
NetworkInfo extraNetInfo = mCm.getActiveNetworkInfo();
assertEquals("network type is not MOBILE", ConnectivityManager.TYPE_MOBILE,
extraNetInfo.getType());
assertTrue("not connected to cellular network", extraNetInfo.isConnected());
}
}

View File

@@ -112,7 +112,7 @@ public class WifiApStress extends ConnectivityManagerTestBase {
} catch (Exception e) {
// ignore
}
assertTrue("no uplink data connection after Wi-Fi tethering", pingTest(null));
assertTrue("no uplink data connection after Wi-Fi tethering", pingTest());
// disable wifi hotspot
assertTrue("failed to disable wifi hotspot",
mWifiManager.setWifiApEnabled(config, false));

View File

@@ -216,7 +216,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
assertTrue("wifi not connected", waitForNetworkState(ConnectivityManager.TYPE_WIFI,
State.CONNECTED, WIFI_CONNECTION_TIMEOUT));
// Run ping test to verify the data connection
assertTrue("Wi-Fi is connected, but no data connection.", pingTest(null));
assertTrue("Wi-Fi is connected, but no data connection.", pingTest());
long i, sum = 0, avgReconnectTime = 0;
for (i = 1; i <= mReconnectIterations; i++) {
@@ -264,7 +264,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
} else {
assertEquals("mobile not connected", State.CONNECTED,
mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
assertTrue("no connectivity over mobile", pingTest(null));
assertTrue("no connectivity over mobile", pingTest());
}
// Turn screen on again
@@ -281,7 +281,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
avgReconnectTime = sum / i;
logv("average reconnection time is: " + avgReconnectTime);
assertTrue("Reconnect to Wi-Fi network, but no data connection.", pingTest(null));
assertTrue("Reconnect to Wi-Fi network, but no data connection.", pingTest());
}
Bundle result = new Bundle();
result.putLong("actual-iterations", i - 1);