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

Commit a89fd654 authored by Martin Brabham's avatar Martin Brabham
Browse files

Floss: LeRand BTIF + Topshim + Topshim test

This allows the application to generate a random number with the
controller.

This is being used by #floss in order to synchronize the suspend/resume
calls.

Bug: 219982747
Bug: 220182854
Test: system/gd/cert/run_topshim
Test: mma -j $(nproc)
Test: ./build.py
Tag: #floss
Change-Id: I59af5449ac3e8aa2eb8a4eb174829dba90b9d132
parent bd9f7462
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -623,6 +623,10 @@ static void switch_codec_callback(bool is_low_latency_buffer_size) {
                               (jboolean)is_low_latency_buffer_size);
}

static void le_rand_callback(uint64_t random) {
  // Android doesn't support the LeRand API.
}

static void callback_thread_event(bt_cb_thread_evt event) {
  if (event == ASSOCIATE_JVM) {
    JavaVMAttachArgs args;
@@ -701,7 +705,8 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks),
                                             link_quality_report_callback,
                                             generate_local_oob_data_callback,
                                             switch_buffer_size_callback,
                                             switch_codec_callback};
                                             switch_codec_callback,
                                             le_rand_callback};

// The callback to call when the wake alarm fires.
static alarm_cb sAlarmCallback;
+2 −0
Original line number Diff line number Diff line
@@ -12,11 +12,13 @@ service AdapterService {
  rpc ClearEventMask(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc ClearFilterAcceptList(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc DisconnectAllAcls(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc LeRand(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}

enum EventType {
  ADAPTER_STATE = 0;
  SSP_REQUEST = 1;
  LE_RAND = 2;
}
message FetchEventsRequest {}

+6 −0
Original line number Diff line number Diff line
@@ -55,9 +55,12 @@ class AdapterAutomationHelper():
    async def get_next_event(self):
        while True:
            e = await self.adapter_event_stream.read()
            print(e)
            # Match event by some condition.
            if e.event_type == facade_pb2.EventType.ADAPTER_STATE and e.data == "ON" and self.pending_future is not None:
                self.pending_future.set_result(True)
            if e.event_type == facade_pb2.EventType.LE_RAND:
                self.pending_future.set_result(True)

    async def verify_adapter_started(self):
        await asyncio.wait_for(self.pending_future, AdapterAutomationHelper.DEFAULT_TIMEOUT)
@@ -74,6 +77,9 @@ class AdapterAutomationHelper():
    async def disconnect_all_acls(self):
        await self.adapter_stub.DisconnectAllAcls(empty_proto.Empty())

    async def le_rand(self):
        await self.adapter_stub.LeRand(empty_proto.Empty())


class A2dpAutomationHelper():
    """Invoke gRPC on topshim for A2DP testing"""
+8 −7
Original line number Diff line number Diff line
@@ -18,24 +18,25 @@ import asyncio
from mobly import test_runner
from blueberry.tests.gd.rust.topshim.facade import topshim_base_test
from blueberry.tests.gd.rust.topshim.facade.automation_helper import AdapterAutomationHelper
import time


class SuspendTest(topshim_base_test.TopshimBaseTest):

    async def _test_verify_event_filter_cleared(self):
    async def _test_verify_suspend(self):
        self.dut_adapter = AdapterAutomationHelper(port=self.dut_port)
        event_loop = asyncio.get_running_loop()
        self.dut_adapter.fetch_events(event_loop)
        self.dut_adapter.pending_future = event_loop.create_future()
        await self.dut_adapter.clear_event_filter()
        #TODO(optedoblivion): Replace sleep with a call to LeGetRandom and synchronize on
        # the callback
        time.sleep(1)
        await self.dut_adapter.le_rand()
        await asyncio.wait_for(self.dut_adapter.pending_future, AdapterAutomationHelper.DEFAULT_TIMEOUT)
        self.dut_adapter.fetch_events(event_loop)
        self.dut_adapter.pending_future = event_loop.create_future()
        await asyncio.wait_for(self.dut_adapter.pending_future, AdapterAutomationHelper.DEFAULT_TIMEOUT)
        self.dut_adapter.event_handler.cancel()

    def test_verify_event_filter_cleared(self):
        asyncio.run(self._test_verify_event_filter_cleared())
    def test_verify_suspend(self):
        asyncio.run(self._test_verify_suspend())


if __name__ == "__main__":
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ void btif_dm_clear_filter_accept_list();

void btif_dm_disconnect_all_acls();

void btif_dm_le_rand(LeRandCallback callback);

/*callout for reading SMP properties from Text file*/
bool btif_dm_get_smp_config(tBTE_APPL_CFG* p_cfg);

Loading