1 # Copyright (c) 2013 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 from autotest_lib.server import test 6 from autotest_lib.server.cros import interactive_client 7 from autotest_lib.server.cros.bluetooth import bluetooth_device 8 from autotest_lib.server.cros.bluetooth import bluetooth_tester 9 10 11 class BluetoothTest(test.test): 12 """Base class for Bluetooth tests. 13 14 BluetoothTest provides a common warmup() and cleanup() function for the 15 collection of Bluetooth tests that sets the following properties, depending 16 on the arguments to the test and properties of the test object: 17 18 self.device - BluetoothDevice object for the device being tested 19 self.tester - BluetoothTester object for the device's partner tester 20 self.interactive - InteractiveClient object for the device 21 22 The latter two may be None if the test is initialized from the control file 23 with the tester_host parameter as None and/or the interactive argument as 24 False. 25 26 It is not mandatory to use this base class for Bluetooth tests, it is for 27 convenience only. A test with special requirements, or a need to derive 28 from a different base class, may instantiate and clean-up the associated 29 objects on its own. 30 31 """ 32 33 def warmup(self, device_host, tester_host, interactive=False): 34 """Initialize the test member objects based on its arguments.""" 35 if interactive: 36 self.interactive = interactive_client.InteractiveClient(device_host) 37 else: 38 self.interactive = None 39 40 self.device = bluetooth_device.BluetoothDevice(device_host) 41 42 if tester_host: 43 self.tester = bluetooth_tester.BluetoothTester(tester_host) 44 else: 45 self.tester = None 46 47 48 def cleanup(self): 49 """Close the test member objects.""" 50 if self.interactive: 51 self.interactive.close() 52 self.device.copy_logs(self.outputdir) 53 self.device.close() 54 if self.tester: 55 self.tester.copy_logs(self.outputdir) 56 self.tester.close() 57 58 super(BluetoothTest, self).cleanup() 59