• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright 2020 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""A Batch of of Bluetooth Advertisement Monitor API tests"""
7
8from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests \
9     import BluetoothAdapterQuickTests
10from autotest_lib.server.cros.bluetooth.bluetooth_adapter_adv_monitor_tests \
11     import BluetoothAdapterAdvMonitorTests
12from autotest_lib.server.cros.bluetooth.bluetooth_adapter_tests import (
13        SUSPEND_POWER_DOWN_CHIPSETS, SUSPEND_RESET_IF_NO_PEER_CHIPSETS,
14        SUSPEND_POWER_DOWN_MODELS)
15
16
17class bluetooth_AdapterAdvMonitor(BluetoothAdapterQuickTests,
18                                  BluetoothAdapterAdvMonitorTests):
19    """A Batch of Bluetooth Advertisement Monitor tests. This test is written
20       as a batch of tests in order to reduce test time, since auto-test ramp
21       up time is costly. The batch is using BluetoothAdapterQuickTests wrapper
22       methods to start and end a test and a batch of tests.
23
24       This class can be called to run the entire test batch or to run a
25       specific test only.
26
27    """
28
29    test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator
30    batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator
31
32
33    @test_wrapper('Monitor Object Health Tests')
34    def advmon_monitor_health_tests(self):
35        """Tests advertisement monitor object health."""
36        self.advmon_test_monitor_creation()
37        self.advmon_test_monitor_validity()
38
39
40    @test_wrapper('Single Client Tests - Pattern Filter',
41                  devices={'BLE_KEYBOARD':1, 'BLE_MOUSE':1})
42    def advmon_pattern_filter_tests(self):
43        """Tests pattern filter for single client."""
44        self.advmon_test_pattern_filter()
45
46
47    @test_wrapper('Single Client Tests - RSSI Filter Range',
48                  devices={'BLE_KEYBOARD':1, 'BLE_MOUSE':1})
49    def advmon_rssi_filter_range_tests(self):
50        """Tests RSSI filter range for single client."""
51        self.advmon_test_rssi_filter_range()
52
53
54    @test_wrapper('Single Client Tests - RSSI Filter Multi Peers',
55                  devices={'BLE_KEYBOARD':1, 'BLE_MOUSE':1})
56    def advmon_rssi_filter_multi_peers_tests(self):
57        """Tests RSSI filter with multiple peers for single client."""
58        self.advmon_test_rssi_filter_multi_peers()
59
60
61    @test_wrapper('Single Client Tests - RSSI Filter Reset',
62                  devices={'BLE_KEYBOARD':1, 'BLE_MOUSE':1})
63    def advmon_rssi_filter_reset_tests(self):
64        """Tests RSSI filter reset for single client."""
65        self.advmon_test_rssi_filter_reset()
66
67
68    @test_wrapper('Multi Client Tests',
69                  devices={'BLE_KEYBOARD':1, 'BLE_MOUSE':1})
70    def advmon_multi_client_tests(self):
71        """Tests monitor functionality for multiple clients."""
72        self.advmon_test_multi_client()
73
74
75    # Remove flags=['Quick Health'] when this test is migrated to stable suite.
76    @test_wrapper('Foreground Background Combination Tests',
77                  devices={
78                          'BLE_KEYBOARD': 1,
79                          'BLE_MOUSE': 1
80                  },
81                  flags=['Quick Health'])
82    def advmon_fg_bg_combination_tests(self):
83        """Tests foreground and background scanning working together."""
84        self.advmon_test_fg_bg_combination()
85
86
87    # TODO(b/150897528) - Dru loses firmware around suspend, which causes bluez
88    #                     removes all the monitors.
89    @test_wrapper('Suspend Resume Tests',
90                  devices={
91                          'BLE_KEYBOARD': 1,
92                          'BLE_MOUSE': 1
93                  },
94                  skip_models=SUSPEND_POWER_DOWN_MODELS,
95                  skip_chipsets=SUSPEND_POWER_DOWN_CHIPSETS +
96                  SUSPEND_RESET_IF_NO_PEER_CHIPSETS,
97                  flags=['Quick Health'])
98    def advmon_suspend_resume_tests(self):
99        """Tests working of background scanning with suspend resume."""
100        self.advmon_test_suspend_resume()
101
102
103    # TODO(b/150897528) - Dru loses firmware around suspend, which causes bluez
104    #                     removes all the monitors.
105    @test_wrapper('Interleave Scan Tests',
106                  devices={'BLE_MOUSE': 1},
107                  skip_models=SUSPEND_POWER_DOWN_MODELS,
108                  skip_chipsets=SUSPEND_POWER_DOWN_CHIPSETS +
109                  SUSPEND_RESET_IF_NO_PEER_CHIPSETS)
110    def advmon_interleaved_scan_tests(self):
111        """Tests interleave scan."""
112        self.advmon_test_interleaved_scan()
113
114    @batch_wrapper('Advertisement Monitor API')
115    def advmon_health_batch_run(self, num_iterations=1, test_name=None):
116        """Run the Advertisement Monitor test batch or a specific given test.
117           The wrapper of this method is implemented in batch_decorator.
118           Using the decorator a test batch method can implement the only its
119           core tests invocations and let the decorator handle the wrapper,
120           which is taking care for whether to run a specific test or the
121           batch as a whole, and running the batch in iterations.
122
123           @param num_iterations: how many iterations to run.
124           @param test_name: specific test to run otherwise None to run the
125                             whole batch.
126
127        """
128        self.advmon_monitor_health_tests()
129        self.advmon_pattern_filter_tests()
130        self.advmon_rssi_filter_range_tests()
131        self.advmon_rssi_filter_multi_peers_tests()
132        self.advmon_rssi_filter_reset_tests()
133        self.advmon_multi_client_tests()
134        self.advmon_fg_bg_combination_tests()
135        self.advmon_suspend_resume_tests()
136        self.advmon_interleaved_scan_tests()
137
138    def run_once(self,
139                 host,
140                 num_iterations=1,
141                 peer_required=True,
142                 args_dict=None,
143                 test_name=None,
144                 flag='Quick Health'):
145        """Run the batch of Bluetooth Advertisement Monitor API tests.
146
147        @param host: the DUT, usually a chromebook.
148        @param num_iterations: the number of rounds to execute the test.
149        @param test_name: the test to run, or None for all tests.
150
151        """
152
153        # Initialize and run the test batch or the requested specific test.
154        self.quick_test_init(host,
155                             use_btpeer=peer_required,
156                             flag=flag,
157                             args_dict=args_dict)
158        self.advmon_health_batch_run(num_iterations, test_name)
159        self.quick_test_cleanup()
160