• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.os.Bundle;
20 import android.test.InstrumentationTestRunner;
21 import android.test.InstrumentationTestSuite;
22 import android.util.Log;
23 
24 import junit.framework.TestSuite;
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 mce_set_message_status_iterations <iterations>] \
44  *     [-e pair_address <address>] \
45  *     [-e headset_address <address>] \
46  *     [-e a2dp_address <address>] \
47  *     [-e input_address <address>] \
48  *     [-e pan_address <address>] \
49  *     [-e pair_pin <pin>] \
50  *     [-e pair_passkey <passkey>] \
51  *     -w com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner
52  * }
53  * </pre>
54  */
55 public class BluetoothTestRunner extends InstrumentationTestRunner {
56     private static final String TAG = "BluetoothTestRunner";
57 
58     public static int sEnableIterations = 100;
59     public static int sDiscoverableIterations = 1000;
60     public static int sScanIterations = 1000;
61     public static int sEnablePanIterations = 1000;
62     public static int sPairIterations = 100;
63     public static int sConnectHeadsetIterations = 100;
64     public static int sConnectA2dpIterations = 100;
65     public static int sConnectInputIterations = 100;
66     public static int sConnectPanIterations = 100;
67     public static int sStartStopScoIterations = 100;
68     public static int sMceSetMessageStatusIterations = 100;
69 
70     public static String sDeviceAddress = "";
71     public static byte[] sDevicePairPin = {'1', '2', '3', '4'};
72     public static int sDevicePairPasskey = 123456;
73 
74     @Override
getAllTests()75     public TestSuite getAllTests() {
76         TestSuite suite = new InstrumentationTestSuite(this);
77         suite.addTestSuite(BluetoothStressTest.class);
78         return suite;
79     }
80 
81     @Override
getLoader()82     public ClassLoader getLoader() {
83         return BluetoothTestRunner.class.getClassLoader();
84     }
85 
86     @Override
onCreate(Bundle arguments)87     public void onCreate(Bundle arguments) {
88         String val = arguments.getString("enable_iterations");
89         if (val != null) {
90             try {
91                 sEnableIterations = Integer.parseInt(val);
92             } catch (NumberFormatException e) {
93                 // Invalid argument, fall back to default value
94             }
95         }
96 
97         val = arguments.getString("discoverable_iterations");
98         if (val != null) {
99             try {
100                 sDiscoverableIterations = Integer.parseInt(val);
101             } catch (NumberFormatException e) {
102                 // Invalid argument, fall back to default value
103             }
104         }
105 
106         val = arguments.getString("scan_iterations");
107         if (val != null) {
108             try {
109                 sScanIterations = Integer.parseInt(val);
110             } catch (NumberFormatException e) {
111                 // Invalid argument, fall back to default value
112             }
113         }
114 
115         val = arguments.getString("enable_pan_iterations");
116         if (val != null) {
117             try {
118                 sEnablePanIterations = Integer.parseInt(val);
119             } catch (NumberFormatException e) {
120                 // Invalid argument, fall back to default value
121             }
122         }
123 
124         val = arguments.getString("pair_iterations");
125         if (val != null) {
126             try {
127                 sPairIterations = Integer.parseInt(val);
128             } catch (NumberFormatException e) {
129                 // Invalid argument, fall back to default value
130             }
131         }
132 
133         val = arguments.getString("connect_a2dp_iterations");
134         if (val != null) {
135             try {
136                 sConnectA2dpIterations = Integer.parseInt(val);
137             } catch (NumberFormatException e) {
138                 // Invalid argument, fall back to default value
139             }
140         }
141 
142         val = arguments.getString("connect_headset_iterations");
143         if (val != null) {
144             try {
145                 sConnectHeadsetIterations = Integer.parseInt(val);
146             } catch (NumberFormatException e) {
147                 // Invalid argument, fall back to default value
148             }
149         }
150 
151         val = arguments.getString("connect_input_iterations");
152         if (val != null) {
153             try {
154                 sConnectInputIterations = Integer.parseInt(val);
155             } catch (NumberFormatException e) {
156                 // Invalid argument, fall back to default value
157             }
158         }
159 
160         val = arguments.getString("connect_pan_iterations");
161         if (val != null) {
162             try {
163                 sConnectPanIterations = Integer.parseInt(val);
164             } catch (NumberFormatException e) {
165                 // Invalid argument, fall back to default value
166             }
167         }
168 
169         val = arguments.getString("start_stop_sco_iterations");
170         if (val != null) {
171             try {
172                 sStartStopScoIterations = Integer.parseInt(val);
173             } catch (NumberFormatException e) {
174                 // Invalid argument, fall back to default value
175             }
176         }
177 
178         val = arguments.getString("mce_set_message_status_iterations");
179         if (val != null) {
180             try {
181                 sMceSetMessageStatusIterations = Integer.parseInt(val);
182             } catch (NumberFormatException e) {
183                 // Invalid argument, fall back to default value
184             }
185         }
186 
187         val = arguments.getString("device_address");
188         if (val != null) {
189             sDeviceAddress = val;
190         }
191 
192         val = arguments.getString("device_pair_pin");
193         if (val != null) {
194             byte[] pin = BluetoothDevice.convertPinToBytes(val);
195             if (pin != null) {
196                 sDevicePairPin = pin;
197             }
198         }
199 
200         val = arguments.getString("device_pair_passkey");
201         if (val != null) {
202             try {
203                 sDevicePairPasskey = Integer.parseInt(val);
204             } catch (NumberFormatException e) {
205                 // Invalid argument, fall back to default value
206             }
207         }
208 
209         Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations));
210         Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations));
211         Log.i(TAG, String.format("scan_iterations=%d", sScanIterations));
212         Log.i(TAG, String.format("pair_iterations=%d", sPairIterations));
213         Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations));
214         Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations));
215         Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations));
216         Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations));
217         Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations));
218         Log.i(TAG, String.format("device_address=%s", sDeviceAddress));
219         Log.i(TAG, String.format("device_pair_pin=%s", new String(sDevicePairPin)));
220         Log.i(TAG, String.format("device_pair_passkey=%d", sDevicePairPasskey));
221 
222         // Call onCreate last since we want to set the static variables first.
223         super.onCreate(arguments);
224     }
225 }
226