• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#/usr/bin/env python3.4
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"""
17This test script for GATT longevity tests.
18"""
19
20from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
21from acts.test_utils.bt.GattConnectedBaseTest import GattConnectedBaseTest
22from acts.test_utils.bt.GattEnum import GattCharacteristic
23from acts.test_utils.bt.GattEnum import GattDescriptor
24from acts.test_utils.bt.GattEnum import GattEvent
25from acts.test_utils.bt.GattEnum import GattCbStrings
26from acts.test_utils.bt.GattEnum import GattConnectionPriority
27from acts.test_utils.bt.GattEnum import GattCharacteristicAttrLength
28from acts.test_utils.bt.GattEnum import MtuSize
29from acts.test_utils.bt.bt_gatt_utils import setup_gatt_mtu
30
31
32class GattLongevityTest(GattConnectedBaseTest):
33    longevity_iterations = 1100000
34
35    @BluetoothBaseTest.bt_test_wrap
36    def test_write_characteristic_no_resp_longevity(self):
37        """Longevity test write characteristic value
38
39        Longevity test to write characteristic value for
40        self.longevity_iteration times. This is to test the
41        integrity of written data and the robustness of central
42        and peripheral mode of the Android devices under test.
43
44        1. Central: write WRITABLE_CHAR_UUID characteristic with char_value
45           using write command.
46        2. Central: make sure write callback is called.
47        3. Peripheral: receive the written data.
48        4. Verify data written matches data received.
49        5. Repeat steps 1-4 self.longevity_iterations times.
50
51        Expected Result:
52        Verify that write command is properly delivered.
53
54        Returns:
55          Pass if True
56          Fail if False
57
58        TAGS: LE, GATT, Characteristic, Longevity
59        Priority: 0
60        """
61        self.cen_ad.droid.gattClientRequestConnectionPriority(
62            self.bluetooth_gatt,
63            GattConnectionPriority.CONNECTION_PRIORITY_HIGH.value)
64
65        self.cen_ad.droid.gattClientCharacteristicSetWriteType(
66            self.bluetooth_gatt, self.discovered_services_index,
67            self.test_service_index, self.WRITABLE_CHAR_UUID,
68            GattCharacteristic.WRITE_TYPE_NO_RESPONSE.value)
69
70        for i in range(self.longevity_iterations):
71            self.log.debug("Iteration {} started.".format(i + 1))
72            char_value = []
73            for j in range(i, i + self.mtu - 3):
74                char_value.append(j % 256)
75
76            self.cen_ad.droid.gattClientCharacteristicSetValue(
77                self.bluetooth_gatt, self.discovered_services_index,
78                self.test_service_index, self.WRITABLE_CHAR_UUID, char_value)
79
80            self.cen_ad.droid.gattClientWriteCharacteristic(
81                self.bluetooth_gatt, self.discovered_services_index,
82                self.test_service_index, self.WRITABLE_CHAR_UUID)
83
84            # client shall not wait for server, get complete event right away
85            event = self._client_wait(GattEvent.CHAR_WRITE)
86            if event["data"]["Status"] != 0:
87                self.log.error("Write status should be 0")
88                return False
89
90            event = self._server_wait(GattEvent.CHAR_WRITE_REQ)
91
92            self.log.info("{} event found: {}".format(
93                GattCbStrings.CHAR_WRITE_REQ.value.format(
94                    self.gatt_server_callback), event['data']['value']))
95            request_id = event['data']['requestId']
96            found_value = event['data']['value']
97            if found_value != char_value:
98                self.log.info("Values didn't match. Found: {}, "
99                              "Expected: {}".format(found_value, char_value))
100                return False
101
102        return True
103