blob: 9a23a1fca8c363b3a0e27455c45369bb63154692 [file] [log] [blame]
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -07001# 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
5from autotest_lib.server import test
6from autotest_lib.server.cros import interactive_client
Scott James Remnant8d2cbf32013-11-12 11:00:25 -08007from autotest_lib.server.cros.bluetooth import bluetooth_device
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -07008from autotest_lib.server.cros.bluetooth import bluetooth_tester
9
10
11class 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 Remnant8d2cbf32013-11-12 11:00:25 -080018 self.device - BluetoothDevice object for the device being tested
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070019 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 Remnant8d2cbf32013-11-12 11:00:25 -080033 def warmup(self, device_host, tester_host, interactive=False):
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070034 """Initialize the test member objects based on its arguments."""
35 super(BluetoothTest, self).warmup()
36
Scott James Remnant8d2cbf32013-11-12 11:00:25 -080037 self.device = bluetooth_device.BluetoothDevice(device_host)
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070038
39 if tester_host:
40 self.tester = bluetooth_tester.BluetoothTester(tester_host)
41 else:
42 self.tester = None
43
44 if interactive:
Scott James Remnant8d2cbf32013-11-12 11:00:25 -080045 self.interactive = interactive_client.InteractiveClient(device_host)
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070046 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()
Katherine Threlkeld88aa1432015-07-30 11:44:35 -070054 self.device.copy_logs(self.outputdir)
Scott James Remnant8d2cbf32013-11-12 11:00:25 -080055 self.device.close()
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070056 if self.tester:
Katherine Threlkeld88aa1432015-07-30 11:44:35 -070057 self.tester.copy_logs(self.outputdir)
Scott James Remnant1ca2e0e2013-07-31 16:49:07 -070058 self.tester.close()
59
60 super(BluetoothTest, self).cleanup()