Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 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 |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 7 | from autotest_lib.server.cros.bluetooth import bluetooth_device |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 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 | |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 18 | self.device - BluetoothDevice object for the device being tested |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 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 | |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 33 | def warmup(self, device_host, tester_host, interactive=False): |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 34 | """Initialize the test member objects based on its arguments.""" |
| 35 | super(BluetoothTest, self).warmup() |
| 36 | |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 37 | self.device = bluetooth_device.BluetoothDevice(device_host) |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 38 | |
| 39 | if tester_host: |
| 40 | self.tester = bluetooth_tester.BluetoothTester(tester_host) |
| 41 | else: |
| 42 | self.tester = None |
| 43 | |
| 44 | if interactive: |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 45 | self.interactive = interactive_client.InteractiveClient(device_host) |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 46 | else: |
| 47 | self.interactive = None |
| 48 | |
| 49 | |
| 50 | def cleanup(self): |
| 51 | """Close the test member objects.""" |
| 52 | if self.interactive: |
| 53 | self.interactive.close() |
Scott James Remnant | 8d2cbf3 | 2013-11-12 11:00:25 -0800 | [diff] [blame^] | 54 | self.device.close() |
Scott James Remnant | 1ca2e0e | 2013-07-31 16:49:07 -0700 | [diff] [blame] | 55 | if self.tester: |
| 56 | self.tester.close() |
| 57 | |
| 58 | super(BluetoothTest, self).cleanup() |