OSDN Git Service

Add PyHci helpers for page/scan and reading own address
authorZach Johnson <zachoverflow@google.com>
Sat, 29 Feb 2020 01:08:15 +0000 (17:08 -0800)
committerZach Johnson <zachoverflow@google.com>
Sat, 29 Feb 2020 01:09:57 +0000 (17:09 -0800)
Test: cert/run --host --test_filter=AclManagerTest
Change-Id: If61ab95a80f1a3f654ebf0fc9b63857c2b6b401d

gd/hci/cert/acl_manager_test.py
gd/hci/cert/py_hci.py

index ab5dc4e..4f6469c 100644 (file)
@@ -56,16 +56,8 @@ class AclManagerTest(GdFacadeOnlyBaseTestClass):
         with PyHci(self.cert) as cert_hci, \
             EventStream(self.dut.hci_acl_manager.FetchAclData(empty_proto.Empty())) as acl_data_stream:
 
-            # CERT Enables scans and gets its address
-            cert_hci.send_command_with_complete(
-                hci_packets.WriteScanEnableBuilder(
-                    hci_packets.ScanEnable.INQUIRY_AND_PAGE_SCAN))
-
-            cert_hci.send_command_with_complete(hci_packets.ReadBdAddrBuilder())
-
-            read_bd_addr = ReadBdAddrCompleteCapture()
-            assertThat(cert_hci.get_event_stream()).emits(read_bd_addr)
-            cert_address = read_bd_addr.get().GetBdAddr()
+            cert_hci.enable_inquiry_and_page_scan()
+            cert_address = cert_hci.read_own_address()
 
             with EventStream(
                     self.dut.hci_acl_manager.CreateConnection(
@@ -180,15 +172,8 @@ class AclManagerTest(GdFacadeOnlyBaseTestClass):
             EventStream(self.dut.hci_acl_manager.FetchAclData(empty_proto.Empty())) as acl_data_stream:
 
             # CERT Enables scans and gets its address
-            cert_hci.send_command_with_complete(
-                hci_packets.WriteScanEnableBuilder(
-                    hci_packets.ScanEnable.INQUIRY_AND_PAGE_SCAN))
-
-            cert_hci.send_command_with_complete(hci_packets.ReadBdAddrBuilder())
-
-            read_bd_addr = ReadBdAddrCompleteCapture()
-            assertThat(cert_hci.get_event_stream()).emits(read_bd_addr)
-            cert_address = read_bd_addr.get().GetBdAddr()
+            cert_hci.enable_inquiry_and_page_scan()
+            cert_address = cert_hci.read_own_address()
 
             with EventStream(
                     self.dut.hci_acl_manager.CreateConnection(
index e79b43f..bf61f79 100644 (file)
@@ -16,6 +16,9 @@
 
 from google.protobuf import empty_pb2 as empty_proto
 from cert.event_stream import EventStream
+from captures import ReadBdAddrCompleteCapture
+from bluetooth_packets_python3 import hci_packets
+from cert.truth import assertThat
 
 
 class PyHci(object):
@@ -51,3 +54,14 @@ class PyHci(object):
 
     def send_command_with_status(self, command):
         self.device.hci.send_command_with_status(command)
+
+    def enable_inquiry_and_page_scan(self):
+        self.send_command_with_complete(
+            hci_packets.WriteScanEnableBuilder(
+                hci_packets.ScanEnable.INQUIRY_AND_PAGE_SCAN))
+
+    def read_own_address(self):
+        self.send_command_with_complete(hci_packets.ReadBdAddrBuilder())
+        read_bd_addr = ReadBdAddrCompleteCapture()
+        assertThat(self.event_stream).emits(read_bd_addr)
+        return read_bd_addr.get().GetBdAddr()