BluetoothTestRunner.java revision 835d8ee61ecddcd3fdc0aadf500d05b914ca375f
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 17package android.bluetooth; 18 19import junit.framework.TestSuite; 20 21import android.os.Bundle; 22import android.test.InstrumentationTestRunner; 23import android.test.InstrumentationTestSuite; 24import 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.frameworks.coretests/android.bluetooth.BluetoothTestRunner 51 * } 52 * </pre> 53 */ 54public 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 sPairAddress = ""; 69 public static String sHeadsetAddress = ""; 70 public static String sA2dpAddress = ""; 71 public static String sInputAddress = ""; 72 public static String sPanAddress = ""; 73 74 public static byte[] sPairPin = {'1', '2', '3', '4'}; 75 public static int sPairPasskey = 123456; 76 77 @Override 78 public TestSuite getAllTests() { 79 TestSuite suite = new InstrumentationTestSuite(this); 80 suite.addTestSuite(BluetoothStressTest.class); 81 return suite; 82 } 83 84 @Override 85 public ClassLoader getLoader() { 86 return BluetoothTestRunner.class.getClassLoader(); 87 } 88 89 @Override 90 public void onCreate(Bundle arguments) { 91 String val = arguments.getString("enable_iterations"); 92 if (val != null) { 93 try { 94 sEnableIterations = Integer.parseInt(val); 95 } catch (NumberFormatException e) { 96 // Invalid argument, fall back to default value 97 } 98 } 99 100 val = arguments.getString("discoverable_iterations"); 101 if (val != null) { 102 try { 103 sDiscoverableIterations = Integer.parseInt(val); 104 } catch (NumberFormatException e) { 105 // Invalid argument, fall back to default value 106 } 107 } 108 109 val = arguments.getString("scan_iterations"); 110 if (val != null) { 111 try { 112 sScanIterations = Integer.parseInt(val); 113 } catch (NumberFormatException e) { 114 // Invalid argument, fall back to default value 115 } 116 } 117 118 val = arguments.getString("enable_pan_iterations"); 119 if (val != null) { 120 try { 121 sEnablePanIterations = Integer.parseInt(val); 122 } catch (NumberFormatException e) { 123 // Invalid argument, fall back to default value 124 } 125 } 126 127 val = arguments.getString("pair_iterations"); 128 if (val != null) { 129 try { 130 sPairIterations = Integer.parseInt(val); 131 } catch (NumberFormatException e) { 132 // Invalid argument, fall back to default value 133 } 134 } 135 136 val = arguments.getString("connect_a2dp_iterations"); 137 if (val != null) { 138 try { 139 sConnectA2dpIterations = Integer.parseInt(val); 140 } catch (NumberFormatException e) { 141 // Invalid argument, fall back to default value 142 } 143 } 144 145 val = arguments.getString("connect_headset_iterations"); 146 if (val != null) { 147 try { 148 sConnectHeadsetIterations = Integer.parseInt(val); 149 } catch (NumberFormatException e) { 150 // Invalid argument, fall back to default value 151 } 152 } 153 154 val = arguments.getString("connect_input_iterations"); 155 if (val != null) { 156 try { 157 sConnectInputIterations = Integer.parseInt(val); 158 } catch (NumberFormatException e) { 159 // Invalid argument, fall back to default value 160 } 161 } 162 163 val = arguments.getString("connect_pan_iterations"); 164 if (val != null) { 165 try { 166 sConnectPanIterations = Integer.parseInt(val); 167 } catch (NumberFormatException e) { 168 // Invalid argument, fall back to default value 169 } 170 } 171 172 val = arguments.getString("start_stop_sco_iterations"); 173 if (val != null) { 174 try { 175 sStartStopScoIterations = Integer.parseInt(val); 176 } catch (NumberFormatException e) { 177 // Invalid argument, fall back to default value 178 } 179 } 180 val = arguments.getString("pair_address"); 181 if (val != null) { 182 sPairAddress = val; 183 } 184 185 val = arguments.getString("headset_address"); 186 if (val != null) { 187 sHeadsetAddress = val; 188 } 189 190 val = arguments.getString("a2dp_address"); 191 if (val != null) { 192 sA2dpAddress = val; 193 } 194 195 val = arguments.getString("input_address"); 196 if (val != null) { 197 sInputAddress = val; 198 } 199 200 val = arguments.getString("pan_address"); 201 if (val != null) { 202 sPanAddress = val; 203 } 204 205 val = arguments.getString("pair_pin"); 206 if (val != null) { 207 sPairPin = BluetoothDevice.convertPinToBytes(val); 208 } 209 210 val = arguments.getString("pair_passkey"); 211 if (val != null) { 212 try { 213 sPairPasskey = Integer.parseInt(val); 214 } catch (NumberFormatException e) { 215 // Invalid argument, fall back to default value 216 } 217 } 218 219 Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations)); 220 Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations)); 221 Log.i(TAG, String.format("scan_iterations=%d", sScanIterations)); 222 Log.i(TAG, String.format("pair_iterations=%d", sPairIterations)); 223 Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations)); 224 Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations)); 225 Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations)); 226 Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations)); 227 Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations)); 228 Log.i(TAG, String.format("pair_address=%s", sPairAddress)); 229 Log.i(TAG, String.format("a2dp_address=%s", sA2dpAddress)); 230 Log.i(TAG, String.format("headset_address=%s", sHeadsetAddress)); 231 Log.i(TAG, String.format("input_address=%s", sInputAddress)); 232 Log.i(TAG, String.format("pan_address=%s", sPanAddress)); 233 Log.i(TAG, String.format("pair_pin=%s", new String(sPairPin))); 234 Log.i(TAG, String.format("pair_passkey=%d", sPairPasskey)); 235 236 // Call onCreate last since we want to set the static variables first. 237 super.onCreate(arguments); 238 } 239} 240