• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 execute Bluetooth basic functionality test cases.
18This test was designed to be run in a shield box.
19"""
20
21from acts.test_decorators import test_tracker_info
22from acts_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
23from acts_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
24from acts_contrib.test_utils.bt.bt_test_utils import orchestrate_rfcomm_connection
25from acts_contrib.test_utils.bt.bt_test_utils import write_read_verify_data
26
27
28class RfcommStressTest(BluetoothBaseTest):
29    default_timeout = 10
30    scan_discovery_time = 5
31    message = (
32        "Space: the final frontier. These are the voyages of "
33        "the starship Enterprise. Its continuing mission: to explore "
34        "strange new worlds, to seek out new life and new civilizations,"
35        " to boldly go where no man has gone before.")
36
37    def setup_class(self):
38        super().setup_class()
39        self.client_ad = self.android_devices[0]
40        self.server_ad = self.android_devices[1]
41
42    @test_tracker_info(uuid='10452f63-e1fd-4345-a4da-e00fc4609a69')
43    def test_rfcomm_connection_stress(self):
44        """Stress test an RFCOMM connection
45
46        Test the integrity of RFCOMM. Verify that file descriptors are cleared
47        out properly.
48
49        Steps:
50        1. Establish a bonding between two Android devices.
51        2. Write data to RFCOMM from the client droid.
52        3. Read data from RFCOMM from the server droid.
53        4. Stop the RFCOMM connection.
54        5. Repeat steps 2-4 1000 times.
55
56        Expected Result:
57        Each iteration should read and write to the RFCOMM connection
58        successfully.
59
60        Returns:
61          Pass if True
62          Fail if False
63
64        TAGS: Classic, Stress, RFCOMM
65        Priority: 1
66        """
67        iterations = 1000
68        for n in range(iterations):
69            if not orchestrate_rfcomm_connection(self.client_ad,
70                                                 self.server_ad):
71                return False
72            self.client_ad.droid.bluetoothRfcommStop()
73            self.server_ad.droid.bluetoothRfcommStop()
74            self.log.info("Iteration {} completed".format(n))
75        return True
76
77    @test_tracker_info(uuid='2dba96ec-4e5d-4394-85ef-b57b66399fbc')
78    def test_rfcomm_connection_write_msg_stress(self):
79        """Stress test an RFCOMM connection
80
81        Test the integrity of RFCOMM. Verify that file descriptors are cleared
82        out properly.
83
84        Steps:
85        1. Establish a bonding between two Android devices.
86        2. Write data to RFCOMM from the client droid.
87        3. Read data from RFCOMM from the server droid.
88        4. Stop the RFCOMM connection.
89        5. Repeat steps 2-4 1000 times.
90
91        Expected Result:
92        Each iteration should read and write to the RFCOMM connection
93        successfully.
94
95        Returns:
96          Pass if True
97          Fail if False0
98
99        TAGS: Classic, Stress, RFCOMM
100        Priority: 1
101        """
102        iterations = 1000
103        for n in range(iterations):
104            if not orchestrate_rfcomm_connection(self.client_ad,
105                                                 self.server_ad):
106                return False
107            if not write_read_verify_data(self.client_ad, self.server_ad,
108                                          self.message, False):
109                return False
110            self.client_ad.droid.bluetoothRfcommStop()
111            self.server_ad.droid.bluetoothRfcommStop()
112            self.log.info("Iteration {} completed".format(n))
113        return True
114
115    @test_tracker_info(uuid='78dca597-89c0-431c-a553-531f230fc3c0')
116    def test_rfcomm_read_write_stress(self):
117        """Stress test an RFCOMM connection's read and write capabilities
118
119        Test the integrity of RFCOMM. Verify that file descriptors are cleared
120        out properly.
121
122        Steps:
123        1. Establish a bonding between two Android devices.
124        2. Write data to RFCOMM from the client droid.
125        3. Read data from RFCOMM from the server droid.
126        4. Repeat steps 2-3 10000 times.
127        5. Stop the RFCOMM connection.
128
129        Expected Result:
130        Each iteration should read and write to the RFCOMM connection
131        successfully.
132
133        Returns:
134          Pass if True
135          Fail if False
136
137        TAGS: Classic, Stress, RFCOMM
138        Priority: 1
139        """
140        iterations = 1000
141        if not orchestrate_rfcomm_connection(self.client_ad, self.server_ad):
142            return False
143        for n in range(iterations):
144            self.log.info("Write message.")
145            if not write_read_verify_data(self.client_ad, self.server_ad,
146                                          self.message, False):
147                return False
148            self.log.info("Iteration {} completed".format(n))
149        self.client_ad.droid.bluetoothRfcommStop()
150        self.server_ad.droid.bluetoothRfcommStop()
151        return True
152