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

Commit be9cc98f authored by Zach Johnson's avatar Zach Johnson
Browse files

Add HciMatchers.Exactly, for more compact tests

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --host
Change-Id: If87927d3e491f234000b7c9321832897e91bba04
parent d8567101
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
#   See the License for the specific language governing permissions and
#   limitations under the License.

import logging
import bluetooth_packets_python3 as bt_packets
import logging

@@ -165,7 +166,11 @@ class HciMatchers(object):

    @staticmethod
    def LoopbackOf(packet):
        data = bytes(hci_packets.LoopbackCommandBuilder(packet).Serialize())
        return HciMatchers.Exactly(hci_packets.LoopbackCommandBuilder(packet))

    @staticmethod
    def Exactly(packet):
        data = bytes(packet.Serialize())
        return lambda event: data == event.payload


+5 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ from cert.gd_base_test import GdBaseTestClass
from cert.event_stream import EventStream
from cert.truth import assertThat
from cert.py_hal import PyHal
from cert.matchers import HciMatchers
from google.protobuf import empty_pb2
from facade import rootservice_pb2 as facade_rootservice_pb2
from hal import facade_pb2 as hal_facade_pb2
@@ -50,12 +51,12 @@ class SimpleHalTest(GdBaseTestClass):
        self.cert_hal.close()
        super().teardown_test()

    def test_fetch_hci_event(self):
    def test_stream_events(self):
        self.dut_hal.send_hci_command(
            hci_packets.LeAddDeviceToConnectListBuilder(hci_packets.ConnectListAddressType.RANDOM, '0C:05:04:03:02:01'))
        event = hci_packets.LeAddDeviceToConnectListCompleteBuilder(1, hci_packets.ErrorCode.SUCCESS)

        assertThat(self.dut_hal.get_hci_event_stream()).emits(lambda packet: bytes(event.Serialize()) in packet.payload)
        assertThat(self.dut_hal.get_hci_event_stream()).emits(
            HciMatchers.Exactly(hci_packets.LeAddDeviceToConnectListCompleteBuilder(1, hci_packets.ErrorCode.SUCCESS)))

    def test_loopback_hci_command(self):
        self.dut_hal.send_hci_command(hci_packets.WriteLoopbackModeBuilder(hci_packets.LoopbackMode.ENABLE_LOCAL))
@@ -64,8 +65,7 @@ class SimpleHalTest(GdBaseTestClass):
                                                              '0C:05:04:03:02:01')
        self.dut_hal.send_hci_command(command)

        assertThat(
            self.dut_hal.get_hci_event_stream()).emits(lambda packet: bytes(command.Serialize()) in packet.payload)
        assertThat(self.dut_hal.get_hci_event_stream()).emits(HciMatchers.LoopbackOf(command))

    def test_inquiry_from_dut(self):
        self.cert_hal.send_hci_command(hci_packets.WriteScanEnableBuilder(hci_packets.ScanEnable.INQUIRY_AND_PAGE_SCAN))