1e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe/*
2e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * Copyright (C) 2010 The Android Open Source Project
3e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe *
4e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * Licensed under the Apache License, Version 2.0 (the "License");
5e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * you may not use this file except in compliance with the License.
6e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * You may obtain a copy of the License at
7e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe *
8e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe *      http://www.apache.org/licenses/LICENSE-2.0
9e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe *
10e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * Unless required by applicable law or agreed to in writing, software
11e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * distributed under the License is distributed on an "AS IS" BASIS,
12e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * See the License for the specific language governing permissions and
14e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe * limitations under the License.
15e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe */
16e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
17e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowepackage android.bluetooth;
18e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
19e1d666b632608a2f708cb3df06c796e16d5d1717Eric Roweimport junit.framework.TestSuite;
20e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
21e1d666b632608a2f708cb3df06c796e16d5d1717Eric Roweimport android.os.Bundle;
22e1d666b632608a2f708cb3df06c796e16d5d1717Eric Roweimport android.test.InstrumentationTestRunner;
23e1d666b632608a2f708cb3df06c796e16d5d1717Eric Roweimport android.test.InstrumentationTestSuite;
24826af6266c79d76b81fe850b9cd3d351597e4adbEric Roweimport android.util.Log;
25e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
267e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe/**
277e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * Instrumentation test runner for Bluetooth tests.
287e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * <p>
297e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * To run:
307e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * <pre>
317e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * {@code
327e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * adb shell am instrument \
337e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e enable_iterations <iterations>] \
347e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e discoverable_iterations <iterations>] \
357e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e scan_iterations <iterations>] \
367e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e enable_pan_iterations <iterations>] \
377e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e pair_iterations <iterations>] \
387e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e connect_a2dp_iterations <iterations>] \
397e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e connect_headset_iterations <iterations>] \
407e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e connect_input_iterations <iterations>] \
417e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e connect_pan_iterations <iterations>] \
42835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe *     [-e start_stop_sco_iterations <iterations>] \
437e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e pair_address <address>] \
447e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e headset_address <address>] \
457e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e a2dp_address <address>] \
467e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e input_address <address>] \
477e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e pan_address <address>] \
487e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e pair_pin <pin>] \
497e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe *     [-e pair_passkey <passkey>] \
507af75afb2c8608dbe73509036eefd3281d646a5fEric Rowe *     -w com.android.bluetooth.tests/android.bluetooth.BluetoothTestRunner
517e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * }
527e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe * </pre>
537e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe */
54e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowepublic class BluetoothTestRunner extends InstrumentationTestRunner {
55826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe    private static final String TAG = "BluetoothTestRunner";
56826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
57e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public static int sEnableIterations = 100;
58e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public static int sDiscoverableIterations = 1000;
59e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public static int sScanIterations = 1000;
607e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe    public static int sEnablePanIterations = 1000;
61826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe    public static int sPairIterations = 100;
62826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe    public static int sConnectHeadsetIterations = 100;
63826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe    public static int sConnectA2dpIterations = 100;
647e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe    public static int sConnectInputIterations = 100;
657e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe    public static int sConnectPanIterations = 100;
66835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe    public static int sStartStopScoIterations = 100;
67826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
682b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe    public static String sDeviceAddress = "";
692b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe    public static byte[] sDevicePairPin = {'1', '2', '3', '4'};
702b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe    public static int sDevicePairPasskey = 123456;
71e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
72e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    @Override
73e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public TestSuite getAllTests() {
74e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        TestSuite suite = new InstrumentationTestSuite(this);
75e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        suite.addTestSuite(BluetoothStressTest.class);
76e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        return suite;
77e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    }
78e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
79e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    @Override
80e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public ClassLoader getLoader() {
81e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        return BluetoothTestRunner.class.getClassLoader();
82e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    }
83e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
84e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    @Override
85e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    public void onCreate(Bundle arguments) {
86e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        String val = arguments.getString("enable_iterations");
87e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        if (val != null) {
88e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            try {
89e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                sEnableIterations = Integer.parseInt(val);
90e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            } catch (NumberFormatException e) {
91e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                // Invalid argument, fall back to default value
92e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            }
93e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        }
94e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
95e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        val = arguments.getString("discoverable_iterations");
96e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        if (val != null) {
97e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            try {
98e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                sDiscoverableIterations = Integer.parseInt(val);
99e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            } catch (NumberFormatException e) {
100e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                // Invalid argument, fall back to default value
101e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            }
102e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        }
103e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe
104e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        val = arguments.getString("scan_iterations");
105e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        if (val != null) {
106e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            try {
107e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                sScanIterations = Integer.parseInt(val);
108e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            } catch (NumberFormatException e) {
109e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe                // Invalid argument, fall back to default value
110e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe            }
111e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe        }
112826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
1137e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        val = arguments.getString("enable_pan_iterations");
1147e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        if (val != null) {
1157e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            try {
1167e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                sEnablePanIterations = Integer.parseInt(val);
1177e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            } catch (NumberFormatException e) {
1187e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                // Invalid argument, fall back to default value
1197e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            }
1207e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        }
1217e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe
122826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        val = arguments.getString("pair_iterations");
123826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
124826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            try {
125826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                sPairIterations = Integer.parseInt(val);
126826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            } catch (NumberFormatException e) {
127826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                // Invalid argument, fall back to default value
128826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            }
129826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
130826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
131826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        val = arguments.getString("connect_a2dp_iterations");
132826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
133826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            try {
134826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                sConnectA2dpIterations = Integer.parseInt(val);
135826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            } catch (NumberFormatException e) {
136826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                // Invalid argument, fall back to default value
137826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            }
138826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
139826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
140826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        val = arguments.getString("connect_headset_iterations");
141826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
142826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            try {
143826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                sConnectHeadsetIterations = Integer.parseInt(val);
144826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            } catch (NumberFormatException e) {
145826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                // Invalid argument, fall back to default value
146826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            }
147826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
148826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
1497e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        val = arguments.getString("connect_input_iterations");
1507e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        if (val != null) {
1517e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            try {
1527e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                sConnectInputIterations = Integer.parseInt(val);
1537e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            } catch (NumberFormatException e) {
1547e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                // Invalid argument, fall back to default value
1557e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            }
1567e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        }
1577e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe
1587e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        val = arguments.getString("connect_pan_iterations");
1597e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        if (val != null) {
1607e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            try {
1617e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                sConnectPanIterations = Integer.parseInt(val);
1627e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            } catch (NumberFormatException e) {
1637e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe                // Invalid argument, fall back to default value
1647e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe            }
1657e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        }
1667e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe
167835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe        val = arguments.getString("start_stop_sco_iterations");
168835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe        if (val != null) {
169835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe            try {
170835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe                sStartStopScoIterations = Integer.parseInt(val);
171835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe            } catch (NumberFormatException e) {
172835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe                // Invalid argument, fall back to default value
173835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe            }
174835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe        }
175826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
1762b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        val = arguments.getString("device_address");
177826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
1782b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe            sDeviceAddress = val;
179826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
180826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
1812b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        val = arguments.getString("device_pair_pin");
182826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
1832b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe            byte[] pin = BluetoothDevice.convertPinToBytes(val);
1842b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe            if (pin != null) {
1852b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe                sDevicePairPin = pin;
1862b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe            }
187826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
188826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
1892b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        val = arguments.getString("device_pair_passkey");
190826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        if (val != null) {
191826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            try {
1922b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe                sDevicePairPasskey = Integer.parseInt(val);
193826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            } catch (NumberFormatException e) {
194826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe                // Invalid argument, fall back to default value
195826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe            }
196826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        }
197826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
198826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations));
199826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations));
200826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("scan_iterations=%d", sScanIterations));
201826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("pair_iterations=%d", sPairIterations));
202826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations));
203826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations));
2047e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        Log.i(TAG, String.format("connect_input_iterations=%d", sConnectInputIterations));
2057e4d0c0982cb28a86bf3d45c3b316ec7eab1e017Eric Rowe        Log.i(TAG, String.format("connect_pan_iterations=%d", sConnectPanIterations));
206835d8ee61ecddcd3fdc0aadf500d05b914ca375fEric Rowe        Log.i(TAG, String.format("start_stop_sco_iterations=%d", sStartStopScoIterations));
2072b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        Log.i(TAG, String.format("device_address=%s", sDeviceAddress));
2082b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        Log.i(TAG, String.format("device_pair_pin=%s", new String(sDevicePairPin)));
2092b1fb45fabcb6f6e6edfd1a7a8e394928a27afe8Eric Rowe        Log.i(TAG, String.format("device_pair_passkey=%d", sDevicePairPasskey));
210826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe
211826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        // Call onCreate last since we want to set the static variables first.
212826af6266c79d76b81fe850b9cd3d351597e4adbEric Rowe        super.onCreate(arguments);
213e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe    }
214e1d666b632608a2f708cb3df06c796e16d5d1717Eric Rowe}
215