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

Commit 3cc11eaa authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Adds SL4A_SL4A test for LE scanning

Tag: #stability
Bug: 249828494
Test: system/gd/cert/run --clean --sl4a_sl4a LeScanningTest
Ignore-AOSP-First: Merging into QPR branch first
Change-Id: I8a9d0b67d41a40ff62ce5d7c8b886e2de562c5c4
parent 3ae98d68
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class LeScanner(Closable):
    def scan_for_address_expect_none(self, address, addr_type):
        if self.is_scanning:
            print("Already scanning!")
            return
            return None
        self.is_scanning = True
        logging.info("Start scanning for identity address {} or type {}".format(address, addr_type))
        self.device.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
@@ -66,11 +66,12 @@ class LeScanner(Closable):
        advertising_address = self.__wait_for_scan_result_event(expected_event_name, 1)
        assertThat(advertising_address).isNone()
        logging.info("Filter advertisement with address {}".format(advertising_address))
        return advertising_address

    def scan_for_address(self, address, addr_type):
        if self.is_scanning:
            print("Already scanning!")
            return
            return None
        self.is_scanning = True
        logging.info("Start scanning for identity address {} or type {}".format(address, addr_type))
        self.device.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
@@ -87,11 +88,12 @@ class LeScanner(Closable):
        advertising_address = self.__wait_for_scan_result_event(expected_event_name)
        assertThat(advertising_address).isNotNone()
        logging.info("Filter advertisement with address {}".format(advertising_address))
        return advertising_address

    def scan_for_address_with_irk(self, address, addr_type, irk):
        if self.is_scanning:
            print("Already scanning!")
            return
            return None
        self.is_scanning = True
        logging.info("Start scanning for identity address {} or type {} using irk {}".format(address, addr_type, irk))
        self.device.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
@@ -108,11 +110,12 @@ class LeScanner(Closable):
        advertising_address = self.__wait_for_scan_result_event(expected_event_name)
        assertThat(advertising_address).isNotNone()
        logging.info("Filter advertisement with address {}".format(advertising_address))
        return advertising_address

    def scan_for_address_with_irk_pending_intent(self, address, addr_type, irk):
        if self.is_scanning:
            print("Already scanning!")
            return
            return None
        self.is_scanning = True
        logging.info("Start scanning for identity address {} or type {} using irk {}".format(address, addr_type, irk))
        self.device.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
@@ -131,6 +134,7 @@ class LeScanner(Closable):
        advertising_address = self.__wait_for_scan_result_event(expected_event_name)
        assertThat(advertising_address).isNotNone()
        logging.info("Filter advertisement with address {}".format(advertising_address))
        return advertising_address

    def scan_for_name(self, name):
        if self.is_scanning:
+91 −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
import time

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 LeScanningTest(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_result_address(self):
        cert_public_address, irk = self.__get_cert_public_address_and_irk_from_bt_config()
        self.cert_advertiser_.advertise_public_extended_pdu()
        advertising_name = self.cert_advertiser_.get_local_advertising_name()

        # Scan with name and verify we get back a scan result with the RPA
        scan_result_addr = self.dut_scanner_.scan_for_name(advertising_name)
        assertThat(scan_result_addr).isNotNone()
        assertThat(scan_result_addr).isNotEqualTo(cert_public_address)

        # Bond
        logging.info("Bonding with %s", scan_result_addr)
        self.dut_security_.create_bond_numeric_comparison(scan_result_addr)
        self.dut_scanner_.stop_scanning()

        # Start advertising again and scan for identity address
        scan_result_addr = self.dut_scanner_.scan_for_address(cert_public_address, ble_address_types["public"])
        assertThat(scan_result_addr).isNotNone()
        assertThat(scan_result_addr).isNotEqualTo(cert_public_address)

        # Teardown advertiser and scanner
        self.dut_scanner_.stop_scanning()
        self.cert_advertiser_.stop_advertising()
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ from blueberry.tests.sl4a_sl4a.advertising.le_advertising import LeAdvertisingTe
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.scanning.le_scanning import LeScanningTest
from blueberry.tests.sl4a_sl4a.security.irk_rotation_test import IrkRotationTest
from blueberry.tests.sl4a_sl4a.security.oob_pairing_test import OobPairingTest

@@ -30,6 +31,7 @@ ALL_TESTS = [
    GattNotifyTest,
    IrkRotationTest,
    LeAdvertisingTest,
    LeScanningTest,
    OobPairingTest,
]