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

Commit e19b3893 authored by Eric Rowe's avatar Eric Rowe Committed by Android (Google) Code Review
Browse files

Merge "Modify bluetooth test cases GB for new HC APIs"

parents 4c9d691a 826af626
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ public class BluetoothStressTest extends InstrumentationTestCase {

    public void testEnable() {
        int iterations = BluetoothTestRunner.sEnableIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        for (int i = 0; i < iterations; i++) {
@@ -53,6 +57,10 @@ public class BluetoothStressTest extends InstrumentationTestCase {

    public void testDiscoverable() {
        int iterations = BluetoothTestRunner.sDiscoverableIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        mTestUtils.enable(adapter);

@@ -67,6 +75,10 @@ public class BluetoothStressTest extends InstrumentationTestCase {

    public void testScan() {
        int iterations = BluetoothTestRunner.sScanIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        mTestUtils.enable(adapter);

@@ -78,4 +90,67 @@ public class BluetoothStressTest extends InstrumentationTestCase {

        mTestUtils.disable(adapter);
    }

    public void testPair() {
        int iterations = BluetoothTestRunner.sPairIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sPairAddress);
        mTestUtils.enable(adapter);

        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);
    }

    public void testConnectA2dp() {
        int iterations = BluetoothTestRunner.sConnectA2dpIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sA2dpAddress);
        mTestUtils.enable(adapter);
        mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
                BluetoothTestRunner.sPairPin);

        for (int i = 0; i < iterations; i++) {
            mTestUtils.writeOutput("connectA2dp iteration " + (i + 1) + " of " + iterations);
            mTestUtils.connectProfile(adapter, device, BluetoothProfile.A2DP);
            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.A2DP);
        }

        // TODO: Unpair from device if device can accept pairing after unpairing
        mTestUtils.disable(adapter);
    }

    public void testConnectHeadset() {
        int iterations = BluetoothTestRunner.sConnectHeadsetIterations;
        if (iterations == 0) {
            return;
        }

        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = adapter.getRemoteDevice(BluetoothTestRunner.sHeadsetAddress);
        mTestUtils.enable(adapter);
        mTestUtils.pair(adapter, device, BluetoothTestRunner.sPairPasskey,
                BluetoothTestRunner.sPairPin);

        for (int i = 0; i < iterations; i++) {
            mTestUtils.writeOutput("connectHeadset iteration " + (i + 1) + " of " + iterations);
            mTestUtils.connectProfile(adapter, device, BluetoothProfile.HEADSET);
            mTestUtils.disconnectProfile(adapter, device, BluetoothProfile.HEADSET);
        }

        // TODO: Unpair from device if device can accept pairing after unpairing
        mTestUtils.disable(adapter);
    }
}
+84 −2
Original line number Diff line number Diff line
@@ -21,11 +21,24 @@ import junit.framework.TestSuite;
import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
import android.util.Log;

public class BluetoothTestRunner extends InstrumentationTestRunner {
    private static final String TAG = "BluetoothTestRunner";

    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() {
@@ -41,8 +54,6 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {

    @Override
    public void onCreate(Bundle arguments) {
        super.onCreate(arguments);

        String val = arguments.getString("enable_iterations");
        if (val != null) {
            try {
@@ -69,5 +80,76 @@ public class BluetoothTestRunner extends InstrumentationTestRunner {
                // Invalid argument, fall back to default value
            }
        }

        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 {
                sConnectA2dpIterations = Integer.parseInt(val);
            } catch (NumberFormatException e) {
                // Invalid argument, fall back to default value
            }
        }

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

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

        val = arguments.getString("headset_address");
        if (val != null) {
            sHeadsetAddress = val;
        }

        val = arguments.getString("a2dp_address");
        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
            }
        }

        Log.i(TAG, String.format("enable_iterations=%d", sEnableIterations));
        Log.i(TAG, String.format("discoverable_iterations=%d", sDiscoverableIterations));
        Log.i(TAG, String.format("scan_iterations=%d", sScanIterations));
        Log.i(TAG, String.format("pair_iterations=%d", sPairIterations));
        Log.i(TAG, String.format("connect_a2dp_iterations=%d", sConnectA2dpIterations));
        Log.i(TAG, String.format("connect_headset_iterations=%d", sConnectHeadsetIterations));
        Log.i(TAG, String.format("pair_address=%s", sPairAddress));
        Log.i(TAG, String.format("a2dp_address=%s", sA2dpAddress));
        Log.i(TAG, String.format("headset_address=%s", sHeadsetAddress));
        Log.i(TAG, String.format("pair_pin=%s", new String(sPairPin)));
        Log.i(TAG, String.format("pair_passkey=%d", sPairPasskey));

        // Call onCreate last since we want to set the static variables first.
        super.onCreate(arguments);
    }
}
+651 −133

File changed.

Preview size limit exceeded, changes collapsed.