1 #/usr/bin/env python3.4 2 # 3 # Copyright (C) 2016 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 # use this file except in compliance with the License. You may obtain a copy of 7 # the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 # License for the specific language governing permissions and limitations under 15 # the License. 16 17 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest 18 from acts.test_utils.bt.bt_test_utils import * 19 20 import time 21 import pprint 22 23 24 class ToolsTest(BluetoothBaseTest): 25 tests = None 26 default_timeout = 10 27 28 def __init__(self, controllers): 29 BluetoothBaseTest.__init__(self, controllers) 30 self.tests = ("test_toggle_bluetooth", 31 "test_toggle_airplane_mode", 32 "test_create_10_sms", 33 "test_continuously_log_battery_stats", ) 34 35 @BluetoothBaseTest.bt_test_wrap 36 def test_toggle_bluetooth(self): 37 """ 38 Test the integrity of toggling bluetooth on and off. 39 Steps: 40 1. Toggle bluetooth off. 41 2. Toggle bluetooth on. 42 3. Repeat steps 1 and 2 one-hundred times. 43 :return: boolean test_result 44 """ 45 droid, ed = (self.android_devices[0].droid, self.android_devices[0].ed) 46 n = 0 47 test_result = True 48 test_result_list = [] 49 while n < 100: 50 self.log.info("Toggling bluetooth iteration {}.".format(n)) 51 test_result = reset_bluetooth([self.android_devices[0]]) 52 start_time = time.time() 53 connected_devices = droid.bluetoothGetConnectedDevices() 54 print(pprint.pformat(connected_devices)) 55 while time.time() < start_time + 10 and len( 56 connected_devices) != 1: 57 time.sleep(1) 58 connected_devices = droid.bluetoothGetConnectedDevices() 59 print(pprint.pformat(connected_devices)) 60 if len(connected_devices) != 1: 61 print("died at iteration {}".format(n)) 62 return False 63 test_result_list.append(test_result) 64 n += 1 65 if False in test_result_list: 66 return False 67 return test_result 68 69 @BluetoothBaseTest.bt_test_wrap 70 def test_toggle_airplane_mode(self): 71 """ 72 Test the integrity of toggling airplane mode on and off. 73 Steps: 74 1. Toggle airplane off. 75 2. Toggle airplane on. 76 3. Repeat steps 1 and 2 one-hundred times. 77 :return: boolean test_result 78 """ 79 droid, ed = (self.android_devices[0].droid, self.android_devices[0].ed) 80 n = 0 81 test_result = True 82 test_result_list = [] 83 while n < 100: 84 self.log.info("Toggling bluetooth iteration {}.".format(n)) 85 droid.toggleAirplaneMode(True) 86 time.sleep(6) 87 droid.toggleAirplaneMode(False) 88 start_time = time.time() 89 connected_devices = droid.bluetoothGetConnectedDevices() 90 print(pprint.pformat(connected_devices)) 91 while time.time() < start_time + 10 and len( 92 connected_devices) != 1: 93 time.sleep(1) 94 connected_devices = droid.bluetoothGetConnectedDevices() 95 print(pprint.pformat(connected_devices)) 96 if len(connected_devices) != 1: 97 print("died at iteration {}".format(n)) 98 return False 99 test_result_list.append(test_result) 100 n += 1 101 if False in test_result_list: 102 return False 103 return test_result 104 105 @BluetoothBaseTest.bt_test_wrap 106 def test_create_10_sms(self): 107 phone_number = input("Enter a phone number: ") 108 message_size = input("Enter message size: ") 109 for _ in range(10): 110 self.android_devices[0].droid.smsSendTextMessage( 111 phone_number, generate_id_by_size(int(message_size)), False) 112 time.sleep(3) 113 return True 114 115 @BluetoothBaseTest.bt_test_wrap 116 def test_continuously_log_battery_stats(self): 117 interval = input("Enter time interval to collect stats: ") 118 while True: 119 self.log.info(log_energy_info( 120 [self.android_devices[0]], "Log_time: {}".format(time.time()))) 121 time.sleep(int(interval)) 122 return True 123