1 # Copyright 2017 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 """Server side bluetooth adapter stress tests involving suspend resume. 6 First we test powering on the adapter, suspend/resume the DUT, and make sure 7 the adapter is still powered on and in a working state. 8 9 Next we test powering off the adapter, suspend/resume, and verify the adapter 10 is still powered off. 11 """ 12 13 import logging 14 15 from autotest_lib.client.common_lib import error 16 from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests 17 from autotest_lib.server.cros.multimedia import bluetooth_le_facade_adapter 18 19 20 test_case_log = bluetooth_adapter_tests.test_case_log 21 22 23 class bluetooth_AdapterSuspendResume( 24 bluetooth_adapter_tests.BluetoothAdapterTests): 25 """Server side bluetooth adapter suspend resume test.""" 26 27 SUSPEND_TIME = 10 28 29 def suspend_resume(self, suspend_time=SUSPEND_TIME): 30 """Suspend the DUT for a while and then resume. 31 32 @param suspend_time: the suspend time in seconds. 33 34 """ 35 logging.info('The DUT suspends for %d seconds...', suspend_time) 36 self.host.suspend(suspend_time=suspend_time) 37 logging.info('The DUT is waken up.') 38 39 40 # --------------------------------------------------------------- 41 # Definitions of all test cases 42 # --------------------------------------------------------------- 43 44 @test_case_log 45 def test_case_adapter_on_SR(self): 46 """Test Case: Power on - SR""" 47 self.test_power_on_adapter() 48 self.test_bluetoothd_running() 49 self.suspend_resume() 50 self.test_bluetoothd_running() 51 self.test_adapter_work_state() 52 self.test_power_on_adapter() 53 54 @test_case_log 55 def test_case_adapter_off_SR(self): 56 """Test Case: Power on - SR""" 57 self.test_power_off_adapter() 58 self.test_bluetoothd_running() 59 self.suspend_resume() 60 self.test_power_off_adapter() 61 self.test_bluetoothd_running() 62 63 64 def run_once(self, host, num_iterations=1): 65 """Running Bluetooth adapter suspend resume autotest. 66 67 @param host: device under test host. 68 @param num_iterations: number of times to perform suspend resume tests. 69 70 """ 71 self.host = host 72 ble_adapter = bluetooth_le_facade_adapter.BluetoothLEFacadeRemoteAdapter 73 self.bluetooth_le_facade = ble_adapter(self.host) 74 self.bluetooth_facade = self.bluetooth_le_facade 75 76 for i in xrange(num_iterations): 77 logging.debug('Starting loop #%d', i) 78 self.test_case_adapter_on_SR() 79 self.test_case_adapter_off_SR() 80 81 if self.fails: 82 raise error.TestFail(self.fails) 83