• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""A Batch of of Bluetooth Classic health tests"""
6
7
8from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import \
9     BluetoothAdapterQuickTests
10from autotest_lib.server.cros.bluetooth.bluetooth_adapter_pairing_tests import \
11     BluetoothAdapterPairingTests
12from autotest_lib.server.cros.bluetooth.bluetooth_adapter_hidreports_tests \
13     import BluetoothAdapterHIDReportTests
14from autotest_lib.server.cros.bluetooth.bluetooth_sdp_tests import \
15     BluetoothSDPTests
16
17
18class bluetooth_AdapterCLHealth(BluetoothAdapterQuickTests,
19        BluetoothAdapterPairingTests,
20        BluetoothAdapterHIDReportTests,
21        BluetoothSDPTests):
22    """A Batch of Bluetooth Classic health tests. This test is written as a batch
23       of tests in order to reduce test time, since auto-test ramp up time is
24       costly. The batch is using BluetoothAdapterQuickTests wrapper methods to
25       start and end a test and a batch of tests.
26
27       This class can be called to run the entire test batch or to run a
28       specific test only
29    """
30
31    test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator
32    batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator
33
34
35    @test_wrapper('Discovery Test', devices={"MOUSE":1})
36    def cl_adapter_discovery_test(self):
37        """Performs pairing test with mouse peripheral"""
38        device = self.devices['MOUSE'][0]
39
40        self.test_discover_device(device.address)
41        self.test_device_name(device.address, device.name)
42
43
44    @test_wrapper('Discoverable Test', devices={"MOUSE":1})
45    def cl_adapter_discoverable_test(self):
46        """Verifies that DUT can become discoverable and be discovered"""
47
48        device = self.devices['MOUSE'][0]
49
50        # Put DUT into discoverable state
51        self.test_discoverable()
52
53        # Try and discover DUT from peripheral device
54        self.test_discover_by_device(device)
55
56
57    @test_wrapper('Pairing Test', devices={"MOUSE":1})
58    def cl_adapter_pairing_test(self):
59        """Performs pairing test with mouse peripheral"""
60        device = self.devices['MOUSE'][0]
61        self.pairing_test(device,
62                          check_connected_method=\
63                          self.test_mouse_right_click)
64
65
66    @test_wrapper('keyboard Pairing Test', devices={"KEYBOARD":1})
67    def cl_adapter_keyboard_pairing_test(self):
68        """Performs pairing test with keyboard peripheral"""
69        device = self.devices['KEYBOARD'][0]
70        self.pairing_test(device,
71                          check_connected_method=\
72                          self.run_keyboard_tests)
73
74
75    @test_wrapper('Pairing Suspend Resume Test', devices={"MOUSE": 1})
76    def cl_adapter_pairing_suspend_resume_test(self):
77        """Performs pairing test over resume with mouse peripheral"""
78        device = self.devices['MOUSE'][0]
79        self.pairing_test(device,
80                          check_connected_method=\
81                          self.test_mouse_right_click,
82                          suspend_resume=True)
83
84
85    @test_wrapper('Pairing Twice Test', devices={"MOUSE":1})
86    def cl_adapter_pairing_twice_test(self):
87        """Performs pairing twice test with  mouse peripheral"""
88        device = self.devices['MOUSE'][0]
89        self.pairing_test(device,
90                          check_connected_method=\
91                          self.test_mouse_right_click,
92                          pairing_twice=True)
93
94
95    @test_wrapper('HID Reports Test', devices={"MOUSE":1})
96    def cl_HID_reports_test(self):
97        """Performs HID report test with mouse peripheral"""
98        device = self.devices['MOUSE'][0]
99        self.run_hid_reports_test(device,
100                          check_connected_method=\
101                          self.test_mouse_right_click)
102
103
104    @test_wrapper('HID keyboard Reports Test', devices={'KEYBOARD':1})
105    def cl_HID_keyboard_reports_test(self):
106        """Performs HID report test with keyboard peripheral"""
107        device = self.devices['KEYBOARD'][0]
108        self.run_hid_reports_test(device,
109                          check_connected_method=\
110                          self.run_keyboard_tests)
111
112
113    @test_wrapper('HID Reports Suspend Resume Test', devices={"MOUSE": 1})
114    def cl_HID_reports_suspend_resume_test(self):
115        """Performs HID report test over resume with mouse peripheral"""
116        device = self.devices['MOUSE'][0]
117        self.run_hid_reports_test(device,
118                          check_connected_method=\
119                          self.test_mouse_right_click, suspend_resume=True)
120
121
122    @test_wrapper('HID Reports Reboot Test', devices={"MOUSE":1})
123    def cl_HID_reports_reboot_test(self):
124        """Performs HID report test over reboot with mouse peripheral"""
125        device = self.devices['MOUSE'][0]
126        self.run_hid_reports_test(device,
127                          check_connected_method=\
128                          self.test_mouse_right_click, reboot=True)
129
130
131    @test_wrapper('Connect Disconnect Loop Test', devices={"MOUSE":1})
132    def cl_connect_disconnect_loop_test(self):
133        """Performs connect/disconnect test with mouse peripheral"""
134        device = self.devices['MOUSE'][0]
135        self.connect_disconnect_loop(device=device, loops=3)
136
137
138    @test_wrapper('Page scan during Inquiry', devices={"MOUSE": 1})
139    def cl_page_scan_during_inquiry(self):
140        """Checks page scan is working during inquiry.
141
142        Scan and pair peer device.
143        Start inquiry.
144        Disconnect peer device from DUT.
145        Reconnect peer device by initiating connection from peer.
146        """
147        device = self.devices['MOUSE'][0]
148
149        # Setup
150        self.assert_discover_and_pair(device)
151        self.test_start_discovery()
152
153        # Disconnection should set up page scan so a reconnect immediately
154        # afterwards should always succeed
155        self.test_disconnection_by_adapter(device.address)
156        self.test_connection_by_device(device)
157
158        # Cleanup
159        self.test_stop_discovery()
160
161    @test_wrapper('SDP Service Browse Test', devices={"BLUETOOTH_TESTER":1})
162    def cl_sdp_service_browse_test(self):
163        """Performs sdp browse with tester peripheral"""
164        device = self.devices['BLUETOOTH_TESTER'][0]
165        self.sdp_service_browse_test(device=device)
166
167
168    @test_wrapper('SDP Service Attribute Request Test', \
169                  devices={"BLUETOOTH_TESTER":1})
170    def cl_sdp_service_attribute_request_test(self):
171        """Performs sdp browse with tester peripheral"""
172        device = self.devices['BLUETOOTH_TESTER'][0]
173        self.sdp_service_attribute_request_test(device=device)
174
175
176    @test_wrapper('SDP Service Search Attribute Request Test', \
177                  devices={"BLUETOOTH_TESTER":1})
178    def cl_sdp_service_search_attribute_request_test(self):
179        """Performs sdp browse with tester peripheral"""
180        device = self.devices['BLUETOOTH_TESTER'][0]
181        self.sdp_service_search_attribute_request_test(device=device)
182
183
184    @test_wrapper('SDP Service Search Request Basic Test', \
185                  devices={"BLUETOOTH_TESTER":1})
186    def cl_sdp_service_search_request_basic_test(self):
187        """Performs sdp browse with tester peripheral"""
188        device = self.devices['BLUETOOTH_TESTER'][0]
189        self.sdp_service_search_request_basic_test(device=device)
190
191
192    @batch_wrapper('Classic Health')
193    def cl_health_batch_run(self, num_iterations=1, test_name=None):
194        """Run the Classic health test batch or a specific given test.
195           The wrapper of this method is implemented in batch_decorator.
196           Using the decorator a test batch method can implement the only its
197           core tests invocations and let the decorator handle the wrapper,
198           which is taking care for whether to run a specific test or the
199           batch as a whole, and running the batch in iterations
200
201           @param num_iterations: how many interations to run
202           @param test_name: specifc test to run otherwise None to run the
203                             whole batch
204        """
205        self.cl_HID_keyboard_reports_test()
206        self.cl_HID_reports_reboot_test()
207        self.cl_HID_reports_suspend_resume_test()
208        self.cl_HID_reports_test()
209        self.cl_adapter_discoverable_test()
210        self.cl_adapter_discovery_test()
211        self.cl_adapter_keyboard_pairing_test()
212        self.cl_adapter_pairing_suspend_resume_test()
213        self.cl_adapter_pairing_test()
214        self.cl_adapter_pairing_twice_test()
215        self.cl_connect_disconnect_loop_test()
216        self.cl_sdp_service_attribute_request_test()
217        self.cl_sdp_service_browse_test()
218        self.cl_sdp_service_search_attribute_request_test()
219        self.cl_sdp_service_search_request_basic_test()
220
221
222    def run_once(self,
223                 host,
224                 num_iterations=1,
225                 args_dict=None,
226                 test_name=None,
227                 flag='Quick Health'):
228        """Run the batch of Bluetooth Classic health tests
229
230        @param host: the DUT, usually a chromebook
231        @param num_iterations: the number of rounds to execute the test
232        @test_name: the test to run, or None for all tests
233        """
234
235        # Initialize and run the test batch or the requested specific test
236        self.quick_test_init(host,
237                             use_btpeer=True,
238                             flag=flag,
239                             args_dict=args_dict)
240        self.cl_health_batch_run(num_iterations, test_name)
241        self.quick_test_cleanup()
242