Fix WiFi test:
-- In environment where there are too many APs, sometimes, the AP will not show in the scan list.
Part of the reason is due to the change that the scanning on each frequency is shortened to save power.
to avoid that, change the test to connect without scanning.
-- Increase the timer to wait for WiFi to be connected
Change-Id: If1a72607b3c7ad13dbbf788607665986eaf5b6b3
This commit is contained in:
@@ -60,13 +60,14 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
|
||||
public static final String LOG_TAG = "ConnectivityManagerTestActivity";
|
||||
public static final int WAIT_FOR_SCAN_RESULT = 10 * 1000; //10 seconds
|
||||
public static final int WIFI_SCAN_TIMEOUT = 50 * 1000;
|
||||
public static final int SHORT_TIMEOUT = 5 * 1000;
|
||||
public static final long LONG_TIMEOUT = 50 * 1000;
|
||||
public static final int WIFI_SCAN_TIMEOUT = 50 * 1000; // 50 seconds
|
||||
public static final int SHORT_TIMEOUT = 5 * 1000; // 5 seconds
|
||||
public static final long LONG_TIMEOUT = 50 * 1000; // 50 seconds
|
||||
public static final long WIFI_CONNECTION_TIMEOUT = 5 * 60 * 1000; // 5 minutes
|
||||
// 2 minutes timer between wifi stop and start
|
||||
public static final long WIFI_STOP_START_INTERVAL = 2 * 60 * 1000;
|
||||
public static final long WIFI_STOP_START_INTERVAL = 2 * 60 * 1000; // 2 minutes
|
||||
// Set ping test timer to be 3 minutes
|
||||
public static final long PING_TIMER = 3 * 60 *1000;
|
||||
public static final long PING_TIMER = 3 * 60 *1000; // 3 minutes
|
||||
public static final int SUCCESS = 0; // for Wifi tethering state change
|
||||
public static final int FAILURE = 1;
|
||||
public static final int INIT = -1;
|
||||
@@ -573,7 +574,7 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
String ssid = config.SSID;
|
||||
config.SSID = convertToQuotedString(ssid);
|
||||
|
||||
//If Wifi is not enabled, enable it
|
||||
// If Wifi is not enabled, enable it
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
log("Wifi is not enabled, enable it");
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
@@ -584,59 +585,16 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
boolean foundApInScanResults = false;
|
||||
for (int retry = 0; retry < 5; retry++) {
|
||||
List<ScanResult> netList = mWifiManager.getScanResults();
|
||||
if (netList != null) {
|
||||
log("size of scan result list: " + netList.size());
|
||||
for (int i = 0; i < netList.size(); i++) {
|
||||
ScanResult sr= netList.get(i);
|
||||
if (sr.SSID.equals(ssid)) {
|
||||
log("found " + ssid + " in the scan result list");
|
||||
log("retry: " + retry);
|
||||
foundApInScanResults = true;
|
||||
mWifiManager.connect(config,
|
||||
new WifiManager.ActionListener() {
|
||||
public void onSuccess() {
|
||||
}
|
||||
public void onFailure(int reason) {
|
||||
log("connect failure " + reason);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Save network configuration and connect to network without scanning
|
||||
mWifiManager.connect(config,
|
||||
new WifiManager.ActionListener() {
|
||||
public void onSuccess() {
|
||||
}
|
||||
}
|
||||
if (foundApInScanResults) {
|
||||
return true;
|
||||
} else {
|
||||
// Start an active scan
|
||||
mWifiManager.startScanActive();
|
||||
mScanResultIsAvailable = false;
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (!mScanResultIsAvailable) {
|
||||
if ((System.currentTimeMillis() - startTime) > WIFI_SCAN_TIMEOUT) {
|
||||
log("wait for scan results timeout");
|
||||
return false;
|
||||
}
|
||||
// wait for the scan results to be available
|
||||
synchronized (this) {
|
||||
// wait for the scan result to be available
|
||||
try {
|
||||
this.wait(WAIT_FOR_SCAN_RESULT);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if ((mWifiManager.getScanResults() == null) ||
|
||||
(mWifiManager.getScanResults().size() <= 0)) {
|
||||
continue;
|
||||
}
|
||||
mScanResultIsAvailable = true;
|
||||
}
|
||||
public void onFailure(int reason) {
|
||||
log("connect failure " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
cmActivity.disableWifi();
|
||||
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
|
||||
State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
|
||||
State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
// Wait for 10 seconds for broadcasts to be sent out
|
||||
@@ -184,7 +184,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
log("wifi state is enabled");
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
if (!mWifiOnlyFlag) {
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
|
||||
State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
@@ -217,7 +217,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
|
||||
sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
|
||||
// Disable Wifi
|
||||
@@ -257,7 +257,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
|
||||
// Wait for Wifi to be connected and mobile to be disconnected
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
if (!mWifiOnlyFlag) {
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
|
||||
State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
@@ -279,10 +279,10 @@ public class ConnectivityManagerMobileTest extends
|
||||
|
||||
// connect to Wifi
|
||||
assertTrue("failed to connect to " + mTestAccessPoint,
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
|
||||
// Wait for a few seconds to avoid the state that both Mobile and Wifi is connected
|
||||
sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
|
||||
@@ -418,9 +418,9 @@ public class ConnectivityManagerMobileTest extends
|
||||
|
||||
// Connect to Wifi
|
||||
assertTrue("failed to connect to " + mTestAccessPoint,
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
|
||||
// validate state and broadcast
|
||||
if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
|
||||
@@ -454,7 +454,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
|
||||
try {
|
||||
Thread.sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT);
|
||||
@@ -484,7 +484,7 @@ public class ConnectivityManagerMobileTest extends
|
||||
cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
|
||||
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
if (!mWifiOnlyFlag) {
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
|
||||
State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
@@ -505,11 +505,11 @@ public class ConnectivityManagerMobileTest extends
|
||||
assertNotNull("SSID is null", mTestAccessPoint);
|
||||
//Connect to mTestAccessPoint
|
||||
assertTrue("failed to connect to " + mTestAccessPoint,
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
cmActivity.connectToWifi(mTestAccessPoint));
|
||||
assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
assertNotNull("Not associated with any AP",
|
||||
cmActivity.mWifiManager.getConnectionInfo().getBSSID());
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public class WifiConnectionTest
|
||||
|
||||
// step 2: verify Wifi state and network state;
|
||||
assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
|
||||
State.CONNECTED, 6 * ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
State.CONNECTED, ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
|
||||
// step 3: verify the current connected network is the given SSID
|
||||
assertNotNull("Wifi connection returns null", mAct.mWifiManager.getConnectionInfo());
|
||||
|
||||
@@ -248,7 +248,7 @@ public class WifiStressTest
|
||||
assertTrue(mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
|
||||
ConnectivityManagerTestActivity.SHORT_TIMEOUT));
|
||||
assertTrue(mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
// Run ping test to verify the data connection
|
||||
assertTrue("Wi-Fi is connected, but no data connection.", mAct.pingTest(null));
|
||||
|
||||
@@ -302,7 +302,7 @@ public class WifiStressTest
|
||||
ConnectivityManagerTestActivity.SHORT_TIMEOUT));
|
||||
assertTrue("Wait for Wi-Fi connection timeout after wake up",
|
||||
mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
|
||||
6 * ConnectivityManagerTestActivity.LONG_TIMEOUT));
|
||||
ConnectivityManagerTestActivity.WIFI_CONNECTION_TIMEOUT));
|
||||
long connectionTime = System.currentTimeMillis() - startTime;
|
||||
sum += connectionTime;
|
||||
log("average reconnection time is: " + sum/(i+1));
|
||||
|
||||
Reference in New Issue
Block a user