[Bluetooth] Adding bluetooth_AdapterReboot test

Adding bluetooth_AdapterReboot test for bluetooth and
corresponding stress test.

BUG=chormium:716576
TEST=$ test_that ${CHROMEBOOK_IP} bluetooth_AdapterReboot OR
bluetooth_AdapterReboot.stress_100

Change-Id: I5bbaa680d58f9736e5d3a21531e3eff14e9b5a71
Reviewed-on: https://chromium-review.googlesource.com/636750
Commit-Ready: Ruchi Jahagirdar <rjahagir@chromium.org>
Tested-by: Ruchi Jahagirdar <rjahagir@chromium.org>
Reviewed-by: Shyh-In Hwang <josephsih@chromium.org>
diff --git a/server/site_tests/bluetooth_AdapterReboot/bluetooth_AdapterReboot.py b/server/site_tests/bluetooth_AdapterReboot/bluetooth_AdapterReboot.py
new file mode 100644
index 0000000..d52c126
--- /dev/null
+++ b/server/site_tests/bluetooth_AdapterReboot/bluetooth_AdapterReboot.py
@@ -0,0 +1,73 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Server side bluetooth adapter stress tests involving reboot.
+First we test powering on the adapter, reboot the DUT, and make sure
+the adapter is still powered on and in a working state.
+
+Next we test powering off the adapter, reboot, and verify the adapter
+is still powered off.
+"""
+
+import logging
+
+from autotest_lib.client.bin import utils
+from autotest_lib.client.common_lib import error
+from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests
+from autotest_lib.server.cros.multimedia import bluetooth_le_facade_adapter
+
+
+test_case_log = bluetooth_adapter_tests.test_case_log
+
+
+class bluetooth_AdapterReboot(
+        bluetooth_adapter_tests.BluetoothAdapterTests):
+    """Server side bluetooth adapter reboot test."""
+
+    # ---------------------------------------------------------------
+    # Definitions of all test cases
+    # ---------------------------------------------------------------
+
+    @test_case_log
+    def test_case_adapter_on_reboot(self):
+        """Test Case: Power on - reboot"""
+        self.test_power_on_adapter()
+        self.test_bluetoothd_running()
+        self.host.reboot()
+        # NOTE: We need to recreate the bluetooth_facade after a reboot.
+        self.bluetooth_facade = self.ble_adapter(self.host)
+        self.test_bluetoothd_running()
+        self.test_adapter_work_state()
+        self.test_power_on_adapter()
+
+    @test_case_log
+    def test_case_adapter_off_reboot(self):
+        """Test Case: Power on - reboot"""
+        self.test_power_off_adapter()
+        self.test_bluetoothd_running()
+        self.host.reboot()
+        # NOTE: We need to recreate the bluetooth_facade after a reboot.
+        self.bluetooth_facade = self.ble_adapter(self.host)
+        self.test_power_off_adapter()
+        self.test_bluetoothd_running()
+
+
+    def run_once(self, host, num_iterations=1):
+        """Running Bluetooth adapter reboot autotest.
+
+        @param host: device under test host.
+        @param num_iterations: number of times to perform reboot tests.
+
+        """
+        self.host = host
+        self.ble_adapter = bluetooth_le_facade_adapter.BluetoothLEFacadeRemoteAdapter
+        self.bluetooth_facade = self.ble_adapter(self.host)
+
+        for i in xrange(num_iterations):
+            logging.debug('Starting loop #%d', i)
+            self.test_case_adapter_on_reboot()
+            self.test_case_adapter_off_reboot()
+
+        if self.fails:
+            raise error.TestFail(self.fails)
diff --git a/server/site_tests/bluetooth_AdapterReboot/control b/server/site_tests/bluetooth_AdapterReboot/control
new file mode 100644
index 0000000..18abcd8
--- /dev/null
+++ b/server/site_tests/bluetooth_AdapterReboot/control
@@ -0,0 +1,30 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.server import utils
+
+
+AUTHOR = 'rjahagir'
+NAME = 'bluetooth_AdapterReboot'
+PURPOSE = 'Test bluetooth adapter state with rebooting the DUT.'
+CRITERIA = 'Adapter should power on or off with correct parameters.'
+ATTRIBUTES = 'suite:bluetooth, suite:bluetooth_sanity'
+TIME = 'SHORT' # This takes about 5 minutes on cyan.
+TEST_CATEGORY = 'Functional'
+TEST_CLASS = 'bluetooth'
+TEST_TYPE = 'server'
+DEPENDENCIES = 'bluetooth'
+
+DOC = """
+This test case verifies that the Bluetooth adapter of the DUT can
+behave normally when subjected to rebooting the DUT.
+"""
+
+args_dict = utils.args_to_dict(args)
+
+def run(machine):
+    host = hosts.create_host(machine)
+    job.run_test('bluetooth_AdapterReboot', host=host)
+
+parallel_simple(run, machines)
diff --git a/server/site_tests/bluetooth_AdapterReboot/control.stress_100 b/server/site_tests/bluetooth_AdapterReboot/control.stress_100
new file mode 100644
index 0000000..07f609e
--- /dev/null
+++ b/server/site_tests/bluetooth_AdapterReboot/control.stress_100
@@ -0,0 +1,30 @@
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from autotest_lib.server import utils
+
+
+AUTHOR = 'rjahagir'
+NAME = 'bluetooth_AdapterReboot'
+PURPOSE = 'Test bluetooth adapter state with rebooting the DUT.'
+CRITERIA = 'Adapter should power on or off with correct parameters.'
+ATTRIBUTES = 'suite:bluetooth, suite:bluetooth_stress'
+TIME = 'LONG' # This takes about 2 hours on cyan.
+TEST_CATEGORY = 'Functional'
+TEST_CLASS = 'bluetooth'
+TEST_TYPE = 'server'
+DEPENDENCIES = 'bluetooth'
+
+DOC = """
+This test case verifies that the Bluetooth adapter of the DUT can
+behave normally when subjected to rebooting the DUT.
+"""
+
+args_dict = utils.args_to_dict(args)
+
+def run(machine):
+    host = hosts.create_host(machine)
+    job.run_test('bluetooth_AdapterReboot', host=host, num_iterations=100)
+
+parallel_simple(run, machines)