From: Zach Johnson Date: Sat, 14 Nov 2020 21:28:09 +0000 (-0800) Subject: Add HciMatchers.Exactly, for more compact tests X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1ac8435e5d5dcfa75429478412650cd173c70fbd;p=android-x86%2Fsystem-bt.git Add HciMatchers.Exactly, for more compact tests Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --host Change-Id: If87927d3e491f234000b7c9321832897e91bba04 --- diff --git a/gd/cert/matchers.py b/gd/cert/matchers.py index 6653d153b..f57a5218b 100644 --- a/gd/cert/matchers.py +++ b/gd/cert/matchers.py @@ -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 diff --git a/gd/hal/cert/simple_hal_test.py b/gd/hal/cert/simple_hal_test.py index f983680b8..d8be7b2af 100644 --- a/gd/hal/cert/simple_hal_test.py +++ b/gd/hal/cert/simple_hal_test.py @@ -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))