1# Lint as: python2, python3 2# Copyright 2021 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""" Bluetooth test that checks the RSSI of Bluetooth peers 6This to used for checking Bluetooth test beds 7 8""" 9from __future__ import absolute_import 10from __future__ import division 11from __future__ import print_function 12 13import logging 14 15from autotest_lib.server.cros.bluetooth.bluetooth_adapter_quick_tests import ( 16 BluetoothAdapterQuickTests) 17 18from autotest_lib.server.cros.bluetooth.bluetooth_adapter_tests import ( 19 test_retry_and_log) 20 21test_wrapper = BluetoothAdapterQuickTests.quick_test_test_decorator 22batch_wrapper = BluetoothAdapterQuickTests.quick_test_batch_decorator 23 24 25class bluetooth_PeerVerify(BluetoothAdapterQuickTests): 26 """Test to check the RSSI of btpeers.""" 27 28 @test_wrapper('Check if rssi of peers > -70 ', 29 devices={'MOUSE': -1}, 30 use_all_peers=True) 31 @test_retry_and_log(False) 32 def check_rssi(self): 33 """Check if RSSI > -70. """ 34 try: 35 rssi_list = [] 36 self.result = {} 37 for n, device in enumerate(self.devices['MOUSE']): 38 rssi = self.get_device_sample_rssi(device) 39 rssi_list.append(rssi) 40 logging.info('RSSI for peer %s is %s', n, rssi) 41 logging.info('RSSI values are %s', rssi_list) 42 self.results = {'rssi': rssi_list} 43 return all([ 44 True if rssi is not None and rssi > -70 else False 45 for rssi in rssi_list 46 ]) 47 except Exception as e: 48 logging.debug('exception in test_check_rssi %s', str(e)) 49 return False 50 51 @batch_wrapper('Verify Peer RSSI') 52 def verify_peer_batch_run(self, num_iterations=1, test_name=None): 53 """ Batch of checks for btpeer. """ 54 self.check_rssi() 55 56 def run_once(self, 57 host, 58 num_iterations=1, 59 args_dict=None, 60 test_name=None, 61 flag='Quick Health'): 62 """Running Bluetooth adapter suspend resume with peer autotest. 63 64 @param host: the DUT, usually a chromebook 65 @param num_iterations: the number of times to execute the test 66 @param test_name: the test to run or None for all tests 67 @param flag: run tests with this flag (default: Quick Health) 68 69 """ 70 71 # Initialize and run the test batch or the requested specific test 72 self.quick_test_init(host, 73 use_btpeer=True, 74 flag=flag, 75 args_dict=args_dict) 76 self.verify_peer_batch_run(num_iterations, test_name) 77 self.quick_test_cleanup() 78