Skip to content

Commit b2a2096

Browse files
author
Xia Wang
committed
Fix WiFi stress test
- Disable lock screen after screen is turned on. Without disabling lock screen, device will screen off automatically after around 10 seconds - Add a longer timer for ping test when the data traffic is stalled. For a short ping test, it is hard to tell whether it is a transient issue or a real issue. bug# 7426823 Change-Id: If1a560e11dcdff519562bb2a22651d1fd523b5a2
1 parent 86e1b96 commit b2a2096

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

core/tests/ConnectivityManagerTest/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@
7474
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
7575
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
7676
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
77+
<uses-permission android:name="android.permission.INJECT_EVENTS" />
7778
</manifest>

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public class ConnectivityManagerTestActivity extends Activity {
6565
public static final long LONG_TIMEOUT = 50 * 1000;
6666
// 2 minutes timer between wifi stop and start
6767
public static final long WIFI_STOP_START_INTERVAL = 2 * 60 * 1000;
68+
// Set ping test timer to be 3 minutes
69+
public static final long PING_TIMER = 3 * 60 *1000;
6870
public static final int SUCCESS = 0; // for Wifi tethering state change
6971
public static final int FAILURE = 1;
7072
public static final int INIT = -1;
@@ -517,37 +519,36 @@ public void turnScreenOn() {
517519
* @return true if the ping test is successful, false otherwise.
518520
*/
519521
public boolean pingTest(String[] pingServerList) {
520-
boolean result = false;
521522
String[] hostList = {"www.google.com", "www.yahoo.com",
522523
"www.bing.com", "www.facebook.com", "www.ask.com"};
523524
if (pingServerList != null) {
524525
hostList = pingServerList;
525526
}
526-
try {
527-
// assume the chance that all servers are down is very small
528-
for (int i = 0; i < hostList.length; i++ ) {
529-
String host = hostList[i];
530-
log("Start ping test, ping " + host);
531-
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
532-
int status = p.waitFor();
533-
if (status == 0) {
534-
// if any of the ping test is successful, return true
535-
result = true;
536-
break;
537-
} else {
538-
result = false;
539-
log("ping " + host + " failed.");
527+
528+
long startTime = System.currentTimeMillis();
529+
while ((System.currentTimeMillis() - startTime) < PING_TIMER) {
530+
try {
531+
// assume the chance that all servers are down is very small
532+
for (int i = 0; i < hostList.length; i++ ) {
533+
String host = hostList[i];
534+
log("Start ping test, ping " + host);
535+
Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
536+
int status = p.waitFor();
537+
if (status == 0) {
538+
// if any of the ping test is successful, return true
539+
return true;
540+
}
540541
}
542+
} catch (UnknownHostException e) {
543+
log("Ping test Fail: Unknown Host");
544+
} catch (IOException e) {
545+
log("Ping test Fail: IOException");
546+
} catch (InterruptedException e) {
547+
log("Ping test Fail: InterruptedException");
541548
}
542-
} catch (UnknownHostException e) {
543-
log("Ping test Fail: Unknown Host");
544-
} catch (IOException e) {
545-
log("Ping test Fail: IOException");
546-
} catch (InterruptedException e) {
547-
log("Ping test Fail: InterruptedException");
548549
}
549-
log("return");
550-
return result;
550+
// ping test timeout
551+
return false;
551552
}
552553

553554
/**

core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import android.os.Environment;
2929
import android.os.PowerManager;
3030
import android.provider.Settings;
31+
import android.view.KeyEvent;
3132
import android.test.ActivityInstrumentationTestCase2;
3233
import android.test.suitebuilder.annotation.LargeTest;
3334
import android.util.Log;
@@ -289,6 +290,11 @@ public void testWifiReconnectionAfterSleep() {
289290

290291
// Turn screen on again
291292
mAct.turnScreenOn();
293+
// Wait for 2 seconds for the lock screen
294+
sleep(2 * 1000, "wait 2 seconds for lock screen");
295+
// Disable lock screen by inject menu key event
296+
mRunner.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
297+
292298
// Measure the time for Wi-Fi to get connected
293299
long startTime = System.currentTimeMillis();
294300
assertTrue("Wait for Wi-Fi enable timeout after wake up",

0 commit comments

Comments
 (0)