Merge "Add delay in ping connectivity test retry" into lmp-dev
This commit is contained in:
@@ -49,7 +49,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class ConnectivityManagerTestBase extends InstrumentationTestCase {
|
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 WAIT_FOR_SCAN_RESULT = 10 * 1000; //10 seconds
|
||||||
protected static final int WIFI_SCAN_TIMEOUT = 50 * 1000; // 50 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.
|
* @return true if the ping test is successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
protected boolean pingTest(String[] pingServerList) {
|
protected boolean pingTest() {
|
||||||
String[] hostList = {"www.google.com", "www.yahoo.com",
|
|
||||||
"www.bing.com", "www.facebook.com", "www.ask.com"};
|
|
||||||
if (pingServerList != null) {
|
|
||||||
hostList = pingServerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
while ((System.currentTimeMillis() - startTime) < PING_TIMER) {
|
while ((System.currentTimeMillis() - startTime) < PING_TIMER) {
|
||||||
try {
|
try {
|
||||||
// assume the chance that all servers are down is very small
|
// assume the chance that all servers are down is very small
|
||||||
for (int i = 0; i < hostList.length; i++ ) {
|
for (String host : PING_HOST_LIST) {
|
||||||
String host = hostList[i];
|
|
||||||
logv("Start ping test, ping " + host);
|
logv("Start ping test, ping " + host);
|
||||||
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
|
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
|
||||||
int status = p.waitFor();
|
int status = p.waitFor();
|
||||||
@@ -312,6 +305,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logv("Ping test Fail: InterruptedException");
|
logv("Ping test Fail: InterruptedException");
|
||||||
}
|
}
|
||||||
|
SystemClock.sleep(SHORT_TIMEOUT);
|
||||||
}
|
}
|
||||||
// ping test timeout
|
// ping test timeout
|
||||||
return false;
|
return false;
|
||||||
@@ -458,14 +452,7 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase {
|
|||||||
// use ping request against Google public DNS to verify connectivity
|
// use ping request against Google public DNS to verify connectivity
|
||||||
protected boolean checkNetworkConnectivity() {
|
protected boolean checkNetworkConnectivity() {
|
||||||
assertTrue("no active network connection", waitForActiveNetworkConnection(LONG_TIMEOUT));
|
assertTrue("no active network connection", waitForActiveNetworkConnection(LONG_TIMEOUT));
|
||||||
try {
|
return pingTest();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -72,16 +72,6 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase
|
|||||||
super.tearDown();
|
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
|
// Test case 1: Test enabling Wifi without associating with any AP, no broadcast on network
|
||||||
// event should be expected.
|
// event should be expected.
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -336,4 +326,12 @@ public class ConnectivityManagerMobileTest extends ConnectivityManagerTestBase
|
|||||||
assertTrue("wifi state not disabled", waitForWifiState(
|
assertTrue("wifi state not disabled", waitForWifiState(
|
||||||
WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class WifiApStress extends ConnectivityManagerTestBase {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// 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
|
// disable wifi hotspot
|
||||||
assertTrue("failed to disable wifi hotspot",
|
assertTrue("failed to disable wifi hotspot",
|
||||||
mWifiManager.setWifiApEnabled(config, false));
|
mWifiManager.setWifiApEnabled(config, false));
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
|
|||||||
assertTrue("wifi not connected", waitForNetworkState(ConnectivityManager.TYPE_WIFI,
|
assertTrue("wifi not connected", waitForNetworkState(ConnectivityManager.TYPE_WIFI,
|
||||||
State.CONNECTED, WIFI_CONNECTION_TIMEOUT));
|
State.CONNECTED, WIFI_CONNECTION_TIMEOUT));
|
||||||
// Run ping test to verify the data connection
|
// 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;
|
long i, sum = 0, avgReconnectTime = 0;
|
||||||
for (i = 1; i <= mReconnectIterations; i++) {
|
for (i = 1; i <= mReconnectIterations; i++) {
|
||||||
@@ -264,7 +264,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
|
|||||||
} else {
|
} else {
|
||||||
assertEquals("mobile not connected", State.CONNECTED,
|
assertEquals("mobile not connected", State.CONNECTED,
|
||||||
mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
|
mCm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
|
||||||
assertTrue("no connectivity over mobile", pingTest(null));
|
assertTrue("no connectivity over mobile", pingTest());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn screen on again
|
// Turn screen on again
|
||||||
@@ -281,7 +281,7 @@ public class WifiStressTest extends ConnectivityManagerTestBase {
|
|||||||
avgReconnectTime = sum / i;
|
avgReconnectTime = sum / i;
|
||||||
logv("average reconnection time is: " + avgReconnectTime);
|
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();
|
Bundle result = new Bundle();
|
||||||
result.putLong("actual-iterations", i - 1);
|
result.putLong("actual-iterations", i - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user