Home | History | Annotate | Download | only in bt
      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 Test script to test if Bluetooth will reboot successfully
     18 if it is killed.
     19 """
     20 
     21 import time
     22 from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
     23 
     24 
     25 class BtKillProcessTest(BluetoothBaseTest):
     26     def __init__(self, controllers):
     27         BluetoothBaseTest.__init__(self, controllers)
     28         self.dut = self.android_devices[0]
     29 
     30     def _get_bt_pid(self):
     31         process_grep_string = "com.android.bluetooth"
     32         awk = "awk '{print $2}'"
     33         return (self.dut.adb.shell("ps | grep {} | {}".format(
     34             process_grep_string, awk)).decode('ascii'))
     35 
     36     def _is_bt_process_running(self):
     37         if self._get_bt_pid():
     38             return True
     39         else:
     40             return False
     41 
     42     def test_kill_process(self):
     43         """Test that a killed Bluetooth process restarts
     44 
     45         If the Bluetooth process is killed out of band with kill -9
     46         the process should be automatically restarted by Android.
     47 
     48         Steps:
     49         1. Verify Bluetooth process is running
     50         2. Kill the Bluetooth process with kill -9
     51         3. Verify the process is restarted
     52 
     53         Expected Result:
     54         Bluetooth should be restarted automagically by the system.
     55 
     56         Returns:
     57           Pass if True
     58           Fail if False
     59 
     60         TAGS: Bluetooth
     61         Priority: 3
     62         """
     63         pid = self._get_bt_pid()
     64         if not pid:
     65             self.log.error("Failed to find Bluetooth process...")
     66             return False
     67         self.dut.adb.shell("kill -9 {}".format(pid))
     68         #Give up to 5 seconds for the process to restart
     69         search_tries = 5
     70         while search_tries > 0:
     71             if self._is_bt_process_running():
     72                 self.log.info(
     73                     "Bluetooth process is successfully running again")
     74                 return True
     75             search_tries -= 1
     76             #Try looking for the process after waiting an additional second
     77             time.sleep(1)
     78 
     79         self.log.error("Bluetooth process did not restart")
     80         return False
     81