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

Commit 088294c5 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Initial commit for topshim facade

- Add the entry point for the topshim stack with facade
(bt_topshim_facade).
- So far it works only with Android tree; we want to reduce the
dependency further.  So far it depends on 4 shared_libs defined in
Android.bp.
- Introduce the initial layout of the APIs (facade.proto) and the
corresponding implementation (facade/src/*.rs), and sample client code.
We also have a simple Python unittest to verify the framework.  Note
that we want to run it with mobly next.  The existing code is fully
compatible.
- Introduce the use of Python 3 async to help with event stream.
- Currently we generate grpc python manually through protoc.  We will
migrate to Android Build system (and another script) next.

Tag: #gd-refactor
Bug: 181590011
Test: make and run bt_topshim_facade
Change-Id: Ie0a4e5a7c65dd9812240f24444b787e0d5ba8259
parent f9c0a0fa
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -889,6 +889,12 @@ genrule {
        "touch $(genDir)/files/security/__init__.py && " +
        "mkdir -p $(genDir)/files/blueberry/tests/gd/cert && " +
        "touch $(genDir)/files/blueberry/tests/gd/cert/__init__.py && " +
        // Bundle topshim proto here for now
        "mkdir -p $(genDir)/files/rust/topshim/facade && " +
        "$(location aprotoc) -Ipackages/modules/Bluetooth/system/gd/rust/topshim/facade --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-python-plugin) packages/modules/Bluetooth/system/gd/rust/topshim/facade/facade.proto --grpc_out=$(genDir)/files/rust/topshim/facade --python_out=$(genDir)/files/rust/topshim/facade && " +
        "touch $(genDir)/files/rust/__init__.py && " +
        "touch $(genDir)/files/rust/topshim/__init__.py && " +
        "touch $(genDir)/files/rust/topshim/facade/__init__.py && " +
        "$(location soong_zip) -C $(genDir)/files -D $(genDir)/files -o $(out)",
    srcs: [
        ":BluetoothFacadeProto",
+3 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ LOCAL_cert_test_sources := \
LOCAL_host_executables := \
	$(HOST_OUT_EXECUTABLES)/bluetooth_stack_with_facade \
	$(HOST_OUT_EXECUTABLES)/bluetooth_with_facades \
	$(HOST_OUT_EXECUTABLES)/bt_topshim_facade \
	$(HOST_OUT_EXECUTABLES)/root-canal

LOCAL_host_python_extension_libraries := \
@@ -19,11 +20,13 @@ LOCAL_host_python_extension_libraries := \

LOCAL_host_libraries := \
	$(HOST_OUT_SHARED_LIBRARIES)/libbase.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libbluetooth.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libbluetooth_gd.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libc++.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libchrome.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libcrypto-host.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libevent-host.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libflatbuffers-cpp.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libgrpc++_unsecure.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libgrpc++.so \
	$(HOST_OUT_SHARED_LIBRARIES)/libgrpc_wrap.so \
+1 −0
Original line number Diff line number Diff line
*_pb2*.py
+73 −0
Original line number Diff line number Diff line
rust_binary_host {
    name: "bt_topshim_facade",
    defaults: ["gd_rust_defaults"],
    crate_name: "bt_topshim_facade",
    srcs: ["src/main.rs"],
    rustlibs: [
        "libbluetooth_rs",
        "libbt_common",
        "libtokio",
        "libbt_packets",
        "libfutures",
        "libgrpcio",
        "libnum_traits",
        "libnix",
        "liblog_rust",
        "libbt_facade_helpers",
        "libbt_topshim",
        "libbt_topshim_facade_protobuf",
    ],
    static_libs: [
        "libbt_topshim_cxx",
        "libbt-bta",
        "libbt-common",
        "libbtdevice",
        "libbtif",
        "libbt-hci",
        "libbt-stack",
        "libbt-utils",
        "libbtcore",
        "libosi",
        "libbt-protos-lite",
        "libbte",
        "libbt-sbc-decoder",
        "libbt-sbc-encoder",
        "libFraunhoferAAC",
        "libg722codec",
        "libudrv-uipc",
        "libbluetooth_gd", // Gabeldorsche
        "libbluetooth_rust_interop",
    ],
    shared_libs: [
        "libcrypto",
        "libflatbuffers-cpp",
        "libbluetooth",
        "libchrome",
    ],
    sanitize: {
        never: true,
    },
    proc_macros: [
        "libpaste",
    ],
}

rust_protobuf {
    name: "libbt_topshim_facade_protobuf",
    crate_name: "bt_topshim_facade_protobuf",
    source_stem: "topshim_facade",
    host_supported: true,
    grpc_protos: ["facade.proto"],
}

genrule {
    name: "libbt_topshim_facade_py_proto",
    tools: [
        "aprotoc",
        "protoc-gen-grpc-python-plugin",
        "soong_zip",
    ],
    cmd: "$(location aprotoc) --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-python-plugin) -Ipackages/modules/Bluetooth/system/gd/rust/topshim/facade $(in) --grpc_out=$(genDir) --python_out=$(genDir)",
    srcs: ["facade.proto"],
    out: ["facade_pb2.py", "facade_pb2_grpc.py"],
}
+41 −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
import unittest

from topshim_base_test import TopshimBaseTest


class AdapterTest(TopshimBaseTest):

    async def asyncSetUp(self):
        await super().asyncSetUp()
        from automation_helper import AdapterAutomationHelper

        self.dut_adapter = AdapterAutomationHelper()

    async def test_verify_adapter_started(self):
        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.toggle_stack()
        await self.dut_adapter.verify_adapter_started()
        self.dut_adapter.event_handler.cancel()


if __name__ == "__main__":
    unittest.main()
Loading