1#!/usr/bin/env python3 2# 3# Copyright (C) 2016 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6# use this file except in compliance with the License. You may obtain a copy of 7# the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations under 15# the License. 16""" 17Test script to exercise Gatt Apis. 18""" 19 20from acts.controllers.sl4a_lib import rpc_client 21from acts.test_decorators import test_tracker_info 22from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 23from acts.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 24 25 26class GattApiTest(BluetoothBaseTest): 27 def __init__(self, controllers): 28 BluetoothBaseTest.__init__(self, controllers) 29 self.ad = self.android_devices[0] 30 31 def setup_class(self): 32 return setup_multiple_devices_for_bt_test(self.android_devices) 33 34 def setup_test(self): 35 for a in self.android_devices: 36 a.ed.clear_all_events() 37 return True 38 39 def teardown_test(self): 40 return True 41 42 @BluetoothBaseTest.bt_test_wrap 43 @test_tracker_info(uuid='fffe5c46-eb97-477b-ac3e-3f70700bb84e') 44 def test_open_gatt_server(self): 45 """Test a gatt server. 46 47 Test opening a gatt server. 48 49 Steps: 50 1. Create a gatt server callback. 51 2. Open the gatt server. 52 53 Expected Result: 54 Api to open gatt server should not fail. 55 56 Returns: 57 Pass if True 58 Fail if False 59 60 TAGS: LE, GATT 61 Priority: 1 62 """ 63 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 64 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 65 return True 66 67 @BluetoothBaseTest.bt_test_wrap 68 @test_tracker_info(uuid='12828c2c-b6ae-4670-a829-9867e75fb711') 69 def test_open_gatt_server_on_same_callback(self): 70 """Test repetitive opening of a gatt server. 71 72 Test opening a gatt server on the same callback twice in a row. 73 74 Steps: 75 1. Create a gatt server callback. 76 2. Open the gatt server. 77 3. Open the gatt server on the same callback as step 2. 78 79 Expected Result: 80 Api to open gatt server should not fail. 81 82 Returns: 83 Pass if True 84 Fail if False 85 86 TAGS: LE, GATT 87 Priority: 2 88 """ 89 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 90 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 91 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 92 return True 93 94 @BluetoothBaseTest.bt_test_wrap 95 @test_tracker_info(uuid='63fc684d-6c1d-455e-afdb-1887123b4d2f') 96 def test_open_gatt_server_on_invalid_callback(self): 97 """Test gatt server an an invalid callback. 98 99 Test opening a gatt server with an invalid callback. 100 101 Steps: 102 1. Open a gatt server with the gall callback set to -1. 103 104 Expected Result: 105 Api should fail to open a gatt server. 106 107 Returns: 108 Pass if True 109 Fail if False 110 111 TAGS: LE, GATT 112 Priority: 2 113 """ 114 invalid_callback_index = -1 115 try: 116 self.ad.droid.gattServerOpenGattServer(invalid_callback_index) 117 except rpc_client.Sl4aApiError as e: 118 self.log.info("Failed successfully with exception: {}.".format(e)) 119 return True 120 return False 121