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

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

Revert "Revert "Floss: Add new Suspend Topshim test""

This reverts commit 976c9242.

Bug: 220174310
Test: mm -j $(nproc) device-tests platform_tests
Tag: #floss
Change-Id: I572ae1e88439f4b15edaefbbd8d98a0f93cf2be7
parent 0b9e24b4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
syntax = "proto3";

import "google/protobuf/empty.proto";

package blueberry.facade.topshim;

service AdapterService {
  rpc FetchEvents(FetchEventsRequest) returns (stream FetchEventsResponse) {}
  rpc ToggleStack(ToggleStackRequest) returns (ToggleStackResponse) {}
  rpc SetDiscoveryMode(SetDiscoveryModeRequest) returns (SetDiscoveryModeResponse) {}
  rpc ClearEventFilter(google.protobuf.Empty) returns (google.protobuf.Empty) {}
}

enum EventType {
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import grpc
from blueberry.facade.topshim import facade_pb2
from blueberry.facade.topshim import facade_pb2_grpc

from google.protobuf import empty_pb2 as empty_proto


class AdapterAutomationHelper():
    # Timeout for async wait
@@ -60,6 +62,9 @@ class AdapterAutomationHelper():
    async def verify_adapter_started(self):
        await asyncio.wait_for(self.pending_future, AdapterAutomationHelper.DEFAULT_TIMEOUT)

    async def clear_event_filter(self):
        await self.adapter_stub.ClearEventFilter(empty_proto.Empty())


class A2dpAutomationHelper():
    """Invoke gRPC on topshim for A2DP testing"""
+42 −0
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 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):
        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)
        self.dut_adapter.event_handler.cancel()

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


if __name__ == "__main__":
    test_runner.main()
+3 −2
Original line number Diff line number Diff line
@@ -20,7 +20,8 @@ import os
import argparse

TEST_SUITES = [
    "blueberry.tests.gd.rust.topshim.facade.adapter_test"
    "blueberry.tests.gd.rust.topshim.facade.adapter_test",
    "blueberry.tests.gd.rust.topshim.facade.suspend_test"
]

SOONG_UI_BASH = 'build/soong/soong_ui.bash'
@@ -135,7 +136,7 @@ def main():
    if not all(test_results):
        failures = [i for i, x in enumerate(test_results) if not x]
        for index in failures:
            print('TEST FAILLED: ' + TEST_SUITES[index])
            print('TEST FAILED: ' + TEST_SUITES[index])
        sys.exit(0)
    print('TEST PASSED ' + str(len(test_results)) + ' tests were run')

+8 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
use bt_topshim::btif;
use bt_topshim::btif::{BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface};

use bt_topshim_facade_protobuf::empty::Empty;
use bt_topshim_facade_protobuf::facade::{
    EventType, FetchEventsRequest, FetchEventsResponse, SetDiscoveryModeRequest,
    SetDiscoveryModeResponse, ToggleStackRequest, ToggleStackResponse,
@@ -118,4 +119,11 @@ impl AdapterService for AdapterServiceImpl {
            sink.success(SetDiscoveryModeResponse::default()).await.unwrap();
        })
    }

    fn clear_event_filter(&mut self, ctx: RpcContext<'_>, _req: Empty, sink: UnarySink<Empty>) {
        self.btif_intf.lock().unwrap().clear_event_filter();
        ctx.spawn(async move {
            sink.success(Empty::default()).await.unwrap();
        })
    }
}
Loading