blob: ad3c6c5c7b70ecf0a782a730ef58100366379b67 [file] [log] [blame]
Yoni Shavit99696e92019-05-02 14:45:02 -07001# 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
howardchung4e03f362019-06-10 17:18:33 +08005"""A Batch of Bluetooth stand alone sanity tests"""
Yoni Shavit99696e92019-05-02 14:45:02 -07006
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -07007import logging
8
Daniel Winkler74b7f7b2020-01-17 15:59:29 -08009from autotest_lib.server.cros.bluetooth import advertisements_data
Yoni Shavit93c24912019-05-14 10:37:04 -070010from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import \
11 BluetoothAdapterQuickTests
Shijin Abrahambcd7c022020-01-30 17:50:41 -080012from autotest_lib.server.cros.bluetooth import bluetooth_dbus_api_tests
howardchung414856e2019-06-11 15:34:07 +080013from autotest_lib.server.cros.bluetooth import bluetooth_default_state_test
14from autotest_lib.server.cros.bluetooth import bluetooth_valid_address_test
Daniel Winkler74b7f7b2020-01-17 15:59:29 -080015from autotest_lib.server.cros.bluetooth.bluetooth_adapter_leadvertising_tests \
16 import bluetooth_AdapterLEAdvertising
Yoni Shavit99696e92019-05-02 14:45:02 -070017
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -070018
howardchung414856e2019-06-11 15:34:07 +080019class bluetooth_AdapterSASanity(BluetoothAdapterQuickTests,
20 bluetooth_default_state_test.bluetooth_Sanity_DefaultStateTest,
Daniel Winkler74b7f7b2020-01-17 15:59:29 -080021 bluetooth_valid_address_test.bluetooth_Sanity_ValidAddressTest,
Shijin Abrahambcd7c022020-01-30 17:50:41 -080022 bluetooth_dbus_api_tests.BluetoothDBusAPITests,
Daniel Winkler74b7f7b2020-01-17 15:59:29 -080023 bluetooth_AdapterLEAdvertising):
Shijin Abrahambcd7c022020-01-30 17:50:41 -080024
Yoni Shavit99696e92019-05-02 14:45:02 -070025 """A Batch of Bluetooth stand alone sanity tests. This test is written as
26 a batch of tests in order to reduce test time, since auto-test ramp up
27 time is costy. The batch is using BluetoothAdapterQuickTests wrapper
28 methods to start and end a test and a batch of tests.
29
30 This class can be called to run the entire test batch or to run a
howardchung4e03f362019-06-10 17:18:33 +080031 specific test only
Yoni Shavit99696e92019-05-02 14:45:02 -070032 """
33
Yoni Shavit93c24912019-05-14 10:37:04 -070034 test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator
35 batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator
36
37
38 @test_wrapper('Stand Alone basic test')
Yoni Shavit99696e92019-05-02 14:45:02 -070039 def sa_basic_test(self):
40 """Set of basic stand alone test"""
41
Yoni Shavit99696e92019-05-02 14:45:02 -070042 # The bluetoothd must be running in the beginning.
43 self.test_bluetoothd_running()
44
45 # It is possible that the adapter is not powered on yet.
46 # Power it on anyway and verify that it is actually powered on.
47 self.test_power_on_adapter()
48
49 # Verify that the adapter could be powered off and powered on,
50 # and that it is in the correct working state.
51 self.test_power_off_adapter()
52 self.test_power_on_adapter()
53 self.test_adapter_work_state()
54
55 # Verify that the bluetoothd could be simply stopped and then
56 # be started again, and that it is in the correct working state.
57 self.test_stop_bluetoothd()
58 self.test_start_bluetoothd()
59 self.test_adapter_work_state()
60
61 # Verify that the adapter could be reset off and on which includes
62 # removing all cached information.
63 self.test_reset_off_adapter()
64 self.test_reset_on_adapter()
65 self.test_adapter_work_state()
66
67 # Verify that the adapter supports basic profiles.
68 self.test_UUIDs()
69
70 # Verify that the adapter could start and stop discovery.
71 self.test_start_discovery()
72 self.test_stop_discovery()
73 self.test_start_discovery()
74
75 # Verify that the adapter could set both discoverable and
76 # non-discoverable successfully.
77 self.test_discoverable()
78 self.test_nondiscoverable()
79 self.test_discoverable()
80
81 # Verify that the adapter could set pairable and non-pairable.
82 self.test_pairable()
83 self.test_nonpairable()
84 self.test_pairable()
85
howardchung4e03f362019-06-10 17:18:33 +080086
87 @test_wrapper('Adapter suspend resume test')
88 def sa_adapter_suspend_resume_test(self):
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -070089 """Test dapter power states is perserved through suspend resume."""
howardchung4e03f362019-06-10 17:18:33 +080090 def adapter_on_SR_test():
91 """Test Case: Power on - SR"""
92 self.test_power_on_adapter()
93 self.test_bluetoothd_running()
94 self.suspend_resume()
95 self.test_bluetoothd_running()
96 self.test_adapter_work_state()
97 self.test_power_on_adapter()
98
99
100 def adapter_off_SR_test():
101 """Test Case: Power off - SR"""
102 self.test_power_off_adapter()
103 self.test_bluetoothd_running()
104 self.suspend_resume()
105 self.test_power_off_adapter()
106 self.test_bluetoothd_running()
107
108 adapter_on_SR_test()
109 adapter_off_SR_test()
110
111
112 @test_wrapper('Adapter present test')
113 def sa_adapter_present_test(self):
114 """Verify that the client has a Bluetooth adapter."""
115
116 # Reset the adapter (if any) to the powered off state.
117 self.test_reset_off_adapter()
118
119 # Verify that there is an adapter. This will only return True if both
120 # the kernel and bluetooth daemon see the adapter.
121 self.test_has_adapter()
122
123
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -0700124 @test_wrapper('Adapter DiscoverableTimeout test')
125 def sa_adapter_discoverable_timeout_test(self):
126 """Verify that DiscoverableTimout Property works."""
howardchungb8cd3c72019-09-11 11:05:04 +0800127 result = self.test_discoverable_timeout(timeout_values=[0, 7, 15])
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -0700128 logging.info("Result is %s", result)
129
Shijin Abrahama9f47922019-06-28 12:43:43 -0700130 @test_wrapper('Adapter PairableTimeout test')
131 def sa_adapter_pairable_timeout_test(self):
132 """Verify that PairableTimout Property works."""
howardchungb8cd3c72019-09-11 11:05:04 +0800133 result = self.test_pairable_timeout(timeout_values=[0, 7, 15])
Shijin Abrahama9f47922019-06-28 12:43:43 -0700134 logging.info("Result is %s", result)
135
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -0700136
howardchung414856e2019-06-11 15:34:07 +0800137 @test_wrapper('Default state test')
138 def sa_default_state_test(self):
139 """Verify that the Bluetooth adapter has correct state."""
140 self.default_state_test()
141
142
143 @test_wrapper('Valid address test')
144 def sa_valid_address_test(self):
145 """Verify that the client Bluetooth adapter has a valid address."""
146 self.valid_address_test()
147
148
Daniel Winklerc907d412020-02-04 15:11:44 -0800149 @test_wrapper('Valid adapter ID test')
150 def sa_valid_id_test(self):
151 """Verify that the adapter has a correctly-formatted ID"""
152 self.test_check_valid_adapter_id()
153
154
155 @test_wrapper('Valid adapter alias test')
156 def sa_valid_alias_test(self):
157 """Verify that the adapter has a correctly-formatted alias"""
158 self.test_check_valid_alias()
159
160
Daniel Winkler74b7f7b2020-01-17 15:59:29 -0800161 @test_wrapper('Multiple LE advertising test')
162 def sa_multiple_advertising_test(self):
163 """Run all test cases for multiple advertisements."""
164 self.run_le_advertising_test(self.host, \
165 advertisements_data.ADVERTISEMENTS, 'multi_advertising', \
166 num_iterations=1)
167
168
169 @test_wrapper('Single LE advertising test')
170 def sa_single_advertising_test(self):
171 """Run all test cases for single advertisements."""
172 self.run_le_advertising_test(self.host, \
173 advertisements_data.ADVERTISEMENTS, 'single_advertising', \
174 num_iterations=1)
175
176
177 @test_wrapper('Suspend resume LE advertising test')
178 def sa_suspend_resume_advertising_test(self):
179 """Run all test cases for multiple advertisements."""
180 self.run_le_advertising_test(self.host, \
181 advertisements_data.ADVERTISEMENTS, 'suspend_resume', \
182 num_iterations=1)
183
184
185 @test_wrapper('Reboot LE advertising test')
186 def sa_reboot_advertising_test(self):
187 """Run all test cases for single advertisements."""
188 self.run_le_advertising_test(self.host, \
189 advertisements_data.ADVERTISEMENTS, 'reboot', \
190 num_iterations=1)
191
Shijin Abrahambcd7c022020-01-30 17:50:41 -0800192 @test_wrapper('DBUS API tests')
193 def sa_dbus_api_tests(self):
194 """ Verify that the Bluetooth DBus API calls work."""
195 self.test_dbus_start_discovery_success()
196 self.test_dbus_start_discovery_fail_discovery_in_progress()
197 self.test_dbus_start_discovery_fail_power_off()
198 self.test_dbus_stop_discovery_success()
199 self.test_dbus_stop_discovery_fail_discovery_not_in_progress()
200 self.test_dbus_stop_discovery_fail_power_off()
201
202
Daniel Winkler74b7f7b2020-01-17 15:59:29 -0800203
Yoni Shavit93c24912019-05-14 10:37:04 -0700204 @batch_wrapper('Stand Alone Sanity')
Yoni Shavit99696e92019-05-02 14:45:02 -0700205 def sa_sanity_batch_run(self, num_iterations=1, test_name=None):
Yoni Shavit93c24912019-05-14 10:37:04 -0700206 """Run the stand alone sanity test batch or a specific given test.
207 The wrapper of this method is implemented in batch_decorator.
208 Using the decorator a test batch method can implement the only its
209 core tests invocations and let the decorator handle the wrapper,
210 which is taking care for whether to run a specific test or the
211 batch as a whole, and running the batch in iterations
Yoni Shavit99696e92019-05-02 14:45:02 -0700212
Yoni Shavit93c24912019-05-14 10:37:04 -0700213 @param num_iterations: how many interations to run
214 @param test_name: specifc test to run otherwise None to run the
215 whole batch
216 """
217 self.sa_basic_test()
howardchung4e03f362019-06-10 17:18:33 +0800218 self.sa_adapter_suspend_resume_test()
219 self.sa_adapter_present_test()
Shijin Abraham0d7d8fa2019-06-14 16:48:46 -0700220 self.sa_adapter_discoverable_timeout_test()
howardchung414856e2019-06-11 15:34:07 +0800221 self.sa_default_state_test()
222 self.sa_valid_address_test()
Shijin Abrahambcd7c022020-01-30 17:50:41 -0800223 #self.sa_dbus_api_tests() Disabled since tests is not stable yet.
Yoni Shavit99696e92019-05-02 14:45:02 -0700224
225
howardchung92d14702019-10-17 15:57:54 +0800226 def run_once(self, host, num_iterations=1, test_name=None,
227 flag='Quick Sanity'):
Yoni Shavit99696e92019-05-02 14:45:02 -0700228 """Run the batch of Bluetooth stand sanity tests
229
230 @param host: the DUT, usually a chromebook
231 @param num_iterations: the number of rounds to execute the test
232 """
233 # Initialize and run the test batch or the requested specific test
howardchung92d14702019-10-17 15:57:54 +0800234 self.quick_test_init(host, use_chameleon=False, flag=flag)
Yoni Shavit99696e92019-05-02 14:45:02 -0700235 self.sa_sanity_batch_run(num_iterations, test_name)
236 self.quick_test_cleanup()