Merge "Fix WiFi stress test" into jb-mr1-dev

This commit is contained in:
Xia Wang
2012-10-31 21:18:28 -07:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 23 deletions

View File

@ -74,4 +74,5 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
</manifest> </manifest>

View File

@ -65,6 +65,8 @@ public class ConnectivityManagerTestActivity extends Activity {
public static final long LONG_TIMEOUT = 50 * 1000; public static final long LONG_TIMEOUT = 50 * 1000;
// 2 minutes timer between wifi stop and start // 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;
// Set ping test timer to be 3 minutes
public static final long PING_TIMER = 3 * 60 *1000;
public static final int SUCCESS = 0; // for Wifi tethering state change public static final int SUCCESS = 0; // for Wifi tethering state change
public static final int FAILURE = 1; public static final int FAILURE = 1;
public static final int INIT = -1; public static final int INIT = -1;
@ -517,37 +519,36 @@ public class ConnectivityManagerTestActivity extends Activity {
* @return true if the ping test is successful, false otherwise. * @return true if the ping test is successful, false otherwise.
*/ */
public boolean pingTest(String[] pingServerList) { public boolean pingTest(String[] pingServerList) {
boolean result = false;
String[] hostList = {"www.google.com", "www.yahoo.com", String[] hostList = {"www.google.com", "www.yahoo.com",
"www.bing.com", "www.facebook.com", "www.ask.com"}; "www.bing.com", "www.facebook.com", "www.ask.com"};
if (pingServerList != null) { if (pingServerList != null) {
hostList = pingServerList; hostList = pingServerList;
} }
try {
// assume the chance that all servers are down is very small long startTime = System.currentTimeMillis();
for (int i = 0; i < hostList.length; i++ ) { while ((System.currentTimeMillis() - startTime) < PING_TIMER) {
String host = hostList[i]; try {
log("Start ping test, ping " + host); // assume the chance that all servers are down is very small
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host); for (int i = 0; i < hostList.length; i++ ) {
int status = p.waitFor(); String host = hostList[i];
if (status == 0) { log("Start ping test, ping " + host);
// if any of the ping test is successful, return true Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
result = true; int status = p.waitFor();
break; if (status == 0) {
} else { // if any of the ping test is successful, return true
result = false; return true;
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");
} }
} 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"); // ping test timeout
return result; return false;
} }
/** /**

View File

@ -28,6 +28,7 @@ import android.net.wifi.WifiManager;
import android.os.Environment; import android.os.Environment;
import android.os.PowerManager; import android.os.PowerManager;
import android.provider.Settings; import android.provider.Settings;
import android.view.KeyEvent;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log; import android.util.Log;
@ -289,6 +290,11 @@ public class WifiStressTest
// Turn screen on again // Turn screen on again
mAct.turnScreenOn(); mAct.turnScreenOn();
// Wait for 2 seconds for the lock screen
sleep(2 * 1000, "wait 2 seconds for lock screen");
// Disable lock screen by inject menu key event
mRunner.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
// Measure the time for Wi-Fi to get connected // Measure the time for Wi-Fi to get connected
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
assertTrue("Wait for Wi-Fi enable timeout after wake up", assertTrue("Wait for Wi-Fi enable timeout after wake up",