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

Commit df2a3640 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "avatar: add first test for aics" into main

parents 94ec5316 9a69820a
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
# Copyright 2024 Google LLC
#
# 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
#
#     https://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 avatar

from avatar import PandoraDevices, BumblePandoraDevice
from mobly import base_test, signals
from mobly.asserts import assert_in  # type: ignore

from pandora.host_pb2 import RANDOM
from pandora_experimental.gatt_grpc import GATT

from bumble.att import UUID
from bumble.gatt import GATT_AUDIO_INPUT_CONTROL_SERVICE
from bumble.profiles.aics import AICSService


class AicsTest(base_test.BaseTestClass):

    def setup_class(self) -> None:
        self.devices = PandoraDevices(self)
        self.dut, self.ref, *_ = self.devices

        if not isinstance(self.ref, BumblePandoraDevice):
            raise signals.TestAbortClass('Test require Bumble as reference device.')

    def teardown_class(self) -> None:
        if self.devices:
            self.devices.stop_all()

    @avatar.asynchronous
    async def setup_test(self) -> None:
        await asyncio.gather(self.dut.reset(), self.ref.reset())

        self.ref.device.add_service(AICSService())  # type: ignore

    def test_gatt_discover_aics_service(self) -> None:
        advertise = self.ref.host.Advertise(legacy=True, connectable=True)
        dut_ref_connection = self.dut.host.ConnectLE(public=self.ref.address, own_address_type=RANDOM).connection
        assert dut_ref_connection
        advertise.cancel()  # type: ignore

        dut_gatt = GATT(self.dut.channel)  # type: ignore
        services = dut_gatt.DiscoverServices(dut_ref_connection).services
        uuids = [UUID(service.uuid) for service in services]

        assert_in(GATT_AUDIO_INPUT_CONTROL_SERVICE, uuids)
+11 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ _BUMBLE_BTSNOOP_FMT = 'bumble_btsnoop_{pid}_{instance}.log'
import a2dp_test

# Import test cases modules.
import aics_test
import asha_test
import avatar.cases.host_test
import avatar.cases.le_host_test
@@ -32,6 +33,7 @@ _TEST_CLASSES_LIST = [
    avatar.cases.security_test.SecurityTest,
    avatar.cases.le_security_test.LeSecurityTest,
    a2dp_test.A2dpTest,
    aics_test.AicsTest,
    sdp_test.SdpTest,
    gatt_test.GattTest,
    asha_test.AshaTest,
@@ -41,11 +43,17 @@ _TEST_CLASSES_LIST = [

def _parse_cli_args() -> Tuple[Namespace, List[str]]:
    parser = argparse.ArgumentParser(description='Avatar test runner.')
    parser.add_argument('-o', '--log_path', type=str, metavar='<PATH>', help='Path to the test configuration file.')
    parser.add_argument(
        '-o',
        '--log_path',
        type=str,
        metavar='<PATH>',
        help='Path to the test configuration file.',
    )
    return parser.parse_known_args()


if __name__ == "__main__":
if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    # This is a hack for `tradefed` because of `b/166468397`.