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_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 23from acts_contrib.test_utils.bt.bt_test_utils import setup_multiple_devices_for_bt_test 24 25 26class GattApiTest(BluetoothBaseTest): 27 def setup_class(self): 28 super().setup_class() 29 self.ad = self.android_devices[0] 30 31 return setup_multiple_devices_for_bt_test(self.android_devices) 32 33 def setup_test(self): 34 for a in self.android_devices: 35 a.ed.clear_all_events() 36 return True 37 38 def teardown_test(self): 39 return True 40 41 @BluetoothBaseTest.bt_test_wrap 42 @test_tracker_info(uuid='fffe5c46-eb97-477b-ac3e-3f70700bb84e') 43 def test_open_gatt_server(self): 44 """Test a gatt server. 45 46 Test opening a gatt server. 47 48 Steps: 49 1. Create a gatt server callback. 50 2. Open the gatt server. 51 52 Expected Result: 53 Api to open gatt server should not fail. 54 55 Returns: 56 Pass if True 57 Fail if False 58 59 TAGS: LE, GATT 60 Priority: 1 61 """ 62 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 63 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 64 return True 65 66 @BluetoothBaseTest.bt_test_wrap 67 @test_tracker_info(uuid='12828c2c-b6ae-4670-a829-9867e75fb711') 68 def test_open_gatt_server_on_same_callback(self): 69 """Test repetitive opening of a gatt server. 70 71 Test opening a gatt server on the same callback twice in a row. 72 73 Steps: 74 1. Create a gatt server callback. 75 2. Open the gatt server. 76 3. Open the gatt server on the same callback as step 2. 77 78 Expected Result: 79 Api to open gatt server should not fail. 80 81 Returns: 82 Pass if True 83 Fail if False 84 85 TAGS: LE, GATT 86 Priority: 2 87 """ 88 gatt_server_cb = self.ad.droid.gattServerCreateGattServerCallback() 89 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 90 self.ad.droid.gattServerOpenGattServer(gatt_server_cb) 91 return True 92 93 @BluetoothBaseTest.bt_test_wrap 94 @test_tracker_info(uuid='63fc684d-6c1d-455e-afdb-1887123b4d2f') 95 def test_open_gatt_server_on_invalid_callback(self): 96 """Test gatt server an an invalid callback. 97 98 Test opening a gatt server with an invalid callback. 99 100 Steps: 101 1. Open a gatt server with the gall callback set to -1. 102 103 Expected Result: 104 Api should fail to open a gatt server. 105 106 Returns: 107 Pass if True 108 Fail if False 109 110 TAGS: LE, GATT 111 Priority: 2 112 """ 113 invalid_callback_index = -1 114 try: 115 self.ad.droid.gattServerOpenGattServer(invalid_callback_index) 116 except rpc_client.Sl4aApiError as e: 117 self.log.info("Failed successfully with exception: {}.".format(e)) 118 return True 119 return False 120