1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.bluetooth; 18 19 import junit.framework.TestSuite; 20 21 import android.os.Bundle; 22 import android.test.InstrumentationTestRunner; 23 import android.test.InstrumentationTestSuite; 24 import android.util.Log; 25 26 /** 27 * Instrumentation test runner for Bluetooth tests. 28 * <p> 29 * To run: 30 * <pre> 31 * {@code 32 * adb shell am instrument \ 33 * [-e enable_iterations <iterations>] \ 34 * [-e discoverable_iterations <iterations>] \ 35 * [-e scan_iterations <iterations>] \ 36 * [-e enable_pan_iterations <iterations>] \ 37 * [-e pair_iterations <iterations>] \ 38 * [-e connect_a2dp_iterations <iterations>] \ 39 * [-e connect_headset_iterations <iterations>] \ 40 * [-e connect_input_iterations <iterations>] \ 41 * [-e connect_pan_iterations <iterations>] \ 42 * [-e start_stop_sco_iterations <iterations>] \ 43 * [-e pair_address <address>] \ 44 * [-e headset_address <address>] \ 45 * [-e a2dp_address <address>] \ 46 * [-e input_address <address>] \ 47 * [-e pan_address <address>] \ 48 * [-e pair_pin <pin>] \ 49 * [-e pair_passkey <passkey>] \ 50 * -w com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner 51 * } 52 * </pre> 53 */ 54 public class BluetoothTestRunner extends InstrumentationTestRunner { 55 private static final String TAG = "BluetoothTestRunner"; 56 57 public static int sEnableIterations = 100; 58 public static int sDiscoverableIterations = 1000; 59 public static int sScanIterations = 1000; 60 public static int sEnablePanIterations = 1000; 61 public static int sPairIterations = 100; 62 public static int sConnectHeadsetIterations = 100; 63 public static int sConnectA2dpIterations = 100; 64 public static int sConnectInputIterations = 100; 65 public static int sConnectPanIterations = 100; 66 public static int sStartStopScoIterations = 100; 67 68 public static String sDeviceAddress = ""; 69 public static byte[] sDevicePairPin = {'1', '2', '3', '4'}; 70 public static int sDevicePairPasskey = 123456; 71 72 @Override getAllTests()73 public TestSuite getAllTests() { 74 TestSuite suite = new InstrumentationTestSuite(this); 75 suite.addTestSuite(BluetoothStressTest.class); 76 return suite; 77 } 78 79 @Override getLoader()80 public ClassLoader getLoader() { 81 return BluetoothTestRunner.class.getClassLoader(); 82 } 83 84 @Override onCreate(Bundle arguments)85 public void onCreate(Bundle arguments) { 86 String val = arguments.getString("enable_iterations"); 87 if (val != null) { 88 try { 89 sEnableIterations = Integer.parseInt(val); 90 } catch (NumberFormatException e) { 91 // Invalid argument, fall back to default value 92 } 93 } 94 95 val = arguments.getString("discoverable_iterations"); 96 if (val != null) { 97 try { 98 sDiscoverableIterations = Integer.parseInt(val); 99 } catch (NumberFormatException e) { 100 // Invalid argument, fall back to default value 101 } 102 } 103 104 val = arguments.getString("scan_iterations"); 105 if (val != null) { 106 try { 107 sScanIterations = Integer.parseInt(val); 108 } catch (NumberFormatException e) { 109 // Invalid argument, fall back to default value 110 } 111 } 112 113 val = arguments.getString("enable_pan_iterations"); 114 if (val != null) { 115 try { 116 sEnablePanIterations = Integer.parseInt(val); 117 } catch (NumberFormatException e) { 118 // Invalid argument, fall back to default value 119 } 120 } 121 122 val = arguments.getString("pair_iterations"); 123 if (val != null) { 124 try { 125 sPairIterations = Integer.parseInt(val); 126 } catch (NumberFormatException e) { 127 // Invalid argument, fall back to default value 128 } 129 } 130 131 val = arguments.getString("connect_a2dp_iterations"); 132 if (val != null) { 133 try { 134 sConnectA2dpIterations = Integer.parseInt(val); 135 } catch (NumberFormatException e) { 136 // Invalid argument, fall back to default value 137 } 138 } 139 140 val = arguments.getString("connect_headset_iterations"); 141 if (val != null) { 142 try { 143 sConnectHeadsetIterations = Integer.parseInt(val); 144 } catch (NumberFormatException e) { 145 // Invalid argument, fall back to default value 146 } 147 } 148 149 val = arguments.getString("connect_input_iterations"); 150 if (val != null) { 151 try { 152 sConnectInputIterations = Integer.parseInt(val); 153 } catch (NumberFormatException e) { 154 // Invalid argument, fall back to default value 155 } 156 } 157 158 val = arguments.getString("connect_pan_iterations"); 159 if (val != null) { 160 try { 161 sConnectPanIterations = Integer.parseInt(val); 162 } catch (NumberFormatException e) { 163 // Invalid argument, fall back to default value 164 } 165 } 166 167 val = arguments.getString("start_stop_sco_iterations"); 168 if (val != null) { 169 try { 170 sStartStopScoIterations = Integer.parseInt(val); 171 } catch (NumberFormatException e) { 172 // Invalid argument, fall back to default value 173 } 174 } 175 176 val = arguments.getString("device_address"); 177 if (val != null) { 178 sDeviceAddress = val; 179 } 180 181 val = arguments.getString("device_pair_pin"); 182 if (val != null) { 183 byte[] pin = BluetoothDevice.convertPinToBytes(val); 184 if (pin != null) { 185 sDevicePairPin = pin; 186 } 187 } 188 189 val = arguments.getString("device_pair_passkey"); 190 if (val != null) { 191 try { 192 sDevicePairPasskey = Integer.parseInt(val); 193 } catch (NumberFormatException e) { 194 // Invalid argument, fall back to default value 195 } 196 } 197 198 Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations)); 199 Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations)); 200 Log.i(TAG, String.format("scan_iterations=%d", sScanIterations)); 201 Log.i(TAG, String.format("pair_iterations=%d", sPairIterations)); 202 Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations)); 203 Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations)); 204 Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations)); 205 Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations)); 206 Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations)); 207 Log.i(TAG, String.format("device_address=%s", sDeviceAddress)); 208 Log.i(TAG, String.format("device_pair_pin=%s", new String(sDevicePairPin))); 209 Log.i(TAG, String.format("device_pair_passkey=%d", sDevicePairPasskey)); 210 211 // Call onCreate last since we want to set the static variables first. 212 super.onCreate(arguments); 213 } 214 } 215