summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Turney <tturney@google.com>2017-05-31 02:07:30 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-05-31 02:07:30 +0000
commit033630800a002e2ce95584fa8bff12ac750762be (patch)
tree0e446267c9fca3047991e9738eecb0ea40f97dd6
parente039f050ec8e186524a9b493c94938629c7b461e (diff)
parent0a3a7cf03bc3f4d986fa0dab078ccecb7a530460 (diff)
downloadplatform_tools_test_connectivity-033630800a002e2ce95584fa8bff12ac750762be.tar.gz
platform_tools_test_connectivity-033630800a002e2ce95584fa8bff12ac750762be.tar.bz2
platform_tools_test_connectivity-033630800a002e2ce95584fa8bff12ac750762be.zip
Merge "PTS Cmd Line Tool for Bluetooth Adapter" into oc-dev
-rw-r--r--acts/tests/google/bt/pts/bta_lib.py102
-rw-r--r--acts/tests/google/bt/pts/cmd_input.py144
2 files changed, 244 insertions, 2 deletions
diff --git a/acts/tests/google/bt/pts/bta_lib.py b/acts/tests/google/bt/pts/bta_lib.py
new file mode 100644
index 0000000000..e1147ec169
--- /dev/null
+++ b/acts/tests/google/bt/pts/bta_lib.py
@@ -0,0 +1,102 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# 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
+#
+# http://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.
+"""
+Bluetooth adapter libraries
+"""
+
+from acts.test_utils.bt.BtEnum import BluetoothScanModeType
+from acts.test_utils.bt.bt_test_utils import set_bt_scan_mode
+
+import pprint
+
+
+class BtaLib():
+ def __init__(self, log, mac_addr, dut):
+ self.advertisement_list = []
+ self.dut = dut
+ self.log = log
+ self.mac_addr = mac_addr
+
+ def set_scan_mode(self, scan_mode):
+ """Set the Scan mode of the Bluetooth Adapter"""
+ for mode in BluetoothScanModeType:
+ if scan_mode == mode.name:
+ set_bt_scan_mode(self.dut, mode.value)
+ return
+
+ def set_device_name(self, line):
+ """Set Bluetooth Adapter Name"""
+ self.dut.droid.bluetoothSetLocalName(line)
+
+ def enable(self):
+ """Enable Bluetooth Adapter"""
+ self.dut.droid.bluetoothToggleState(True)
+
+ def disable(self):
+ """Disable Bluetooth Adapter"""
+ self.dut.droid.bluetoothToggleState(False)
+
+ def init_bond(self):
+ """Initiate bond to PTS device"""
+ self.dut.droid.bluetoothDiscoverAndBond(self.mac_addr)
+
+ def start_discovery(self):
+ """Start BR/EDR Discovery"""
+ self.dut.droid.bluetoothStartDiscovery()
+
+ def stop_discovery(self):
+ """Stop BR/EDR Discovery"""
+ self.dut.droid.bluetoothCancelDiscovery()
+
+ def get_discovered_devices(self):
+ """Get Discovered Br/EDR Devices"""
+ if self.dut.droid.bluetoothIsDiscovering():
+ self.dut.droid.bluetoothCancelDiscovery()
+ self.log.info(
+ pprint.pformat(self.dut.droid.bluetoothGetDiscoveredDevices()))
+
+ def bond(self):
+ """Bond to PTS device"""
+ self.dut.droid.bluetoothBond(self.mac_addr)
+
+ def disconnect(self):
+ """BTA disconnect"""
+ self.dut.droid.bluetoothDisconnectConnected(self.mac_addr)
+
+ def unbond(self):
+ """Unbond from PTS device"""
+ self.dut.droid.bluetoothUnbond(self.mac_addr)
+
+ def start_pairing_helper(self, line):
+ """Start or stop Bluetooth Pairing Helper"""
+ if line:
+ self.dut.droid.bluetoothStartPairingHelper(bool(line))
+ else:
+ self.dut.droid.bluetoothStartPairingHelper()
+
+ def push_pairing_pin(self, line):
+ """Push pairing pin to the Android Device"""
+ self.dut.droid.eventPost("BluetoothActionPairingRequestUserConfirm",
+ line)
+
+ def get_pairing_pin(self):
+ """Get pairing PIN"""
+ self.log.info(
+ self.dut.ed.pop_event("BluetoothActionPairingRequest", 1))
+
+ def fetch_uuids_with_sdp(self):
+ """BTA fetch UUIDS with SDP"""
+ self.log.info(self.dut.droid.bluetoothFetchUuidsWithSdp(self.mac_addr))
diff --git a/acts/tests/google/bt/pts/cmd_input.py b/acts/tests/google/bt/pts/cmd_input.py
index 2217f76448..f6b76e90d6 100644
--- a/acts/tests/google/bt/pts/cmd_input.py
+++ b/acts/tests/google/bt/pts/cmd_input.py
@@ -17,14 +17,15 @@
Python script for wrappers to various libraries.
"""
+from acts.test_utils.bt.BtEnum import BluetoothScanModeType
from acts.test_utils.bt.GattEnum import GattServerResponses
from ble_lib import BleLib
+from bta_lib import BtaLib
from gattc_lib import GattClientLib
from gatts_lib import GattServerLib
-import gatt_test_database
-
import cmd
+import gatt_test_database
"""Various Global Strings"""
CMD_LOG = "CMD {} result: {}"
FAILURE = "CMD {} threw exception: {}"
@@ -43,6 +44,7 @@ class CmdInput(cmd.Cmd):
self.log = log
# Initialize libraries
+ self.bta_lib = BtaLib(log, mac_addr, self.pri_dut)
self.ble_lib = BleLib(log, mac_addr, self.pri_dut)
self.gattc_lib = GattClientLib(log, mac_addr, self.pri_dut)
self.gatts_lib = GattServerLib(log, mac_addr, self.pri_dut)
@@ -584,3 +586,141 @@ class CmdInput(cmd.Cmd):
self.log.info(FAILURE.format(cmd, err))
"""End Ble wrappers"""
+ """Begin Bta wrappers"""
+
+ def complete_bta_start_pairing_helper(self, text, line, begidx, endidx):
+ options = ['true', 'false']
+ if not text:
+ completions = list(options)[:]
+ else:
+ completions = [s for s in options if s.startswith(text)]
+ return completions
+
+ def complete_bta_set_scan_mode(self, text, line, begidx, endidx):
+ completions = [e.name for e in BluetoothScanModeType]
+ if not text:
+ completions = completions[:]
+ else:
+ completions = [s for s in completions if s.startswith(text)]
+ return completions
+
+ def do_bta_set_scan_mode(self, line):
+ """Set the Scan mode of the Bluetooth Adapter"""
+ cmd = "Set the Scan mode of the Bluetooth Adapter"
+ try:
+ self.bta_lib.set_scan_mode(line)
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_set_device_name(self, line):
+ """Set Bluetooth Adapter Name"""
+ cmd = "Set Bluetooth Adapter Name"
+ try:
+ self.bta_lib.set_device_name(line)
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_enable(self, line):
+ """Enable Bluetooth Adapter"""
+ cmd = "Enable Bluetooth Adapter"
+ try:
+ self.bta_lib.enable()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_disable(self, line):
+ """Disable Bluetooth Adapter"""
+ cmd = "Disable Bluetooth Adapter"
+ try:
+ self.bta_lib.disable()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_init_bond(self, line):
+ """Initiate bond to PTS device"""
+ cmd = "Initiate Bond"
+ try:
+ self.bta_lib.init_bond()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_start_discovery(self, line):
+ """Start BR/EDR Discovery"""
+ cmd = "Start BR/EDR Discovery"
+ try:
+ self.bta_lib.start_discovery()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_stop_discovery(self, line):
+ """Stop BR/EDR Discovery"""
+ cmd = "Stop BR/EDR Discovery"
+ try:
+ self.bta_lib.stop_discovery()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_get_discovered_devices(self, line):
+ """Get Discovered Br/EDR Devices"""
+ cmd = "Get Discovered Br/EDR Devices\n"
+ try:
+ self.bta_lib.get_discovered_devices()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_bond(self, line):
+ """Bond to PTS device"""
+ cmd = "Bond to the PTS dongle directly"
+ try:
+ self.bta_lib.bond()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_disconnect(self, line):
+ """BTA disconnect"""
+ cmd = "BTA disconnect"
+ try:
+ self.bta_lib.disconnect()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_unbond(self, line):
+ """Unbond from PTS device"""
+ cmd = "Unbond from the PTS dongle"
+ try:
+ self.bta_lib.unbond()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_start_pairing_helper(self, line):
+ """Start or stop Bluetooth Pairing Helper"""
+ cmd = "Start or stop BT Pairing helper"
+ try:
+ self.bta_lib.start_pairing_helper(line)
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_push_pairing_pin(self, line):
+ cmd = "Push the pin to the Android Device"
+ try:
+ self.bta_lib.push_pairing_pin(line)
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_get_pairing_pin(self, line):
+ """Get pairing PIN"""
+ cmd = "Get Pin Info"
+ try:
+ self.bta_lib.get_pairing_pin()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ def do_bta_fetch_uuids_with_sdp(self, line):
+ """BTA fetch UUIDS with SDP"""
+ cmd = "Fetch UUIDS with SDP"
+ try:
+ self.bta_lib.fetch_uuids_with_sdp()
+ except Exception as err:
+ self.log.info(FAILURE.format(cmd, err))
+
+ """End Bta wrappers"""