summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTsu Chiang Chuang <tsu@google.com>2011-11-07 11:52:08 -0800
committerTsu Chiang Chuang <tsu@google.com>2011-11-10 10:21:39 -0800
commit212efacb848f13b1565ef434e331a69e930d8935 (patch)
treea3ce60e58f59f507a0c5abe601204292f6d29cd0
parent843e04d977fd348ed474da1d3c6a62e7dc837444 (diff)
downloadframeworks_base-212efacb848f13b1565ef434e331a69e930d8935.zip
frameworks_base-212efacb848f13b1565ef434e331a69e930d8935.tar.gz
frameworks_base-212efacb848f13b1565ef434e331a69e930d8935.tar.bz2
Adding mobile microbenchmark tests.
Change-Id: Ifcd67b0265045778965aeff8e213c3929da02c3d
-rw-r--r--core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java81
-rw-r--r--core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java51
2 files changed, 115 insertions, 17 deletions
diff --git a/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java b/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
index 0cc883f..01a5fd0 100644
--- a/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
+++ b/core/tests/bandwidthtests/src/com/android/bandwidthtest/BandwidthTest.java
@@ -90,7 +90,26 @@ public class BandwidthTest extends InstrumentationTestCase {
*/
@LargeTest
public void testWifiDownload() throws Exception {
- assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
+ assertTrue("Could not connect to wifi!", setDeviceWifiAndAirplaneMode(mSsid));
+ downloadFile();
+ }
+
+ /**
+ * Ensure that downloading on mobile reports reasonable stats.
+ */
+ @LargeTest
+ public void testMobileDownload() throws Exception {
+ // As part of the setup we disconnected from wifi; make sure we are connected to mobile and
+ // that we have data.
+ assertTrue("Do not have mobile data!", hasMobileData());
+ downloadFile();
+ }
+
+ /**
+ * Helper method that downloads a file using http connection from a test server and reports the
+ * data usage stats to instrumentation out.
+ */
+ protected void downloadFile() throws Exception {
NetworkStats pre_test_stats = fetchDataFromProc(mUid);
String ts = Long.toString(System.currentTimeMillis());
@@ -120,11 +139,28 @@ public class BandwidthTest extends InstrumentationTestCase {
}
/**
- * Ensure that downloading on wifi reports reasonable stats.
+ * Ensure that uploading on wifi reports reasonable stats.
*/
@LargeTest
public void testWifiUpload() throws Exception {
assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
+ uploadFile();
+ }
+
+ /**
+ * Ensure that uploading on wifi reports reasonable stats.
+ */
+ @LargeTest
+ public void testMobileUpload() throws Exception {
+ assertTrue(hasMobileData());
+ uploadFile();
+ }
+
+ /**
+ * Helper method that downloads a test file to upload. The stats reported to instrumentation out
+ * only include upload stats.
+ */
+ protected void uploadFile() throws Exception {
// Download a file from the server.
String ts = Long.toString(System.currentTimeMillis());
String targetUrl = BandwidthTestUtil.buildDownloadUrl(
@@ -156,12 +192,30 @@ public class BandwidthTest extends InstrumentationTestCase {
}
/**
- * We want to make sure that if we use the Download Manager to download stuff,
+ * We want to make sure that if we use wifi and the Download Manager to download stuff,
* accounting still goes to the app making the call and that the numbers still make sense.
*/
@LargeTest
public void testWifiDownloadWithDownloadManager() throws Exception {
assertTrue(setDeviceWifiAndAirplaneMode(mSsid));
+ downloadFileUsingDownloadManager();
+ }
+
+ /**
+ * We want to make sure that if we use mobile data and the Download Manager to download stuff,
+ * accounting still goes to the app making the call and that the numbers still make sense.
+ */
+ @LargeTest
+ public void testMobileDownloadWithDownloadManager() throws Exception {
+ assertTrue(hasMobileData());
+ downloadFileUsingDownloadManager();
+ }
+
+ /**
+ * Helper method that downloads a file from a test server using the download manager and reports
+ * the stats to instrumentation out.
+ */
+ protected void downloadFileUsingDownloadManager() throws Exception {
// If we are using the download manager, then the data that is written to /proc/uid_stat/
// is accounted against download manager's uid, since it uses pre-ICS API.
int downloadManagerUid = mConnectionUtil.downloadManagerUid();
@@ -195,6 +249,7 @@ public class BandwidthTest extends InstrumentationTestCase {
/**
* Fetch network data from /proc/uid_stat/uid
+ *
* @return populated {@link NetworkStats}
*/
public NetworkStats fetchDataFromProc(int uid) {
@@ -210,7 +265,8 @@ public class BandwidthTest extends InstrumentationTestCase {
}
/**
- * Turn on Airplane mode and connect to the wifi
+ * Turn on Airplane mode and connect to the wifi.
+ *
* @param ssid of the wifi to connect to
* @return true if we successfully connected to a given network.
*/
@@ -219,12 +275,25 @@ public class BandwidthTest extends InstrumentationTestCase {
assertTrue(mConnectionUtil.connectToWifi(ssid));
assertTrue(mConnectionUtil.waitForWifiState(WifiManager.WIFI_STATE_ENABLED,
ConnectionUtil.LONG_TIMEOUT));
- return mConnectionUtil.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
- ConnectionUtil.LONG_TIMEOUT);
+ assertTrue(mConnectionUtil.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+ State.CONNECTED, ConnectionUtil.LONG_TIMEOUT));
+ return mConnectionUtil.hasData();
+ }
+
+ /**
+ * Helper method to make sure we are connected to mobile data.
+ *
+ * @return true if we successfully connect to mobile data.
+ */
+ public boolean hasMobileData() {
+ assertTrue("Not connected to mobile", mConnectionUtil.isConnectedToMobile());
+ assertFalse("Still connected to wifi.", mConnectionUtil.isConnectedToWifi());
+ return mConnectionUtil.hasData();
}
/**
* Output the {@link NetworkStats} to Instrumentation out.
+ *
* @param label to attach to this given stats.
* @param stats {@link NetworkStats} to add.
* @param results {@link Bundle} to be added to.
diff --git a/core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java b/core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java
index d663aad..a5e5ab0 100644
--- a/core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java
+++ b/core/tests/bandwidthtests/src/com/android/bandwidthtest/util/ConnectionUtil.java
@@ -44,6 +44,8 @@ import com.android.bandwidthtest.NetworkState;
import com.android.bandwidthtest.NetworkState.StateTransitionDirection;
import com.android.internal.util.AsyncChannel;
+import java.io.IOException;
+import java.net.UnknownHostException;
import java.util.List;
/*
@@ -257,14 +259,14 @@ public class ConnectionUtil {
mConnectivityState[networkType].recordState(networkState);
}
- /**
- * Set the state transition criteria
- *
- * @param networkType
- * @param initState
- * @param transitionDir
- * @param targetState
- */
+ /**
+ * Set the state transition criteria
+ *
+ * @param networkType
+ * @param initState
+ * @param transitionDir
+ * @param targetState
+ */
public void setStateTransitionCriteria(int networkType, State initState,
StateTransitionDirection transitionDir, State targetState) {
mConnectivityState[networkType].setStateTransitionCriteria(
@@ -495,7 +497,8 @@ public class ConnectionUtil {
* @return true if connected to a mobile network, false otherwise.
*/
public boolean isConnectedToMobile() {
- return (mNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
+ NetworkInfo networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ return networkInfo.isConnected();
}
/**
@@ -503,10 +506,10 @@ public class ConnectionUtil {
* @return true if connected to wifi, false otherwise.
*/
public boolean isConnectedToWifi() {
- return (mNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI);
+ NetworkInfo networkInfo = mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ return networkInfo.isConnected();
}
-
/**
* Associate the device to given SSID
* If the device is already associated with a WiFi, disconnect and forget it,
@@ -681,4 +684,30 @@ public class ConnectionUtil {
}
Log.v(LOG_TAG, "onDestroy, inst=" + Integer.toHexString(hashCode()));
}
+
+ /**
+ * Helper method used to test data connectivity by pinging a series of popular sites.
+ * @return true if device has data connectivity, false otherwise.
+ */
+ public boolean hasData() {
+ String[] hostList = {"www.google.com", "www.yahoo.com",
+ "www.bing.com", "www.facebook.com", "www.ask.com"};
+ try {
+ for (int i = 0; i < hostList.length; ++i) {
+ String host = hostList[i];
+ Process p = Runtime.getRuntime().exec("ping -c 10 -w 100 " + host);
+ int status = p.waitFor();
+ if (status == 0) {
+ return true;
+ }
+ }
+ } catch (UnknownHostException e) {
+ Log.e(LOG_TAG, "Ping test Failed: Unknown Host");
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Ping test Failed: IOException");
+ } catch (InterruptedException e) {
+ Log.e(LOG_TAG, "Ping test Failed: InterruptedException");
+ }
+ return false;
+ }
} \ No newline at end of file