diff options
author | Xia Wang <xiaw@google.com> | 2010-12-21 13:13:42 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-12-21 13:13:42 -0800 |
commit | b057c3dbe6814b4e83126deb8631ad4780ea2082 (patch) | |
tree | a533f33cfe131a778b01afdf45c60644b0a0c34f /core/tests | |
parent | f48e94005b6f7d648ebe659960bed32998779439 (diff) | |
parent | 73055f12d7764e322f3f83717525a2dba01f9ef9 (diff) | |
download | frameworks_base-b057c3dbe6814b4e83126deb8631ad4780ea2082.zip frameworks_base-b057c3dbe6814b4e83126deb8631ad4780ea2082.tar.gz frameworks_base-b057c3dbe6814b4e83126deb8631ad4780ea2082.tar.bz2 |
Merge "Few changes for Wi-Fi Stress Test"
Diffstat (limited to 'core/tests')
3 files changed, 48 insertions, 42 deletions
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java index af74c6f..3d5588c 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java @@ -22,6 +22,10 @@ import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; +import android.os.IPowerManager; +import android.os.PowerManager; +import android.os.ServiceManager; +import android.os.SystemClock; import android.provider.Settings; import android.util.Log; import android.view.KeyEvent; @@ -460,6 +464,26 @@ public class ConnectivityManagerTestActivity extends Activity { return mWifiManager.setWifiEnabled(true); } + // Turn screen off + public void turnScreenOff() { + log("Turn screen off"); + PowerManager pm = + (PowerManager) getSystemService(Context.POWER_SERVICE); + pm.goToSleep(SystemClock.uptimeMillis() + 100); + } + + // Turn screen on + public void turnScreenOn() { + log("Turn screen on"); + IPowerManager mPowerManagerService = IPowerManager.Stub.asInterface( + ServiceManager.getService("power"));; + try { + mPowerManagerService.userActivityWithForce(SystemClock.uptimeMillis(), false, true); + } catch (Exception e) { + log(e.toString()); + } + } + /** * Associate the device to given SSID * If the device is already associated with a WiFi, disconnect and forget it, diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java index 2ac7265..ea79f8c 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java @@ -26,7 +26,10 @@ import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiManager; import android.os.Environment; +import android.os.IPowerManager; import android.os.PowerManager; +import android.os.ServiceManager; +import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -46,7 +49,6 @@ public class WifiApStress private final static String OUTPUT_FILE = "WifiStressTestOutput.txt"; private ConnectivityManagerTestActivity mAct; private int iterations; - private PowerManager.WakeLock mWakelock = null; private BufferedWriter mOutputWriter = null; private int mLastIteration = 0; @@ -61,17 +63,11 @@ public class WifiApStress ConnectivityManagerStressTestRunner mRunner = (ConnectivityManagerStressTestRunner)getInstrumentation(); iterations = mRunner.mSoftapIterations; - PowerManager pm = - (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); - mWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wifiApStress"); - mWakelock.acquire(); + mAct.turnScreenOn(); } @Override public void tearDown() throws Exception { - if (mWakelock != null) { - mWakelock.release(); - } // write the total number of iterations into output file mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE))); diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java index 7914417..ae009ca 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiStressTest.java @@ -30,7 +30,9 @@ import android.net.wifi.WifiConfiguration.ProxySettings; import android.net.wifi.WifiManager; import android.os.Environment; import android.os.PowerManager; +import android.os.IPowerManager; import android.os.SystemClock; +import android.os.ServiceManager; import android.provider.Settings; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; @@ -57,7 +59,7 @@ public class WifiStressTest /** * Wi-Fi idle time for default sleep policy */ - private final static long WIFI_IDLE_MS = 5 * 1000; + private final static long WIFI_IDLE_MS = 60 * 1000; /** * The delay for Wi-Fi to get into idle, after screen off + WIFI_IDEL_MS + WIFI_IDLE_DELAY @@ -73,7 +75,6 @@ public class WifiStressTest private String mSsid; private String mPassword; private ConnectivityManagerStressTestRunner mRunner; - private PowerManager.WakeLock wl = null; private BufferedWriter mOutputWriter = null; public WifiStressTest() { @@ -90,10 +91,11 @@ public class WifiStressTest mPassword = mRunner.mReconnectPassword; mScanIterations = mRunner.mScanIterations; mWifiSleepTime = mRunner.mSleepTime; - wl = null; mOutputWriter = new BufferedWriter(new FileWriter(new File( Environment.getExternalStorageDirectory(), OUTPUT_FILE), true)); + mAct.turnScreenOn(); if (!mAct.mWifiManager.isWifiEnabled()) { + log("Enable wi-fi before stress tests."); if (!mAct.enableWifi()) { tearDown(); fail("enable wifi failed."); @@ -106,9 +108,6 @@ public class WifiStressTest @Override public void tearDown() throws Exception { log("tearDown()"); - if ((wl != null) && wl.isHeld()) { - wl.release(); - } if (mOutputWriter != null) { mOutputWriter.close(); } @@ -129,26 +128,6 @@ public class WifiStressTest } } - private void turnScreenOff() { - log("Turn screen off"); - if (wl != null) { - log("release wake lock"); - wl.release(); - } - PowerManager pm = - (PowerManager) mRunner.getContext().getSystemService(Context.POWER_SERVICE); - pm.goToSleep(SystemClock.uptimeMillis() + 50); - } - - private void turnScreenOn() { - log("Turn screen on"); - PowerManager pm = - (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); - wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, - "wifiStressTest"); - wl.acquire(); - } - public void log(String message) { Log.v(TAG, message); } @@ -247,7 +226,6 @@ public class WifiStressTest Settings.Secure.WIFI_IDLE_MS, WIFI_IDLE_MS); // Connect to a Wi-Fi network - turnScreenOn(); WifiConfiguration config = new WifiConfiguration(); config.SSID = mSsid; config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); @@ -267,26 +245,34 @@ public class WifiStressTest ConnectivityManagerTestActivity.LONG_TIMEOUT)); int i; for (i = 0; i < mReconnectIterations; i++) { - // 1. Put device into sleep - // 2. Wait for the device to sleep for sometime, very 3G is connected - // 3. Wake up the device + // 1. Put device into sleep mode + // 2. Wait for the device to sleep for sometime, verify wi-fi is off and mobile is on. + // 3. Maintain the sleep mode for some time, + // 4. Verify the Wi-Fi is still off, and data is on + // 5. Wake up the device, verify Wi-Fi is enabled and connected. writeOutput(String.format("iteration %d out of %d", i, mReconnectIterations)); log("iteration: " + i); - turnScreenOff(); + mAct.turnScreenOff(); PowerManager pm = (PowerManager)mRunner.getContext().getSystemService(Context.POWER_SERVICE); assertFalse(pm.isScreenOn()); - sleep(WIFI_IDLE_MS + WIFI_IDLE_DELAY, "Interruped while wait for wifi to be idle"); + sleep(WIFI_IDLE_MS, "Interruped while wait for wifi to be idle"); assertTrue("Wait for Wi-Fi to idle timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED, - ConnectivityManagerTestActivity.SHORT_TIMEOUT)); + 6 * ConnectivityManagerTestActivity.SHORT_TIMEOUT)); + // use long timeout as the pppd startup may take several retries. assertTrue("Wait for cellular connection timeout", mAct.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT)); sleep(mWifiSleepTime + WIFI_IDLE_DELAY, "Interrupted while device is in sleep mode"); + // Verify the wi-fi is still off and data connection is on + assertEquals("Wi-Fi is reconnected", State.DISCONNECTED, + mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()); + assertEquals("Cellular connection is down", State.CONNECTED, + mAct.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()); // Turn screen on again - turnScreenOn(); + mAct.turnScreenOn(); assertTrue("Wait for Wi-Fi enable timeout after wake up", mAct.waitForWifiState(WifiManager.WIFI_STATE_ENABLED, ConnectivityManagerTestActivity.SHORT_TIMEOUT)); |