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

Commit 1b7dedaa authored by Martin Brabham's avatar Martin Brabham
Browse files

Blueberry2: SL4A + SL4AA OobPairingTest

Bug: 236738437
Test: mma -j $(nproc)
Test: ./build.py
Test: system/gd/cert/run --clean --sl4a_sl4a OobPairingTest
Tag: #stability
Ignore-AOSP-First: Need in tm-dev stat and can't put it in AOSP yet
Change-Id: I57cdfe7f2603f94308bcca1820038575b328eb67
parent 7cae0f83
Loading
Loading
Loading
Loading
+115 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2022 - 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.

import binascii
import io
import logging
import os
import queue

from blueberry.tests.gd.cert.context import get_current_context
from blueberry.tests.gd.cert.truth import assertThat
from blueberry.tests.gd_sl4a.lib.bt_constants import ble_address_types
from blueberry.tests.sl4a_sl4a.lib import sl4a_sl4a_base_test
from blueberry.tests.sl4a_sl4a.lib.security import Security


class OobPairingTest(sl4a_sl4a_base_test.Sl4aSl4aBaseTestClass):

    def __get_cert_public_address_and_irk_from_bt_config(self):
        # Pull IRK from SL4A cert side to pass in from SL4A DUT side when scanning
        bt_config_file_path = os.path.join(get_current_context().get_full_output_path(),
                                           "DUT_%s_bt_config.conf" % self.cert.serial)
        try:
            self.cert.adb.pull(["/data/misc/bluedroid/bt_config.conf", bt_config_file_path])
        except AdbError as error:
            logging.error("Failed to pull SL4A cert BT config")
            return False
        logging.debug("Reading SL4A cert BT config")
        with io.open(bt_config_file_path) as f:
            for line in f.readlines():
                stripped_line = line.strip()
                if (stripped_line.startswith("Address")):
                    address_fields = stripped_line.split(' ')
                    # API currently requires public address to be capitalized
                    address = address_fields[2].upper()
                    logging.debug("Found cert address: %s" % address)
                    continue
                if (stripped_line.startswith("LE_LOCAL_KEY_IRK")):
                    irk_fields = stripped_line.split(' ')
                    irk = irk_fields[2]
                    logging.debug("Found cert IRK: %s" % irk)
                    continue

        return address, irk

    def setup_class(self):
        super().setup_class()

    def setup_test(self):
        assertThat(super().setup_test()).isTrue()

    def teardown_test(self):
        super().teardown_test()

    def __test_scan(self, address_type="public"):
        cert_public_address, irk = self.__get_cert_public_address_and_irk_from_bt_config()
        rpa_address = self.cert_advertiser_.advertise_rpa_public_extended_pdu()
        self.dut_scanner_.start_identity_address_scan(cert_public_address, ble_address_types[address_type])
        self.dut_scanner_.stop_scanning()
        self.cert_advertiser_.stop_advertising()

    def test_classic_generate_local_oob_data(self):
        oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_BREDR)
        assertThat(oob_data).isNotNone()
        oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_BREDR)
        assertThat(oob_data).isNotNone()

    def test_classic_generate_local_oob_data_stress(self):
        for i in range(1, 20):
            oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_BREDR)
            assertThat(oob_data).isNotNone()
            oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_BREDR)
            assertThat(oob_data).isNotNone()

    def test_le_generate_local_oob_data(self):
        oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_LE)
        assertThat(oob_data).isNotNone()
        oob_data = self.cert_security_.generate_oob_data(Security.TRANSPORT_LE)
        assertThat(oob_data).isNotNone()

    def test_le_generate_local_oob_data_stress(self):
        for i in range(1, 20):
            oob_data = self.dut_security_.generate_oob_data(Security.TRANSPORT_LE)
            assertThat(oob_data).isNotNone()
            oob_data = self.cert_security_.generate_oob_data(Security.TRANSPORT_LE)
            assertThat(oob_data).isNotNone()

    def test_le_bond_oob(self):
        oob_data = self.cert_security_.generate_oob_data(Security.TRANSPORT_LE)
        assertThat(oob_data).isNotNone()
        self.dut_security_.create_bond_out_of_band(oob_data)

    def test_le_bond_oob_stress(self):
        for i in range(0, 10):
            logging.info("Stress #%d" % i)
            self.test_le_bond_oob()
            self.dut_security_.remove_all_bonded_devices()
            self.cert_security_.remove_all_bonded_devices()

    def test_le_generate_local_oob_data_after_le_bond_oob(self):
        self.test_le_bond_oob()
        self.test_le_generate_local_oob_data()
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
from blueberry.tests.sl4a_sl4a.gatt.gatt_connect_test import GattConnectTest
from blueberry.tests.sl4a_sl4a.gatt.gatt_connect_with_irk_test import GattConnectWithIrkTest
from blueberry.tests.sl4a_sl4a.gatt.gatt_notify_test import GattNotifyTest
from blueberry.tests.sl4a_sl4a.security.oob_pairing_test import OobPairingTest

from mobly import suite_runner
import argparse
@@ -25,6 +26,7 @@ ALL_TESTS = [
    GattConnectTest,
    GattConnectWithIrkTest,
    GattNotifyTest,
    OobPairingTest,
]