• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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 tests about sending bluetooth HID reports."""
6
7import logging
8import time
9
10from autotest_lib.client.common_lib import error
11from autotest_lib.server.cros.bluetooth import bluetooth_adpater_tests
12from autotest_lib.server.cros.multimedia import remote_facade_factory
13
14
15class bluetooth_AdapterHIDReports(
16        bluetooth_adpater_tests.BluetoothAdapterTests):
17    """Server side bluetooth tests about sending bluetooth HID reports.
18
19    This test tries to send HID reports to a DUT and verifies if the DUT
20    could receive the reports correctly. For the time being, only bluetooth
21    mouse events are tested. Bluetooth keyboard events will be supported
22    later.
23    """
24
25    TEST_SLEEP_SECS = 5
26
27    def _run_mouse_tests(self, device):
28        """Run all bluetooth mouse reports tests.
29
30        @param device: the bluetooth HID device.
31
32        """
33        self.test_mouse_left_click(device)
34        self.test_mouse_right_click(device)
35        self.test_mouse_move_in_x(device, 80)
36        self.test_mouse_move_in_y(device, -50)
37        self.test_mouse_move_in_xy(device, -60, 100)
38        self.test_mouse_scroll_down(device, 70)
39        self.test_mouse_scroll_up(device, 40)
40        self.test_mouse_click_and_drag(device, 90, 30)
41
42
43    def run_once(self, host, device_type, num_iterations=1, min_pass_count=1):
44        """Running Bluetooth HID reports tests.
45
46        @param host: the DUT, usually a chromebook
47        @param device_type : the bluetooth HID device type, e.g., 'MOUSE'
48        @param num_iterations: the number of rounds to execute the test
49        @param min_pass_count: the minimal pass count to pass this test
50
51        """
52        self.host = host
53        factory = remote_facade_factory.RemoteFacadeFactory(host)
54        self.bluetooth_facade = factory.create_bluetooth_hid_facade()
55        self.input_facade = factory.create_input_facade()
56
57        pass_count = 0
58        self.total_fails = {}
59        for iteration in xrange(1, num_iterations + 1):
60            self.fails = []
61
62            # Get the bluetooth device object.
63            device = self.get_device(device_type)
64
65            # Reset the adapter and set it pairable.
66            self.test_reset_on_adapter()
67            self.test_pairable()
68
69            # Let the adapter pair, and connect to the target device.
70            time.sleep(self.TEST_SLEEP_SECS)
71            self.test_discover_device(device.address)
72            time.sleep(self.TEST_SLEEP_SECS)
73            self.test_pairing(device.address, device.pin, trusted=True)
74            time.sleep(self.TEST_SLEEP_SECS)
75            self.test_connection_by_adapter(device.address)
76
77            # Run tests about mouse reports.
78            if device_type == 'MOUSE':
79                self._run_mouse_tests(device)
80
81            # Disconnect the device, and remove the pairing.
82            self.test_disconnection_by_adapter(device.address)
83            self.test_remove_pairing(device.address)
84
85            if bool(self.fails):
86                self.total_fails['Round %d' % iteration] = self.fails
87            else:
88                pass_count += 1
89
90            fail_count = iteration - pass_count
91            logging.info('===  (pass = %d, fail = %d) / total %d  ===\n',
92                         pass_count, fail_count, num_iterations)
93
94        if pass_count < min_pass_count:
95            raise error.TestFail(self.total_fails)
96