Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9acd79f authored by Eric Rowe's avatar Eric Rowe
Browse files

DO NOT MERGE Add additional options and receiver to BT tests

Add address and iterations options to bluetooth pair stress test.  Refactored
BroadcastReceiver into two receivers with one specific to pairing.  The pairing
receiver checks that we are pairing with the correct device, and also will
accept the pairing dialogue/enter a predefined password automatically.

Change-Id: I9c5283f8e9747e8b0129b7400a6b1345e78e46eb
parent b6634127
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -80,12 +80,17 @@ public class BluetoothStressTest extends InstrumentationTestCase {
    }

    public void testPair() {
        int iterations = BluetoothTestRunner.sPairIterations;
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sHeadsetAddress);

        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sPairAddress);
        mTestUtils.enable(adapter);
        mTestUtils.pair(adapter, device);

        for (int i = 0; i < iterations; i++) {
            mTestUtils.writeOutput("pair iteration " + (i + 1) + " of " + iterations);
            mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
                    BluetoothTestRunner.sPairPin);
            mTestUtils.unpair(adapter, device);
        }
        mTestUtils.disable(adapter);
    }

@@ -95,7 +100,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sA2dpAddress);

        mTestUtils.enable(adapter);
        mTestUtils.pair(adapter, device);
        mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
                BluetoothTestRunner.sPairPin);

        for (int i = 0; i < iterations; i++) {
            mTestUtils.writeOutput("connectA2dp iteration " + (i + 1) + " of " + iterations);
@@ -113,7 +119,8 @@ public class BluetoothStressTest extends InstrumentationTestCase {
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sHeadsetAddress);

        mTestUtils.enable(adapter);
        mTestUtils.pair(adapter, device);
        mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
                BluetoothTestRunner.sPairPin);

        for (int i = 0; i < iterations; i++) {
            mTestUtils.writeOutput("connectHeadset iteration " + (i + 1) + " of " + iterations);
+33 −0
Original line number Diff line number Diff line
@@ -26,12 +26,17 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {
    public static int sEnableIterations = 100;
    public static int sDiscoverableIterations = 1000;
    public static int sScanIterations = 1000;
    public static int sPairIterations = 100;
    public static int sConnectHeadsetIterations = 100;
    public static int sConnectA2dpIterations = 100;

    public static String sPairAddress = "";
    public static String sHeadsetAddress = "";
    public static String sA2dpAddress = "";

    public static byte[] sPairPin = {'1', '2', '3', '4'};
    public static int sPairPasskey = 123456;

    @Override
    public TestSuite getAllTests() {
        TestSuite suite = new InstrumentationTestSuite(this);
@@ -75,6 +80,15 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {
            }
        }

        val = arguments.getString("pair_iterations");
        if (val != null) {
            try {
                sPairIterations = Integer.parseInt(val);
            } catch (NumberFormatException e) {
                // Invalid argument, fall back to default value
            }
        }

        val = arguments.getString("connect_a2dp_iterations");
        if (val != null) {
            try {
@@ -93,6 +107,11 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {
            }
        }

        val = arguments.getString("pair_address");
        if (val != null) {
            sPairAddress = val;
        }

        val = arguments.getString("headset_address");
        if (val != null) {
            sHeadsetAddress = val;
@@ -102,5 +121,19 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {
        if (val != null) {
            sA2dpAddress = val;
        }

        val = arguments.getString("pair_pin");
        if (val != null) {
            sPairPin = BluetoothDevice.convertPinToBytes(val);
        }

        val = arguments.getString("pair_passkey");
        if (val != null) {
            try {
                sPairPasskey = Integer.parseInt(val);
            } catch (NumberFormatException e) {
                // Invalid argument, fall back to default value
            }
        }
    }
}
+246 −151

File changed.

Preview size limit exceeded, changes collapsed.