summaryrefslogtreecommitdiffstats
path: root/core/tests/ConnectivityManagerTest
diff options
context:
space:
mode:
authorXia Wang <xiaw@google.com>2013-05-21 14:18:56 -0700
committerXia Wang <xiaw@google.com>2013-05-31 14:10:12 -0700
commit1c6911ac1d6c4cfecaaa1c1d6814707d77aed4be (patch)
treed6275329ebeb0194633964942fc0f70dbc72f5af /core/tests/ConnectivityManagerTest
parente302c70643e006581c535c76c1c5d50372586ede (diff)
downloadframeworks_base-1c6911ac1d6c4cfecaaa1c1d6814707d77aed4be.zip
frameworks_base-1c6911ac1d6c4cfecaaa1c1d6814707d77aed4be.tar.gz
frameworks_base-1c6911ac1d6c4cfecaaa1c1d6814707d77aed4be.tar.bz2
Add option to set frequency band
- The reason to add the test runner is to set frequency band when the runner is created which happens before the test activity is actually launch. As the test activity will disable/enable wifi when it is created, this cycle will ensure the frequency is set successfully. Change-Id: Ie9de3d8bab3dda7d4bb9ba604ddd5cb33164e397
Diffstat (limited to 'core/tests/ConnectivityManagerTest')
-rw-r--r--core/tests/ConnectivityManagerTest/AndroidManifest.xml16
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/WifiAssociationTestRunner.java88
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java25
3 files changed, 117 insertions, 12 deletions
diff --git a/core/tests/ConnectivityManagerTest/AndroidManifest.xml b/core/tests/ConnectivityManagerTest/AndroidManifest.xml
index a63a453..54881d5 100644
--- a/core/tests/ConnectivityManagerTest/AndroidManifest.xml
+++ b/core/tests/ConnectivityManagerTest/AndroidManifest.xml
@@ -32,11 +32,7 @@
</intent-filter>
</activity>
</application>
- <!-- default test runner -->
- <instrumentation android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.android.connectivitymanagertest"
- android:label="default instrumentation test runner"
- />
+
<!--
This declares that this app uses the instrumentation test runner targeting
the package of connectivitymanagertest. To run the tests use the command:
@@ -68,6 +64,16 @@
android:label="Test runner for Connectivity Manager Stress Tests"
/>
+ <!-- run associate test:
+ "adb shell am instrument -e ssid <ssid> -e password <password>
+ -e ecurity-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
+ -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
+ -->
+ <instrumentation android:name=".WifiAssociationTestRunner"
+ android:targetPackage="com.android.connectivitymanagertest"
+ android:label="Test runner for Wifi association test"
+ />
+
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/WifiAssociationTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/WifiAssociationTestRunner.java
new file mode 100644
index 0000000..722df2e
--- /dev/null
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/WifiAssociationTestRunner.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.connectivitymanagertest;
+
+import android.content.Context;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.test.InstrumentationTestRunner;
+import android.test.InstrumentationTestSuite;
+import android.util.Log;
+
+import com.android.connectivitymanagertest.functional.WifiAssociationTest;
+
+import junit.framework.TestSuite;
+import junit.framework.Assert;
+
+/**
+ * Instrumentation Test Runner for wifi association test.
+ * The instrument will set frequency band if it is necessary
+ *
+ * To run the association tests:
+ *
+ * adb shell am instrument -e ssid <ssid> -e password <password> \
+ * -e security-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
+ * -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
+ */
+public class WifiAssociationTestRunner extends InstrumentationTestRunner {
+ private static final String TAG = "WifiAssociationTestRunner";
+ public int mBand;
+
+ @Override
+ public TestSuite getAllTests() {
+ TestSuite suite = new InstrumentationTestSuite(this);
+ suite.addTestSuite(WifiAssociationTest.class);
+ return suite;
+ }
+
+ @Override
+ public ClassLoader getLoader() {
+ return WifiAssociationTestRunner.class.getClassLoader();
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ Bundle arguments = icicle;
+ String mFrequencyBand = arguments.getString("frequency-band");
+ if (mFrequencyBand != null) {
+ setFrequencyBand(mFrequencyBand);
+ }
+ }
+
+ private void setFrequencyBand(String band) {
+ WifiManager mWifiManager = (WifiManager)getContext().getSystemService(Context.WIFI_SERVICE);
+ if (band.equals("2.4")) {
+ Log.v(TAG, "set frequency band to 2.4");
+ mBand = WifiManager.WIFI_FREQUENCY_BAND_2GHZ;
+ } else if (band.equals("5.0")) {
+ Log.v(TAG, "set frequency band to 5.0");
+ mBand = WifiManager.WIFI_FREQUENCY_BAND_5GHZ;
+ } else if (band.equals("auto")) {
+ Log.v(TAG, "set frequency band to auto");
+ mBand = WifiManager.WIFI_FREQUENCY_BAND_AUTO;
+ } else {
+ Assert.fail("invalid frequency band");
+ }
+ int currentFreq = mWifiManager.getFrequencyBand();
+ if (mBand == currentFreq) {
+ Log.v(TAG, "frequency band has been set");
+ return;
+ }
+ mWifiManager.setFrequencyBand(mBand, true);
+ }
+}
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
index 87a98bf..f12e62e 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiAssociationTest.java
@@ -17,6 +17,7 @@
package com.android.connectivitymanagertest.functional;
import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.WifiAssociationTestRunner;
import android.content.Context;
import android.os.Bundle;
@@ -27,22 +28,19 @@ import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.GroupCipher;
import android.net.wifi.WifiConfiguration.PairwiseCipher;
import android.net.wifi.WifiConfiguration.Protocol;
-import android.net.wifi.WifiConfiguration.Status;
import android.net.wifi.WifiManager;
import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.ActivityInstrumentationTestCase2;
-import android.test.InstrumentationTestRunner;
import android.util.Log;
/**
* Test Wi-Fi connection with different configuration
* To run this tests:
- * adb shell am instrument -e ssid <ssid> -e password <password>
- * -e security-type <security-type>
- * -w com.android.connectivitymanagertest/android.test.InstrumentationTestRunner
+ * * adb shell am instrument -e ssid <ssid> -e password <password> \
+ * -e security-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
+ * -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
*/
public class WifiAssociationTest
extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
@@ -51,6 +49,8 @@ public class WifiAssociationTest
private String mSsid = null;
private String mPassword = null;
private String mSecurityType = null;
+ private String mFrequencyBand = null;
+ private int mBand;
private WifiManager mWifiManager = null;
enum SECURITY_TYPE {
@@ -64,15 +64,18 @@ public class WifiAssociationTest
@Override
public void setUp() throws Exception {
super.setUp();
- InstrumentationTestRunner mRunner = (InstrumentationTestRunner)getInstrumentation();
+ WifiAssociationTestRunner mRunner = (WifiAssociationTestRunner)getInstrumentation();
mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
mAct = getActivity();
Bundle arguments = mRunner.getArguments();
mSecurityType = arguments.getString("security-type");
mSsid = arguments.getString("ssid");
mPassword = arguments.getString("password");
+ mFrequencyBand = arguments.getString("frequency-band");
+ mBand = mRunner.mBand;
assertNotNull("Security type is empty", mSecurityType);
assertNotNull("Ssid is empty", mSsid);
+ validateFrequencyBand();
// enable Wifi and verify wpa_supplicant is started
assertTrue("enable Wifi failed", mAct.enableWifi());
sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT,
@@ -88,6 +91,14 @@ public class WifiAssociationTest
super.tearDown();
}
+ private void validateFrequencyBand() {
+ if (mFrequencyBand != null) {
+ int currentFreq = mWifiManager.getFrequencyBand();
+ Log.v(TAG, "read frequency band: " + currentFreq);
+ assertTrue("device frequency band is not set successfully", (mBand == currentFreq));
+ }
+ }
+
/**
* Connect to the provided Wi-Fi network
* @param config is the network configuration