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

Commit 9c1965c4 authored by Henri Chataing's avatar Henri Chataing
Browse files

blueberry/tests: Remove sl4a_sl4a and gd_sl4a tests

Bug: 333555245
Test: None
Flag: EXEMPT, dead code removal
Change-Id: I2dc2a537a5b9f2146039c22258edad7f95453d0d
parent 4521cb17
Loading
Loading
Loading
Loading
+0 −62
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.sl4a_sl4a.lib import sl4a_sl4a_base_test
from blueberry.tests.gd_sl4a.lib.bt_constants import ble_address_types
from mobly import test_runner


class LeAdvertisingTest(sl4a_sl4a_base_test.Sl4aSl4aBaseTestClass):

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

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

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

    def test_advertise_name(self):
        rpa_address = self.cert_advertiser_.advertise_public_extended_pdu()
        self.dut_scanner_.scan_for_name(self.cert_advertiser_.get_local_advertising_name())
        self.dut_scanner_.stop_scanning()
        self.cert_advertiser_.stop_advertising()

    def test_advertise_name_stress(self):
        for i in range(0, 10):
            self.test_advertise_name()

    def test_advertise_name_twice_no_stop(self):
        rpa_address = self.cert_advertiser_.advertise_public_extended_pdu()
        self.dut_scanner_.scan_for_name(self.cert_advertiser_.get_local_advertising_name())
        self.dut_scanner_.stop_scanning()
        rpa_address = self.cert_advertiser_.advertise_public_extended_pdu()
        self.dut_scanner_.scan_for_name(self.cert_advertiser_.get_local_advertising_name())
        self.dut_scanner_.stop_scanning()
        self.cert_advertiser_.stop_advertising()


if __name__ == '__main__':
    test_runner.main()
+0 −970

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −148
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2021 - 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 io
import logging
import os
import queue

from blueberry.facade import common_pb2 as common
from blueberry.tests.gd.cert.context import get_current_context
from blueberry.tests.gd.cert.truth import assertThat
from blueberry.tests.gd_sl4a.lib.ble_lib import generate_ble_advertise_objects
from blueberry.tests.gd_sl4a.lib.ble_lib import generate_ble_scan_objects
from blueberry.tests.gd_sl4a.lib.bt_constants import adv_succ
from blueberry.tests.gd_sl4a.lib.bt_constants import ble_address_types
from blueberry.tests.gd_sl4a.lib.bt_constants import ble_advertise_settings_modes
from blueberry.tests.gd_sl4a.lib.bt_constants import ble_scan_settings_modes
from blueberry.tests.gd_sl4a.lib.bt_constants import scan_result
from blueberry.tests.sl4a_sl4a.lib import sl4a_sl4a_base_test
from blueberry.utils.bt_gatt_constants import GattCallbackString
from blueberry.utils.bt_gatt_constants import GattTransport
from mobly import test_runner
from mobly.controllers.android_device_lib.adb import AdbError


class GattConnectWithIrkTest(sl4a_sl4a_base_test.Sl4aSl4aBaseTestClass):

    def setup_class(self):
        super().setup_class()
        self.default_timeout = 10  # seconds

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

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

    def _wait_for_event(self, expected_event_name, device):
        try:
            event_info = device.ed.pop_event(expected_event_name, self.default_timeout)
            logging.info(event_info)
        except queue.Empty as error:
            logging.error("Failed to find event: %s", expected_event_name)
            return False
        return True

    def _wait_for_scan_result_event(self, expected_event_name, device):
        try:
            event_info = device.ed.pop_event(expected_event_name, self.default_timeout)
        except queue.Empty as error:
            logging.error("Could not find scan result event: %s", expected_event_name)
            return None
        return event_info['data']['Result']['deviceInfo']['address']

    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 test_scan_connect_unbonded_device_public_address_with_irk(self):
        # Set up SL4A cert side to advertise
        logging.info("Starting advertising")
        self.cert.sl4a.bleSetAdvertiseSettingsIsConnectable(True)
        self.cert.sl4a.bleSetAdvertiseDataIncludeDeviceName(True)
        self.cert.sl4a.bleSetAdvertiseSettingsAdvertiseMode(ble_advertise_settings_modes['low_latency'])
        self.cert.sl4a.bleSetAdvertiseSettingsOwnAddressType(common.RANDOM_DEVICE_ADDRESS)
        advertise_callback, advertise_data, advertise_settings = generate_ble_advertise_objects(self.cert.sl4a)
        self.cert.sl4a.bleStartBleAdvertising(advertise_callback, advertise_data, advertise_settings)

        # Wait for SL4A cert to start advertising
        assertThat(self._wait_for_event(adv_succ.format(advertise_callback), self.cert)).isTrue()
        logging.info("Advertising started")

        # Pull IRK from SL4A cert side to pass in from SL4A DUT side when scanning
        cert_public_address, irk = self._get_cert_public_address_and_irk_from_bt_config()

        # Set up SL4A DUT side to scan
        addr_type = ble_address_types["public"]
        logging.info("Start scanning for PUBLIC_ADDRESS %s with address type %d and IRK %s" %
                     (cert_public_address, addr_type, irk))
        self.dut.sl4a.bleSetScanSettingsScanMode(ble_scan_settings_modes['low_latency'])
        self.dut.sl4a.bleSetScanSettingsLegacy(False)
        filter_list, scan_settings, scan_callback = generate_ble_scan_objects(self.dut.sl4a)
        expected_event_name = scan_result.format(scan_callback)

        # Start scanning on SL4A DUT
        self.dut.sl4a.bleSetScanFilterDeviceAddressTypeAndIrkHexString(cert_public_address, int(addr_type), irk)
        self.dut.sl4a.bleBuildScanFilter(filter_list)
        self.dut.sl4a.bleStartBleScan(filter_list, scan_settings, scan_callback)
        logging.info("Started scanning")

        # Verify that scan result is received on SL4A DUT
        mac_address = self._wait_for_scan_result_event(expected_event_name, self.dut)
        assertThat(mac_address).isNotNone()
        logging.info("Filter advertisement with address {}".format(mac_address))

        # Try to connect GATT
        gatt_callback = self.dut.sl4a.gattCreateGattCallback()
        bluetooth_gatt = self.dut.sl4a.gattClientConnectGatt(gatt_callback, mac_address, False,
                                                             GattTransport.TRANSPORT_LE, False, None)
        assertThat(bluetooth_gatt).isNotNone()

        # Verify that GATT connect event occurs on SL4A DUT
        expected_event_name = GattCallbackString.GATT_CONN_CHANGE.format(gatt_callback)
        assertThat(self._wait_for_event(expected_event_name, self.dut)).isTrue()

        # Test over
        self.cert.sl4a.bleStopBleAdvertising(advertise_callback)
        self.dut.sl4a.bleStopBleScan(scan_callback)


if __name__ == '__main__':
    test_runner.main()
+0 −98
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
# Copyright (C) 2016 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.
"""
This test script exercises GATT notify/indicate procedures.

Original location:
  tools/test/connectivity/acts_tests/tests/google/ble/gatt/GattNotifyTest.py
"""

from blueberry.tests.gd.cert.test_decorators import test_tracker_info

from blueberry.tests.gd.cert.truth import assertThat
from blueberry.tests.sl4a_sl4a.lib import gatt_connected_base_test
from blueberry.utils.bt_gatt_constants import GattCharDesc
from blueberry.utils.bt_gatt_constants import GattDescriptor
from blueberry.utils.bt_gatt_constants import GattEvent
from mobly import test_runner


class GattNotifyTest(gatt_connected_base_test.GattConnectedBaseTest):

    @test_tracker_info(uuid='e0ba60af-c1f2-4516-a5d5-89e2def0c757')
    def test_notify_char(self):
        """Test notify characteristic value.

        Test GATT notify characteristic value.

        Steps:
        1. Central: write CCC - register for notifications.
        2. Peripheral: receive CCC modification.
        3. Peripheral: send characteristic notification.
        4. Central: receive notification, verify it's conent matches what was
           sent

        Expected Result:
        Verify that notification registration and delivery works.

        Returns:
          Pass if True
          Fail if False

        TAGS: LE, GATT, Characteristic
        Priority: 0
        """
        # write CCC descriptor to enable notifications
        self.central.sl4a.gattClientDescriptorSetValue(
            self.bluetooth_gatt, self.discovered_services_index, self.test_service_index, self.NOTIFIABLE_CHAR_UUID,
            GattCharDesc.GATT_CLIENT_CHARAC_CFG_UUID, GattDescriptor.ENABLE_NOTIFICATION_VALUE)

        self.central.sl4a.gattClientWriteDescriptor(self.bluetooth_gatt, self.discovered_services_index,
                                                    self.test_service_index, self.NOTIFIABLE_CHAR_UUID,
                                                    GattCharDesc.GATT_CLIENT_CHARAC_CFG_UUID)

        # enable notifications in app
        self.central.sl4a.gattClientSetCharacteristicNotification(self.bluetooth_gatt, self.discovered_services_index,
                                                                  self.test_service_index, self.NOTIFIABLE_CHAR_UUID,
                                                                  True)

        event = self._server_wait(GattEvent.DESC_WRITE_REQ)

        request_id = event['data']['requestId']
        bt_device_id = 0
        status = 0
        # confirm notification registration was successful
        self.peripheral.sl4a.gattServerSendResponse(self.gatt_server, bt_device_id, request_id, status, 0, [])
        # wait for client to get response
        event = self._client_wait(GattEvent.DESC_WRITE)

        # set notified value
        notified_value = [1, 5, 9, 7, 5, 3, 6, 4, 8, 2]
        self.peripheral.sl4a.gattServerCharacteristicSetValue(self.notifiable_char_index, notified_value)

        # send notification
        self.peripheral.sl4a.gattServerNotifyCharacteristicChanged(self.gatt_server, bt_device_id,
                                                                   self.notifiable_char_index, False)

        # wait for client to receive the notification
        event = self._client_wait(GattEvent.CHAR_CHANGE)
        assertThat(event["data"]["CharacteristicValue"]).isEqualTo(notified_value)

        return True


if __name__ == '__main__':
    test_runner.main()
+0 −169
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 LeL2capCoCTest(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):
        self.dut_scanner_.stop_scanning()
        self.cert_advertiser_.stop_advertising()
        self.dut_security_.remove_all_bonded_devices()
        self.cert_security_.remove_all_bonded_devices()
        super().teardown_test()

    # Scans for the cert device by name. We expect to get back a RPA.
    def __scan_for_cert_by_name(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)

        return scan_result_addr

    def __scan_for_irk(self):
        cert_public_address, irk = self.__get_cert_public_address_and_irk_from_bt_config()
        rpa_address = self.cert_advertiser_.advertise_public_extended_pdu()
        id_addr = self.dut_scanner_.scan_for_address_with_irk(cert_public_address, ble_address_types["public"], irk)
        self.dut_scanner_.stop_scanning()
        return id_addr

    def __create_le_bond_oob_single_sided(self,
                                          wait_for_oob_data=True,
                                          wait_for_device_bonded=True,
                                          addr=None,
                                          addr_type=ble_address_types["random"]):
        oob_data = self.cert_security_.generate_oob_data(Security.TRANSPORT_LE, wait_for_oob_data)
        if wait_for_oob_data:
            assertThat(oob_data[0]).isEqualTo(0)
            assertThat(oob_data[1]).isNotNone()
        self.dut_security_.create_bond_out_of_band(oob_data[1], addr, addr_type, wait_for_device_bonded)
        return oob_data[1].to_sl4a_address()

    def __create_le_bond_oob_double_sided(self,
                                          wait_for_oob_data=True,
                                          wait_for_device_bonded=True,
                                          addr=None,
                                          addr_type=ble_address_types["random"]):
        # Genearte OOB data on DUT, but we don't use it
        self.dut_security_.generate_oob_data(Security.TRANSPORT_LE, wait_for_oob_data)
        self.__create_le_bond_oob_single_sided(wait_for_oob_data, wait_for_device_bonded, addr, addr_type)

    def __test_le_l2cap_insecure_coc(self):
        logging.info("Testing insecure L2CAP CoC")
        cert_rpa = self.__scan_for_cert_by_name()

        # Listen on an insecure l2cap coc on the cert
        psm = self.cert_l2cap_.listen_using_l2cap_le_coc(False)
        self.dut_l2cap_.create_l2cap_le_coc(cert_rpa, psm, False)

        # Cleanup
        self.dut_scanner_.stop_scanning()
        self.dut_l2cap_.close_l2cap_le_coc_client()
        self.cert_advertiser_.stop_advertising()
        self.cert_l2cap_.close_l2cap_le_coc_server()

    def __test_le_l2cap_secure_coc(self):
        logging.info("Testing secure L2CAP CoC")
        cert_rpa = self.__create_le_bond_oob_single_sided()

        # Listen on an secure l2cap coc on the cert
        psm = self.cert_l2cap_.listen_using_l2cap_le_coc(True)
        self.dut_l2cap_.create_l2cap_le_coc(cert_rpa, psm, True)

        # Cleanup
        self.dut_scanner_.stop_scanning()
        self.dut_l2cap_.close_l2cap_le_coc_client()
        self.cert_advertiser_.stop_advertising()
        self.cert_l2cap_.close_l2cap_le_coc_server()
        self.dut_security_.remove_all_bonded_devices()
        self.cert_security_.remove_all_bonded_devices()

    def __test_le_l2cap_secure_coc_after_irk_scan(self):
        logging.info("Testing secure L2CAP CoC after IRK scan")
        cert_config_addr, irk = self.__get_cert_public_address_and_irk_from_bt_config()
        cert_id_addr = self.__scan_for_irk()

        assertThat(cert_id_addr).isEqualTo(cert_config_addr)
        self.__create_le_bond_oob_single_sided(True, True, cert_id_addr, ble_address_types["public"])
        self.cert_advertiser_.stop_advertising()
        self.__test_le_l2cap_secure_coc()

    def __test_secure_le_l2cap_coc_stress(self):
        for i in range(0, 10):
            self.__test_le_l2cap_secure_coc()

    def __test_insecure_le_l2cap_coc_stress(self):
        for i in range(0, 10):
            self.__test_le_l2cap_insecure_coc()

    def __test_le_l2cap_coc_stress(self):
        #for i in range (0, 10):
        self.__test_le_l2cap_insecure_coc()
        self.__test_le_l2cap_secure_coc()

    def __test_secure_le_l2cap_coc_after_irk_scan_stress(self):
        for i in range(0, 10):
            self.__test_le_l2cap_secure_coc_after_irk_scan()
Loading