From 6e541436a563fc320b5d8dc3b205cfe460d22b76 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Thu, 12 Nov 2020 18:09:49 -0800 Subject: [PATCH] Add HciMatchers.LoopbackOf to avoid imprecise matching Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --host Change-Id: Id9b18af3075225b3ac09a6af485d424476151b33 --- gd/cert/matchers.py | 5 +++++ gd/hci/cert/direct_hci_test.py | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gd/cert/matchers.py b/gd/cert/matchers.py index 043800610..6653d153b 100644 --- a/gd/cert/matchers.py +++ b/gd/cert/matchers.py @@ -163,6 +163,11 @@ class HciMatchers(object): def RemoteOobDataRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.REMOTE_OOB_DATA_REQUEST) + @staticmethod + def LoopbackOf(packet): + data = bytes(hci_packets.LoopbackCommandBuilder(packet).Serialize()) + return lambda event: data == event.payload + class NeighborMatchers(object): diff --git a/gd/hci/cert/direct_hci_test.py b/gd/hci/cert/direct_hci_test.py index f48fb680b..0ef17e56a 100644 --- a/gd/hci/cert/direct_hci_test.py +++ b/gd/hci/cert/direct_hci_test.py @@ -110,13 +110,10 @@ class DirectHciTest(GdBaseTestClass): def test_local_hci_cmd_and_event(self): # Loopback mode responds with ACL and SCO connection complete self.dut_hci.register_for_events(EventCode.LOOPBACK_COMMAND) - self.dut_hci.send_command_with_complete(WriteLoopbackModeBuilder(LoopbackMode.ENABLE_LOCAL)) self.dut_hci.send_command_with_complete(ReadLocalNameBuilder()) - - looped_bytes = bytes(ReadLocalNameBuilder().Serialize()) - assertThat(self.dut_hci.get_event_stream()).emits(lambda packet: looped_bytes in packet.payload) + assertThat(self.dut_hci.get_event_stream()).emits(HciMatchers.LoopbackOf(ReadLocalNameBuilder())) def test_inquiry_from_dut(self): self.dut_hci.register_for_events(EventCode.INQUIRY_RESULT) -- 2.11.0