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

Commit 65d1afb6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove framework/tests/stress" into main

parents 0f9c3038 4c34c47b
Loading
Loading
Loading
Loading

framework/tests/stress/Android.bp

deleted100644 → 0
+0 −32
Original line number Diff line number Diff line
package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

android_test {
    name: "BluetoothTests",

    defaults: ["framework-bluetooth-tests-defaults"],

    min_sdk_version: "current",
    target_sdk_version: "current",

    // Include all test java files.
    srcs: ["src/**/*.java"],
    jacoco: {
        include_filter: ["android.bluetooth.*"],
        exclude_filter: [],
    },
    libs: [
        "android.test.base",
        "android.test.runner",
    ],
    static_libs: [
        "androidx.test.rules",
        "junit",
        "modules-utils-bytesmatcher",
    ],
    test_suites: [
        "general-tests",
    ],
    certificate: ":com.android.bluetooth.certificate",
}
+0 −47
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.bluetooth.tests"
          android:sharedUserId="android.uid.bluetooth" >

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

    <application >
        <uses-library android:name="android.test.runner" />
    </application>
    <instrumentation android:name="android.bluetooth.BluetoothTestRunner"
            android:targetPackage="com.android.bluetooth.tests"
            android:label="Bluetooth Tests" />
    <instrumentation android:name="android.bluetooth.BluetoothInstrumentation"
            android:targetPackage="com.android.bluetooth.tests"
            android:label="Bluetooth Test Utils" />

</manifest>
 No newline at end of file
+0 −32
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Config for Bluetooth test cases">
    <option name="test-suite-tag" value="apct"/>
    <option name="test-suite-tag" value="apct-instrumentation"/>
    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="BluetoothTests.apk" />
    </target_preparer>

    <option name="test-suite-tag" value="apct"/>
    <option name="test-tag" value="BluetoothTests"/>

    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.bluetooth.tests" />
        <option name="hidden-api-checks" value="false"/>
        <option name="runner" value="android.bluetooth.BluetoothTestRunner"/>
    </test>
</configuration>
+0 −123
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.bluetooth;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Context;
import android.os.Bundle;

import java.util.Set;

public class BluetoothInstrumentation extends Instrumentation {

    private BluetoothTestUtils mUtils = null;
    private BluetoothAdapter mAdapter = null;
    private Bundle mArgs = null;
    private Bundle mSuccessResult = null;

    private BluetoothTestUtils getBluetoothTestUtils() {
        if (mUtils == null) {
            mUtils =
                    new BluetoothTestUtils(
                            getContext(), BluetoothInstrumentation.class.getSimpleName());
        }
        return mUtils;
    }

    private BluetoothAdapter getBluetoothAdapter() {
        if (mAdapter == null) {
            mAdapter =
                    ((BluetoothManager) getContext().getSystemService(Context.BLUETOOTH_SERVICE))
                            .getAdapter();
        }
        return mAdapter;
    }

    @Override
    public void onCreate(Bundle arguments) {
        super.onCreate(arguments);
        mArgs = arguments;
        // create the default result response, but only use it in success code path
        mSuccessResult = new Bundle();
        mSuccessResult.putString("result", "SUCCESS");
        start();
    }

    @Override
    public void onStart() {
        String command = mArgs.getString("command");
        if ("enable".equals(command)) {
            enable();
        } else if ("disable".equals(command)) {
            disable();
        } else if ("unpairAll".equals(command)) {
            unpairAll();
        } else if ("getName".equals(command)) {
            getName();
        } else if ("getAddress".equals(command)) {
            getAddress();
        } else if ("getBondedDevices".equals(command)) {
            getBondedDevices();
        } else {
            finish(null);
        }
    }

    public void enable() {
        getBluetoothTestUtils().enable(getBluetoothAdapter());
        finish(mSuccessResult);
    }

    public void disable() {
        getBluetoothTestUtils().disable(getBluetoothAdapter());
        finish(mSuccessResult);
    }

    public void unpairAll() {
        getBluetoothTestUtils().unpairAll(getBluetoothAdapter());
        finish(mSuccessResult);
    }

    public void getName() {
        String name = getBluetoothAdapter().getName();
        mSuccessResult.putString("name", name);
        finish(mSuccessResult);
    }

    public void getAddress() {
        String name = getBluetoothAdapter().getAddress();
        mSuccessResult.putString("address", name);
        finish(mSuccessResult);
    }

    public void getBondedDevices() {
        Set<BluetoothDevice> devices = getBluetoothAdapter().getBondedDevices();
        int i = 0;
        for (BluetoothDevice device : devices) {
            mSuccessResult.putString(String.format("device-%02d", i), device.getAddress());
            i++;
        }
        finish(mSuccessResult);
    }

    public void finish(Bundle result) {
        if (result == null) {
            result = new Bundle();
        }
        finish(Activity.RESULT_OK, result);
    }
}
+0 −90
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.bluetooth;

import android.content.Context;
import android.test.InstrumentationTestCase;

/**
 * Instrumentation test case for stress test involving rebooting the device.
 *
 * <p>This test case tests that bluetooth is enabled after a device reboot. Because the device will
 * reboot, the instrumentation must be driven by a script on the host side.
 */
public class BluetoothRebootStressTest extends InstrumentationTestCase {
    private static final String TAG = "BluetoothRebootStressTest";
    private static final String OUTPUT_FILE = "BluetoothRebootStressTestOutput.txt";

    private BluetoothTestUtils mTestUtils;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        Context context = getInstrumentation().getTargetContext();
        mTestUtils = new BluetoothTestUtils(context, TAG, OUTPUT_FILE);
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();

        mTestUtils.close();
    }

    /** Test method used to start the test by turning bluetooth on. */
    public void testStart() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        mTestUtils.enable(adapter);
    }

    /**
     * Test method used in the middle iterations of the test to check if bluetooth is on. Does not
     * toggle bluetooth after the check. Assumes that bluetooth has been turned on by {@code
     * #testStart()}
     */
    public void testMiddleNoToggle() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        assertTrue(adapter.isEnabled());
    }

    /**
     * Test method used in the middle iterations of the test to check if bluetooth is on. Toggles
     * bluetooth after the check. Assumes that bluetooth has been turned on by {@code #testStart()}
     */
    public void testMiddleToggle() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        assertTrue(adapter.isEnabled());

        mTestUtils.disable(adapter);
        mTestUtils.enable(adapter);
    }

    /**
     * Test method used in the stop the test by turning bluetooth off. Assumes that bluetooth has
     * been turned on by {@code #testStart()}
     */
    public void testStop() {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();

        assertTrue(adapter.isEnabled());

        mTestUtils.disable(adapter);
    }
}
Loading