Merge commit '8f5007ba4789e0c9e1a620e7211fa24143a66a0a' into gingerbread-plus-aosp * commit '8f5007ba4789e0c9e1a620e7211fa24143a66a0a': Improve logging and flexibility of BT stress tests.
This commit is contained in:
@@ -1205,8 +1205,12 @@
|
|||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<instrumentation
|
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||||
android:name="android.test.InstrumentationTestRunner"
|
android:targetPackage="com.android.frameworks.coretests"
|
||||||
android:targetPackage="com.android.frameworks.coretests"
|
android:label="Frameworks Core Tests" />
|
||||||
android:label="Frameworks Core Tests" />
|
|
||||||
|
<instrumentation android:name="android.bluetooth.BluetoothTestRunner"
|
||||||
|
android:targetPackage="com.android.frameworks.coretests"
|
||||||
|
android:label="Bluetooth Tests" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -16,16 +16,23 @@
|
|||||||
|
|
||||||
package android.bluetooth;
|
package android.bluetooth;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import android.app.Instrumentation;
|
import android.app.Instrumentation;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.os.Environment;
|
||||||
import android.test.InstrumentationTestCase;
|
import android.test.InstrumentationTestCase;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class BluetoothStressTest extends InstrumentationTestCase {
|
public class BluetoothStressTest extends InstrumentationTestCase {
|
||||||
private static final String TAG = "BluetoothEnablerStressTest";
|
private static final String TAG = "BluetoothStressTest";
|
||||||
|
private static final String OUTPUT_FILE = "BluetoothStressTestOutput.txt";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout for {@link BluetoothAdapter#disable()} in ms.
|
* Timeout for {@link BluetoothAdapter#disable()} in ms.
|
||||||
@@ -67,14 +74,12 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
*/
|
*/
|
||||||
private static final int POLL_TIME = 100;
|
private static final int POLL_TIME = 100;
|
||||||
|
|
||||||
private static final int ENABLE_ITERATIONS = 100;
|
|
||||||
private static final int DISCOVERABLE_ITERATIONS = 1000;
|
|
||||||
private static final int SCAN_ITERATIONS = 1000;
|
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
private Instrumentation mInstrumentation;
|
private Instrumentation mInstrumentation;
|
||||||
|
|
||||||
|
private BufferedWriter mOutputWriter;
|
||||||
|
|
||||||
private class BluetoothReceiver extends BroadcastReceiver {
|
private class BluetoothReceiver extends BroadcastReceiver {
|
||||||
private int mFiredFlags = 0;
|
private int mFiredFlags = 0;
|
||||||
|
|
||||||
@@ -144,6 +149,14 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
mInstrumentation = getInstrumentation();
|
mInstrumentation = getInstrumentation();
|
||||||
mContext = mInstrumentation.getTargetContext();
|
mContext = mInstrumentation.getTargetContext();
|
||||||
|
|
||||||
|
try {
|
||||||
|
mOutputWriter = new BufferedWriter(new FileWriter(new File(
|
||||||
|
Environment.getExternalStorageDirectory(), OUTPUT_FILE), true));
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, "Test output file could not be opened", e);
|
||||||
|
mOutputWriter = null;
|
||||||
|
}
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
|
||||||
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
|
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
|
||||||
@@ -157,24 +170,34 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
|
||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
|
|
||||||
|
if (mOutputWriter != null) {
|
||||||
|
try {
|
||||||
|
mOutputWriter.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, "Test output file could not be closed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnableDisable() {
|
public void testEnable() {
|
||||||
|
int iterations = BluetoothTestRunner.sEnableIterations;
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
for (int i = 0; i < ENABLE_ITERATIONS; i++) {
|
for (int i = 0; i < iterations; i++) {
|
||||||
Log.i(TAG, "Enable iteration " + (i + 1) + " of " + ENABLE_ITERATIONS);
|
writeOutput("enable iteration " + (i + 1) + " of " + iterations);
|
||||||
enable(adapter);
|
enable(adapter);
|
||||||
disable(adapter);
|
disable(adapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDiscoverable() {
|
public void testDiscoverable() {
|
||||||
|
int iterations = BluetoothTestRunner.sDiscoverableIterations;
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
enable(adapter);
|
enable(adapter);
|
||||||
|
|
||||||
for (int i = 0; i < DISCOVERABLE_ITERATIONS; i++) {
|
for (int i = 0; i < iterations; i++) {
|
||||||
Log.i(TAG, "Discoverable iteration " + (i + 1) + " of " + DISCOVERABLE_ITERATIONS);
|
writeOutput("discoverable iteration " + (i + 1) + " of " + iterations);
|
||||||
discoverable(adapter);
|
discoverable(adapter);
|
||||||
undiscoverable(adapter);
|
undiscoverable(adapter);
|
||||||
}
|
}
|
||||||
@@ -183,11 +206,12 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testScan() {
|
public void testScan() {
|
||||||
|
int iterations = BluetoothTestRunner.sScanIterations;
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
enable(adapter);
|
enable(adapter);
|
||||||
|
|
||||||
for (int i = 0; i < SCAN_ITERATIONS; i++) {
|
for (int i = 0; i < iterations; i++) {
|
||||||
Log.i(TAG, "Scan iteration " + (i + 1) + " of " + SCAN_ITERATIONS);
|
writeOutput("scan iteration " + (i + 1) + " of " + iterations);
|
||||||
startScan(adapter);
|
startScan(adapter);
|
||||||
stopScan(adapter);
|
stopScan(adapter);
|
||||||
}
|
}
|
||||||
@@ -217,7 +241,7 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
mask = 0; // Don't check for received intents since we might have missed them.
|
mask = 0; // Don't check for received intents since we might have missed them.
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fail("disable() invalid state: " + state);
|
fail("disable() invalid state: state=" + state);
|
||||||
}
|
}
|
||||||
|
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
@@ -227,6 +251,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
assertFalse(adapter.isEnabled());
|
assertFalse(adapter.isEnabled());
|
||||||
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("disable() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -238,9 +264,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("disable() timeout: " +
|
fail(String.format("disable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
|
||||||
"state=" + state + " (expected " + BluetoothAdapter.STATE_OFF + ") " +
|
state, BluetoothAdapter.STATE_OFF, firedFlags, mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enable(BluetoothAdapter adapter) {
|
private void enable(BluetoothAdapter adapter) {
|
||||||
@@ -272,6 +297,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
assertTrue(adapter.isEnabled());
|
assertTrue(adapter.isEnabled());
|
||||||
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("enable() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -283,9 +310,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("enable() timeout: " +
|
fail(String.format("enable() timeout: state=%d (expected %d), flags=0x%x (expected 0x%x)",
|
||||||
"state=" + state + " (expected " + BluetoothAdapter.STATE_OFF + ") " +
|
state, BluetoothAdapter.STATE_ON, firedFlags, mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void discoverable(BluetoothAdapter adapter) {
|
private void discoverable(BluetoothAdapter adapter) {
|
||||||
@@ -310,6 +336,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||||
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("discoverable() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -320,10 +348,9 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("discoverable() timeout: " +
|
fail(String.format("discoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
|
||||||
"scanMode=" + scanMode + " (expected " +
|
+ "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,
|
||||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE + ") " +
|
firedFlags, mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void undiscoverable(BluetoothAdapter adapter) {
|
private void undiscoverable(BluetoothAdapter adapter) {
|
||||||
@@ -348,6 +375,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
|
if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
|
||||||
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
if ((mReceiver.getFiredFlags() & mask) == mask) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("undiscoverable() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -358,10 +387,9 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("undiscoverable() timeout: " +
|
fail(String.format("undiscoverable() timeout: scanMode=%d (expected %d), flags=0x%x "
|
||||||
"scanMode=" + scanMode + " (expected " +
|
+ "(expected 0x%x)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE, firedFlags,
|
||||||
BluetoothAdapter.SCAN_MODE_CONNECTABLE + ") " +
|
mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startScan(BluetoothAdapter adapter) {
|
private void startScan(BluetoothAdapter adapter) {
|
||||||
@@ -382,6 +410,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
while (System.currentTimeMillis() - s < START_DISCOVERY_TIMEOUT) {
|
while (System.currentTimeMillis() - s < START_DISCOVERY_TIMEOUT) {
|
||||||
if (adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
|
if (adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("startScan() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sleep(POLL_TIME);
|
sleep(POLL_TIME);
|
||||||
@@ -389,9 +419,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("startScan() timeout: " +
|
fail(String.format("startScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
|
||||||
"isDiscovering=" + adapter.isDiscovering() + " " +
|
adapter.isDiscovering(), firedFlags, mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopScan(BluetoothAdapter adapter) {
|
private void stopScan(BluetoothAdapter adapter) {
|
||||||
@@ -414,6 +443,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
while (System.currentTimeMillis() - s < CANCEL_DISCOVERY_TIMEOUT) {
|
while (System.currentTimeMillis() - s < CANCEL_DISCOVERY_TIMEOUT) {
|
||||||
if (!adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
|
if (!adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
|
writeOutput(String.format("stopScan() completed in %d ms",
|
||||||
|
(System.currentTimeMillis() - s)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sleep(POLL_TIME);
|
sleep(POLL_TIME);
|
||||||
@@ -421,9 +452,22 @@ public class BluetoothStressTest extends InstrumentationTestCase {
|
|||||||
|
|
||||||
int firedFlags = mReceiver.getFiredFlags();
|
int firedFlags = mReceiver.getFiredFlags();
|
||||||
mReceiver.resetFiredFlags();
|
mReceiver.resetFiredFlags();
|
||||||
fail("stopScan() timeout: " +
|
fail(String.format("stopScan() timeout: isDiscovering=%b, flags=0x%x (expected 0x%x)",
|
||||||
"isDiscovering=" + adapter.isDiscovering() + " " +
|
adapter.isDiscovering(), firedFlags, mask));
|
||||||
"flags=" + firedFlags + " (expected " + mask + ")");
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeOutput(String s) {
|
||||||
|
if (mOutputWriter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Log.i(TAG, s);
|
||||||
|
mOutputWriter.write(s + "\n");
|
||||||
|
mOutputWriter.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, "Could not write to output file", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sleep(long time) {
|
private void sleep(long time) {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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 android.bluetooth;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.test.InstrumentationTestRunner;
|
||||||
|
import android.test.InstrumentationTestSuite;
|
||||||
|
|
||||||
|
public class BluetoothTestRunner extends InstrumentationTestRunner {
|
||||||
|
public static int sEnableIterations = 100;
|
||||||
|
public static int sDiscoverableIterations = 1000;
|
||||||
|
public static int sScanIterations = 1000;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestSuite getAllTests() {
|
||||||
|
TestSuite suite = new InstrumentationTestSuite(this);
|
||||||
|
suite.addTestSuite(BluetoothStressTest.class);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassLoader getLoader() {
|
||||||
|
return BluetoothTestRunner.class.getClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle arguments) {
|
||||||
|
super.onCreate(arguments);
|
||||||
|
|
||||||
|
String val = arguments.getString("enable_iterations");
|
||||||
|
if (val != null) {
|
||||||
|
try {
|
||||||
|
sEnableIterations = Integer.parseInt(val);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Invalid argument, fall back to default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val = arguments.getString("discoverable_iterations");
|
||||||
|
if (val != null) {
|
||||||
|
try {
|
||||||
|
sDiscoverableIterations = Integer.parseInt(val);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Invalid argument, fall back to default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val = arguments.getString("scan_iterations");
|
||||||
|
if (val != null) {
|
||||||
|
try {
|
||||||
|
sScanIterations = Integer.parseInt(val);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Invalid argument, fall back to default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user